Optimise Image Sequence Importer
Addresses the issue at mlavik1#56
This commit is contained in:
Родитель
13abae6746
Коммит
9227bdebd9
|
@ -30,9 +30,6 @@ namespace UnityVolumeRendering
|
|||
|
||||
List<string> imagePaths = GetSortedImagePaths();
|
||||
|
||||
if (!ImageSetHasUniformDimensions(imagePaths))
|
||||
throw new IndexOutOfRangeException("Image sequence has non-uniform dimensions");
|
||||
|
||||
Vector3Int dimensions = GetVolumeDimensions(imagePaths);
|
||||
int[] data = FillSequentialData(dimensions, imagePaths);
|
||||
VolumeDataset dataset = FillVolumeDataset(data, dimensions);
|
||||
|
@ -60,34 +57,6 @@ namespace UnityVolumeRendering
|
|||
return imagePaths;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if every image in the set has the same XY dimensions.
|
||||
/// </summary>
|
||||
/// <param name="imagePaths">The list of image paths to check.</param>
|
||||
/// <returns>True if at least one image differs from another.</returns>
|
||||
private bool ImageSetHasUniformDimensions(List<string> imagePaths)
|
||||
{
|
||||
bool hasUniformDimension = true;
|
||||
|
||||
Vector2Int previous, current;
|
||||
previous = GetImageDimensions(imagePaths[0]);
|
||||
|
||||
foreach (var path in imagePaths)
|
||||
{
|
||||
current = GetImageDimensions(path);
|
||||
|
||||
if (current.x != previous.x || current.y != previous.y)
|
||||
{
|
||||
hasUniformDimension = false;
|
||||
break;
|
||||
}
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
return hasUniformDimension;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the XY dimensions of an image at the path.
|
||||
/// </summary>
|
||||
|
@ -142,6 +111,12 @@ namespace UnityVolumeRendering
|
|||
byte[] bytes = File.ReadAllBytes(path);
|
||||
texture.LoadImage(bytes);
|
||||
|
||||
if (texture.width != dimensions.x || texture.height != dimensions.y)
|
||||
{
|
||||
Texture2D.DestroyImmediate(texture);
|
||||
throw new IndexOutOfRangeException("Image sequence has non-uniform dimensions");
|
||||
}
|
||||
|
||||
Color[] pixels = texture.GetPixels(); // Order priority: X -> Y -> Z
|
||||
int[] imageData = DensityHelper.ConvertColorsToDensities(pixels);
|
||||
|
||||
|
@ -177,4 +152,4 @@ namespace UnityVolumeRendering
|
|||
return dataset;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче