Skip to content

Commit 3a24051

Browse files
committed
visualization & commandline interface bugfixes
1 parent 587e399 commit 3a24051

File tree

3 files changed

+35
-19
lines changed

3 files changed

+35
-19
lines changed

CorpusCallosum/cc_visualization.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,30 @@ def load_contours_from_template_dir(
119119

120120
fsaverage_contour = None
121121
contours: list[CCContour] = []
122+
# First pass: collect all indices to determine the range
123+
indices = []
122124
for thickness_file in thickness_files:
125+
try:
126+
idx = int(thickness_file.stem.split("_")[-1])
127+
indices.append(idx)
128+
except ValueError:
129+
# skip files that do not follow the expected naming
130+
continue
131+
132+
# Calculate z_positions centered around the middle slice
133+
num_slices = len(indices)
134+
middle_idx = num_slices // 2
135+
136+
for i, thickness_file in enumerate(thickness_files):
123137
try:
124138
idx = int(thickness_file.stem.split("_")[-1])
125139
except ValueError:
126140
# skip files that do not follow the expected naming
127141
continue
128142

143+
# Calculate z_position: use the index offset from middle, scaled by resolution
144+
z_position = (idx - indices[middle_idx]) * resolution
145+
129146
contour_file = template_dir / f"contour_{idx}.txt"
130147

131148
if not contour_file.exists():
@@ -138,15 +155,11 @@ def load_contours_from_template_dir(
138155
# create measurement points (points = 2 x levelpaths) according to number of thickness values
139156
fsaverage_contour.create_levelpaths(num_points=num_thickness_values // 2, update_data=True)
140157
current_contour = fsaverage_contour.copy()
158+
current_contour.z_position = z_position
141159
current_contour.load_thickness_values(thickness_file)
142160

143161
else:
144-
# this is kinda ugly - maybe we need to overload the constructor to load the contour and thickness values?
145-
# FIXME: The z_position in from_contour is still incorrect, currently all Contours would be "registered" for
146-
# the midslice.
147-
current_contour = CCContour.from_contour_file(contour_file, thickness_file, z_position=0.0)
148-
# current_contour.load_contour(contour_file)
149-
# current_contour.load_thickness_values(thickness_file)
162+
current_contour = CCContour.from_contour_file(contour_file, thickness_file, z_position=z_position)
150163

151164
current_contour.fill_thickness_values()
152165
contours.append(current_contour)

CorpusCallosum/fastsurfer_cc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def _set_help_sid(action):
148148
parser.add_argument(
149149
"--subdivisions",
150150
type=float,
151+
nargs='*',
151152
metavar="FRAC",
152153
default=_FixFloatFormattingList([1 / 6, 1 / 2, 2 / 3, 3 / 4], ".3f"),
153154
help="List of subdivision fractions for the corpus callosum subsegmentation."

CorpusCallosum/shape/contour.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -714,20 +714,22 @@ def _load_thickness_values(
714714
else:
715715
raise ValueError("Thickness values file must contain a single column")
716716

717-
if len(values) != len(contour):
718-
if original_thickness_vertices is None:
719-
new_values = values
720-
elif np.sum(~np.isnan(values)) == len(original_thickness_vertices):
721-
new_values = np.full(len(contour), np.nan)
722-
new_values[original_thickness_vertices] = values[~np.isnan(values)]
723-
else:
724-
raise ValueError(
725-
f"Number of thickness values {len(values)} does not match number of points in the contour "
726-
f"{len(contour)} and current number of measurement points {len(original_thickness_vertices)} does "
727-
f"not match the number of set thickness values {np.sum(~np.isnan(values))}."
728-
)
717+
if len(values) == len(contour):
718+
# Perfect match - use values directly
719+
new_values = values
720+
elif original_thickness_vertices is None:
721+
# No original vertices specified, use values as-is (may differ in length)
722+
new_values = values
723+
elif np.sum(~np.isnan(values)) == len(original_thickness_vertices):
724+
# Values match the number of measurement points, map them to the contour
725+
new_values = np.full(len(contour), np.nan)
726+
new_values[original_thickness_vertices] = values[~np.isnan(values)]
729727
else:
730-
raise ValueError(f"Number of thickness values in {input_path} does not match the vertices of the path!")
728+
raise ValueError(
729+
f"Number of thickness values {len(values)} does not match number of points in the contour "
730+
f"{len(contour)} and current number of measurement points {len(original_thickness_vertices)} does "
731+
f"not match the number of set thickness values {np.sum(~np.isnan(values))}."
732+
)
731733

732734
return new_values
733735

0 commit comments

Comments
 (0)