Added optional downscaled option
This commit is contained in:
Родитель
6dfab009ba
Коммит
5f0d380920
|
@ -65,7 +65,10 @@ namespace UnityVolumeRendering
|
|||
|
||||
// Load all DICOM files
|
||||
List<DICOMSliceFile> files = new List<DICOMSliceFile>();
|
||||
foreach (string filePath in fileCandidates)
|
||||
|
||||
IEnumerable<string> sortedFiles = fileCandidates.OrderBy(s => s);
|
||||
|
||||
foreach (string filePath in sortedFiles)
|
||||
{
|
||||
DICOMSliceFile sliceFile = ReadDICOMFile(filePath);
|
||||
if(sliceFile != null)
|
||||
|
@ -90,13 +93,10 @@ namespace UnityVolumeRendering
|
|||
return new List<DICOMSeries>(seriesByUID.Values);
|
||||
}
|
||||
|
||||
public VolumeDataset ImportDICOMSeries(DICOMSeries series)
|
||||
public VolumeDataset ImportDICOMSeries(DICOMSeries series, bool forceDownScaling = false)
|
||||
{
|
||||
List<DICOMSliceFile> files = series.dicomFiles;
|
||||
|
||||
// Sort files by slice location
|
||||
files.Sort((DICOMSliceFile a, DICOMSliceFile b) => { return a.location.CompareTo(b.location); });
|
||||
|
||||
// Check if the series is missing the slice location tag
|
||||
bool needsCalcLoc = false;
|
||||
foreach (DICOMSliceFile file in files)
|
||||
|
@ -107,6 +107,9 @@ namespace UnityVolumeRendering
|
|||
// Calculate slice location from "Image Position" (0020,0032)
|
||||
if (needsCalcLoc)
|
||||
CalcSliceLocFromPos(files);
|
||||
|
||||
// Sort files by slice location
|
||||
files.Sort((DICOMSliceFile a, DICOMSliceFile b) => { return a.location.CompareTo(b.location); });
|
||||
|
||||
Debug.Log($"Importing {files.Count} DICOM slices");
|
||||
|
||||
|
@ -156,6 +159,11 @@ namespace UnityVolumeRendering
|
|||
dataset.scaleZ = Mathf.Abs(files[files.Count - 1].location - files[0].location);
|
||||
}
|
||||
|
||||
if (forceDownScaling)
|
||||
{
|
||||
dataset.DownScaleData();
|
||||
}
|
||||
|
||||
dataset.FixDimensions();
|
||||
|
||||
return dataset;
|
||||
|
|
|
@ -11,15 +11,18 @@ namespace UnityVolumeRendering
|
|||
public class ImageSequenceImporter
|
||||
{
|
||||
private string directoryPath;
|
||||
private bool forceDownScaling;
|
||||
private string[] supportedImageTypes = new string[]
|
||||
{
|
||||
"*.png",
|
||||
"*.jpg",
|
||||
"*.jpeg"
|
||||
};
|
||||
|
||||
public ImageSequenceImporter(string directoryPath)
|
||||
public ImageSequenceImporter(string directoryPath, bool forceDownScaling = false)
|
||||
{
|
||||
this.directoryPath = directoryPath;
|
||||
this.forceDownScaling = forceDownScaling;
|
||||
}
|
||||
|
||||
public VolumeDataset Import()
|
||||
|
@ -36,6 +39,11 @@ namespace UnityVolumeRendering
|
|||
int[] data = FillSequentialData(dimensions, imagePaths);
|
||||
VolumeDataset dataset = FillVolumeDataset(data, dimensions);
|
||||
|
||||
if (forceDownScaling)
|
||||
{
|
||||
dataset.DownScaleData();
|
||||
}
|
||||
|
||||
dataset.FixDimensions();
|
||||
|
||||
return dataset;
|
||||
|
|
|
@ -29,8 +29,8 @@ namespace UnityVolumeRendering
|
|||
private DataContentFormat contentFormat;
|
||||
private Endianness endianness;
|
||||
private int skipBytes;
|
||||
|
||||
public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat, Endianness endianness, int skipBytes)
|
||||
private bool forceDownScaling;
|
||||
public RawDatasetImporter(string filePath, int dimX, int dimY, int dimZ, DataContentFormat contentFormat, Endianness endianness, int skipBytes, bool forceDownScaling = false)
|
||||
{
|
||||
this.filePath = filePath;
|
||||
this.dimX = dimX;
|
||||
|
@ -39,12 +39,13 @@ namespace UnityVolumeRendering
|
|||
this.contentFormat = contentFormat;
|
||||
this.endianness = endianness;
|
||||
this.skipBytes = skipBytes;
|
||||
this.forceDownScaling = forceDownScaling;
|
||||
}
|
||||
|
||||
public VolumeDataset Import()
|
||||
{
|
||||
// Check that the file exists
|
||||
if(!File.Exists(filePath))
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
Debug.LogError("The file does not exist: " + filePath);
|
||||
return null;
|
||||
|
@ -86,8 +87,13 @@ namespace UnityVolumeRendering
|
|||
reader.Close();
|
||||
fs.Close();
|
||||
|
||||
if (forceDownScaling)
|
||||
{
|
||||
dataset.DownScaleData();
|
||||
}
|
||||
|
||||
dataset.FixDimensions();
|
||||
|
||||
|
||||
return dataset;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче