Skip to content

Commit 17e4a89

Browse files
committed
Check if dataset exceeds max limit, and crop it if it does. This is a temporary solution. Later, we should try to downsample it instead
1 parent 2abbe8f commit 17e4a89

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

Assets/Scripts/Importing/DICOMImporter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ public VolumeDataset ImportDICOMSeries(DICOMSeries series)
156156
dataset.scaleZ = Mathf.Abs(files[files.Count - 1].location - files[0].location);
157157
}
158158

159+
dataset.FixDimensions();
160+
159161
return dataset;
160162
}
161163

Assets/Scripts/Importing/ImageSequenceImporter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public VolumeDataset Import()
3636
int[] data = FillSequentialData(dimensions, imagePaths);
3737
VolumeDataset dataset = FillVolumeDataset(data, dimensions);
3838

39+
dataset.FixDimensions();
40+
3941
return dataset;
4042
}
4143

Assets/Scripts/Importing/RawDatasetImporter.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public VolumeDataset Import()
8585

8686
reader.Close();
8787
fs.Close();
88+
89+
dataset.FixDimensions();
90+
8891
return dataset;
8992
}
9093

Assets/Scripts/VolumeData/VolumeDataset.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33

44
namespace UnityVolumeRendering
55
{
6+
/// <summary>
7+
/// An imported dataset. Has a dimension and a 3D pixel array.
8+
/// </summary>
69
[Serializable]
710
public class VolumeDataset : ScriptableObject
811
{
12+
// Flattened 3D array of data sample values.
913
[SerializeField]
1014
public int[] data = null;
15+
1116
[SerializeField]
1217
public int dimX, dimY, dimZ;
18+
1319
[SerializeField]
1420
public float scaleX = 0.0f, scaleY = 0.0f, scaleZ = 0.0f;
1521

@@ -53,6 +59,41 @@ public int GetMaxDataValue()
5359
return maxDataValue;
5460
}
5561

62+
/// <summary>
63+
/// Ensures that the dataset is not too large.
64+
/// </summary>
65+
public void FixDimensions()
66+
{
67+
int MAX_DIM = 2048; // 3D texture max size. See: https://docs.unity3d.com/Manual/class-Texture3D.html
68+
69+
if (Mathf.Max(dimX, dimY, dimZ) > MAX_DIM)
70+
{
71+
Debug.LogWarning("Dimension exceeds limits. Cropping dataset. This might result in an incomplete dataset.");
72+
73+
int newDimX = Mathf.Min(dimX, MAX_DIM);
74+
int newDimY = Mathf.Min(dimY, MAX_DIM);
75+
int newDimZ = Mathf.Min(dimZ, MAX_DIM);
76+
int[] newData = new int[dimX * dimY * dimZ];
77+
78+
for (int z = 0; z < newDimZ; z++)
79+
{
80+
for (int y = 0; y < newDimY; y++)
81+
{
82+
for (int x = 0; x < newDimX; x++)
83+
{
84+
int oldIndex = (z * dimX * dimY) + (y * dimX) + x;
85+
int newIndex = (z * newDimX * newDimY) + (y * newDimX) + x;
86+
newData[newIndex] = data[oldIndex];
87+
}
88+
}
89+
}
90+
data = newData;
91+
dimX = newDimX;
92+
dimY = newDimY;
93+
dimZ = newDimZ;
94+
}
95+
}
96+
5697
private void CalculateValueBounds()
5798
{
5899
minDataValue = int.MaxValue;

0 commit comments

Comments
 (0)