Commit f85cec93 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬
Browse files

Test the new mapper for gradient opacity support

Change-Id: I73158e89943e8f991b08c14d62e6df24887ef6de
parent 6b290237
......@@ -26,7 +26,6 @@ set (GenericVolumeCxxTests
TestMinIntensityRendering.cxx
TestProjectedTetrahedra.cxx
TestSmartVolumeMapper.cxx
TestSmartVolumeMapperGradientOpacity.cxx
TestSmartVolumeMapperWindowLevel.cxx
)
......@@ -37,6 +36,7 @@ set (OpenGLNew_OR_OpenGL2_CxxTests
TestGPURayCastClipping.cxx
#TestGPURayCastCropping1.cxx
#TestGPURayCastDataTypesMinIP1.cxx
TestGPURayCastGradientOpacity.cxx
TestGPURayCastVolumePolyData.cxx
TestGPURayCastVolumeRotation.cxx
TestGPURayCastVolumeScale.cxx
......@@ -51,7 +51,6 @@ endif()
# These tests are built for the OpenGL backend
set (VolumeOpenGLCxxTests
# TestGPUCastGradientOpacity.cxx
HomogeneousRayIntegration.cxx
LinearRayIntegration.cxx
PartialPreIntegration.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestGPURayCastGradientOpacity.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 "vtkGPUVolumeRayCastMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStructuredPointsReader.h"
#include "vtkSLCReader.h"
#include "vtkStructuredPoints.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include <vtkNew.h>
#include "vtkVolumeProperty.h"
#include "vtkVolume.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkRegressionTestImage.h"
#include "vtkTestUtilities.h"
#include "vtkTransform.h"
#include "vtkCullerCollection.h"
#include "vtkCuller.h"
#include "vtkFrustumCoverageCuller.h"
#include "vtkVolumeTextureMapper3D.h"
#include <vtkXMLImageDataReader.h>
#include <vtkFixedPointVolumeRayCastMapper.h>
//#define USE_TEXTURE_MAPPER_3D
int TestGPUCastGradientOpacity(int argc, char *argv[])
{
// Create the standard renderer, render window, and interactor.
vtkRenderer *ren1 = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
ren1->Delete();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renWin->Delete();
iren->SetDesiredUpdateRate(3);
// Create the reader for the data.
// This is the data that will be volume rendered.
vtkXMLImageDataReader *reader = vtkXMLImageDataReader::New();
char *cfname=vtkTestUtilities::ExpandDataFileName(argc,argv,"Data/Torso.vti");
std::cerr << "cfname " << cfname << std::endl;
reader->SetFileName(cfname);
delete[] cfname;
#if 0
vtkFixedPointVolumeRayCastMapper* volumeMapper= vtkFixedPointVolumeRayCastMapper::New();
#else
vtkGPUVolumeRayCastMapper* volumeMapper= vtkGPUVolumeRayCastMapper::New();
#endif
volumeMapper->SetInputConnection(reader->GetOutputPort());
vtkVolume *volume=vtkVolume::New();
volume->SetMapper(volumeMapper);
// Create gradient opacity function
vtkPiecewiseFunction* scalarFunction = vtkPiecewiseFunction::New();
scalarFunction->AddPoint(-680, 0.0);
scalarFunction->AddPoint(0, 0.03);
scalarFunction->AddPoint(300, 0.2);
vtkColorTransferFunction* colorFunction = vtkColorTransferFunction::New();
colorFunction->AddHSVPoint(-1024, 0.09, 0.33, 0.82);
colorFunction->AddHSVPoint(-330, 0.09, 0.33, 0.82);
colorFunction->AddRGBPoint(100, 1.0, 1.0, 1.0);
colorFunction->AddRGBPoint(3072, 1.0, 1.0, 1.0);
vtkPiecewiseFunction* gradientOpacityFunction = vtkPiecewiseFunction::New();
gradientOpacityFunction->AddPoint(50, 0.0);
gradientOpacityFunction->AddPoint(100, 1.0);
vtkVolumeProperty* volumeProperty = volume->GetProperty();
volumeProperty->SetGradientOpacity(0, gradientOpacityFunction);
volumeProperty->SetDisableGradientOpacity(0);
volumeProperty->SetScalarOpacity(scalarFunction);
volumeProperty->SetColor(0, colorFunction);
volumeProperty->SetAmbient(0, 0.0);
volumeProperty->SetDiffuse(0, 0.5);
volumeProperty->SetSpecular(0, 1.0);
volumeProperty->ShadeOn();
ren1->AddViewProp(volume);
ren1->SetBackground(0.1,0.2,0.4);
renWin->SetSize(1000, 1000);
renWin->Render();
ren1->ResetCamera();
renWin->Render();
int retVal = vtkTesting::Test(argc, argv, renWin, 75);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
// Clean up.
iren->Delete();
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestSmartVolumeMapperGradientOpacity.cxx
Module: TestGPURayCastGradientOpacity.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
......@@ -15,21 +15,22 @@
// This code volume renders the torso dataset and tests the gradient opacity
// function support for volume mappers
#include "vtkCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkMetaImageReader.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartVolumeMapper.h"
#include "vtkTestUtilities.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
int TestSmartVolumeMapperGradientOpacity(int argc, char* argv[])
int TestGPURayCastGradientOpacity(int argc, char* argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
......@@ -58,12 +59,14 @@ int TestSmartVolumeMapperGradientOpacity(int argc, char* argv[])
reader->Update();
delete [] fname;
vtkNew<vtkSmartVolumeMapper> mapper;
mapper->SetInputConnection(reader->GetOutputPort());
vtkNew<vtkGPUVolumeRayCastMapper> mapper1;
mapper1->SetInputConnection(reader->GetOutputPort());
vtkNew<vtkGPUVolumeRayCastMapper> mapper2;
mapper2->SetInputConnection(reader->GetOutputPort());
vtkNew<vtkColorTransferFunction> ctf;
ctf->AddHSVPoint(1.0, 0.095, 0.33, 0.82);
ctf->AddHSVPoint(53.3, 0, 1, 0.36);
ctf->AddHSVPoint(53.3, 0.04, 0.7, 0.63);
ctf->AddHSVPoint(256, 0.095, 0.33, 0.82);
vtkNew<vtkPiecewiseFunction> pwf;
......@@ -73,29 +76,37 @@ int TestSmartVolumeMapperGradientOpacity(int argc, char* argv[])
pwf->AddPoint(641.0, 1.0);
vtkNew<vtkPiecewiseFunction> gf;
gf->AddPoint(5, 0.0);
gf->AddPoint(10, 0.0);
gf->AddPoint(70, 1.0);
vtkNew<vtkVolumeProperty> volumeProperty1;
volumeProperty1->SetScalarOpacity(pwf.GetPointer());
volumeProperty1->SetColor(ctf.GetPointer());
volumeProperty1->SetDisableGradientOpacity(1);
volumeProperty1->ShadeOn();
vtkNew<vtkVolume> volume1;
volume1->SetMapper(mapper.GetPointer());
volume1->SetMapper(mapper1.GetPointer());
volume1->SetProperty(volumeProperty1.GetPointer());
ren1->AddVolume(volume1.GetPointer());
volume1->RotateX(-20);
ren1->ResetCamera();
ren1->GetActiveCamera()->Zoom(2.2);
vtkNew<vtkVolumeProperty> volumeProperty2;
volumeProperty2->SetScalarOpacity(pwf.GetPointer());
volumeProperty2->SetColor(ctf.GetPointer());
volumeProperty2->SetGradientOpacity(gf.GetPointer());
volumeProperty2->SetDisableGradientOpacity(0);
volumeProperty2->ShadeOn();
vtkNew<vtkVolume> volume2;
volume2->SetMapper(mapper.GetPointer());
volume2->SetMapper(mapper2.GetPointer());
volume2->SetProperty(volumeProperty2.GetPointer());
volume2->RotateX(-20);
ren2->AddVolume(volume2.GetPointer());
ren2->ResetCamera();
ren2->GetActiveCamera()->Zoom(2.2);
renWin->Render();
......@@ -105,5 +116,6 @@ int TestSmartVolumeMapperGradientOpacity(int argc, char* argv[])
iren->Start();
}
return !((retVal == vtkTesting::PASSED) || (retVal == vtkTesting::DO_INTERACTOR));
return !((retVal == vtkTesting::PASSED) ||
(retVal == vtkTesting::DO_INTERACTOR));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment