@@ -34,19 +34,19 @@ def surface_to_outline(shape: dict, slice_thickness: float=5e-3) -> dict:
3434 dorsal = projected (mesh , normal = [0 , 0 , 1 ], ignore_sign = True )
3535 lateral = projected (mesh , normal = [0 , - 1 , 0 ], ignore_sign = True )
3636
37- # Get a centreline on the x-axis that extends the full length of the organism
37+ # Get bounds for a centreline on the x-axis that extends the full length of the organism
3838 bounds = mesh .bounding_box
3939 xmin = bounds .vertices [0 , 0 ]
4040 xmax = bounds .vertices [7 , 0 ]
41- centreline_x = np .arange (xmin , xmax , slice_thickness )
42-
41+
4342 # calculate the shape heights, widths, and y and z coordinates of the centreline
4443 widths = []
4544 heights = []
45+ centreline_x = []
4646 centreline_y = []
4747 centreline_z = []
4848
49- for x in centreline_x :
49+ for x in np . arange ( xmin , xmax , slice_thickness ) :
5050 # Get the points where a line perpendicular to the x-axis intersects
5151 # the dorsal and lateral shapes
5252
@@ -55,27 +55,38 @@ def surface_to_outline(shape: dict, slice_thickness: float=5e-3) -> dict:
5555 # and the intersection of that line with the dorsal shape
5656 intersect = intersection (dorsal , line )
5757
58+ # If there is no intersection, go to the next x-point. This can happen
59+ # at the start or end of the bounding box
60+ if not intersect :
61+ continue
62+
5863 # The length of that line is the width of the shape at this x position
59- widths . append ( intersect .length )
64+ w = intersect .length
6065 # and the centre point of that line is the y coordinate of the centreline
6166 centre = intersect .interpolate (0.5 , normalized = True )
62- # No intersection means the y coordinate of the centreline is 0.0
63- centreline_y .append (- centre .y if centre else 0.0 )
67+ y = - centre .y
6468
6569 # Do similar for the lateral outline
6670 line = LineString ([[- 1000 , x ], [1000 , x ]])
6771 intersect = intersection (lateral , line )
72+ if not intersect :
73+ continue
74+
6875 heights .append (intersect .length )
6976 centre = intersect .interpolate (0.5 , normalized = True )
70- centreline_z .append (centre .x if centre else 0.0 )
77+
78+ widths .append (w )
79+ centreline_x .append (x )
80+ centreline_y .append (y )
81+ centreline_z .append (centre .x )
7182
7283 # Create an echoSMs shape dict using the metadata from the input surface shape
7384 to_remove = ['x' , 'y' , 'z' , 'facets_0' , 'facets_1' , 'facets_2' ,
7485 'normals_x' , 'normals_y' , 'normals_z' ]
7586 outline_shape = {k : v for k , v in shape .items () if k not in to_remove }
7687
7788 # Add the outline shape data
78- outline_shape ['x' ] = centreline_x . tolist ()
89+ outline_shape ['x' ] = centreline_x
7990 outline_shape ['y' ] = centreline_y
8091 outline_shape ['z' ] = centreline_z
8192 outline_shape ['height' ] = heights
0 commit comments