microsoft / MixedRealityToolkit-Unity

This repository is for the legacy Mixed Reality Toolkit (MRTK) v2. For the latest version of the MRTK please visit https://github.com/MixedRealityToolkit/MixedRealityToolkit-Unity
https://aka.ms/mrtkdocs
MIT License
6.01k stars 2.12k forks source link

Medical Example Create New Volume #1441

Closed ccarrieta closed 6 years ago

ccarrieta commented 6 years ago

Overview

When Creating a new Volume

Expected Behavior

New volume Created

Actual Behavior

Error IndexOutOfRangeException: Array index is out of range

Steps to reproduce

(Links to sample github project preferred)

Unity Editor Version

Mixed Reality Toolkit Release Version

ChBrandy commented 6 years ago

I can reproduce it with Unity 2017.2.0f3. I have tried with the BrainSlices folder as well as other image data sets. Non of them is working and ends in the above mentioned error.

ChBrandy commented 6 years ago

I played around a bit with it and found the following behaviour: if all 256 images are present in BrainSlices folder: Following exception pops up during processing of img004.jpg

IndexOutOfRangeException: Array index is out of range. HoloToolkit.Unity.VolumeBuffer`1[UnityEngine.Color32].SetVoxel (Int3 pos, Color32 val) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeBuffer.cs:54) HoloToolkit.Unity.VolumeImportImages.ConvertFolderToVolume (System.String folder, Boolean inferAlpha, HoloToolkit.Unity.Int3& size) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeImportImages.cs:50) HoloToolkit.Unity.VolumeInformationEditor.OnInspectorGUI () (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:38) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1240) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> NO volume created

In case I remove all images and leave only img001-003 in the folder: Following exception pops up during processing of img003.jpg

IndexOutOfRangeException: Array index is out of range. HoloToolkit.Unity.VolumeBuffer`1[UnityEngine.Color32].SetVoxel (Int3 pos, Color32 val) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeBuffer.cs:54) HoloToolkit.Unity.VolumeImportImages.ConvertFolderToVolume (System.String folder, Boolean inferAlpha, HoloToolkit.Unity.Int3& size) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeImportImages.cs:51) HoloToolkit.Unity.VolumeInformationEditor.OnInspectorGUI () (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:38) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1240) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> NO volume created

In case I remove all images and leave only img001-002 in the folder: Following exception pops up during processing of img002.jpg

SetPixels32 called with invalid number of pixels in the array UnityEngine.Texture3D:SetPixels32(Color32[]) HoloToolkit.Unity.VolumeTextureUtils:BuildTexture(Byte[], Int3, Int3) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeTextureUtils.cs:72) HoloToolkit.Unity.VolumeInformationEditor:OnInspectorGUI() (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:47) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> volume created

In case I remove all images and leave only img001: Following exception pops up during processing of img001.jpg

SetPixels32 called with invalid number of pixels in the array UnityEngine.Texture3D:SetPixels32(Color32[]) HoloToolkit.Unity.VolumeTextureUtils:BuildTexture(Byte[], Int3, Int3) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeTextureUtils.cs:72) HoloToolkit.Unity.VolumeInformationEditor:OnInspectorGUI() (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:47) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> volume created

Similar behaviour I can see for other image datasets. Seems the volumebuffer size is calculated by the images in the folder and this is not working right(?).

ccarrieta commented 6 years ago

That’s correct I got the same result

Sent from my iPhone

On Dec 8, 2017, at 1:55 AM, ChBrandy notifications@github.com wrote:

I played around a bit with it and found the following behaviour: if all 256 images are present in BrainSlices folder: Following exception pops up during processing of img004.jpg

IndexOutOfRangeException: Array index is out of range. HoloToolkit.Unity.VolumeBuffer`1[UnityEngine.Color32].SetVoxel (Int3 pos, Color32 val) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeBuffer.cs:54) HoloToolkit.Unity.VolumeImportImages.ConvertFolderToVolume (System.String folder, Boolean inferAlpha, HoloToolkit.Unity.Int3& size) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeImportImages.cs:50) HoloToolkit.Unity.VolumeInformationEditor.OnInspectorGUI () (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:38) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1240) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> NO volume created

In case I remove all images and leave only img001-003 in the folder: Following exception pops up during processing of img003.jpg

IndexOutOfRangeException: Array index is out of range. HoloToolkit.Unity.VolumeBuffer`1[UnityEngine.Color32].SetVoxel (Int3 pos, Color32 val) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeBuffer.cs:54) HoloToolkit.Unity.VolumeImportImages.ConvertFolderToVolume (System.String folder, Boolean inferAlpha, HoloToolkit.Unity.Int3& size) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeImportImages.cs:51) HoloToolkit.Unity.VolumeInformationEditor.OnInspectorGUI () (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:38) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1240) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> NO volume created

In case I remove all images and leave only img001-002 in the folder: Following exception pops up during processing of img002.jpg

SetPixels32 called with invalid number of pixels in the array UnityEngine.Texture3D:SetPixels32(Color32[]) HoloToolkit.Unity.VolumeTextureUtils:BuildTexture(Byte[], Int3, Int3) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeTextureUtils.cs:72) HoloToolkit.Unity.VolumeInformationEditor:OnInspectorGUI() (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:47) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> volume created

In case I remove all images and leave only img001: Following exception pops up during processing of img001.jpg

SetPixels32 called with invalid number of pixels in the array UnityEngine.Texture3D:SetPixels32(Color32[]) HoloToolkit.Unity.VolumeTextureUtils:BuildTexture(Byte[], Int3, Int3) (at Assets/HoloToolkit-Examples/Medical/Scripts/VolumeTextureUtils.cs:72) HoloToolkit.Unity.VolumeInformationEditor:OnInspectorGUI() (at Assets/HoloToolkit-Examples/Medical/Editor/VolumeInformationEditor.cs:47) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

==> volume created

Similar behaviour I can see for other image datasets. Seems the volumebuffer size is calculated by the images in the folder and this is not working right(?).

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

doughtmw commented 6 years ago

It seems to be an issue with the usage of the sqrMagnitude function for VolumeBuffer creation. Just requires a couple changes!

  1. In VolumeBuffer.cs change the line: this.DataArray = new T[this.Size.sqrMagnitude]; to: this.DataArray = new T[this.Size.x * this.Size.y * this.Size.z];

  2. In VolumeTextureUtils.cs change the line: var colors = new Color32[volumeSizePow2.sqrMagnitude]; to: var colors = new Color32[volumeSizePow2.x * volumeSizePow2.y * volumeSizePow2.z];

Hope that helps.

SimonDarksideJ commented 6 years ago

The medical example is being deprecated for the moment.