[vtkusers] Rendering multiple objects in one render window
WangQ
wangq1979 at outlook.com
Mon Dec 28 09:06:23 EST 2015
Hello there,
I am quite new to VTK, and I am trying to render a volume and an isosurface in one render window using viewpoint. I follow the example of http://www.vtk.org/Wiki/VTK/Examples/Cxx/Visualization/StructuredDataTypes but no luck so far. Here is the code I wrote. Could anyone help to figure out where is wrong?
Would appreciate any help.
// Create an image data vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New(); // load data here
// Define viewport ranges double upperViewport[4] = {0.0, 0.0, 1.0, 0.5}; double centerViewport[4] = {0.0, 0.5, 1.0, 1.0};
// create render window vtkSmartPointer<vtkRenderWindow> renWin = vtkSmartPointer<vtkRenderWindow>::New(); vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New(); renWin->SetSize(1200, 600); renWin->Render(); renWin->SetWindowName("Volume Clipping"); iren->SetRenderWindow(renWin);
/**************************************************************** create volume renderer to render stacked tomograms ****************************************************************/ vtkSmartPointer<vtkSmartVolumeMapper> volumeMapper = vtkSmartPointer<vtkSmartVolumeMapper>::New(); volumeMapper->SetBlendModeToComposite(); // composite first volumeMapper->SetInputData(imageData); volumeMapper->SetInterpolationModeToLinear(); volumeMapper->SetRequestedRenderModeToGPU();
vtkSmartPointer<vtkVolumeProperty> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New(); volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION); volumeProperty->ShadeOff();
vtkSmartPointer<vtkColorTransferFunction> color = vtkSmartPointer<vtkColorTransferFunction>::New(); //color->SetColorSpaceToRGB(); color->AddRGBPoint(0.0, 0.0, 0.0, 1.0); color->AddRGBPoint(0.25, 0.0, 1.0, 1.0); color->AddRGBPoint(0.5, 0.0, 1.0, 0.0); color->AddRGBPoint(0.75, 1.0, 1.0, 0.0); color->AddRGBPoint(1.0, 1.0, 0.0, 0.0); color->SetScaleToLinear(); volumeProperty->SetColor(color);
vtkSmartPointer<vtkPiecewiseFunction> compositeOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New(); compositeOpacity->AddPoint(-1.0, 0.0); compositeOpacity->AddPoint(0.0, 0.0); compositeOpacity->AddPoint(0.39, 0.4); compositeOpacity->AddPoint(0.4, 0.8); compositeOpacity->AddPoint(1.0, 1.0); volumeProperty->SetScalarOpacity(compositeOpacity); vtkSmartPointer<vtkVolume> volume = vtkSmartPointer<vtkVolume>::New(); volume->SetMapper(volumeMapper); volume->SetProperty(volumeProperty);
vtkSmartPointer<vtkRenderer> volumeRenderer = vtkSmartPointer<vtkRenderer>::New(); renWin->AddRenderer(volumeRenderer); volumeRenderer->SetViewPoint(upperViewport); // position volume rendering at upper part volumeRenderer->SetBackground(0.4, 0.5, 0.6);
vtkSmartPointer<vtkScalarBarWidget> scalarWidget = vtkSmartPointer<vtkScalarBarWidget>::New(); scalarWidget->SetInteractor(iren); scalarWidget->GetScalarBarActor()->SetTitle("Concentration"); scalarWidget->GetScalarBarActor()->SetLookupTable(color); scalarWidget->GetScalarBarActor()->SetOrientationToHorizontal(); scalarWidget->RepositionableOn(); scalarWidget->ResizableOn(); scalarWidget->EnabledOn();
vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New(); axes->SetTotalLength(50.0, 50.0, 50.0); /**********************************End of volume renderer*********************************/
/**************************************************************** create contour renderer to contouring stacked tomograms ****************************************************************/ // Create an isosurface vtkSmartPointer<vtkContourFilter> contourFilter = vtkSmartPointer<vtkContourFilter>::New(); contourFilter->SetInputData(imageData); const double isovalue = 0.6; contourFilter->GenerateValues(1, isovalue, isovalue); // (numContours, rangeStart, rangeEnd) // Map the contours to graphical primitives vtkSmartPointer<vtkPolyDataMapper> contourMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); contourMapper->SetInputData(contourFilter->GetOutput());
// Create an actor for the contours vtkSmartPointer<vtkActor> contourActor = vtkSmartPointer<vtkActor>::New(); contourActor->SetMapper(contourMapper);
// Create the outline vtkSmartPointer<vtkOutlineFilter> outlineFilter = vtkSmartPointer<vtkOutlineFilter>::New(); outlineFilter->SetInputData(imageData); vtkSmartPointer<vtkPolyDataMapper> outlineMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); outlineMapper->SetInputData(outlineFilter->GetOutput()); vtkSmartPointer<vtkActor> outlineActor = vtkSmartPointer<vtkActor>::New(); outlineActor->SetMapper(outlineMapper);
// Visualize vtkSmartPointer<vtkRenderer> contourRenderer = vtkSmartPointer<vtkRenderer>::New(); renWin->AddRenderer(contourRenderer); contourRenderer->SetViewPoint(centerViewport); contourRenderer->SetBackground(0.5, .4, .6); /**********************************End of contour renderer*********************************/
volumeRenderer->AddActor(volume); volumeRenderer->AddActor(axes);
contourRenderer->AddActor(contourActor); contourRenderer->AddActor(outlineActor);
contourRenderer->SetActiveCamera(volumeRenderer->GetActiveCamera()); volumeRenderer->ResetCamera(); contourRenderer->ResetCamera();
// Render composite. In default mode. For coverage. renWin->Render(); iren->Start();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20151228/8a36b771/attachment.html>
More information about the vtkusers
mailing list