draw Package

draw Package

This module uses Panda3D to allow for simple rendering in 3D. Panda3D may be downloaded and installed for free from http://www.panda3d.org/.

Basic usage consist of creating Render object and then add some objects to it. Finally, one executes run() function to display graphics. Output window can be controlled with mouse in a standard way: scroll or move mouse with both buttons pressed to zoom, hold left button and move mouse to move up and down, hold right button and move to rotate the view around the origin.

warning:For now, only one invocation of run() per application is possible. We are working to allow for multiple windows.
warning:Interface of this submodule may slightly evolve during development.

The simplest code to render a half-transparent cube with side = 10au at the origin looks like this:

from pydmga import draw
from pydmga.draw import render
from pydmga.draw import assets

r = draw.Render(render.Color.WHITE_OPAQUE)
r.add(draw.Asset(assets.cube, (0.0, 0.0, 0.0), 5.0, render.Color.BLUE_QUARTER))
r.run()

assets Module

This module grants access to simple models located in models folder. Currently only sphere and cube are supported.

pydmga.draw.assets.cube(loader, x, y, z, r)

This loads a cube object and return it as an object ready to be attached to renderer by add() function. samle code:

cube = assets.cube(renderer, 0, 0, 0, 10.0)
renderer.add(render.primitive(cube))
pydmga.draw.assets.sphere(loader, x, y, z, r)

This loads a sphere object and return it as an object ready to be attached to renderer by add() function. samle code:

sphere = assets.sphere(renderer, 0, 0, 0, 10.0)
renderer.add(render.primitive(sphere))

gen Module

warning:deprecated
class pydmga.draw.gen.TrajectoryGenerator(repository, count, box_rad=5.0)

Bases: direct.showbase.ShowBase.ShowBase

dist(s, o)
doOutput()
simulation(task)
startOutput()
stopOutput()

geometry Module

This file defines geometry used to read and write data about balls in 3D, their voronoi diagrams and motion (in time).

it is used by:
  • voro_render.py
  • voro_render_gui.py
  • voro_gen.py
class pydmga.draw.geometry.ArrayInput(balls, cells)

Bases: pydmga.draw.geometry.Input

advance()
current_frame()
first_frame()
go(frame)
last_frame()
leap(offset)
class pydmga.draw.geometry.Ball(id, x=0.0, y=0.0, z=0.0, r=1.0)
class pydmga.draw.geometry.Input

base class for moving voronoi, it allows for navigating through the animation. It’s like interface - for me to not forgot what methods are needed ;)

advance()
current_frame()
first_frame()
go(frame)
last_frame()
leap(offset)
class pydmga.draw.geometry.MultiFileInput(repository_path, start_frame=0, end_frame=None)

Bases: pydmga.draw.geometry.Input

