Operating system: MAC
Slicer version: 4.6.2
Hi everyone,
I am currently writting my own loadable module and I would need to segment a volume (for example by thresholding it) and display the segmentation in color over the segmented volume, as it is done in the “Segmentations” module (“Segment Editor”, the threshold effect).
To do so, I read the code of this loadable module (mostly qSlicerSegmentEditorAbstractEffect.cxx and SegmentEditorThresholdEffect.py) and I managed to extract some of the things I would need but I’m missing things and I’m a bit lost in the two files mentionned.
Thanks for any answer that could help me understand how to do this.
Here is what I have for the moment:
///////////////////////////////////////////////////////////////////////////
vtkMRMLScalarVolumeNode* volumeNode = … ;
vtkImageData* image = … ;
vtkNew thresholdFilter;
thresholdFilter->SetInValue(255);
thresholdFilter->SetOutValue(0);
thresholdFilter->SetInputData(image);
thresholdFilter->ThresholdBetween(min,max);
qSlicerLayoutManager* layoutManager = qSlicerApplication::application()->layoutManager();
foreach (QString sliceViewName, layoutManager->sliceViewNames())
{
qMRMLSliceWidget* sliceWidget = layoutManager->sliceWidget(sliceViewName);
vtkNew<vtkLookupTable> lookupTable;
vtkNew<vtkImageMapToRGBA> colorMapper;
vtkNew<vtkImageMapper> mapper;
vtkNew<vtkActor2D> actor;
lookupTable->SetRampToLinear();
lookupTable->SetNumberOfTableValues(2);
lookupTable->SetTableRange(0,255);
lookupTable->SetTableValue(0,0,0,0,0);
lookupTable->SetTableValue(1,0.5,0.7,0.5,0.8);
colorMapper->SetOutputFormatToRGBA();
colorMapper->SetLookupTable(lookupTable.GetPointer());
actor->VisibilityOn();
actor->SetMapper(mapper.GetPointer());
mapper->SetColorWindow(255);
mapper->SetColorLevel(128);
colorMapper->SetInputConnection(thresholdFilter->GetOutputPort());
mapper->SetInputConnection(colorMapper->GetOutputPort());
vtkRenderWindow* renderWindow = sliceWidget->sliceView()->renderWindow();
vtkRenderer* renderer = vtkRenderer::SafeDownCast(renderWindow->GetRenderers()->GetItemAsObject(0));
renderer->AddActor2D(actor.GetPointer());
sliceWidget->sliceView()->scheduleRender();
}
vtkSlicerApplicationLogic* slicerAppLogic = this->module()->appLogic();
vtkMRMLSelectionNode* selectionNode = slicerAppLogic->GetSelectionNode();
selectionNode->SetReferenceActiveVolumeID(volumeNode->GetID());
slicerAppLogic->PropagateVolumeSelection();
/////////////////////////////////////////////////////////////////////////////////////////////////
Regards,
Sandra.