Skip to content

Commit

Permalink
tumor contouring - not complete
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshEhrlich committed Sep 17, 2021
1 parent fb12427 commit b92c7fb
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 3 deletions.
121 changes: 120 additions & 1 deletion LumpNav2/LumpNav2.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ def setup(self):
self.ui.brightnessSliderWidget.connect('valuesChanged(double, double)', self.onBrightnessSliderChanged)
self.ui.markPointsButton.connect('toggled(bool)', self.onMarkPointsClicked)
self.ui.threeDViewButton.connect('toggled(bool)', self.on3DViewsToggled)
self.ui.deleteLastFiducialButton('clicked()', self.onDeleteLastFiducialClicked)
self.ui.deleteAllFiducialsButton('clicked()', self.onDeleteAllFiducialsClicked)

self.pivotSamplingTimer.connect('timeout()', self.onPivotSamplingTimeout)

Expand Down Expand Up @@ -428,6 +430,14 @@ def onMarkPointsClicked(self, pushed):
# deactivate placement mode
interactionNode.SetCurrentInteractionMode(interactionNode.ViewTransform)

def onDeleteLastFiducialClicked(self):
logging.debug('onDeleteLastFiducialClicked')
self.logic.setDeleteLastFiducialClicked

def onDeleteAllFiducialsClicked(self):
logging.debug('onDeleteAllFiducialsClicked')
self.logic.setDeleteAllFiducialsClicked

