Skip to content

Commit

Permalink
VolumeRenderedObject inspector: Load PET scan
Browse files Browse the repository at this point in the history
  • Loading branch information
mlavik1 committed Aug 25, 2024
1 parent 45e2a0d commit 3b44143
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
34 changes: 34 additions & 0 deletions Assets/Editor/VolumeRenderedObjectCustomInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using UnityEditor;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.IO;

namespace UnityVolumeRendering
{
Expand All @@ -11,6 +12,7 @@ public class VolumeRenderedObjectCustomInspector : Editor, IProgressView
private bool tfSettings = true;
private bool lightSettings = true;
private bool otherSettings = true;
private bool secondaryVolumeSettings = true;
private float currentProgress = 1.0f;
private string currentProgressDescrition = "";
private bool progressDirty = false;
Expand Down Expand Up @@ -137,6 +139,30 @@ public override void OnInspectorGUI()
}
}

// Secondary volume
secondaryVolumeSettings = EditorGUILayout.Foldout(secondaryVolumeSettings, "Overlay volume");
VolumeRenderedObject secondaryObject = volrendObj.GetSecondaryVolume();
if (secondaryObject == null)
{
if (GUILayout.Button("Load PET data"))
{
ImportPetScan(volrendObj);
}
}
else
{
if (GUILayout.Button("Edit secondary transfer function"))
{
TransferFunctionEditorWindow.ShowWindow(secondaryObject);
}

if (GUILayout.Button("Remove secondary volume"))
{
volrendObj.SetSecondaryVolume(null);
GameObject.Destroy(secondaryObject.gameObject);
}
}

// Other settings
GUILayout.Space(10);
otherSettings = EditorGUILayout.Foldout(otherSettings, "Other Settings");
Expand All @@ -152,5 +178,13 @@ public override void OnInspectorGUI()
volrendObj.SetSamplingRateMultiplier(EditorGUILayout.Slider("Sampling rate multiplier", volrendObj.GetSamplingRateMultiplier(), 0.2f, 2.0f));
}
}
private static async void ImportPetScan(VolumeRenderedObject targetObject)
{
VolumeRenderedObject petObject = await VolumeRendererEditorFunctions.DicomImportAsync(true);
petObject.transferFunction.colourControlPoints = new List<TFColourControlPoint>() { new TFColourControlPoint(0.0f, Color.red), new TFColourControlPoint(1.0f, Color.red) };
petObject.transferFunction.GenerateTexture();
targetObject.SetSecondaryVolume(petObject);
petObject.gameObject.SetActive(false);
}
}
}
10 changes: 6 additions & 4 deletions Assets/Editor/VolumeRendererEditorFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static void ShowDatasetImporter()
[MenuItem("Volume Rendering/Load dataset/Load DICOM")]
private static void ShowDICOMImporter()
{
DicomImportAsync(true);
_ = DicomImportAsync(true);
}

[MenuItem("Volume Rendering/Load dataset/Load PET-CT DICOM")]
Expand All @@ -45,11 +45,12 @@ private static void ShowPETCTDICOMImporter()
[MenuItem("Assets/Volume Rendering/Import dataset/Import DICOM")]
private static void ImportDICOMAsset()
{
DicomImportAsync(false);
_ = DicomImportAsync(false);
}

private static async void DicomImportAsync(bool spawnInScene)
public static async Task<VolumeRenderedObject> DicomImportAsync(bool spawnInScene)
{
VolumeRenderedObject obj = null;
string dir = EditorUtility.OpenFolderPanel("Select a folder to load", "", "");
if (Directory.Exists(dir))
{
Expand All @@ -66,7 +67,7 @@ private static async void DicomImportAsync(bool spawnInScene)
if (spawnInScene)
{
VolumeDataset dataset = importTask.Result[i];
VolumeRenderedObject obj = await VolumeObjectFactory.CreateObjectAsync(dataset);
obj = await VolumeObjectFactory.CreateObjectAsync(dataset);
obj.transform.position = new Vector3(i, 0, 0);
}
else
Expand All @@ -83,6 +84,7 @@ private static async void DicomImportAsync(bool spawnInScene)
{
Debug.LogError("Directory doesn't exist: " + dir);
}
return obj;
}

private static async void PETCTDicomImportAsync()
Expand Down
5 changes: 5 additions & 0 deletions Assets/Scripts/VolumeObject/VolumeRenderedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public SlicingPlane CreateSlicingPlane()
return slicingPlaneComp;
}

public VolumeRenderedObject GetSecondaryVolume()
{
return this.secondaryVolume;
}

public void SetSecondaryVolume(VolumeRenderedObject volumeObject)
{
this.secondaryVolume = volumeObject;
Expand Down

0 comments on commit 3b44143

Please sign in to comment.