@@ -208,9 +208,16 @@ def controlPointBasedARAP(triangulatedPoints, camera, segmentator, zSubdivisions
208208 t = helper .rayPlaneIntersectionMat (centroid , np .expand_dims (planeNormal , 0 ), np .zeros (glottalCameraRays .shape ), glottalCameraRays )
209209 glottalOutlinePoints = t * glottalCameraRays
210210
211+ xy , wh = segmentator .vocalfoldBoundingBox ()
212+ mesh_extents = torch .stack ([xy , xy + wh ]).detach ().cpu ().numpy ()
213+ meshCameraRays = camera .getRayMat (mesh_extents )
214+ t = helper .rayPlaneIntersectionMat (centroid , np .expand_dims (planeNormal , 0 ), np .zeros (meshCameraRays .shape ), meshCameraRays )
215+ meshExtentPoints = t * meshCameraRays
211216
212- # Project Glottal Midline Extrema into Pointcloud
213-
217+
218+
219+
220+ # Project Glottal Midline Extrema into Pointcloud
214221 upperMidLine , lowerMidLine = segmentator .glottalMidlines ()[i ]
215222
216223 # Search for the next best midline if the computation didnt work.
@@ -235,6 +242,7 @@ def controlPointBasedARAP(triangulatedPoints, camera, segmentator, zSubdivisions
235242 glottalOutlinePoints = glottalOutlinePoints - centroid
236243 gml_point1 = np .expand_dims (gml_point1 , 0 ) - centroid
237244 gml_point2 = np .expand_dims (gml_point2 , 0 ) - centroid
245+ meshExtentPoints = meshExtentPoints - centroid
238246
239247 # Compute rotation matrix, aligning the plane normal to the +Y Axis
240248 rotPlane = helper .rotateAlign (planeNormal / np .linalg .norm (planeNormal ), np .array ([0.0 , 1.0 , 0.0 ]))
@@ -244,6 +252,7 @@ def controlPointBasedARAP(triangulatedPoints, camera, segmentator, zSubdivisions
244252 glottalOutlinePoints = np .matmul (rotPlane , glottalOutlinePoints .T ).T
245253 gml_point1 = np .matmul (rotPlane , gml_point1 .T ).T
246254 gml_point2 = np .matmul (rotPlane , gml_point2 .T ).T
255+ meshExtentPoints = np .matmul (rotPlane , meshExtentPoints .T ).T
247256
248257
249258
@@ -258,6 +267,7 @@ def controlPointBasedARAP(triangulatedPoints, camera, segmentator, zSubdivisions
258267 gml_point1 = rotateX (gml_point1 , - gmplAngle , deg = False )
259268 gml_point2 = rotateX (gml_point2 , - gmplAngle , deg = False )
260269 glottalOutlinePoints = rotateX (glottalOutlinePoints , - gmplAngle , deg = False )
270+ meshExtentPoints = rotateX (meshExtentPoints , - gmplAngle , deg = False )
261271
262272
263273 # Move everything, such that the glottal midlie lies directly ontop the Z Axus
@@ -266,16 +276,19 @@ def controlPointBasedARAP(triangulatedPoints, camera, segmentator, zSubdivisions
266276 gml_point1 -= np .array ([[0.0 , 0.0 , zOffset ]])
267277 gml_point2 -= np .array ([[0.0 , 0.0 , zOffset ]])
268278 glottalOutlinePoints -= np .array ([0.0 , 0.0 , zOffset ])
279+ meshExtentPoints -= np .array ([0.0 , 0.0 , zOffset ])
269280
270281 # Rotate everything around by 90 degrees again
271282 alignedPoints = rotateX (alignedPoints , - 90 ).astype (np .float )
272283 gml_point1 = rotateX (gml_point1 , - 90 ).astype (np .float )
273284 gml_point2 = rotateX (gml_point2 , - 90 ).astype (np .float )
274285 glottalOutlinePoints = rotateX (glottalOutlinePoints , - 90 ).astype (np .float )
286+ meshExtentPoints = rotateX (meshExtentPoints , - 90 ).astype (np .float )
275287
276288
277289 # Set Y Values to zero of the glottal outline points
278290 glottalOutlinePoints [:, 1 ] = 0.0
291+ meshExtentPoints [:, 1 ] = 0.0
279292
280293 if flip_y :
281294 alignedPoints [:, 1 ] = - alignedPoints [:, 1 ]
@@ -294,7 +307,7 @@ def controlPointBasedARAP(triangulatedPoints, camera, segmentator, zSubdivisions
294307
295308 # Find X-Y-Z Extent of Vocalfolds to generate fitting M5 Model
296309 if first :
297- minX , maxX , minY , maxY , minZ , maxZ = findXYZExtent (aligned )
310+ minX , maxX , minY , maxY , minZ , maxZ = findXYZExtent (meshExtentPoints )
298311 first = False
299312
300313 # Generate M5 Model for left and right vocalfold
0 commit comments