|
| 1 | +/*========================================================================= |
| 2 | +
|
| 3 | + Program: Visualization Toolkit |
| 4 | + Module: TestGPURayCastVolumeOrientation.cxx |
| 5 | +
|
| 6 | + Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen |
| 7 | + All rights reserved. |
| 8 | + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. |
| 9 | +
|
| 10 | + This software is distributed WITHOUT ANY WARRANTY; without even |
| 11 | + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 12 | + PURPOSE. See the above copyright notice for more information. |
| 13 | +
|
| 14 | +=========================================================================*/ |
| 15 | +// This test volume renders a dataset that has a transform that |
| 16 | +// doesn't preserve orientation. |
| 17 | + |
| 18 | +#include <vtkColorTransferFunction.h> |
| 19 | +#include <vtkGPUVolumeRayCastMapper.h> |
| 20 | +#include <vtkImageData.h> |
| 21 | +#include <vtkInteractorStyleTrackballCamera.h> |
| 22 | +#include <vtkNew.h> |
| 23 | +#include <vtkOutlineFilter.h> |
| 24 | +#include <vtkPiecewiseFunction.h> |
| 25 | +#include <vtkPolyDataMapper.h> |
| 26 | +#include <vtkRegressionTestImage.h> |
| 27 | +#include <vtkRenderWindow.h> |
| 28 | +#include <vtkRenderWindowInteractor.h> |
| 29 | +#include <vtkRenderer.h> |
| 30 | +#include <vtkSmartPointer.h> |
| 31 | +#include <vtkTestUtilities.h> |
| 32 | +#include <vtkVolumeProperty.h> |
| 33 | +#include <vtkXMLImageDataReader.h> |
| 34 | + |
| 35 | +int TestGPURayCastVolumeOrientation(int argc, char *argv[]) |
| 36 | +{ |
| 37 | + cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl; |
| 38 | + double scalarRange[2]; |
| 39 | + |
| 40 | + vtkNew<vtkActor> outlineActor; |
| 41 | + vtkNew<vtkPolyDataMapper> outlineMapper; |
| 42 | + vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper; |
| 43 | + |
| 44 | + vtkNew<vtkXMLImageDataReader> reader; |
| 45 | + const char* volumeFile = vtkTestUtilities::ExpandDataFileName( |
| 46 | + argc, argv, "Data/vase_1comp.vti"); |
| 47 | + reader->SetFileName(volumeFile); |
| 48 | + volumeMapper->SetInputConnection(reader->GetOutputPort()); |
| 49 | + delete[] volumeFile; |
| 50 | + |
| 51 | + // Add outline filter |
| 52 | + vtkNew<vtkOutlineFilter> outlineFilter; |
| 53 | + outlineFilter->SetInputConnection(reader->GetOutputPort()); |
| 54 | + outlineMapper->SetInputConnection(outlineFilter->GetOutputPort()); |
| 55 | + outlineActor->SetMapper(outlineMapper.GetPointer()); |
| 56 | + |
| 57 | + volumeMapper->GetInput()->GetScalarRange(scalarRange); |
| 58 | + volumeMapper->SetSampleDistance(0.1); |
| 59 | + volumeMapper->SetAutoAdjustSampleDistances(0); |
| 60 | + volumeMapper->SetBlendModeToComposite(); |
| 61 | + |
| 62 | + vtkNew<vtkRenderWindow> renWin; |
| 63 | + renWin->SetMultiSamples(0); |
| 64 | + renWin->SetSize(400, 400); |
| 65 | + |
| 66 | + vtkNew<vtkRenderWindowInteractor> iren; |
| 67 | + iren->SetRenderWindow(renWin.GetPointer()); |
| 68 | + vtkNew<vtkInteractorStyleTrackballCamera> style; |
| 69 | + iren->SetInteractorStyle(style.GetPointer()); |
| 70 | + |
| 71 | + renWin->Render(); // make sure we have an OpenGL context. |
| 72 | + |
| 73 | + vtkNew<vtkRenderer> ren; |
| 74 | + ren->SetBackground(0.2, 0.2, 0.5); |
| 75 | + renWin->AddRenderer(ren.GetPointer()); |
| 76 | + |
| 77 | + vtkNew<vtkPiecewiseFunction> scalarOpacity; |
| 78 | + scalarOpacity->AddPoint(50, 0.0); |
| 79 | + scalarOpacity->AddPoint(75, 1.0); |
| 80 | + |
| 81 | + vtkNew<vtkVolumeProperty> volumeProperty; |
| 82 | + volumeProperty->ShadeOn(); |
| 83 | + volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION); |
| 84 | + volumeProperty->SetScalarOpacity(scalarOpacity.GetPointer()); |
| 85 | + |
| 86 | + vtkNew<vtkColorTransferFunction> colorTransferFunction; |
| 87 | + colorTransferFunction->RemoveAllPoints(); |
| 88 | + colorTransferFunction->AddRGBPoint(scalarRange[0], 0.6, 0.4, 0.1); |
| 89 | + volumeProperty->SetColor(colorTransferFunction.GetPointer()); |
| 90 | + |
| 91 | + vtkNew<vtkVolume> volume; |
| 92 | + volume->SetMapper(volumeMapper.GetPointer()); |
| 93 | + volume->SetProperty(volumeProperty.GetPointer()); |
| 94 | + |
| 95 | + // Set a transform that doesn't preserve orientation |
| 96 | + volume->SetScale(1.0, -1.0, 1.0); |
| 97 | + outlineActor->SetScale(1.0, -1.0, 1.0); |
| 98 | + |
| 99 | + ren->AddViewProp(volume.GetPointer()); |
| 100 | + ren->AddActor(outlineActor.GetPointer()); |
| 101 | + ren->ResetCamera(); |
| 102 | + |
| 103 | + int valid = volumeMapper->IsRenderSupported(renWin.GetPointer(), |
| 104 | + volumeProperty.GetPointer()); |
| 105 | + int retVal; |
| 106 | + if (valid) |
| 107 | + { |
| 108 | + renWin->Render(); |
| 109 | + |
| 110 | + iren->Initialize(); |
| 111 | + retVal = vtkRegressionTestImage(renWin.GetPointer()); |
| 112 | + if (retVal == vtkRegressionTester::DO_INTERACTOR) |
| 113 | + { |
| 114 | + iren->Start(); |
| 115 | + } |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + retVal = vtkTesting::PASSED; |
| 120 | + cout << "Required extensions not supported" << endl; |
| 121 | + } |
| 122 | + |
| 123 | + return !retVal; |
| 124 | +} |
0 commit comments