Commit 5c6bde06 authored by Allison Vacanti's avatar Allison Vacanti

Fix volume clip bug and add regression test.

When clipping a volume using in-shader clipping planes, it was possible
for the starting point of the ray cast to lie beyond the data volume.
The raycast code is written such that the first sample is always taken
before testing termination criteria, and in these cases we would always
take a single sample outside of the volume, leading to artifacts.

Fixed this behavior by checking that the starting position calculated
by AdjustSampleRangeForClipping is indeed inside of the volume bounds and
aborting the raycast if it is not.

The existing TestGPURayCastClipping test would have caught this, except
that the vase.vti volume used for testing has all 0's at the boundaries,
so the rendering was correct even with the edge-clamp repetition outside
of the volume (the faulty samples always computed RGBA=vec4(0)). I
replaced the vase.vti of this test with a wavelet with finite boundary
values that will catch this problem if there's a regression.
parent ccd60e52
......@@ -27,10 +27,10 @@
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRTAnalyticSource.h>
#include <vtkSmartPointer.h>
#include <vtkTestUtilities.h>
#include <vtkVolumeProperty.h>
#include <vtkXMLImageDataReader.h>
int TestGPURayCastClipping(int argc, char *argv[])
......@@ -38,15 +38,9 @@ int TestGPURayCastClipping(int argc, char *argv[])
vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
vtkNew<vtkXMLImageDataReader> reader;
const char* volumeFile = vtkTestUtilities::ExpandDataFileName(
argc, argv, "Data/vase_1comp.vti");
delete [] volumeFile;
vtkNew<vtkRTAnalyticSource> wavelet;
......@@ -77,7 +71,7 @@ int TestGPURayCastClipping(int argc, char *argv[])
colorTransferFunction->AddRGBPoint(scalarRange[1], 1.0, 0.5, 0.1);
// Test cropping now
const double* bounds = reader->GetOutput()->GetBounds();
const double* bounds = wavelet->GetOutput()->GetBounds();
vtkNew<vtkPlane> clipPlane1;
clipPlane1->SetOrigin(0.45 * (bounds[0] + bounds[1]), 0.0, 0.0);
clipPlane1->SetNormal(0.8, 0.0, 0.0);
......@@ -2376,6 +2376,12 @@ namespace vtkvolume
\n }\
\n }\
\n if (any(greaterThan(startPosTex, in_texMax[0])) ||\
\n any(lessThan(startPosTex, in_texMin[0])))\
\n {\
\n return false;\
\n }\
\n return true;\
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment