Skip to content

Commit 82809a2

Browse files
committed
Refactoring in manipulate_x scripts
1 parent f37ce0a commit 82809a2

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

morphman/manipulate_area.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,7 @@ def get_asymmetric_displacement(A, angle_asymmetric, factor_, frenet_normals_arr
402402

403403
def update_factor(A, AB_length, B, P_mid, factor, tmp_id1, tmp_id2):
404404
"""
405-
Update values in Factor based on midpoint between
406-
A and B.
405+
Update values in Factor based on midpoint between A and B.
407406
408407
Args:
409408
P_mid (ndarray): Midpoint
@@ -521,21 +520,19 @@ def read_command_line_area(input_path=None, output_path=None):
521520
args = parser.parse_args(["-i" + input_path, "-o" + output_path])
522521

523522
if args.method in ["stenosis", "bulge", "linear"] and args.region_of_interest == "first_line":
524-
raise ValueError("Can not set region of interest to 'first_line' for 'stenosis'," + \
525-
" 'bulge', or 'linear'")
523+
raise ValueError("Can not set region of interest to 'first_line' for 'stenosis', 'bulge', or 'linear'")
526524

527525
if args.method == "variation" and args.ratio is not None and args.beta != 0.5:
528526
print("WARNING: The beta value you provided will be ignored, using ratio instead.")
529527

530528
if args.region_points is not None:
531529
if len(args.region_points) % 3 != 0 or len(args.region_points) > 6:
532-
raise ValueError("ERROR: Please provide region point(s) as a multiple of 3, and maximum" +
533-
" two points.")
530+
raise ValueError("ERROR: Please provide region point(s) as a multiple of 3, and maximum two points.")
534531

535532
if args.no_smooth_point is not None and len(args.no_smooth_point):
536533
if len(args.no_smooth_point) % 3 != 0:
537-
raise ValueError("ERROR: Please provide the no smooth point(s) as a multiple" +
538-
" of 3.")
534+
raise ValueError("ERROR: Please provide the no smooth point(s) as a multiple of 3.")
535+
539536
if args.angle_asymmetric is not None:
540537
angle_radians = args.angle_asymmetric * np.pi / 180 # Convert from deg to rad
541538
else:

morphman/manipulate_bifurcation.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
from morphman.common.vessel_reconstruction_tools import *
1414

1515

16-
def manipulate_bifurcation(input_filepath, output_filepath, smooth, smooth_factor, angle,
17-
keep_fixed_1, keep_fixed_2, bif, lower, no_smooth, no_smooth_point,
18-
poly_ball_size, cylinder_factor, resampling_step,
16+
def manipulate_bifurcation(input_filepath, output_filepath, smooth, smooth_factor, angle, keep_fixed_1, keep_fixed_2,
17+
bif, lower, no_smooth, no_smooth_point, poly_ball_size, cylinder_factor, resampling_step,
1918
region_of_interest, region_points, tension, continuity):
2019
"""
2120
Objective rotation of daughter branches, by rotating
@@ -27,6 +26,8 @@ def manipulate_bifurcation(input_filepath, output_filepath, smooth, smooth_facto
2726
Includes the option to rotate only one of the daughter branches.
2827
2928
Args:
29+
tension (float): Tension parameter of Kochanek splines
30+
continuity (float): Continuity parameter of Kochanek splines
3031
input_filepath (str): Path to input surface.
3132
output_filepath (str): Path to output surface.
3233
smooth (bool): Determine if the voronoi diagram should be smoothed.
@@ -144,8 +145,7 @@ def manipulate_bifurcation(input_filepath, output_filepath, smooth, smooth_facto
144145

145146
# Clip the voronoi diagram
146147
print("-- Clipping Voronoi diagram")
147-
voronoi_clipped, voronoi_bifurcation = get_split_voronoi_diagram(voronoi, [patch_cl,
148-
clipped_centerline])
148+
voronoi_clipped, voronoi_bifurcation = get_split_voronoi_diagram(voronoi, [patch_cl, clipped_centerline])
149149
write_polydata(voronoi_clipped, voronoi_clipped_path)
150150
write_polydata(voronoi_bifurcation, voronoi_bifurcation_path)
151151

@@ -284,7 +284,7 @@ def rotate_voronoi(clipped_voronoi, patch_cl, div_points, m, R):
284284
for i in range(1, patch_cl.GetNumberOfCells()):
285285
pnt = cell_line[i].GetPoints().GetPoint(0)
286286
new = cell_line[0].GetPoints().GetPoint(locator[0].FindClosestPoint(pnt))
287-
if get_distance(pnt, new) < tolerance*10:
287+
if get_distance(pnt, new) < tolerance * 10:
288288
not_rotate.append(i)
289289

290290
def check_rotate(point):
@@ -369,7 +369,7 @@ def rotate_cl(patch_cl, div_points, rotation_matrices, R):
369369

370370
start = cell.GetPoint(0)
371371
dist = line0.GetPoint(locator0.FindClosestPoint(start))
372-
test = get_distance(start, dist) > tolerance*10
372+
test = get_distance(start, dist) > tolerance * 10
373373

374374
if test or len(div_points) == 2:
375375
locator = get_vtk_point_locator(cell)
@@ -615,7 +615,6 @@ def read_command_line_bifurcation(input_path=None, output_path=None):
615615
parser.add_argument("-c", "--continuity", type=float, default=0.8,
616616
help="Set continuity of the KochanekSpline from -1 to 1")
617617

618-
619618
# Bifurcation reconstruction arguments
620619
parser.add_argument("--bif", type=str2bool, default=False,
621620
help="interpolate bif as well")
@@ -638,7 +637,6 @@ def read_command_line_bifurcation(input_path=None, output_path=None):
638637
if not (-1 <= args.continuity <= 1):
639638
raise ValueError("Tension has to be between -1 and 1, not {}".format(args.continuity))
640639

641-
642640
return dict(input_filepath=args.ifile, smooth=args.smooth, output_filepath=args.ofile,
643641
smooth_factor=args.smooth_factor, angle=ang_,
644642
keep_fixed_1=args.keep_fixed_1, keep_fixed_2=args.keep_fixed_2,

morphman/manipulate_curvature.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
## PURPOSE. See the above copyright notices for more information.
77

88
from argparse import ArgumentParser, RawDescriptionHelpFormatter
9+
910
from vtk.numpy_interface import dataset_adapter as dsa
1011

1112
# Local import
@@ -66,9 +67,9 @@ def manipulate_curvature(input_filepath, smooth, smooth_factor, smooth_factor_li
6667
no_smooth_point, voronoi, pole_ids, resampling_step)
6768
# Get region of interest
6869
centerline_splined, centerline_remaining, \
69-
centerline_diverging, region_points, diverging_ids = get_line_to_change(capped_surface, centerlines,
70-
region_of_interest, "variation",
71-
region_points, None)
70+
centerline_diverging, region_points, diverging_ids = get_line_to_change(capped_surface, centerlines,
71+
region_of_interest, "variation",
72+
region_points, None)
7273

7374
write_polydata(centerline_splined, centerline_spline_path)
7475
write_polydata(centerline_remaining, centerline_remaining_path)
@@ -129,8 +130,8 @@ def get_dx(p0, p1, smooth_line, cl_id, id_end, id_mid, id_start):
129130
"""Get the displacement for the Voronoi point
130131
131132
Args:
132-
p0 (list): Point i on the old centerline.
133-
p1 (list): Point i on the new centerline.
133+
p0 (ndarray): Point i on the old centerline.
134+
p1 (ndarray): Point i on the new centerline.
134135
smooth_line (bool): Turn on/off increasing curvuature.
135136
cl_id (int): ID of point i
136137
id_end (int): Point ID of start transition region.
@@ -200,7 +201,7 @@ def make_voronoi_smooth(voronoi, old_cl, new_cl, smooth_line, div_voronoi, div_p
200201

201202
# Offset diverging centerlines
202203
div_offset = []
203-
if div_voronoi != []:
204+
if len(div_voronoi) > 0:
204205
for i in range(len(div_voronoi)):
205206
cl_id = locator.FindClosestPoint(div_points[i])
206207
p0 = np.asarray(old_cl.GetPoint(cl_id))

morphman/manipulate_surface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ def read_command_line_surface(input_path=None, output_path=None):
422422

423423
if args.frequency_deviation <= 0:
424424
raise ArgumentTypeError("The standard deviation has to be larger than zero." +
425-
" Please provide a valid value, not {}" \
426-
.format(args.frequency_deviation))
425+
" Please provide a valid value, not" +
426+
" {}".format(args.frequency_deviation))
427427

428428
return dict(input_filepath=args.ifile, smooth=args.smooth, output_filepath=args.ofile,
429429
smooth_factor=args.smooth_factor, resampling_step=args.resampling_step,

0 commit comments

Comments
 (0)