Display a segmentation in color over the segmented volume - loadable module

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Display a segmentation in color over the segmented volume - loadable module

Lebreton Sandra
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<vtkImageThreshold> 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.

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ
Reply | Threaded
Open this post in threaded view
|

Re: Display a segmentation in color over the segmented volume - loadable module

lasso2

Hi Sandra,

 

We moved discussions to https://discourse.slicer.org. Could you please post your question there (in Developer category)?

 

thanks,

Andras

 

 

From: [hidden email]
Sent: Wednesday, May 10, 2017 4:59 AM
To: [hidden email]
Subject: [slicer-devel] Display a segmentation in color over the segmented volume - loadable module

 

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<vtkImageThreshold> 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.

_______________________________________________
slicer-devel mailing list
[hidden email]
http://massmail.spl.harvard.edu/mailman/listinfo/slicer-devel
To unsubscribe: send email to [hidden email] with unsubscribe as the subject
http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/FAQ