Its kind of input that uses multiple files to store information: one file with full description (in this way its wery simple to program

advance()
current_frame()
first_frame()
go(frame)
last_frame()
leap(offset)
class pydmga.draw.geometry.OneFrame

OneFrame - class of one Frame of animation of voronoi diagram

For now its very simple

class pydmga.draw.geometry.Position(x=0.0, y=0.0, z=0.0)

render Module

class pydmga.draw.render.Asset(loader, point, scale, color=None)

Bases: pydmga.draw.render.Primitive

this represents a class of all object loaded from external files

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

class pydmga.draw.render.Color

predefined colors to use with render

BLACK_HALF = (0.0, 0.0, 0.0, 0.5)
BLACK_OPAQUE = (0.0, 0.0, 0.0, 1.0)
BLACK_QUARTER = (0.0, 0.0, 0.0, 0.25)
BLUE10_HALF = (0.0, 0.0, 0.1, 0.5)
BLUE10_OPAQUE = (0.0, 0.0, 0.1, 1.0)
BLUE10_QUARTER = (0.0, 0.0, 0.1, 0.25)
BLUE20_HALF = (0.0, 0.0, 0.2, 0.5)
BLUE20_OPAQUE = (0.0, 0.0, 0.2, 1.0)
BLUE20_QUARTER = (0.0, 0.0, 0.2, 0.25)
BLUE30_HALF = (0.0, 0.0, 0.3, 0.5)
BLUE30_OPAQUE = (0.0, 0.0, 0.3, 1.0)
BLUE30_QUARTER = (0.0, 0.0, 0.3, 0.25)
BLUE40_HALF = (0.0, 0.0, 0.4, 0.5)
BLUE40_OPAQUE = (0.0, 0.0, 0.4, 1.0)
BLUE40_QUARTER = (0.0, 0.0, 0.4, 0.25)
BLUE50_HALF = (0.0, 0.0, 0.5, 0.5)
BLUE50_OPAQUE = (0.0, 0.0, 0.5, 1.0)
BLUE50_QUARTER = (0.0, 0.0, 0.5, 0.25)
BLUE60_HALF = (0.0, 0.0, 0.6, 0.5)
BLUE60_OPAQUE = (0.0, 0.0, 0.6, 1.0)
BLUE60_QUARTER = (0.0, 0.0, 0.6, 0.25)
BLUE70_HALF = (0.0, 0.0, 0.7, 0.5)
BLUE70_OPAQUE = (0.0, 0.0, 0.7, 1.0)
BLUE70_QUARTER = (0.0, 0.0, 0.7, 0.25)
BLUE80_HALF = (0.0, 0.0, 0.8, 0.5)
BLUE80_OPAQUE = (0.0, 0.0, 0.8, 1.0)
BLUE80_QUARTER = (0.0, 0.0, 0.8, 0.25)
BLUE90_HALF = (0.0, 0.0, 0.9, 0.5)
BLUE90_OPAQUE = (0.0, 0.0, 0.9, 1.0)
BLUE90_QUARTER = (0.0, 0.0, 0.9, 0.25)
BLUE_HALF = (0.0, 0.0, 1.0, 0.5)
BLUE_OPAQUE = (0.0, 0.0, 1.0, 1.0)
BLUE_QUARTER = (0.0, 0.0, 1.0, 0.25)
GRAY10_HALF = (0.1, 0.1, 0.1, 0.5)
GRAY10_OPAQUE = (0.1, 0.1, 0.1, 1.0)
GRAY10_QUARTER = (0.1, 0.1, 0.1, 0.25)
GRAY20_HALF = (0.2, 0.2, 0.2, 0.5)
GRAY20_OPAQUE = (0.2, 0.2, 0.2, 1.0)
GRAY20_QUARTER = (0.2, 0.2, 0.2, 0.25)
GRAY30_HALF = (0.3, 0.3, 0.3, 0.5)
GRAY30_OPAQUE = (0.3, 0.3, 0.3, 1.0)
GRAY30_QUARTER = (0.3, 0.3, 0.3, 0.25)
GRAY40_HALF = (0.4, 0.4, 0.4, 0.5)
GRAY40_OPAQUE = (0.4, 0.4, 0.4, 1.0)
GRAY40_QUARTER = (0.4, 0.4, 0.4, 0.25)
GRAY50_HALF = (0.5, 0.5, 0.5, 0.5)
GRAY50_OPAQUE = (0.5, 0.5, 0.5, 1.0)
GRAY50_QUARTER = (0.5, 0.5, 0.5, 0.25)
GRAY60_HALF = (0.6, 0.6, 0.6, 0.5)
GRAY60_OPAQUE = (0.6, 0.6, 0.6, 1.0)
GRAY60_QUARTER = (0.6, 0.6, 0.6, 0.25)
GRAY70_HALF = (0.7, 0.7, 0.7, 0.5)
GRAY70_OPAQUE = (0.7, 0.7, 0.7, 1.0)
GRAY70_QUARTER = (0.7, 0.7, 0.7, 0.25)
GRAY80_HALF = (0.8, 0.8, 0.8, 0.5)
GRAY80_OPAQUE = (0.8, 0.8, 0.8, 1.0)
GRAY80_QUARTER = (0.8, 0.8, 0.8, 0.25)
GRAY90_HALF = (0.9, 0.9, 0.9, 0.5)
GRAY90_OPAQUE = (0.9, 0.9, 0.9, 1.0)
GRAY90_QUARTER = (0.9, 0.9, 0.9, 0.25)
GREEN10_HALF = (0.0, 0.1, 0.0, 0.5)
GREEN10_OPAQUE = (0.0, 0.1, 0.0, 1.0)
GREEN10_QUARTER = (0.0, 0.1, 0.0, 0.25)
GREEN20_HALF = (0.0, 0.2, 0.0, 0.5)
GREEN20_OPAQUE = (0.0, 0.2, 0.0, 1.0)
GREEN20_QUARTER = (0.0, 0.2, 0.0, 0.25)
GREEN30_HALF = (0.0, 0.3, 0.0, 0.5)
GREEN30_OPAQUE = (0.0, 0.3, 0.0, 1.0)
GREEN30_QUARTER = (0.0, 0.3, 0.0, 0.25)
GREEN40_HALF = (0.0, 0.4, 0.0, 0.5)
GREEN40_OPAQUE = (0.0, 0.4, 0.0, 1.0)
GREEN40_QUARTER = (0.0, 0.4, 0.0, 0.25)
GREEN50_HALF = (0.0, 0.5, 0.0, 0.5)
GREEN50_OPAQUE = (0.0, 0.5, 0.0, 1.0)
GREEN50_QUARTER = (0.0, 0.5, 0.0, 0.25)
GREEN60_HALF = (0.0, 0.6, 0.0, 0.5)
GREEN60_OPAQUE = (0.0, 0.6, 0.0, 1.0)
GREEN60_QUARTER = (0.0, 0.6, 0.0, 0.25)
GREEN70_HALF = (0.0, 0.7, 0.0, 0.5)
GREEN70_OPAQUE = (0.0, 0.7, 0.0, 1.0)
GREEN70_QUARTER = (0.0, 0.7, 0.0, 0.25)
GREEN80_HALF = (0.0, 0.8, 0.0, 0.5)
GREEN80_OPAQUE = (0.0, 0.8, 0.0, 1.0)
GREEN80_QUARTER = (0.0, 0.8, 0.0, 0.25)
GREEN90_HALF = (0.0, 0.9, 0.0, 0.5)
GREEN90_OPAQUE = (0.0, 0.9, 0.0, 1.0)
GREEN90_QUARTER = (0.0, 0.9, 0.0, 0.25)
GREEN_HALF = (0.0, 1.0, 0.0, 0.5)
GREEN_OPAQUE = (0.0, 1.0, 0.0, 1.0)
GREEN_QUARTER = (0.0, 1.0, 0.0, 0.25)
RED10_HALF = (0.1, 0.0, 0.0, 0.5)
RED10_OPAQUE = (0.1, 0.0, 0.0, 1.0)
RED10_QUARTER = (0.1, 0.0, 0.0, 0.25)
RED20_HALF = (0.2, 0.0, 0.0, 0.5)
RED20_OPAQUE = (0.2, 0.0, 0.0, 1.0)
RED20_QUARTER = (0.2, 0.0, 0.0, 0.25)
RED30_HALF = (0.3, 0.0, 0.0, 0.5)
RED30_OPAQUE = (0.3, 0.0, 0.0, 1.0)
RED30_QUARTER = (0.3, 0.0, 0.0, 0.25)
RED40_HALF = (0.4, 0.0, 0.0, 0.5)
RED40_OPAQUE = (0.4, 0.0, 0.0, 1.0)
RED40_QUARTER = (0.4, 0.0, 0.0, 0.25)
RED50_HALF = (0.5, 0.0, 0.0, 0.5)
RED50_OPAQUE = (0.5, 0.0, 0.0, 1.0)
RED50_QUARTER = (0.5, 0.0, 0.0, 0.25)
RED60_HALF = (0.6, 0.0, 0.0, 0.5)
RED60_OPAQUE = (0.6, 0.0, 0.0, 1.0)
RED60_QUARTER = (0.6, 0.0, 0.0, 0.25)
RED70_HALF = (0.7, 0.0, 0.0, 0.5)
RED70_OPAQUE = (0.7, 0.0, 0.0, 1.0)
RED70_QUARTER = (0.7, 0.0, 0.0, 0.25)
RED80_HALF = (0.8, 0.0, 0.0, 0.5)
RED80_OPAQUE = (0.8, 0.0, 0.0, 1.0)
RED80_QUARTER = (0.8, 0.0, 0.0, 0.25)
RED90_HALF = (0.9, 0.0, 0.0, 0.5)
RED90_OPAQUE = (0.9, 0.0, 0.0, 1.0)
RED90_QUARTER = (0.9, 0.0, 0.0, 0.25)
RED_HALF = (1.0, 0.0, 0.0, 0.5)
RED_OPAQUE = (1.0, 0.0, 0.0, 1.0)
RED_QUARTER = (1.0, 0.0, 0.0, 0.25)
WHITE_HALF = (1.0, 1.0, 1.0, 0.5)
WHITE_OPAQUE = (1.0, 1.0, 1.0, 1.0)
WHITE_QUARTER = (1.0, 1.0, 1.0, 0.25)
class pydmga.draw.render.ConvexPolygons(points=None, color=None)

Bases: pydmga.draw.render.Primitive

It allows to create a set of polygons with common points, for example it works perfectly for Voronoi Diagram Cells

add_side(vertices, color=None)

creates a whole new side with all new vertices

add_side_point(number)

adds new point to a side

add_side_points(numbers)

adds all vertices with numbers in number to a current side

add_vertex(point, color=None)

stores new vertex with given color

add_vertices(vertices, color=None)

adds many points all in the same color

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

start_side()

closes last side and starts new one (new polygon), all subsequent calls to add_side_point will be addressing this newly created side

class pydmga.draw.render.GreatArcs(origin, radius, thickness=1.0, color=(0.0, 1.0, 0.0, 1.0))

Bases: pydmga.draw.render.OnSpherePrimitive

this class can draw a collection of great arcs on the given sphere (that is a part of the biggest possible circle on a sphere, which has origin at the origin of a sphere)

add_arcs(vertices, closed=True, cast_to_sphere=False)

adds a collection of fragments of great arcs between given points points should be on the surface of the ball the default behaviour is that it creates a closed curve

add_vertex(vertex, cast_to_sphere=False)

adds a single point to this object you can connect them wit connect() function

add_vertices(vertices, cast_to_sphere=False)

adds a list of vertices you can connect them wit connect() function

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

connect(indices_list, closed=True)

connects given list of indices by set of fragments of great arcs the default behaviour is that it creates a closed curve

class pydmga.draw.render.Lines(points, thickness=1.0, color=None)

Bases: pydmga.draw.render.Primitive

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

class pydmga.draw.render.OnSpherePrimitive(origin, radius)

Bases: pydmga.draw.render.Primitive

cast_to_sphere(vertex)
cross(u, v, c=(0, 0, 0))
distance(v, u=(0, 0, 0))
dot(u, v, c=(0, 0, 0))
normalize(v, u=(0, 0, 0))
class pydmga.draw.render.Outline(points, thickness=1.0, color=None)

Bases: pydmga.draw.render.Primitive

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

class pydmga.draw.render.PointCloud

Bases: pydmga.draw.render.Primitive

This can be used to render a set of points

add_vertex(point, size=1.0, color=None)

adds new vertex with given color and size s

add_vertices(points, size, color)

adds many points all in the same color

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

class pydmga.draw.render.Primitive

Bases: object

basic class for all primitives that Render class can handle

attach_to(render)

each geometry object should overwrite this

class pydmga.draw.render.Render(bgcolor=None, ltcolor=None)

Bases: direct.showbase.ShowBase.ShowBase

simple class for rendering things using Panda3D

add(primitive)

adds a class of type Primitive to this render object

clear()

removes all nodes from render

class pydmga.draw.render.SphereArcs(origin, radius, thickness=1.0, color=(0.0, 1.0, 0.0, 1.0))

Bases: pydmga.draw.render.OnSpherePrimitive

this allow to draw part of circles that are the result of intersection of two spheres to define this you need to give three points that lie on the plane defined by two intersecting balls

add_arc(center, from_v, to_v)

center = of the circle, the cutting plane from_v = first vertex on arc, should lie on the cutting plane and on the sphere to_t - last vertex on arc, should lie on the cutting plane and on the sphere moreover we require that dist(center, from_v) == dist(center, to_v)

add_cutting_plane_arc(normal, distance, from_v, to_v)

giving other center and distance gives us chance to handle degenerate case when center = origin of sphere

attach_to(render)

creates Panda3D representation that can be attached to render this function is mainly used inside Render class and its derivatives and user not need to worry to call it

class pydmga.draw.render.VoroRender(input)

Bases: pydmga.draw.render.Render

frame_iterator_task(task)