Domain class used to build the computational domain

Domain class used to build the computational domain

class cromosim.domain.Domain(name='Domain', background='White', pixel_size=1.0, xmin=0.0, width=100, ymin=0.0, height=100)[source]

Bases: object

To define the computational domain :
  • a background : empty (white) or a PNG image which only contains the colors white, red (for the doors) and black (for the walls)

  • supplementary doors represented by matplotlib shapes : line2D

  • supplementary walls represented by matplotlib shapes : line2D, circle, ellipse, rectangle or polygon

To compute the obstacle distances and the desired velocities

Examples

  • An example with a domain built using only shape elements : cromosim/examples/domain_manually_computed.py

  • An example with a domain built using an image and shape elements : cromosim/examples/domain_auto_computed.py

Attributes
pixel_sizefloat

size of a pixel in meters

widthint

width of the background image (number of pixels)

heightint

height of the background image (number of pixels)

xminfloat

x coordinate of the origin (bottom left corner)

xmaxfloat

xmax = xmin + width*pixel_size

yminfloat

y coordinate of the origin (bottom left corner)

ymaxfloat

ymax = ymin + height*pixel_size

Xnumpy array

x coordinates (meshgrid)

Ynumpy array

y coordinates (meshgrid)

imagenumpy array

pixel array (r,g,b,a) The Pillow image is converted to a numpy arrays, then using flipud the origin of the image is put it down left instead the top left

image_rednumpy array

red values of the image (r,g,b,a)

image_greennumpy array

green values of the image (r,g,b,a)

image_bluenumpy array

blue values of the image (r,g,b,a)

masknumpy array

boolean array : true for black pixels

mask_idnumpy array

black pixel indices

wall_distancenumpy array

distance (m) to the wall

wall_grad_Xnumpy array

gradient of the distance to the wall (first component)

wall_grad_Ynumpy array

gradient of the distance to the wall (second component)

door_distancenumpy array

distance (m) to the door

desired_velocity_Xnumpy array

opposite of the gradient of the distance to the door : desired velocity (first component)

desired_velocity_Ynumpy array

opposite of the gradient of the distance to the door : desired velocity (second component)

Methods

add_door(self, shape)

To add a door represented by matplotlib shapes : line2D (only)

add_wall(self, shape)

To add a wall represented by matplotlib shapes : line2D, circle, ellipse, rectangle or polygon

build_domain(self)

To build the domain : reads the background image (if supplied) and initializes all the color arrrays

compute_desired_velocity(self)

To compute the geodesic distance to the doors in using a fast-marching method.

compute_wall_distance(self)

To compute the geodesic distance to the walls in using a fast-marching method

plot(self[, id, dpi])

To plot the computational domain

plot_desired_velocity(self[, id, dpi])

To plot the desired velocity

plot_wall_dist(self[, id, dpi])

To plot the wall distances

add_door(self, shape)[source]

To add a door represented by matplotlib shapes : line2D (only)

Parameters
shapematplotlib shape

line2D

add_wall(self, shape)[source]

To add a wall represented by matplotlib shapes : line2D, circle, ellipse, rectangle or polygon

Parameters
shapematplotlib shape

line2D, circle, ellipse, rectangle or polygon

build_domain(self)[source]

To build the domain : reads the background image (if supplied) and initializes all the color arrrays

compute_desired_velocity(self)[source]

To compute the geodesic distance to the doors in using a fast-marching method. The opposite of the gradient of this distance corresponds to the desired velocity which permits to reach the closest door

Returns
door_distancenumpy array

distance to the closest door

desired_velocity_Xnumpy array

opposite of the gradient of the door distance, x component

desired_velocity_Ynumpy array

opposite of the gradient of the door distance, y component

compute_wall_distance(self)[source]

To compute the geodesic distance to the walls in using a fast-marching method

plot(self, id=1, dpi=150)[source]

To plot the computational domain

Parameters
idinteger

Figure id (number)

dpiinteger

Figure resolution

plot_desired_velocity(self, id=1, dpi=150)[source]

To plot the desired velocity

Parameters
idinteger

Figure id (number)

dpiinteger

Figure resolution

plot_wall_dist(self, id=1, dpi=150)[source]

To plot the wall distances

Parameters
idinteger

Figure id (number)

dpiinteger

Figure resolution