Hi, I am working on writing a visualization function that applies a different color to a 3D rendering of a volume to only an area masked with tissue segment.
I am using split volume function to split segments into scalar volume nodes. The idea I am using so far is to use one of the split volume, apply a different preset to that split volume and use the color and component from split volume to set color on original volume scan. In example of screenshot below, I have the original volume and bone tissue split volume from the original scan with a different preset and I want to apply this preset to only bone covered areas of original volume.
Below is the code I have written so far and it is crashing as it calls the “setColor” to set different color transfer function to bone segment of original volume components. I wanted to ask if this is right way to do it or if there is any other efficient method to do something like this.
// -----------------------------------------------------------------------------------
void qSegmenterAppModuleWidget::testFunction() {
Q_D(qTestApp);
//volume nodes
vtkMRMLScalarVolumeNode* vnodeOriginal = vtkMRMLScalarVolumeNode::SafeDownCast(qSlicerApplication::application()->mrmlScene()->GetNodeByID("vtkMRMLScalarVolumeNode1"));
vtkMRMLScalarVolumeNode* vnodeSplit = vtkMRMLScalarVolumeNode::SafeDownCast(qSlicerApplication::application()->mrmlScene()->GetNodeByID("vtkMRMLScalarVolumeNode2"));
vtkSlicerVolumeRenderingLogic* rlo = vtkSlicerVolumeRenderingLogic::SafeDownCast(qSlicerApplication::application()->moduleLogic("VolumeRendering"));
//volume rendering display nodes
vtkMRMLVolumeRenderingDisplayNode* displayNode3DSplit = rlo->GetFirstVolumeRenderingDisplayNode(vnodeSplit);
vtkMRMLVolumeRenderingDisplayNode* displayNode3DOriginal = rlo->GetFirstVolumeRenderingDisplayNode(vnodeOriginal);
//volume property nodes
vtkMRMLVolumePropertyNode* volPropertyNodeSplit = displayNode3DSplit->GetVolumePropertyNode();
vtkMRMLVolumePropertyNode* volPropertyNodeOriginal = displayNode3DOriginal->GetVolumePropertyNode();
vtkDataArray* volArraySplit = vnodeSplit->GetImageData()->GetPointData()->GetScalars();
for (int i = 0; i < volArraySplit->GetNumberOfTuples(); i++)
{
if (volArraySplit->GetComponent(i, 0) > 0)
{
vtkColorTransferFunction* function = volPropertyNodeSplit->GetColor(volArraySplit->GetComponent(i, 0));
volPropertyNodeOriginal->SetColor(function, i);
}
}
}
