Skip to content

Commit

Permalink
ENH: Generating orientation marker style directly from shader
Browse files Browse the repository at this point in the history
  • Loading branch information
RuoyanMeng authored and RafaelPalomar committed Apr 17, 2023
1 parent dcbefc3 commit b6dbd4a
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 205 deletions.
22 changes: 3 additions & 19 deletions Liver/Liver.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ def setup(self):
self.resectionsWidget.DistanceMapNodeComboBox.connect('currentNodeChanged(vtkMRMLNode*)', self.onResectionDistanceMapNodeChanged)
self.resectionsWidget.DistanceMapNodeComboBox.addAttribute('vtkMRMLScalarVolumeNode', 'DistanceMap', 'True')
self.resectionsWidget.DistanceMapNodeComboBox.addAttribute('vtkMRMLScalarVolumeNode', 'Computed', 'True')
self.resectionsWidget.MarkerStyleNodeComboBox.connect('currentNodeChanged(vtkMRMLNode*)', self.onMarkerStyleNodeChanged)
self.resectionsWidget.MarkerStyleNodeComboBox.addAttribute('vtkMRMLScalarVolumeNode', 'DistanceMap', 'True')
self.resectionsWidget.MarkerStyleNodeComboBox.addAttribute('vtkMRMLScalarVolumeNode', 'Computed', 'True')
self.resectionsWidget.LiverSegmentSelectorWidget.connect('currentSegmentChanged(QString)', self.onResectionLiverModelNodeChanged)
self.resectionsWidget.LiverSegmentSelectorWidget.connect('currentNodeChanged(vtkMRMLNode*)', self.onResectionLiverSegmentationNodeChanged)
self.resectionsWidget.ResectionColorPickerButton.connect('colorChanged(QColor)', self.onResectionColorChanged)
Expand Down Expand Up @@ -366,14 +363,9 @@ def onResectionNodeChanged(self):
self.resectionsWidget.LiverSegmentSelectorWidget.blockSignals(False)

self.resectionsWidget.DistanceMapNodeComboBox.blockSignals(True)
self.resectionsWidget.DistanceMapNodeComboBox.setCurrentNode(
activeResectionNode.GetDistanceMapVolumeNode())
self.resectionsWidget.DistanceMapNodeComboBox.setCurrentNode(activeResectionNode.GetDistanceMapVolumeNode())
self.resectionsWidget.DistanceMapNodeComboBox.blockSignals(False)

self.resectionsWidget.MarkerStyleNodeComboBox.blockSignals(True)
self.resectionsWidget.MarkerStyleNodeComboBox.setCurrentNode(activeResectionNode.GetMarkerStyleVolumeNode())
self.resectionsWidget.MarkerStyleNodeComboBox.blockSignals(False)

self.resectogramWidget.VascularSegmentsNodeComboBox.blockSignals(True)
self.resectogramWidget.VascularSegmentsNodeComboBox.setCurrentNode(activeResectionNode.GetVascularSegmentsVolumeNode())
self.resectogramWidget.VascularSegmentsNodeComboBox.blockSignals(False)
Expand Down Expand Up @@ -487,8 +479,8 @@ def onResectionNodeChanged(self):

