Difference between revisions of "Documentation/Nightly/Developers/FAQ/MRML"

From Slicer Wiki
Jump to: navigation, search
m
 
(4 intermediate revisions by 2 users not shown)
Line 8: Line 8:
  
 
* Generic pattern  
 
* Generic pattern  
<code>
+
<pre>
vtkNew<vtkMRML???Node> nodeToAdd;
+
vtkNew<vtkMRML???Node> nodeToAdd;
...
+
...
mrmlScene->AddNode(nodeToAdd.GetPointer());
+
mrmlScene->AddNode(nodeToAdd.GetPointer());
</code>
+
</pre>
  
 
* Add a polydata to the scene
 
* Add a polydata to the scene
<code>
+
<pre>
vtkNew<vtkMRMLModelNode> modelNode;
+
vtkNew<vtkMRMLModelNode> modelNode;
modelNode->SetPolyData(polyData);
+
modelNode->SetPolyData(polyData);
mrmlScene->AddNode(modelNode.GetPointer());
+
mrmlScene->AddNode(modelNode.GetPointer());
</code>
+
</pre>
  
 
* Load a polyData from file
 
* Load a polyData from file
<code>
+
<pre>
vtkSlicerModelsLogic* modelsLogic = ...;
+
vtkSlicerModelsLogic* modelsLogic = ...;
//modelsLogic->SetMRMLScene(mrmlScene);
+
//modelsLogic->SetMRMLScene(mrmlScene);
modelsLogic->AddModel(polyDataFileName);
+
modelsLogic->AddModel(polyDataFileName);
</code>
+
</pre>
  
 
== What to do if you get 'No LookupTable was set but number of components in input doesn't match OutputFormat' when loading a MRML scene ? ==
 
== What to do if you get 'No LookupTable was set but number of components in input doesn't match OutputFormat' when loading a MRML scene ? ==
Line 45: Line 45:
  
 
Make sure the <code>colorNodeRef</code> attribute is set on each <code>VolumeDisplay</code> node.
 
Make sure the <code>colorNodeRef</code> attribute is set on each <code>VolumeDisplay</code> node.
 
  
 
== How to change the volumes in the 2D views ? ==
 
== How to change the volumes in the 2D views ? ==
  
<code>
+
<pre>
appLogic = slicer.app.applicationLogic()
+
appLogic = slicer.app.applicationLogic()
selectionNode = appLogic.GetSelectionNode()
+
selectionNode = appLogic.GetSelectionNode()
selectionNode.SetReferenceActiveVolumeID(bg)
+
selectionNode.SetReferenceActiveVolumeID(bg)
selectionNode.SetReferenceSecondaryVolumeID(fg)
+
selectionNode.SetReferenceSecondaryVolumeID(fg)
appLogic.PropagateVolumeSelection()
+
appLogic.PropagateVolumeSelection()
</code>
+
</pre>
  
 
Source: https://github.com/fedorov/ChangeTrackerPy/blob/master/Wizard/Helper.py#L82
 
Source: https://github.com/fedorov/ChangeTrackerPy/blob/master/Wizard/Helper.py#L82
 +
 +
== How to know the min/max offset of a slice view ? ==
 +
<pre>
 +
vtkMRMLSliceNode* redSliceNode = vtkMRMLSliceNode::SafeDownCast( this->GetMRMLScene()->GetNodeByID( "vtkMRMLSliceNodeRed" ));
 +
vtkMRMLSliceLogic* sliceLogic = this->GetMRMLApplicationLogic()->GetSliceLogic( redSliceNode );
 +
 +
double sliceBounds[6] = {0, -1, 0, -1, 0, -1};
 +
sliceLogic->GetLowestVolumeSliceBounds(sliceBounds);
 +
double min = sliceBounds[4];
 +
double max = sliceBounds[5];
 +
</pre>
 +
 +
Source: https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Widgets/qMRMLSliceControllerWidget.cxx#L1267-L1276

Latest revision as of 22:14, 22 September 2017

Home < Documentation < Nightly < Developers < FAQ < MRML


For the latest Slicer documentation, visit the read-the-docs.


MRML

How to add a MRML node into the scene ?

  • Generic pattern
vtkNew<vtkMRML???Node> nodeToAdd;
...
mrmlScene->AddNode(nodeToAdd.GetPointer());
  • Add a polydata to the scene
vtkNew<vtkMRMLModelNode> modelNode;
modelNode->SetPolyData(polyData);
mrmlScene->AddNode(modelNode.GetPointer());
  • Load a polyData from file
vtkSlicerModelsLogic* modelsLogic = ...;
//modelsLogic->SetMRMLScene(mrmlScene);
modelsLogic->AddModel(polyDataFileName);

What to do if you get 'No LookupTable was set but number of components in input doesn't match OutputFormat' when loading a MRML scene ?

If you get the following error messages:

ERROR: In /path/to/VTK/Imaging/vtkImageMapToColors.cxx, line 153
vtkImageMapToColors (0x268f190): RequestInformation: No LookupTable was set but number of components in input doesn't match OutputFormat, therefore input can't be passed through!

ERROR: In /path/to/VTK/Imaging/vtkImageExtractComponents.cxx, line 239
vtkImageExtractComponents (0x26947e0): Execute: Component 1 is not in input.

ERROR: In /path/to/VTK/Imaging/vtkImageExtractComponents.cxx, line 239
vtkImageExtractComponents (0x26947e0): Execute: Component 1 is not in input.

[...]

Make sure the colorNodeRef attribute is set on each VolumeDisplay node.

How to change the volumes in the 2D views ?

appLogic = slicer.app.applicationLogic()
selectionNode = appLogic.GetSelectionNode()
selectionNode.SetReferenceActiveVolumeID(bg)
selectionNode.SetReferenceSecondaryVolumeID(fg)
appLogic.PropagateVolumeSelection()

Source: https://github.com/fedorov/ChangeTrackerPy/blob/master/Wizard/Helper.py#L82

How to know the min/max offset of a slice view ?

vtkMRMLSliceNode* redSliceNode = vtkMRMLSliceNode::SafeDownCast( this->GetMRMLScene()->GetNodeByID( "vtkMRMLSliceNodeRed" ));
vtkMRMLSliceLogic* sliceLogic = this->GetMRMLApplicationLogic()->GetSliceLogic( redSliceNode );

double sliceBounds[6] = {0, -1, 0, -1, 0, -1};
sliceLogic->GetLowestVolumeSliceBounds(sliceBounds);
double min = sliceBounds[4];
double max = sliceBounds[5];

Source: https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Widgets/qMRMLSliceControllerWidget.cxx#L1267-L1276