Skip to content

Commit ba9aa7c

Browse files
committed
Segmentations: Read multi-segmentation dataset
1 parent 4c4efa1 commit ba9aa7c

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

Assets/Scripts/Importing/Utilities/DatasetFormatUtilities.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static ImageFileFormat GetImageFileFormat(string filePath)
1212
case ".vasp":
1313
return ImageFileFormat.VASP;
1414
case ".nii":
15+
return ImageFileFormat.NIFTI;
1516
case ".gz":
1617
return filePath.ToLower().EndsWith(".nii.gz") ? ImageFileFormat.NIFTI : ImageFileFormat.Unknown;
1718
default:

Assets/Scripts/VolumeObject/VolumeRenderedObject.cs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,39 @@ public void AddSegmentation(VolumeDataset dataset)
159159

160160
overlayType = OverlayType.Segmentation;
161161

162-
int segmentationId = segmentationLabels.Count > 0 ? segmentationLabels.Max(l => l.id) + 1 : 1;
162+
int lastSegmentationId = segmentationLabels.Count > 0 ? segmentationLabels.Max(l => l.id) : 0;
163+
int maxSegmentationId = -1;
163164

164165
if (segmentationLabels.Count == 0)
165166
{
166167
secondaryDataset = dataset;
168+
maxSegmentationId = Mathf.RoundToInt(dataset.GetMaxDataValue());
167169
}
168170
else
169171
{
170-
for (int i = 0; i < secondaryDataset.data.Length; i++)
172+
for (int i = 0; i < dataset.data.Length; i++)
171173
{
172-
secondaryDataset.data[i] = dataset.data[i] > 0.0f ? (float)segmentationId : secondaryDataset.data[i];
174+
int value = Mathf.RoundToInt(dataset.data[i]);
175+
if (value > 0)
176+
{
177+
maxSegmentationId = Mathf.Max(maxSegmentationId, value);
178+
secondaryDataset.data[i] = maxSegmentationId + value;
179+
}
173180
}
174181
secondaryDataset.RecalculateBounds();
175182
secondaryDataset.RecreateDataTexture();
176183
secondaryDataset.GetDataTexture().filterMode = FilterMode.Point;
177184
}
178-
SegmentationLabel segmentationLabel = new SegmentationLabel();
179-
segmentationLabel.id = segmentationId;
180-
segmentationLabel.name = dataset.name;
181-
segmentationLabel.colour = Random.ColorHSV();
182-
segmentationLabels.Add(segmentationLabel);
183-
UpdateSegmentationLabels();
185+
for (int i = 1; i <= maxSegmentationId; i++)
186+
{
187+
int segmentationId = i + lastSegmentationId;
188+
SegmentationLabel segmentationLabel = new SegmentationLabel();
189+
segmentationLabel.id = segmentationId;
190+
segmentationLabel.name = dataset.name;
191+
segmentationLabel.colour = Random.ColorHSV();
192+
segmentationLabels.Add(segmentationLabel);
193+
UpdateSegmentationLabels();
194+
}
184195
}
185196

186197
public void RemoveSegmentation(int id)

0 commit comments

Comments
 (0)