/*========================================================================= Program: Visualization Toolkit Module: TestGPURayCastVolumePolyData.cxx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ // This test covers additive method. // This test volume renders a synthetic dataset with unsigned char values, // with the additive method. #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /// Tests volume clipping when intermixed with geometry. int TestGPURayCastClippingPolyData(int argc, char* argv[]) { double scalarRange[2]; vtkNew outlineActor; vtkNew outlineMapper; vtkNew volumeMapper; vtkNew reader; const char* volumeFile = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/vase_1comp.vti"); reader->SetFileName(volumeFile); volumeMapper->SetInputConnection(reader->GetOutputPort()); delete[] volumeFile; /// Outline filter vtkNew outlineFilter; outlineFilter->SetInputConnection(reader->GetOutputPort()); outlineMapper->SetInputConnection(outlineFilter->GetOutputPort()); outlineActor->SetMapper(outlineMapper); volumeMapper->GetInput()->GetScalarRange(scalarRange); volumeMapper->SetSampleDistance(0.1); volumeMapper->SetAutoAdjustSampleDistances(0); volumeMapper->SetBlendModeToComposite(); vtkNew renWin; renWin->SetMultiSamples(0); vtkNew ren; renWin->AddRenderer(ren); renWin->SetSize(400, 400); ren->SetBackground(0.2, 0.2, 0.5); vtkNew iren; vtkNew style; iren->SetInteractorStyle(style); iren->SetRenderWindow(renWin); vtkNew scalarOpacity; scalarOpacity->AddPoint(50, 0.0); scalarOpacity->AddPoint(75, 1.0); vtkNew volumeProperty; volumeProperty->ShadeOn(); volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION); volumeProperty->SetScalarOpacity(scalarOpacity); vtkSmartPointer colorTransferFunction = volumeProperty->GetRGBTransferFunction(0); colorTransferFunction->RemoveAllPoints(); colorTransferFunction->AddRGBPoint(scalarRange[0], 0.6, 0.4, 0.1); vtkSmartPointer volume = vtkSmartPointer::New(); volume->SetMapper(volumeMapper); volume->SetProperty(volumeProperty); /// Sphere int dims[3]; double spacing[3], sphereCenter[3], origin[3]; reader->Update(); vtkSmartPointer im = reader->GetOutput(); im->GetDimensions(dims); im->GetOrigin(origin); im->GetSpacing(spacing); sphereCenter[0] = origin[0] + spacing[0] * dims[0] / 2.5; sphereCenter[1] = origin[1] + spacing[1] * dims[1] / 2.5; sphereCenter[2] = origin[2] + spacing[2] * dims[2] / 2.775; vtkNew sphereSource; sphereSource->SetCenter(sphereCenter); sphereSource->SetRadius(dims[1] / 4.0); sphereSource->SetPhiResolution(40); sphereSource->SetThetaResolution(40); vtkNew sphereMapper; vtkNew sphereActor; sphereMapper->SetInputConnection(sphereSource->GetOutputPort()); sphereActor->SetMapper(sphereMapper); ren->AddViewProp(volume); ren->AddActor(outlineActor); ren->AddActor(sphereActor); /// Clipping planes vtkNew clipPlane1; clipPlane1->SetOrigin(sphereCenter[0], sphereCenter[1], sphereCenter[2]); clipPlane1->SetNormal(1.0, 0.0, 0.0); vtkNew clipPlane2; clipPlane2->SetOrigin(sphereCenter[0], sphereCenter[1], sphereCenter[2]); clipPlane2->SetNormal(0.2, -0.2, 0.0); vtkNew clipPlaneCollection; clipPlaneCollection->AddItem(clipPlane1); clipPlaneCollection->AddItem(clipPlane2); volumeMapper->SetClippingPlanes(clipPlaneCollection); ren->ResetCamera(); ren->GetActiveCamera()->Azimuth(-30); ren->GetActiveCamera()->Elevation(25); ren->GetActiveCamera()->OrthogonalizeViewUp(); renWin->Render(); iren->Initialize(); int retVal = vtkRegressionTestImage(renWin); if (retVal == vtkRegressionTester::DO_INTERACTOR) { iren->Start(); } return !retVal; }