I am rendering a volume; And displaying its coronal plane,transverse plane,sigittal plane. Now i outlined a contour via the VTK tools, the picture like this picture 1, the code is as flows:
m_pContourWidget = vtkSmartPointer< vtkContourWidget >::New();
m_pContourWidget->SetInteractor(m_AxialInteractor);
contourRepresentation =vtkSmartPointer<vtkOrientedGlyphContourRepresentation>::New();
m_pContourWidget->SetPriority(0.9);
contourRepresentation->GetLinesProperty()->SetColor(0, 1, 0);
m_pContourWidget->SetRepresentation(contourRepresentation);
m_pContourWidget->ManagesCursorOn();
m_pContourWidget->On();
But Now I want to color or fill the contour by vtkPolyDataToImageStencil,vtkImageStencilToImage,vtkImageStencil and so on. make it like picture 2.
I have tried using the following code but failed:
vtkSmartPointer tempImageData = vtkSmartPointer::New();
int dim[3];
m_pReader->GetOutput()->GetDimensions(dim);
double o[3];
m_pReader->GetOutput()->GetOrigin(o);
double spacing[3];
m_pReader->GetOutput()->GetSpacing(spacing);
tempImageData->SetSpacing(spacing);
tempImageData->SetDimensions(dim);
tempImageData->SetOrigin(0, 0, 0);
tempImageData->AllocateScalars(VTK_UNSIGNED_CHAR, 1);
int slice = myInteractorStyle1->GetSlice();
tempImageData->SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, slice);
// fill the image with foreground voxels:
unsigned char inval = 255;
unsigned char outval = 0;
vtkIdType count = tempImageData->GetNumberOfPoints();
for (vtkIdType i = 0; i < count; ++i)
{
tempImageData->GetPointData()->GetScalars()->SetTuple1(i, inval);
}
polyDataToImageStencil = vtkSmartPointer<vtkPolyDataToImageStencil>::New();
polyDataToImageStencil->SetTolerance(0);
polyDataToImageStencil->SetInputData(m_pContourWidget->GetContourRepresentation()->GetContourRepresentationAsPolyData());
slice = myInteractorStyle1->GetSlice();
polyDataToImageStencil->SetOutputOrigin(tempImageData->GetOrigin());
polyDataToImageStencil->SetOutputSpacing(tempImageData->GetSpacing());
polyDataToImageStencil->SetOutputWholeExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, slice);
polyDataToImageStencil->Update();
imageStencilToImage = vtkSmartPointer<vtkImageStencilToImage>::New();
imageStencilToImage->SetInputConnection(polyDataToImageStencil->GetOutputPort());
imageStencilToImage->SetInsideValue(1);
imageStencilToImage->Update();
//view the imageStencilToImage
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(imageStencilToImage->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
vtkSmartPointer<vtkRenderer> render = vtkSmartPointer<vtkRenderer>::New();
render->AddActor(actor);
vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(render);
renWin->SetSize(400, 400);
vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkInteractorStyleTrackballCamera> style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
iren->SetInteractorStyle(style);
iren->Initialize();
iren->Start();