Commit b2368075 authored by Allison Vacanti's avatar Allison Vacanti Committed by Kitware Robot

Merge topic 'slicer4600_volume_jitter_woes'

70cc8c0a Fix volume jitter enable/disable.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Ken Martin's avatarKen Martin <ken.martin@kitware.com>
Merge-request: !4688
parents a6fc9e52 70cc8c0a
......@@ -11,6 +11,7 @@ set (VolumeOpenGL2CxxTests
TestGPURayCastJittering.cxx
TestGPURayCastTextureStreaming.cxx
TestGPURayCastTextureStreamingMask.cxx
TestGPURayCastToggleJittering.cxx
TestGPURayCastUserShader.cxx
TestGPURayCastUserShader2.cxx
)
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestGPURayCastJittering.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.
=========================================================================*/
/** Tests stochastic jittering by rendering a volume exhibiting aliasing due
* to a big sampling distance (low sampling frequency), a.k.a. wood-grain
* artifacts. The expected output is 'filtered' due to the noise introduced
* by jittering the entry point of the rays.
*
* Added renderer to expand coverage for vtkDualDepthPeelingPass.
*
* This test builds on TestGPURayCastJittering by rendering with jittering
* enabled, and then without it enabled. This is to test for regressions like
* slice bug 4600 (https://issues.slicer.org/view.php?id=4600).
*/
#include <iostream>
#include <vtkCamera.h>
#include <vtkColorTransferFunction.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkInteractorStyleTrackballCamera.h>
#include <vtkNew.h>
#include <vtkOpenGLRenderer.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRegressionTestImage.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSphereSource.h>
#include <vtkStructuredPointsReader.h>
#include <vtkTestingObjectFactory.h>
#include <vtkTestUtilities.h>
#include <vtkVolume.h>
#include <vtkVolumeProperty.h>
static const char* TestGPURayCastToggleJitteringLog =
"# StreamVersion 1\n"
"EnterEvent 298 27 0 0 0 0 0\n"
"MouseWheelForwardEvent 200 142 0 0 0 0 0\n"
"LeaveEvent 311 71 0 0 0 0 0\n";
int TestGPURayCastToggleJittering(int argc, char* argv[])
{
// Volume peeling is only supported through the dual depth peeling algorithm.
// If the current system only supports the legacy peeler, skip this test:
vtkNew<vtkRenderWindow> renWin;
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
renWin->Render(); // Create the context
vtkNew<vtkRenderer> ren;
renWin->AddRenderer(ren);
vtkOpenGLRenderer *oglRen = vtkOpenGLRenderer::SafeDownCast(ren);
assert(oglRen); // This test should only be enabled for OGL2 backend.
// This will print details about why depth peeling is unsupported:
oglRen->SetDebug(1);
bool supported = oglRen->IsDualDepthPeelingSupported();
oglRen->SetDebug(0);
if (!supported)
{
std::cerr << "Skipping test; volume peeling not supported.\n";
return VTK_SKIP_RETURN_CODE;
}
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
char* volumeFile = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/ironProt.vtk");
vtkNew<vtkStructuredPointsReader> reader;
reader->SetFileName(volumeFile);
delete[] volumeFile;
// Setup actors and mappers
vtkNew<vtkGPUVolumeRayCastMapper> mapper;
mapper->SetInputConnection(reader->GetOutputPort());
mapper->SetAutoAdjustSampleDistances(0);
mapper->SetSampleDistance(2.0);
mapper->UseJitteringOn();
vtkNew<vtkColorTransferFunction> color;
color->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
color->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
color->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
color->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
color->AddRGBPoint(255.0, 0.0, 0.2, 0.0);
vtkNew<vtkPiecewiseFunction> opacity;
opacity->AddPoint(0.0, 0.0);
opacity->AddPoint(255.0, 1.0);
vtkNew<vtkVolumeProperty> property;
property->SetColor(color);
property->SetScalarOpacity(opacity);
property->SetInterpolationTypeToLinear();
property->ShadeOff();
vtkNew<vtkVolume> volume;
volume->SetMapper(mapper);
volume->SetProperty(property);
// Translucent Spheres
vtkNew<vtkSphereSource> sphereSource;
sphereSource->SetCenter(45.f, 45.f, 45.f);
sphereSource->SetRadius(25.0);
vtkNew<vtkActor> sphereActor;
vtkProperty* sphereProperty = sphereActor->GetProperty();
sphereProperty->SetColor(0.0, 1.0, 0.0);
sphereProperty->SetOpacity(0.3);
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphereSource->GetOutputPort());
sphereActor->SetMapper(sphereMapper);
vtkNew<vtkSphereSource> sphereSource2;
sphereSource2->SetCenter(30.f, 30.f, 30.f);
sphereSource2->SetRadius(25.0);
vtkNew<vtkActor> sphereActor2;
vtkProperty* sphereProperty2 = sphereActor2->GetProperty();
sphereProperty2->SetColor(0.9, 0.9, 0.9);
sphereProperty2->SetOpacity(0.3);
vtkNew<vtkPolyDataMapper> sphereMapper2;
sphereMapper2->SetInputConnection(sphereSource2->GetOutputPort());
sphereActor2->SetMapper(sphereMapper2);
// Render window
renWin->SetSize(800, 400);
renWin->SetMultiSamples(0);
// Renderer 1
ren->SetViewport(0.0, 0.0, 0.5, 1.0);
ren->AddVolume(volume);
ren->ResetCamera();
ren->GetActiveCamera()->SetPosition(115.539, 5.50485, 89.8544);
ren->GetActiveCamera()->SetFocalPoint(32.0598, 26.5308, 28.0257);
// Renderer 2 (translucent geometry)
vtkNew<vtkRenderer> ren2;
ren2->SetViewport(0.5, 0.0, 1.0, 1.0);
renWin->AddRenderer(ren2);
ren2->SetUseDepthPeeling(1);
ren2->SetOcclusionRatio(0.0);
ren2->SetMaximumNumberOfPeels(5);
ren2->SetUseDepthPeelingForVolumes(true);
ren2->AddVolume(volume);
ren2->AddActor(sphereActor);
ren2->AddActor(sphereActor2);
ren2->SetActiveCamera(ren->GetActiveCamera());
vtkNew<vtkInteractorStyleTrackballCamera> style;
iren->SetInteractorStyle(style);
// Render with jitter enabled:
mapper->SetUseJittering(1);
renWin->Render();
// And again with jitter disabled:
mapper->SetUseJittering(0);
renWin->Render();
iren->Initialize();
int rv = vtkTesting::InteractorEventLoop(argc, argv, iren,
TestGPURayCastToggleJitteringLog);
return rv;
}
f44a41afa3714c819f194b211c65cd491bf3cb36f0943989c9bcee8cbe0dcb6b7567e53605e392347f820c458321ca89b5899e73fc30decfd24d62202f5aec44
......@@ -3647,6 +3647,10 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::SetMapperShaderParameters(
static_cast<vtkOpenGLRenderWindow *>(ren->GetRenderWindow());
prog->SetUniformi("in_noiseSampler", win->GetNoiseTextureUnit());
}
else
{
prog->SetUniformi("in_noiseSampler", 0);
}
prog->SetUniformi("in_useJittering", this->Parent->UseJittering);
prog->SetUniformi("in_noOfComponents", numComp);
......
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