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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*=========================================================================
Program: Visualization Toolkit
Module: TestGPURayCastAverageIP.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.
=========================================================================*/
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkVolume16Reader.h"
#include "vtkImageData.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkColorTransferFunction.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkSmartPointer.h"
#include "vtkTesting.h"
int TestGPURayCastAverageIP(int argc, char *argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter");
vtkSmartPointer<vtkVolume16Reader> reader =
vtkSmartPointer<vtkVolume16Reader>::New();
reader->SetDataDimensions( 64, 64);
reader->SetDataByteOrderToLittleEndian();
reader->SetImageRange( 1, 93);
reader->SetDataSpacing( 3.2, 3.2, 1.5);
reader->SetFilePrefix( fname );
reader->SetDataMask( 0x7fff);
reader->Update();
delete[] fname;
vtkImageData *input=reader->GetOutput();
int dim[3];
double spacing[3], center[3], origin[3];
input->GetSpacing(spacing);
input->GetDimensions(dim);
input->GetCenter(center);
input->GetOrigin(origin);
vtkSmartPointer< vtkGPUVolumeRayCastMapper > mapper
= vtkSmartPointer< vtkGPUVolumeRayCastMapper >::New();
vtkSmartPointer< vtkVolume > volume
= vtkSmartPointer< vtkVolume >::New();
mapper->SetInputConnection(reader->GetOutputPort());
mapper->SetAutoAdjustSampleDistances(0);
mapper->SetBlendModeToAverageIntensity();
mapper->SetAverageIPScalarRange(600, 3926);
// assume the scalar field is a set of samples taken from a
// contiguous band-limited volumetric field.
// assume max frequency is present:
// min spacing divided by 2. Nyquist-Shannon theorem says so.
// sample distance could be bigger if we compute the actual max frequency
// in the data.
double distance=spacing[0];
if(distance>spacing[1])
{
distance=spacing[1];
}
if(distance>spacing[2])
{
distance=spacing[2];
}
distance=distance/2.0;
// This does not take the screen size of a cell into account.
// distance has to be smaller: min(nyquis,screensize)
mapper->SetSampleDistance(static_cast<float>(distance));
vtkSmartPointer< vtkColorTransferFunction > colorFun
= vtkSmartPointer< vtkColorTransferFunction >::New();
vtkSmartPointer< vtkPiecewiseFunction > opacityFun
= vtkSmartPointer< vtkPiecewiseFunction >::New();
// Create the property and attach the transfer functions
vtkSmartPointer< vtkVolumeProperty > property
= vtkSmartPointer< vtkVolumeProperty >::New();
property->SetIndependentComponents(true);
property->SetColor(colorFun);
property->SetScalarOpacity(opacityFun);
property->SetInterpolationTypeToLinear();
// connect up the volume to the property and the mapper
volume->SetProperty(property);
volume->SetMapper(mapper);
colorFun->AddRGBPoint( 0.0, 0.0 , 0.0 , 0.0);
colorFun->AddRGBPoint( 3926.0, 1 , 1 , 1);
opacityFun->AddPoint( 0.0, 0.0);
opacityFun->AddPoint( 3926.0, 1.0);
vtkSmartPointer< vtkRenderWindowInteractor > iren
= vtkSmartPointer< vtkRenderWindowInteractor >::New();
vtkSmartPointer< vtkRenderWindow > renWin
= vtkSmartPointer< vtkRenderWindow >::New();
renWin->SetSize(300,300);
iren->SetRenderWindow(renWin);
vtkSmartPointer< vtkRenderer > ren =
vtkSmartPointer< vtkRenderer >::New();
renWin->AddRenderer(ren);
renWin->Render();
if (!mapper->IsRenderSupported(renWin,property))
{
cout << "Required extensions not supported." << endl;
return EXIT_SUCCESS;
}
ren->AddViewProp(volume);
iren->Initialize();
ren->GetActiveCamera()->SetPosition(-484.648, 261.986, 144.52);
ren->GetActiveCamera()->SetViewUp(-0.078112, 0.176042, -0.981279);
ren->ResetCamera();
ren->GetActiveCamera()->Zoom(1.5);
renWin->Render();
return vtkTesting::InteractorEventLoop( argc, argv, iren );
}
|