Skip to content
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

XYZ clipping #133

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open

XYZ clipping #133

wants to merge 14 commits into from

Conversation

smallvalthoss
Copy link

CLOSES #132

Added functionality to be able to clip dimensionally into the body to only show, say, 60% of the x dimension while still showing the rest of the body

added csc.rsp to get compression and color working... idk why
Added shader that will allow clipping from specific dimensions
Added functionality to skip voxels if they lay outside the min/max clip dims
updated volumerenderedobject to account for clipping dimensions
added inspector to change the clipping dimensions min/max
final step, changed shader to account for clip shader
@smallvalthoss smallvalthoss changed the title Xyz clipping XYZ clipping Nov 17, 2022
Removed shader.find for clip shader, since it's merged with DirectVolumeRenderingShader now
Changed shader back to DirectVolumeRenderingShader
@smallvalthoss
Copy link
Author

Not sure, but thought this could be a useful addition.

@mlavik1
Copy link
Owner

mlavik1 commented Nov 19, 2022

Thanks! I'll have a look at it as soon as I'm done with this round of flu/cold/covid 😅 (Hopefully over the weekend)

@smallvalthoss
Copy link
Author

Thanks! I'll have a look at it as soon as I'm done with this round of flu/cold/covid 😅 (Hopefully over the weekend)

Oh no! Get better soon! What happened with the build fail?

@mlavik1
Copy link
Owner

mlavik1 commented Nov 21, 2022

Thanks! I'll have a look at it as soon as I'm done with this round of flu/cold/covid sweat_smile (Hopefully over the weekend)

Oh no! Get better soon! What happened with the build fail?

Thank you! :) I'm better now, so I will take a look at this PR in the evening!

And I think I just need to update the license for automatic builds (it failed to activate).

@smallvalthoss
Copy link
Author

the license for automati

Awesome, no worries. I'm also thinking of coding in something to stream real-time MRI, plus having the ability to play dataset "videos". Do you think that would be a useful addition?

@mlavik1
Copy link
Owner

mlavik1 commented Nov 21, 2022

@smallvalthoss That sounds really cool!
Which file format will you be using for that? Also DICOM?
And any thoughts on how you would implement that? Maybe use a dynamic 3D texture, that is updated at run-time?

And regarding your Pull Request:
This is a nice feature to have! Using 3 sliders for controlling the clipping along all 3 dimensions seems very convenient and user friendly. So thanks a lot of this contribution!

I did however realise that it effectively does the same as the already implemented "box cutout" cross section tool, so I think I'd prefer to not modify the main shader and instead:

  1. Move the 3 sliders out of the VolumeRenderedObjectCustomInspector and into a separate window (maybe VolumeClippingEditorWindow? Or can you think of a better name ?).
  2. Create a AxisAlignedCutout class that inherits from CrossSectionObject (and is not a MonoBehaviour btw!). We instantiate this object in our new VolumeClippingEditorWindow, add it to the CrossSectionManager, and update it every frame. When the window is closed we destroy it.
    Then we won't have to add more logic to the already expensive and complex shader :)
    Does that sound good?

I also noticed that you had changed spaces to tabs in the shader (that easily happens 😅 ) Are you using Visual Studio btw? Maybe I can add an .editorconfig file so that VS will use spaces automatically :)

Is it easier that I make these changes, or do you prefer to do them yourself?

@smallvalthoss
Copy link
Author

smallvalthoss commented Nov 21, 2022

@smallvalthoss That sounds really cool! Which file format will you be using for that? Also DICOM? And any thoughts on how you would implement that? Maybe use a dynamic 3D texture, that is updated at run-time?

And regarding your Pull Request: This is a nice feature to have! Using 3 sliders for controlling the clipping along all 3 dimensions seems very convenient and user friendly. So thanks a lot of this contribution!

I did however realise that it effectively does the same as the already implemented "box cutout" cross section tool, so I think I'd prefer to not modify the main shader and instead:

1. Move the 3 sliders out of the `VolumeRenderedObjectCustomInspector` and into a separate window (maybe `VolumeClippingEditorWindow`? Or can you think of a better name ?).

2. Create a `AxisAlignedCutout` class that inherits from `CrossSectionObject` (and is not a MonoBehaviour btw!). We instantiate this object in our new `VolumeClippingEditorWindow`, add it to the `CrossSectionManager`, and update it every frame. When the window is closed we destroy it.
   Then we won't have to add more logic to the already expensive and complex shader :)
   Does that sound good?

I also noticed that you had changed spaces to tabs in the shader (that easily happens 😅 ) Are you using Visual Studio btw? Maybe I can add an .editorconfig file so that VS will use spaces automatically :)

Is it easier that I make these changes, or do you prefer to do them yourself?

@mlavik1

Ohhhh I honestly hadn't known about the box cutout. This is great to know. I didn't want to change your stuff too much, just am a little new and thought that was the only way, haha. The intended use for what I wanted wasn't specifically in the editor. I wanted to add something so that in VR, I could cut away the dataset in a given axis aligned plane. So, I think what you mentioned would work, just slightly modified? I can definitely do what you mentioned for the editor however. It's great to learn best practices for OOP :).

As for the real-time dataset streaming. It is for a separate project. I am not extremely sure about the details just yet. It would likely be a byte array that likely gets passed to, as you say, a dynamic texture. We have a similar feature in a custom shader/loader script that only works with mhd files and raw files to import (might be a nice feature to have to import .mhd files to automatically get the dimensions/spacing). This loader has a byte array and creates a texture every x seconds and passes to the shader. Quite inefficient, but I haven't had much time to work on it.

The project that this is for is going to get real-time data from an MRI sensor to get it into unity.

@mlavik1
Copy link
Owner

mlavik1 commented Nov 22, 2022

Ah, right! It's probably best to make this as re-usable as possible then. So this is my suggestion:

Create new class:

public class AxisAlignedCutout : CrossSectionObject
{
   // Functions for setting the min and max clipping values for each axis.
   // These functions 
  public void SetAxisClipMin(Vector3 min);
  public void SetAxisClipMax(Vector3 max);
  // Functions from CrossSectionObject interface
  public CrossSectionType GetCrossSectionType(); // return CrossSectionType.BoxExclusive;
  public Matrix4x4 GetMatrix(); // Calculate matrix of box based on min/max clipping values (centre = (min+max)/2, scale = max-min)
}

Create new editor window for using 3 sliders to set clipping:

public class AxisClippingEditorWindow : EditorWindow
{
   private void OnEnable()
   {
      // Create AxisAlignedCutout object and add to CrossSectionManager
   }
   private void OnDisable()
   {
      // Remove AxisAlignedCutout from CrossSectionManager
   }
}

I suppose Matrix4x4.TRS can be used to calculate the matrix.

And then in your VR project, you can just do something similar as we do in the new AxisClippingEditorWindow class.
So will you be doing these changes then? If so, let me know if you have any questions!

Ok, that sounds interesting! Please let me know if you get somewhere with that project :)
And if it's a general feature that can be used by many others, it might be relevant to merge in here! We'll see when you know more about what you will do there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Dimensional Min/Max Clipping to DirectVolumeRendering
2 participants