Skip to content

Commit

Permalink
ENH: switch to simpler, better sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
pieper committed May 22, 2023
1 parent 0717bdb commit cf0525b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,53 +316,26 @@
execXHR.responseType = 'json';
execXHR.onload = onLoadFn;
execXHR.send(`#python
needData = False
try:
slicer.util.getNode('vtkMRMLSegmentationNode*')
except slicer.util.MRMLNodeNotFoundException:
needData = True
try:
slicer.util.getNode('vtkMRMLModelNode*')
except slicer.util.MRMLNodeNotFoundException:
needData = True
if needData:
import SampleData
#volumeNode = SampleData.SampleDataLogic().downloadCTACardio() # takes longer to load
volumeNode = SampleData.SampleDataLogic().downloadCTChest()
slicer.modules.volumes.logic().CenterVolume(volumeNode)
slicer.util.setSliceViewerLayers(background=volumeNode, fit=True)
segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentationNode.CreateDefaultDisplayNodes()
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(volumeNode)
segmentationNode.GetSegmentation().AddEmptySegment("Bright things")
segmentEditorWidget = slicer.qMRMLSegmentEditorWidget()
segmentEditorWidget.setMRMLScene(slicer.mrmlScene)
segmentEditorNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentEditorNode")
segmentEditorWidget.setMRMLSegmentEditorNode(segmentEditorNode)
segmentEditorWidget.setSegmentationNode(segmentationNode)
segmentEditorWidget.setSourceVolumeNode(volumeNode)
segmentEditorWidget.setActiveEffectByName("Threshold")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("MinimumThreshold", 400)
effect.self().onApply()
segmentEditorWidget.setActiveEffectByName("Islands")
effect = segmentEditorWidget.activeEffect()
effect.setParameter("Operation", 'SPLIT_ISLANDS_TO_SEGMENTS')
effect.self().onApply()
segmentationNode.CreateClosedSurfaceRepresentation()
import random
for index in range(20):
coord = lambda : -100. + 200 * random.random()
point = [coord(), coord(), coord()]
slicer.modules.markups.logic().AddControlPoint(*point)
nodePatterns = ["vtkMRMLSegmentationNode*", "vtkMRMLMarkups*Node*"]
needDemoData = True
for nodePattern in nodePatterns:
try:
slicer.util.getNode(nodePattern)
needDemoData = False
print(f"Found some {nodePattern}")
except slicer.util.MRMLNodeNotFoundException:
pass
if needDemoData:
filePath = f"{slicer.util.tempDirectory()}/ctacardio-totalseg-models-2023-05-22-Scene.mrb"
print(f"Downloading to {filePath}")
demoDataURL = "https://github.com/pieper/SlicerWeb/releases/download/v0.1/ctacardio-totalseg-models-2023-05-22-Scene.mrb"
slicer.util.downloadFile(demoDataURL, filePath)
slicer.util.loadScene(filePath)
import os
os.remove(filePath)
else:
print("Showing existing data from scene")
`);
}

Expand Down
4 changes: 2 additions & 2 deletions Modules/Scripted/WebServer/Resources/docroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ <h3>WebGL Slicer ThreeD View Cube</h3>
<h3>ThreeJS example</h3>
</a>
<p>Example of using Slicer data with Three JS.</p>
<p>This example uses the /slicer/threeDGraphics endpoint to get a glTF representation of the threeD view. If you have a segmentations or models in Slicer it will load your current threeD view, otherwise it will create a default scene with some segmentations and markups fiducials.</p>
<p>The data is loaded in <a href='https://threejs.org'>threejs</a> demo scene letting you play with a glowing neon light like rendering of your scene. This experiment shows an option for highlighting selected objects in a complex 3D scene. The neon light effect is one of a wide array of different rendering options available in threejs.</p>
<p>This example uses the /slicer/threeDGraphics endpoint to get a glTF representation of the threeD view. If you have a segmentations or models in Slicer it will load your current threeD view, otherwise it will download a scene with sample models.</p>
<p>The data is loaded in <a href='https://threejs.org'>threejs</a> demo scene letting you play with a glowing neon light like rendering of your scene. This experiment shows an option for highlighting selected objects in a complex 3D scene. Random models will be highlighted and you can toggle them by clicking. The neon light effect is one of a wide array of different rendering options available in threejs.</p>
<p>The javascript source code for this demo shows how to access the threeDGraphics endpoint and how to populate the mrml scene using the exec endpoint to send python code from javascript.</p>

<p>Depending on scene complexity this may take a few moments to load.</p>
Expand Down

0 comments on commit cf0525b

Please sign in to comment.