Commit cb672fe7 authored by David E. DeMarle's avatar David E. DeMarle Committed by Kitware Robot

Merge topic 'ospray-volume'

de0f3af2 update comments
19e52d66 new baselines for ospray latest
0a19fc81 Fix new vtk style check
f7edf675 adding ospray init env arg
95909765 removing depth buffer realloc.  Adding back conditional composite
00e4278a crash fix
4ac1e161 protect against no input to prevent crash
0414e8b3 fix unused var comp warnings
...
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1895
parents 6d4ea59f de0f3af2
Pipeline #24919 running with stage
in 1203 minutes and 48 seconds
......@@ -3,16 +3,31 @@ include_directories(${OSPRAY_INCLUDE_DIRS})
set(Module_SRCS
vtkOSPRayActorNode.cxx
vtkOSPRayVolumeNode.cxx
vtkOSPRayCameraNode.cxx
vtkOSPRayCompositePolyDataMapper2Node.cxx
vtkOSPRayLightNode.cxx
vtkOSPRayPass.cxx
vtkOSPRayPolyDataMapperNode.cxx
vtkOSPRayVolumeMapper.cxx
vtkOSPRayVolumeMapperNode.cxx
vtkOSPRayRendererNode.cxx
vtkOSPRayViewNodeFactory.cxx
vtkOSPRayWindowNode.cxx
)
include(vtkObjectFactory)
vtk_add_override(vtkOSPRayVolumeInterface vtkOSPRayVolumeMapper)
vtk_object_factory_configure("${vtk_module_overrides}")
list(APPEND Module_SRCS
${CMAKE_CURRENT_BINARY_DIR}/${vtk-module}ObjectFactory.cxx)
set_source_files_properties(
${vtk-module}ObjectFactory.cxx
PROPERTIES
WRAP_EXCLUDE 1
WRAP_EXCLUDE_PYTHON 1
)
vtk_module_library(vtkRenderingOSPRay ${Module_SRCS})
target_link_libraries(${vtk-module} LINK_PUBLIC ${OSPRAY_LIBRARIES})
......@@ -21,3 +36,6 @@ target_link_libraries(${vtk-module} LINK_PUBLIC ${OSPRAY_LIBRARIES})
if(WIN32)
target_link_libraries(${vtk-module} LINK_PRIVATE Winmm)
endif()
include(vtkOpenGL)
vtk_opengl_link(${vtk-module})
vtk_add_test_cxx(${vtk-module}CxxTests tests
# Surface rendering tests
TestOSPRayCompositePolyDataMapper2.cxx,
TestOSPRayDynamicObject.cxx,
TestOSPRayDynamicScene.cxx,
......@@ -12,7 +13,21 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestOSPRayScalarBar.cxx
TestOSPRayTime.cxx,
TestOSPRayWindow.cxx
#TODO: interaction, pure offscreen, volumes
# Volume rendering tests
TestGPURayCastCameraInside.cxx
TestGPURayCastCellData.cxx
TestGPURayCastCameraInsideSmallSpacing.cxx
TestGPURayCastMapperBenchmark.cxx
TestGPURayCastMapperSampleDistance.cxx
TestGPURayCastPerspectiveParallel.cxx
#TestGPURayCastPositionalLights.cxx
TestGPURayCastVolumeLightKit.cxx
TestGPURayCastVolumePolyData.cxx
TestGPURayCastVolumeScale.cxx
TestGPURayCastVolumeUpdate.cxx
TestGPUVolumeRayCastMapper.cxx
TestOSPRayVolumeRenderer.cxx
TestSmartVolumeMapper.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests RENDERING_FACTORY
vtkOSPRayTestInteractor.cxx
......
This diff is collapsed.
/*=========================================================================
Program: Visualization Toolkit
Module: TestGPURayCastVolumeUpdate.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 volume tests whether updating the volume MTime updates the ,
// geometry in the volume mapper.
#include <vtkColorTransferFunction.h>
#include <vtkDataArray.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkImageData.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkNew.h>
#include <vtkOutlineFilter.h>
#include <vtkOSPRayPass.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPointDataToCellData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRegressionTestImage.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRTAnalyticSource.h>
#include <vtkSmartPointer.h>
#include <vtkTesting.h>
#include <vtkTestUtilities.h>
#include <vtkVolumeProperty.h>
#include <vtkXMLImageDataReader.h>
int TestGPURayCastCellData(int argc, char *argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
bool useOSP = true;
for (int i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-GL"))
{
cerr << "GL" << endl;
useOSP = false;
}
}
double scalarRange[2];
vtkNew<vtkActor> outlineActor;
vtkNew<vtkPolyDataMapper> outlineMapper;
vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
vtkNew<vtkXMLImageDataReader> reader;
char* volumeFile = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/vase_1comp.vti");
reader->SetFileName(volumeFile);
delete[] volumeFile;
vtkNew<vtkPointDataToCellData> pointToCell;
pointToCell->SetInputConnection(reader->GetOutputPort());
volumeMapper->SetInputConnection(pointToCell->GetOutputPort());
// Add outline filter
vtkNew<vtkOutlineFilter> outlineFilter;
outlineFilter->SetInputConnection(pointToCell->GetOutputPort());
outlineMapper->SetInputConnection(outlineFilter->GetOutputPort());
outlineActor->SetMapper(outlineMapper.GetPointer());
volumeMapper->GetInput()->GetScalarRange(scalarRange);
volumeMapper->SetSampleDistance(0.1);
volumeMapper->SetAutoAdjustSampleDistances(0);
volumeMapper->SetBlendModeToComposite();
vtkNew<vtkRenderWindow> renWin;
renWin->SetMultiSamples(0);
renWin->SetSize(400, 400);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin.GetPointer());
vtkNew<vtkInteractorStyleTrackballCamera> style;
iren->SetInteractorStyle(style.GetPointer());
renWin->Render(); // make sure we have an OpenGL context.
vtkNew<vtkRenderer> ren;
ren->SetBackground(0.2, 0.2, 0.5);
renWin->AddRenderer(ren.GetPointer());
vtkNew<vtkPiecewiseFunction> scalarOpacity;
scalarOpacity->AddPoint(50, 0.0);
scalarOpacity->AddPoint(75, 1.0);
vtkNew<vtkVolumeProperty> volumeProperty;
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
volumeProperty->SetScalarOpacity(scalarOpacity.GetPointer());
vtkNew<vtkColorTransferFunction> colorTransferFunction;
colorTransferFunction->RemoveAllPoints();
colorTransferFunction->AddRGBPoint(scalarRange[0], 0.6, 0.4, 0.1);
volumeProperty->SetColor(colorTransferFunction.GetPointer());
vtkNew<vtkVolume> volume;
volume->SetMapper(volumeMapper.GetPointer());
volume->SetProperty(volumeProperty.GetPointer());
ren->AddVolume(volume.GetPointer());
ren->AddActor(outlineActor.GetPointer());
ren->ResetCamera();
vtkNew<vtkOSPRayPass> osprayPass;
if (useOSP)
{
ren->SetPass(osprayPass.GetPointer());
}
renWin->Render();
ren->ResetCamera();
iren->Initialize();
int retVal = vtkRegressionTestImage( renWin.GetPointer() );
if( retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
/*=========================================================================
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 is intended to benchmark render times for the volumemappers
#include "vtkCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkFixedPointVolumeRayCastMapper.h"
#include "vtkImageData.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRTAnalyticSource.h"
#include "vtkTimerLog.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkOSPRayPass.h"
// TODO , tweak the sampling rate and number of samples to test if the
// baseline image would be matched (only visible differences on the edges)
//----------------------------------------------------------------------------
int TestGPURayCastMapperBenchmark(int argc, char* argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
bool useOSP = true;
bool useFP = false;
int EXT=128;
int RES=900;
for (int i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-GL"))
{
useOSP = false;
}
if (!strcmp(argv[i], "-FP"))
{
useFP = true;
}
if (!strcmp(argv[i], "-EXT"))
{
EXT = atoi(argv[i+1]);
}
if (!strcmp(argv[i], "-RES"))
{
RES = atoi(argv[i+1]);
}
}
vtkNew<vtkRTAnalyticSource> wavelet;
wavelet->SetWholeExtent(-(EXT-1), EXT,
-(EXT-1), EXT,
-(EXT-1), EXT);
wavelet->SetCenter(0.0, 0.0, 0.0);
vtkNew<vtkTimerLog> timer;
cerr << "Make data" << endl;
timer->StartTimer();
wavelet->Update();
timer->StopTimer();
double makeDataTime = timer->GetElapsedTime();
cerr << "Make data time: " << makeDataTime << endl;
vtkNew<vtkGPUVolumeRayCastMapper> gpu_volumeMapper;
vtkNew<vtkFixedPointVolumeRayCastMapper> cpu_volumeMapper;
vtkVolumeMapper *volumeMapper = gpu_volumeMapper.GetPointer();
if (useFP)
{
cerr << "USE FP" << endl;
volumeMapper = cpu_volumeMapper.GetPointer();
}
volumeMapper->SetInputConnection(wavelet->GetOutputPort());
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);
volume->SetProperty(volumeProperty.GetPointer());
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->SetSize(RES, RES);
renderWindow->Render(); // make sure we have an OpenGL context.
vtkNew<vtkRenderer> renderer;
renderer->AddVolume(volume.GetPointer());
renderer->ResetCamera();
renderWindow->AddRenderer(renderer.GetPointer());
// Attach OSPRay render pass
vtkNew<vtkOSPRayPass> osprayPass;
if (useOSP && !useFP)
{
renderer->SetPass(osprayPass.GetPointer());
}
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow.GetPointer());
int valid = true;
if (!useFP)
{
valid = gpu_volumeMapper->IsRenderSupported(renderWindow.GetPointer(),
volumeProperty.GetPointer());
}
int retVal;
if (valid)
{
timer->StartTimer();
renderWindow->Render();
timer->StopTimer();
double firstRender = timer->GetElapsedTime();
cerr << "First Render Time: " << firstRender << endl;
int numRenders = 20;
for (int i = 0; i < numRenders; ++i)
{
renderer->GetActiveCamera()->Azimuth(1);
renderer->GetActiveCamera()->Elevation(1);
renderWindow->Render();
}
timer->StartTimer();
numRenders = 100;
for (int i = 0; i < numRenders; ++i)
{
renderer->GetActiveCamera()->Azimuth(1);
renderer->GetActiveCamera()->Elevation(1);
renderer->GetActiveCamera()->OrthogonalizeViewUp();
renderWindow->Render();
}
timer->StopTimer();
double elapsed = timer->GetElapsedTime();
cerr << "Interactive Render Time: " << elapsed / numRenders << endl;
renderer->GetActiveCamera()->SetPosition(0,0,1);
renderer->GetActiveCamera()->SetFocalPoint(0,0,0);
renderer->GetActiveCamera()->SetViewUp(0,1,0);
renderer->ResetCamera();
renderWindow->SetSize(300, 300);
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));
}
/*=========================================================================
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"
#include "vtkOSPRayPass.h"
//----------------------------------------------------------------------------
int TestGPURayCastMapperSampleDistance(int argc, char* argv[])
{
bool useOSP = true;
for (int i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-GL"))
{
cerr << "GL" << endl;
useOSP = false;
}
}
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());
// Attach OSPRay render pass
vtkNew<vtkOSPRayPass> osprayPass;
if (useOSP)
{
renderer->SetPass(osprayPass.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));
}
/*=========================================================================
Program: Visualization Toolkit
Module: TestGPURayCastAdditive.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 switch from perspective to parallel projection.
// This test volume renders a synthetic dataset with unsigned char values,
// with the composite method.
#include "vtkNew.h"
#include "vtkSphere.h"
#include "vtkSampleFunction.h"
#include "vtkGPUVolumeRayCastMapper.h"
#include "vtkTestUtilities.h"
#include "vtkColorTransferFunction.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkVolumeProperty.h"
#include "vtkCamera.h"
#include "vtkRegressionTestImage.h"
#include "vtkImageShiftScale.h"
#include "vtkImageData.h"
#include "vtkPointData.h"
#include "vtkDataArray.h"
#include "vtkOSPRayPass.h"
int TestGPURayCastPerspectiveParallel(int argc,
char *argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
bool useOSP = true;
for (int i = 0; i < argc; i++)
{
if (!strcmp(argv[i], "-GL"))
{
cerr << "GL" << endl;
useOSP = false;
}
}
// Create a spherical implicit function.
vtkSphere *shape=vtkSphere::New();
shape->SetRadius(0.1);
shape->SetCenter(0.0,0.0,0.0);
vtkSampleFunction *source=vtkSampleFunction::New();
source->SetImplicitFunction(shape);
shape->Delete();
source->SetOutputScalarTypeToDouble();
source->SetSampleDimensions(127,127,127); // intentional NPOT dimensions.
source->SetModelBounds(-1.0,1.0,-1.0,1.0,-1.0,1.0);
source->SetCapping(false);
source->SetComputeNormals(false);
source->SetScalarArrayName("values");
source->Update();
vtkDataArray *a=source->GetOutput()->GetPointData()->GetScalars("values");
double range[2];
a->GetRange(range);
vtkImageShiftScale *t=vtkImageShiftScale::New();
t->SetInputConnection(source->GetOutputPort());
source->Delete();
t->SetShift(-range[0]);
double magnitude=range[1]-range[0];
if(magnitude==0.0)
{
magnitude=1.0;
}
t->SetScale(255.0/magnitude);
t->SetOutputScalarTypeToUnsignedChar();
t->Update();
vtkRenderWindow *renWin=vtkRenderWindow::New();
vtkRenderer *ren1=vtkRenderer::New();
ren1->SetBackground(0.1,0.4,0.2);
renWin->AddRenderer(ren1);
ren1->Delete();
renWin->SetSize(301,300); // intentional odd and NPOT width/height
vtkRenderWindowInteractor *iren=vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
renWin->Delete();
renWin->Render(); // make sure we have an OpenGL context.
vtkGPUVolumeRayCastMapper *volumeMapper;
vtkVolumeProperty *volumeProperty;
vtkVolume *volume;
volumeMapper=vtkGPUVolumeRayCastMapper::New();
volumeMapper->SetBlendModeToComposite();
volumeMapper->SetInputConnection(
t->GetOutputPort());
volumeProperty=vtkVolumeProperty::New();
volumeProperty->ShadeOff();
volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
vtkPiecewiseFunction *compositeOpacity = vtkPiecewiseFunction::New();
compositeOpacity->AddPoint(0.0,0.0);
compositeOpacity->AddPoint(80.0,1.0);
compositeOpacity->AddPoint(80.1,0.0);
compositeOpacity->AddPoint(255.0,0.0);
volumeProperty->SetScalarOpacity(compositeOpacity);
vtkColorTransferFunction *color=vtkColorTransferFunction::New();
color->AddRGBPoint(0.0 ,0.0,0.0,1.0);
color->AddRGBPoint(40.0 ,1.0,0.0,0.0);
color->AddRGBPoint(255.0,1.0,1.0,1.0);
volumeProperty->SetColor(color);
color->Delete();
volume=vtkVolume::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
ren1->AddViewProp(volume);
// Attach OSPRay render pass
vtkNew<vtkOSPRayPass> osprayPass;
if (useOSP)
{
ren1->SetPass(osprayPass.GetPointer());
}
int valid=volumeMapper->IsRenderSupported(renWin,volumeProperty);
int retVal;
if(valid)
{
ren1->ResetCamera();
// Render composite. Default camera is perpective.
renWin->Render();
// Switch to parallel
vtkCamera *c=ren1->GetActiveCamera();
c->SetParallelProjection(true);
renWin->Render();
retVal = vtkTesting::Test(argc, argv, renWin, 75);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{