1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*=========================================================================
Program: Visualization Toolkit
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 checks the effects of changing sample distance on the GPURayCast
// volume mapper
#include "vtkCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkImageData.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRTAnalyticSource.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkXMLImageDataReader.h"
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
//----------------------------------------------------------------------------
int TestGPURayCastMapperSampleDistance(int argc, char* argv[])
{
vtkNew<vtkRTAnalyticSource> wavelet;
wavelet->SetWholeExtent(-127, 128,
-127, 128,
-127, 128);
wavelet->SetCenter(0.0, 0.0, 0.0);
vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
volumeMapper->SetInputConnection(wavelet->GetOutputPort());
volumeMapper->SetAutoAdjustSampleDistances(0);
volumeMapper->SetSampleDistance(20);
vtkNew<vtkVolumeProperty> volumeProperty;
vtkNew<vtkColorTransferFunction> ctf;
ctf->AddRGBPoint(37.3531, 0.2, 0.29, 1);
ctf->AddRGBPoint(157.091, 0.87, 0.87, 0.87);
ctf->AddRGBPoint(276.829, 0.7, 0.015, 0.15);
vtkNew<vtkPiecewiseFunction> pwf;
pwf->AddPoint(37.3531, 0.0);
pwf->AddPoint(276.829, 1.0);
volumeProperty->SetColor(ctf.GetPointer());
volumeProperty->SetScalarOpacity(pwf.GetPointer());
vtkNew<vtkVolume> volume;
volume->SetMapper(volumeMapper.GetPointer());
volume->SetProperty(volumeProperty.GetPointer());
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(300, 300);
renderWindow->Render(); // make sure we have an OpenGL context.
vtkNew<vtkRenderer> renderer;
renderer->AddVolume(volume.GetPointer());
renderer->ResetCamera();
renderWindow->AddRenderer(renderer.GetPointer());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.GetPointer());
int valid = volumeMapper->IsRenderSupported(renderWindow.GetPointer(),
volumeProperty.GetPointer());
int retVal;
if (valid)
{
renderWindow->Render();
iren->Initialize();
retVal = vtkRegressionTestImage( renderWindow.GetPointer() );
if( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
}
else
{
retVal = vtkTesting::PASSED;
cout << "Required extensions not supported." << endl;
}
return !((retVal == vtkTesting::PASSED) ||
(retVal == vtkTesting::DO_INTERACTOR));
}
|