Skip to content

XYZ clipping #133

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Assets/Editor/VolumeRenderedObjectCustomInspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace UnityVolumeRendering
[CustomEditor(typeof(VolumeRenderedObject))]
public class VolumeRenderedObjectCustomInspector : Editor
{
private bool clipSettings = false;
private bool tfSettings = true;
private bool lightSettings = true;
private bool otherSettings = true;
Expand All @@ -20,6 +21,30 @@ public override void OnInspectorGUI()
if (newRenderMode != oldRenderMode)
volrendObj.SetRenderMode(newRenderMode);

#region ClippingData
EditorGUILayout.Space();
clipSettings = EditorGUILayout.Foldout(clipSettings, "Clipping Settings");

if (clipSettings)
{
// Clip dim 1
Vector2 ClipDim1 = volrendObj.GetClipDim1();
EditorGUILayout.MinMaxSlider("Clipping Dimension x", ref ClipDim1.x, ref ClipDim1.y, 0.0f, 1.0f);

// Clip dim 2
Vector2 ClipDim2 = volrendObj.GetClipDim2();
EditorGUILayout.MinMaxSlider("Clipping Dimension y", ref ClipDim2.x, ref ClipDim2.y, 0.0f, 1.0f);

// Clip dim 3
Vector2 ClipDim3 = volrendObj.GetClipDim3();
EditorGUILayout.MinMaxSlider("Clipping Dimension y", ref ClipDim3.x, ref ClipDim3.y, 0.0f, 1.0f);

// setting clip dims
volrendObj.SetClipDims(ClipDim1, ClipDim2, ClipDim3);
}
#endregion EndClippingData


// Visibility window
Vector2 visibilityWindow = volrendObj.GetVisibilityWindow();
EditorGUILayout.MinMaxSlider("Visible value range", ref visibilityWindow.x, ref visibilityWindow.y, 0.0f, 1.0f);
Expand Down
2 changes: 2 additions & 0 deletions Assets/Materials/DirectVolumeRenderingMaterial.mat
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,7 @@ Material:
- _UVSec: 0
- _ZWrite: 1
m_Colors:
- _ClipDimMax: {r: 1, g: 1, b: 1, a: 1}
- _ClipDimMin: {r: 0, g: 0, b: 0, a: 1}
- _Color: {r: 1, g: 1, b: 1, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions Assets/Scripts/VolumeObject/VolumeRenderedObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ public class VolumeRenderedObject : MonoBehaviour
private bool cubicInterpolationEnabled = false;

private CrossSectionManager crossSectionManager;

[SerializeField, HideInInspector]
private Vector2 ClipDim1 = new Vector2(0.0f, 1.0f);
[SerializeField, HideInInspector]
private Vector2 ClipDim2 = new Vector2(0.0f, 1.0f);
[SerializeField, HideInInspector]
private Vector2 ClipDim3 = new Vector2(0.0f, 1.0f);

public SlicingPlane CreateSlicingPlane()
{
Expand Down Expand Up @@ -138,6 +145,47 @@ public Vector2 GetVisibilityWindow()
return visibilityWindow;
}

public void SetClipDims(Vector2 dim1, Vector2 dim2, Vector2 dim3)
{
bool different = false;

if (dim1 != ClipDim1)
{
ClipDim1 = dim1;
different = true;
}
if (dim2 != ClipDim2)
{
ClipDim2 = dim2;
different = true;
}
if (dim3 != ClipDim3)
{
ClipDim3 = dim3;
different = true;
}
if (different)
{
UpdateMaterialProperties();
}
}

public Vector2 GetClipDim1()
{
return ClipDim1;
}

public Vector2 GetClipDim2()
{
return ClipDim2;
}

public Vector2 GetClipDim3()
{
return ClipDim3;
}


public bool GetRayTerminationEnabled()
{
return rayTerminationEnabled;
Expand Down Expand Up @@ -241,6 +289,9 @@ private void UpdateMaterialProperties()
meshRenderer.sharedMaterial.SetFloat("_MaxVal", visibilityWindow.y);
meshRenderer.sharedMaterial.SetVector("_TextureSize", new Vector3(dataset.dimX, dataset.dimY, dataset.dimZ));

meshRenderer.sharedMaterial.SetVector("_ClipDimMin", new Vector4(ClipDim1.x, ClipDim2.x, ClipDim3.x, 1f));
meshRenderer.sharedMaterial.SetVector("_ClipDimMax", new Vector4(ClipDim1.y, ClipDim2.y, ClipDim3.y, 1f));

if (rayTerminationEnabled)
meshRenderer.sharedMaterial.EnableKeyword("RAY_TERMINATE_ON");
else
Expand Down
Loading