@@ -44,26 +44,42 @@ def automated_landmarking(input_filepath, curv_method, resampling_step, algorith
4444 nknots , smoothing_factor_curv , smoothing_factor_torsion , iterations )
4545
4646
47- def map_landmarks (landmarks , centerline ):
47+ def map_landmarks (landmarks , centerline , algorithm ):
4848 """
4949 Takes new landmarks and original centerline,
5050 mapping each landmark interface to the original centerline.
5151
5252 Args:
53+ algorithm:
5354 landmarks (dict): Contains landmarks.
5455 centerline (vtkPolyData): Original centerline.
56+ algorithm (str): Landmarking algorith, bogunovic or piccinelli
5557
5658 Returns:
57- landmarks (dict): Contains landmarks mapped to centerline.
59+ mapped_landmarks (dict): Contains landmarks mapped to centerline.
5860 """
61+ mapped_landmarks = {}
62+ landmark_ids = []
5963 locator = get_vtk_point_locator (centerline )
64+ k = 1
6065 for key in landmarks :
6166 landmark = landmarks [key ]
6267 landmark_id = locator .FindClosestPoint (landmark )
63- landmark_mapped = centerline .GetPoint (landmark_id )
64- landmarks [key ] = landmark_mapped
6568
66- return landmarks
69+ if algorithm == "piccinelli" :
70+ if landmark_id in landmark_ids :
71+ continue # Skip for duplicate landmarking point
72+ else :
73+ landmark_ids .append (landmark_id )
74+ landmark_mapped = centerline .GetPoint (landmark_id )
75+ mapped_landmarks ["bend%s" % k ] = landmark_mapped
76+ k += 1
77+ if algorithm == "bogunovic" :
78+ landmark_mapped = centerline .GetPoint (landmark_id )
79+ landmarks [key ] = landmark_mapped
80+ mapped_landmarks = landmarks
81+
82+ return mapped_landmarks
6783
6884
6985def landmarking_bogunovic (centerline , base_path , curv_method , algorithm ,
@@ -225,7 +241,7 @@ def find_interface(start, direction, tol, part):
225241 landmarks [k ] = line .GetPoint (int (v ))
226242
227243 # Map landmarks to initial centerline
228- landmarks = map_landmarks (landmarks , centerline )
244+ landmarks = map_landmarks (landmarks , centerline , algorithm )
229245
230246 # Save landmarks
231247 print ("-- Case was successfully landmarked." )
@@ -312,26 +328,28 @@ def landmarking_piccinelli(centerline, base_path, curv_method, algorithm, resamp
312328 for i in range (len (max_point_tor_ids ) - 1 ):
313329 dist_tor .append (max_point_tor_ids [i + 1 ] - max_point_tor_ids [i ])
314330
331+ curv_remove_ids = []
315332 for i , dx in enumerate (dist ):
316333 if dx < tolerance :
317334 curv1 = curvature [max_point_ids [i ]]
318335 curv2 = curvature [max_point_ids [i + 1 ]]
319336 if curv1 > curv2 :
320- max_point_ids [i + 1 ] = None
337+ curv_remove_ids . append ( max_point_ids [i + 1 ])
321338 else :
322- max_point_ids [i ] = None
339+ curv_remove_ids . append ( max_point_ids [i ])
323340
341+ tor_remove_ids = []
324342 for i , dx in enumerate (dist_tor ):
325343 if dx < tolerance :
326344 tor1 = torsion_smooth [max_point_tor_ids [i ]]
327345 tor2 = torsion_smooth [max_point_tor_ids [i + 1 ]]
328346 if tor1 > tor2 :
329- max_point_tor_ids [i + 1 ] = None
347+ tor_remove_ids . append ( max_point_tor_ids [i + 1 ])
330348 else :
331- max_point_tor_ids [i ] = None
349+ tor_remove_ids . append ( max_point_tor_ids [i ])
332350
333- max_point_ids = [ID for ID in max_point_ids if ID is not None ]
334- max_point_tor_ids = [ID for ID in max_point_tor_ids if ID is not None ]
351+ max_point_ids = [ID for ID in max_point_ids if ID not in curv_remove_ids ]
352+ max_point_tor_ids = [ID for ID in max_point_tor_ids if ID not in tor_remove_ids ]
335353
336354 # Define bend interfaces based on Piccinelli et al.
337355 def find_interface ():
@@ -359,7 +377,7 @@ def find_interface():
359377 landmarks [k ] = line .GetPoints ().GetPoint (int (v ))
360378
361379 # Map landmarks to initial centerline
362- landmarks = map_landmarks (landmarks , centerline )
380+ landmarks = map_landmarks (landmarks , centerline , algorithm )
363381
364382 # Save landmarks
365383 print ("-- Case was successfully landmarked." )
@@ -485,26 +503,26 @@ def create_particles(base_path, algorithm, method):
485503 info_filepath = base_path + "_info.json"
486504 filename_all_landmarks = base_path + "_landmark_%s_%s.particles" % (algorithm , method )
487505 filename_bend_landmarks = base_path + "_anterior_bend.particles"
506+ print ("Saving all landmarks to: %s" % filename_all_landmarks )
488507
489508 output_all = open (filename_all_landmarks , "w" )
490509 output_siphon = open (filename_bend_landmarks , "w" )
491- mani = open (info_filepath , "r" )
492- lines = mani .readlines ()
493- mani .close ()
510+ with open (info_filepath , ) as landmarks_json :
511+ landmarked_points = json .load (landmarks_json )
494512
495- for line in lines :
513+ for key in landmarked_points :
496514 if algorithm == "bogunovic" :
497- if line . split ()[ 1 ][ 0 ] == "(" :
498- coord = line . split ()[ 1 : ]
499- point = "%s %s %s" % (coord [0 ][ 1 : - 1 ], coord [1 ][: - 1 ], coord [ 2 ][: - 1 ])
515+ if key in [ "ant_post" , "post_inf" , "inf_end" , "sup_ant" ] :
516+ p = landmarked_points [ key ]
517+ point = "%s %s %s" % (p [0 ], p [1 ], p [ 2 ])
500518 output_all .write (point + "\n " )
501- if line . split ()[ 0 ] == "sup_ant:" or line . split ()[ 0 ] == "ant_post:" :
502- output_siphon .write (point + "\n " )
519+ if key in [ "ant_post" , "sup_ant" ] :
520+ output_siphon .write (point + "\n " )
503521
504522 elif algorithm == "piccinelli" :
505- if line . split ()[ 0 ][: 4 ] == "bend" :
506- coord = line . split ()[ 1 : ]
507- point = "%s %s %s" % (coord [0 ][ 1 : - 1 ], coord [1 ][: - 1 ], coord [ 2 ][: - 1 ])
523+ if "bend" in key :
524+ p = landmarked_points [ key ]
525+ point = "%s %s %s" % (p [0 ], p [1 ], p [ 2 ])
508526 output_all .write (point + "\n " )
509527
510528 output_all .close ()
@@ -541,9 +559,9 @@ def read_command_line():
541559 parser .add_argument ('-sl' , '--smooth-line' , type = str2bool , default = False ,
542560 help = "If the original centerline should be smoothed " +
543561 "when computing the centerline attributes" )
544- parser .add_argument ('-facc' , '--smoothing-factor-curvature' , type = float , default = 1.0 ,
562+ parser .add_argument ('-facc' , '--smoothing-factor-curvature' , type = float , default = 1.5 ,
545563 help = "Smoothing factor for computing curvature." )
546- parser .add_argument ('-fact' , '--smoothing-factor-torsion' , type = float , default = 1.0 ,
564+ parser .add_argument ('-fact' , '--smoothing-factor-torsion' , type = float , default = 1.2 ,
547565 help = "Smoothing factor for computing torsion." )
548566 parser .add_argument ('-it' , '--iterations' , type = int , default = 100 ,
549567 help = "Smoothing iterations." )
0 commit comments