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_size : float
size of a pixel in meters
- width : int
width of the background image (number of pixels)
- height : int
height of the background image (number of pixels)
- xmin : float
x coordinate of the origin (bottom left corner)
- xmax : float
xmax = xmin + width*pixel_size
- ymin : float
y coordinate of the origin (bottom left corner)
- ymax : float
ymax = ymin + height*pixel_size
- X : numpy array
x coordinates (meshgrid)
- Y : numpy array
y coordinates (meshgrid)
- image : numpy 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_red : numpy array
red values of the image (r,g,b,a)
- image_green : numpy array
green values of the image (r,g,b,a)
- image_blue : numpy array
blue values of the image (r,g,b,a)
- mask : numpy array
boolean array : true for black pixels
- mask_id : numpy array
black pixel indices
- wall_distance : numpy array
distance (m) to the wall
- wall_grad_X : numpy array
gradient of the distance to the wall (first component)
- wall_grad_Y : numpy array
gradient of the distance to the wall (second component)
- door_distance : numpy array
distance (m) to the door
- desired_velocity_X : numpy array
opposite of the gradient of the distance to the door : desired velocity (first component)
- desired_velocity_Y : numpy array
opposite of the gradient of the distance to the door : desired velocity (second component)
Methods
add_door(shape)To add a door represented by a matplotlib shapes : line2D (only) add_wall(shape)To add a wall represented by matplotlib shapes : line2D, circle, ellipse, rectangle or polygon build_domain()To build the domain : reads the background image (if supplied) and initializes all the color arrrays compute_desired_velocity()To compute the geodesic distance to the doors in using a fast-marching method. compute_wall_distance()To compute the geodesic distance to the walls in using a fast-marching method plot([id, dpi])To plot the computational domain plot_desired_velocity([id, dpi])To plot the desired velocity plot_wall_dist([id, dpi])To plot the wall distances -
add_door(shape)[source]¶ To add a door represented by a matplotlib shapes : line2D (only)
Parameters: - shape : matplotlib shape
line2D
-
add_wall(shape)[source]¶ To add a wall represented by matplotlib shapes : line2D, circle, ellipse, rectangle or polygon
Parameters: - shape : matplotlib shape
line2D, circle, ellipse, rectangle or polygon
-
build_domain()[source]¶ To build the domain : reads the background image (if supplied) and initializes all the color arrrays
-
compute_desired_velocity()[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_distance : numpy array
distance to the closest door
- desired_velocity_X : numpy array
opposite of the gradient of the door distance, x component
- desired_velocity_Y : numpy array
opposite of the gradient of the door distance, y component
-
compute_wall_distance()[source]¶ To compute the geodesic distance to the walls in using a fast-marching method
-
plot(id=1, dpi=150)[source]¶ To plot the computational domain
Parameters: - id : integer
Figure id (number)
- dpi : integer
Figure resolution