def onResectionDistanceMapNodeChanged(self):
"""
This function is called when the resection distance map selector changes
"""
This function is called when the resection distance map selector changes
"""
if self._currentResectionNode is not None:
distanceMapNode = self.resectionsWidget.DistanceMapNodeComboBox.currentNode()
self._currentResectionNode.SetTextureNumComps(self.numComps)
Expand All @@ -498,14 +490,6 @@ def onResectionDistanceMapNodeChanged(self):
self.resectionsWidget.ResectionPreviewGroupBox.setEnabled(distanceMapNode is not None)
self.resectogramWidget.Resection2DCheckBox.setEnabled(distanceMapNode is not None)

def onMarkerStyleNodeChanged(self):
"""
This function is called when the Marker Style selector changes
"""
if self._currentResectionNode is not None:
MarkerStyleNode = self.resectionsWidget.MarkerStyleNodeComboBox.currentNode()
self._currentResectionNode.SetMarkerStyleVolumeNode(MarkerStyleNode)

def onResectionLiverSegmentationNodeChanged(self):
self.resectionsWidget.LiverSegmentSelectorWidget.blockSignals(True)
self.resectionsWidget.LiverSegmentSelectorWidget.setCurrentSegmentID('')
Expand Down
51 changes: 0 additions & 51 deletions Liver/Resources/UI/ResectionsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -285,41 +285,6 @@
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="MarkerStyleLabel">
<property name="text">
<string>Marker Style:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="qMRMLNodeComboBox" name="MarkerStyleNodeComboBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="nodeTypes">
<stringlist>
<string>vtkMRMLVectorVolumeNode</string>
</stringlist>
</property>
<property name="noneEnabled">
<bool>true</bool>
</property>
<property name="addEnabled">
<bool>false</bool>
</property>
<property name="removeEnabled">
<bool>false</bool>
</property>
<property name="selectNodeUponCreation">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="ResectionVisualizationGroupBox">
<property name="enabled">
Expand Down Expand Up @@ -892,22 +857,6 @@
</hint>
</hints>
</connection>
<connection>
<sender>ResectionWidget</sender>
<signal>mrmlSceneChanged(vtkMRMLScene*)</signal>
<receiver>MarkerStyleNodeComboBox</receiver>
<slot>setMRMLScene(vtkMRMLScene*)</slot>
<hints>
<hint type="sourcelabel">
<x>293</x>
<y>365</y>
</hint>
<hint type="destinationlabel">
<x>376</x>
<y>167</y>
</hint>
</hints>
</connection>
<connection>
<sender>ResectionOpacityDoubleSlider</sender>
<signal>valueChanged(double)</signal>
Expand Down
9 changes: 0 additions & 9 deletions LiverMarkups/MRML/vtkMRMLMarkupsBezierSurfaceNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ class VTK_SLICER_LIVERMARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsBezierSurfaceNode
vtkMRMLScalarVolumeNode* GetVascularSegmentsVolumeNode() const
{return this->VascularSegments;}

/// Set the Marker Style
void SetMarkerStyleVolumeNode(vtkMRMLScalarVolumeNode* volumeNode)
{this->MarkerStyle = volumeNode; this->Modified();}

/// Get the Marker Style
vtkMRMLScalarVolumeNode* GetMarkerStyleVolumeNode() const
{return this->MarkerStyle;}

/// Get the distance map margin
vtkGetMacro(ResectionMargin, double);

Expand Down Expand Up @@ -142,7 +134,6 @@ class VTK_SLICER_LIVERMARKUPS_MODULE_MRML_EXPORT vtkMRMLMarkupsBezierSurfaceNode
vtkWeakPointer<vtkMRMLModelNode> Target;
vtkWeakPointer<vtkMRMLScalarVolumeNode> DistanceMap;
vtkWeakPointer<vtkMRMLScalarVolumeNode> VascularSegments;
vtkWeakPointer<vtkMRMLScalarVolumeNode> MarkerStyle;
double ResectionMargin;
double UncertaintyMargin;
double HepaticContourThickness;
Expand Down
Binary file added LiverMarkups/Resources/textureB10W.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 19 additions & 26 deletions LiverMarkups/VTKWidgets/vtkOpenGLBezierResectionPolyDataMapper.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class vtkOpenGLBezierResectionPolyDataMapper::vtkInternal
bool ResectionClipOut;
unsigned int GridDivisions;
float GridThicknessFactor;
unsigned int MarkerStyleAvailable;
};

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -175,7 +174,6 @@ void vtkOpenGLBezierResectionPolyDataMapper::ReplaceShaderValues(
"uniform int uResectionClipOut;\n"
"uniform int uInterpolatedMargins;\n"
"uniform int uGridDivisions;\n"
"uniform int uMarkerStyleAvailable;\n"
"uniform float uGridThickness;\n"
"in vec4 vertexWCVSOutput;\n"
"in vec2 uvCoordsOutput;\n"
Expand Down Expand Up @@ -217,17 +215,30 @@ void vtkOpenGLBezierResectionPolyDataMapper::ReplaceShaderValues(
" ambientColor = vec3(0.0);\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" else if(uMarkerStyleAvailable == 1 && marker.a != 0){\n"
" ambientColor = vec3(marker.r,marker.g,marker.b);\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" else{\n"
" ambientColor = uResectionColor;\n"
" diffuseColor = vec3(0.6);\n"
" }\n"
"}\n"

);
" vec3 topLeftColor = vec3(0.0, 1.0, 0.067);\n"
" vec3 topRightColor = vec3(1.0, 0.48, 0.0);\n"
" vec3 bottomLeftColor = vec3(0.66666666667, 0.00392156863, 1.0);\n"
" vec3 bottomRightColor = vec3(0.34117647058, 0.78039215686, 0.79607843137);\n"
" float borderSize = 0.025;\n"
" if ( (uvCoordsOutput.y > 0.5 && uvCoordsOutput.x < borderSize) || (uvCoordsOutput.y > 1.0 - borderSize && uvCoordsOutput.x < 0.5) ) {\n"
" ambientColor = bottomLeftColor;\n"
" diffuseColor = vec3(0.0);\n"
" } else if ( (uvCoordsOutput.x < 0.5 && uvCoordsOutput.y < borderSize) || (uvCoordsOutput.x < borderSize && uvCoordsOutput.y < 0.5) ) {\n"
" ambientColor = topLeftColor;\n"
" diffuseColor = vec3(0.0);\n"
" } else if ( (uvCoordsOutput.y > 0.5 && uvCoordsOutput.x > 1.0 - borderSize) || (uvCoordsOutput.y > 1.0 - borderSize && uvCoordsOutput.x > 0.5) ) {\n"
" ambientColor = bottomRightColor;\n"
" diffuseColor = vec3(0.0);\n"
" } else if ((uvCoordsOutput.x > 0.5 && uvCoordsOutput.y < borderSize) || (uvCoordsOutput.x > 1.0 - borderSize && uvCoordsOutput.y < 0.5) ) {\n"
" ambientColor = topRightColor;\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
"}\n");

vtkShaderProgram::Substitute(
FSSource, "//VTK::Light::Impl",
Expand Down Expand Up @@ -346,11 +357,6 @@ void vtkOpenGLBezierResectionPolyDataMapper::SetMapperShaderParameters(
cellBO.Program->SetUniformf("uGridThickness", this->Impl->GridThicknessFactor);
}

if (cellBO.Program->IsUniformUsed("uMarkerStyleAvailable"))
{
cellBO.Program->SetUniformi("uMarkerStyleAvailable", this->Impl->MarkerStyleAvailable);
}

Superclass::SetMapperShaderParameters(cellBO, ren, actor);
}

Expand Down Expand Up @@ -513,19 +519,6 @@ void vtkOpenGLBezierResectionPolyDataMapper::SetUncertaintyMarginColor(float red
this->Modified();
}

//------------------------------------------------------------------------------
//unsigned int const* vtkOpenGLBezierResectionPolyDataMapper::GetMarkerStyleAvailable() const
//{
// return this->Impl->MarkerStyleAvailable;
//}

//------------------------------------------------------------------------------
void vtkOpenGLBezierResectionPolyDataMapper::SetMarkerStyleAvailable(unsigned int status)
{
this->Impl->MarkerStyleAvailable = status;
this->Modified();
}

//------------------------------------------------------------------------------
float const* vtkOpenGLBezierResectionPolyDataMapper::GetResectionColor() const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ class VTK_SLICER_LIVERMARKUPS_MODULE_VTKWIDGETS_EXPORT vtkOpenGLBezierResectionP
/// Set the thickness factor for the grid
void SetGridThicknessFactor(float thicknessFactor);

/// unsigned int GetMarkerStyleAvailable() const;
void SetMarkerStyleAvailable(unsigned int status);

protected:
vtkOpenGLBezierResectionPolyDataMapper();
Expand Down
74 changes: 37 additions & 37 deletions LiverMarkups/VTKWidgets/vtkOpenGLResection2DPolyDataMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ class vtkOpenGLResection2DPolyDataMapper::vtkInternal
float PortalContourColor[3];
float HepaticContourColor[3];
int TextureNumComps;
unsigned int MarkerStyleAvailable;
float MatRatio[2];
};

Expand Down Expand Up @@ -199,7 +198,8 @@ void vtkOpenGLResection2DPolyDataMapper::ReplaceShaderValues(
"uniform vec3 uUncertaintyMarginColor;\n"
"uniform vec3 uResectionColor;\n"
"uniform int uInterpolatedMargins;\n"
"uniform int uMarkerStyleAvailable;\n"
"uniform vec3 uResectionGridColor;\n"
"uniform int uGridDivisions;\n"
"uniform float uGridThickness;\n"
"in vec2 uvCoordsOutput;\n"
"in vec4 vertexWCVSOutputBS;\n"
Expand Down Expand Up @@ -258,7 +258,7 @@ void vtkOpenGLResection2DPolyDataMapper::ReplaceShaderValues(
"}\n"
"else{\n"
" ambientColor = uResectionColor;\n"
" diffuseColor = vec3(0.6);\n"
" diffuseColor = vec3(0.0);\n"
"}\n"

"if(dist[0] < lowMargin){\n"
Expand All @@ -278,25 +278,43 @@ void vtkOpenGLResection2DPolyDataMapper::ReplaceShaderValues(
" }\n"
"}\n"


"if(uTextureNumComps > 2){\n"
" if( abs(dist[1])<0.5 ){\n"
" ambientColor = vec3(0.0,0.0,0.0);\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" else if( abs(dist[2])<uHepaticContourThickness && dist[1]<10){\n"
" ambientColor = uHepaticContourColor;\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" else if( abs(dist[3])<uPortalContourThickness && dist[1]<10){\n"
" ambientColor = uPortalContourColor;\n"
" diffuseColor = vec3(0.0);\n"
"if(tan(uvCoordsOutput.x*M_PI*uGridDivisions)>10.0-uGridThickness || tan(uvCoordsOutput.y*M_PI*uGridDivisions)>10.0-uGridThickness){\n"
" ambientColor = uResectionGridColor;\n"
" diffuseColor = vec3(0.0);\n"
"}\n"
"else{\n"
" if(uTextureNumComps > 2){\n"
" if( abs(dist[1])<0.5 ){\n"
" ambientColor = vec3(0.0,0.0,0.0);\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" else if( abs(dist[2])<uHepaticContourThickness && dist[1]<10){\n"
" ambientColor = uHepaticContourColor;\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" else if( abs(dist[3])<uPortalContourThickness && dist[1]<10){\n"
" ambientColor = uPortalContourColor;\n"
" diffuseColor = vec3(0.0);\n"
" }\n"
" }\n"
"}\n"


"if(uMarkerStyleAvailable == 1 && marker.a != 0){\n"
" ambientColor = vec3(marker.r,marker.g,marker.b);\n"
"vec3 topLeftColor = vec3(0.0, 1.0, 0.067);\n"
"vec3 topRightColor = vec3(1.0, 0.48, 0.0);\n"
"vec3 bottomLeftColor = vec3(0.66666666667, 0.00392156863, 1.0);\n"
"vec3 bottomRightColor = vec3(0.34117647058, 0.78039215686, 0.79607843137);\n"
"float borderSize = 0.025;\n"
"if ( (uvCoordsOutput.y > 0.5 && uvCoordsOutput.x < borderSize) || (uvCoordsOutput.y > 1.0 - borderSize && uvCoordsOutput.x < 0.5) ) {\n"
" ambientColor = bottomLeftColor;\n"
" diffuseColor = vec3(0.0);\n"
"} else if ( (uvCoordsOutput.x < 0.5 && uvCoordsOutput.y < borderSize) || (uvCoordsOutput.x < borderSize && uvCoordsOutput.y < 0.5) ) {\n"
" ambientColor = topLeftColor;\n"
" diffuseColor = vec3(0.0);\n"
"} else if ( (uvCoordsOutput.y > 0.5 && uvCoordsOutput.x > 1.0 - borderSize) || (uvCoordsOutput.y > 1.0 - borderSize && uvCoordsOutput.x > 0.5) ) {\n"
" ambientColor = bottomRightColor;\n"
" diffuseColor = vec3(0.0);\n"
"} else if ((uvCoordsOutput.x > 0.5 && uvCoordsOutput.y < borderSize) || (uvCoordsOutput.x > 1.0 - borderSize && uvCoordsOutput.y < 0.5) ) {\n"
" ambientColor = topRightColor;\n"
" diffuseColor = vec3(0.0);\n"
"}\n"
);
Expand Down Expand Up @@ -460,11 +478,6 @@ void vtkOpenGLResection2DPolyDataMapper::SetMapperShaderParameters(
cellBO.Program->SetUniformf("uHepaticContourThickness", this->Impl->HepaticContourThickness);
}

if (cellBO.Program->IsUniformUsed("uMarkerStyleAvailable"))
{
cellBO.Program->SetUniformi("uMarkerStyleAvailable", this->Impl->MarkerStyleAvailable);
}

if (cellBO.Program->IsUniformUsed("uMatRatio"))
{
cellBO.Program->SetUniform2f("uMatRatio", this->Impl->MatRatio);
Expand Down Expand Up @@ -829,19 +842,6 @@ void vtkOpenGLResection2DPolyDataMapper::SetTextureNumComps(int numComps)
this->Modified();
}

//------------------------------------------------------------------------------
//unsigned int const* vtkOpenGLBezierResectionPolyDataMapper::GetMarkerStyleAvailable() const
//{
// return this->Impl->MarkerStyleAvailable;
//}

//------------------------------------------------------------------------------
void vtkOpenGLResection2DPolyDataMapper::SetMarkerStyleAvailable(unsigned int status)
{
this->Impl->MarkerStyleAvailable = status;
this->Modified();
}

//------------------------------------------------------------------------------
float const* vtkOpenGLResection2DPolyDataMapper::GetMatRatio() const
{
Expand Down
3 changes: 0 additions & 3 deletions LiverMarkups/VTKWidgets/vtkOpenGLResection2DPolyDataMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ class VTK_SLICER_LIVERMARKUPS_MODULE_VTKWIDGETS_EXPORT vtkOpenGLResection2DPolyD
int GetTextureNumComps() const;
void SetTextureNumComps(int numComps);

// unsigned int GetMarkerStyleAvailable() const;
void SetMarkerStyleAvailable(unsigned int status);

// Get and Set Ratio
void SetMatRatio(float matR[2]);
float const* GetMatRatio() const;
Expand Down
Loading

0 comments on commit b6dbd4a

Please sign in to comment.