def setCustomStyle(self, visible):
"""
Applies UI customization. Hide Slicer widgets and apply custom stylesheet.
Expand Down Expand Up @@ -1155,11 +1165,120 @@ def setAndObserveTumorMarkupsNode(self, tumorMarkups_Needle):
self.tumorMarkups_NeedleObserver = self.tumorMarkups_Needle.AddObserver(slicer.vtkMRMLMarkupsNode.PointModifiedEvent, self.onTumorMarkupsNodeModified)
else:
self.tumorMarkups_NeedleObserver = self.tumorMarkups_Needle.AddObserver(vtk.vtkCommand.ModifiedEvent , self.onTumorMarkupsNodeModified)

def setDeleteLastFiducialClicked(self):

if self.placeButton.isChecked() : # ensures point placed doesn't get logged twice
self.placeButton.click()
numberOfPoints = self.tumorMarkups_Needle.GetNumberOfFiducials()
deleted_coord = [0.0, 0.0, 0.0]
self.tumorMarkups_Needle.GetNthFiducialPosition(numberOfPoints-1,deleted_coord)
self.tumorMarkups_Needle.RemoveMarkup(numberOfPoints-1)
logging.info("Deleted last fiducial at %s", deleted_coord)
if numberOfPoints<=1:
self.ui.deleteLastFiducialButton.setEnabled(False)
self.ui.deleteAllFiducialsButton.setEnabled(False)
self.ui.deleteLastFiducialDuringNavigationButton.setEnabled(False)
self.ui.eraseButton.setEnabled(False)
self.ui.eraseButton.setChecked(False)
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(0.001)
self.tumorModel_Needle.SetPolyDataConnection(sphereSource.GetOutputPort())
self.tumorModel_Needle.Modified()

def setDeleteAllFiducialsClicked(self):
self.tumorMarkups_Needle.RemoveAllMarkups()
logging.info("Deleted all fiducials")
self.deleteLastFiducialButton.setEnabled(False)
self.deleteAllFiducialsButton.setEnabled(False)
self.deleteLastFiducialDuringNavigationButton.setEnabled(False)
self.eraseButton.setEnabled(False)
self.eraseButton.setChecked(False)
sphereSource = vtk.vtkSphereSource()
sphereSource.SetRadius(0.001)
self.tumorModel_Needle.SetPolyDataConnection(sphereSource.GetOutputPort())
self.tumorModel_Needle.Modified()

#TODO: Wrong class placement - should be in widget
def onTumorMarkupsNodeModified(self, observer, eventid):
logging.debug("onTumorMarkupsNodeModified")
self.createTumorFromMarkups()
self.logic.createTumorFromMarkups()

def createTumorFromMarkups(self):
logging.debug('createTumorFromMarkups')
#self.tumorMarkups_Needle.SetDisplayVisibility(0)
# Create polydata point set from markup points
points = vtk.vtkPoints()
cellArray = vtk.vtkCellArray()
numberOfPoints = self.tumorMarkups_Needle.GetNumberOfFiducials()

if numberOfPoints>0:
self.deleteLastFiducialButton.setEnabled(True)
self.deleteAllFiducialsButton.setEnabled(True)
self.deleteLastFiducialDuringNavigationButton.setEnabled(True)
self.eraseButton.setEnabled(True)

# Surface generation algorithms behave unpredictably when there are not enough points
# return if there are very few points
if numberOfPoints<1:
return

points.SetNumberOfPoints(numberOfPoints)
new_coord = [0.0, 0.0, 0.0]
for i in range(numberOfPoints):
self.tumorMarkups_Needle.GetNthFiducialPosition(i,new_coord)
points.SetPoint(i, new_coord)

if self.placeButton.isChecked() :
if self.loggingFlag == False :
self.loggingFlag = True
else :
self.loggingFlag = False
self.tumorMarkups_Needle.GetNthFiducialPosition(numberOfPoints-1,new_coord)
logging.info("Placed point at position: %s", new_coord)

cellArray.InsertNextCell(numberOfPoints)
for i in range(numberOfPoints):
cellArray.InsertCellPoint(i)

pointPolyData = vtk.vtkPolyData()
pointPolyData.SetLines(cellArray)
pointPolyData.SetPoints(points)

delaunay = vtk.vtkDelaunay3D()

logging.debug("use glyphs")
sphere = vtk.vtkCubeSource()
glyph = vtk.vtkGlyph3D()
glyph.SetInputData(pointPolyData)
glyph.SetSourceConnection(sphere.GetOutputPort())
#glyph.SetVectorModeToUseNormal()
#glyph.SetScaleModeToScaleByVector()
#glyph.SetScaleFactor(0.25)
delaunay.SetInputConnection(glyph.GetOutputPort())

surfaceFilter = vtk.vtkDataSetSurfaceFilter()
surfaceFilter.SetInputConnection(delaunay.GetOutputPort())

smoother = vtk.vtkButterflySubdivisionFilter()
smoother.SetInputConnection(surfaceFilter.GetOutputPort())
smoother.SetNumberOfSubdivisions(3)
smoother.Update()

delaunaySmooth = vtk.vtkDelaunay3D()
delaunaySmooth.SetInputData(smoother.GetOutput())
delaunaySmooth.Update()

smoothSurfaceFilter = vtk.vtkDataSetSurfaceFilter()
smoothSurfaceFilter.SetInputConnection(delaunaySmooth.GetOutputPort())

normals = vtk.vtkPolyDataNormals()
normals.SetInputConnection(smoothSurfaceFilter.GetOutputPort())
normals.SetFeatureAngle(100.0)

self.tumorModel_Needle.SetPolyDataConnection(normals.GetOutputPort())

self.tumorModel_Needle.Modified()

#
# LumpNav2Test
Expand Down
13 changes: 11 additions & 2 deletions LumpNav2/Resources/UI/LumpNav2.ui
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,26 @@
<layout class="QHBoxLayout" name="horizontalLayout_4"/>
</item>
<item>
<widget class="QPushButton" name="deleteAllPointsButton">
<widget class="QPushButton" name="deleteAllFiducialsButton">
<property name="text">
<string>Delete All Points</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteLastPointButton">
<widget class="QPushButton" name="deleteLastFiducialButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Delete Last Point</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
Expand Down

0 comments on commit b92c7fb

Please sign in to comment.