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");
reader->SetFileName(volumeFile);
reader->Update();
volumeMapper->SetInputConnection(reader->GetOutputPort());
delete [] volumeFile;
vtkNew<vtkRTAnalyticSource> wavelet;
wavelet->Update();
volumeMapper->SetInputConnection(wavelet->GetOutputPort());
volumeMapper->GetInput()->GetScalarRange(scalarRange);
volumeMapper->SetBlendModeToComposite();
......@@ -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);
......
7d2c50a7692a0921ed0c5a55d2b9a9bc94663e02139254506396bc177cb8158a179c7cb348eb4f3dc0da1bccbf0d35d2855030eedd83d9de9bcefdb9b366be5a
c8aceb3f3c76bc86e167e77d1ca7e424d38fd82bd272dbde6e3f9e71d42eb23968c6938dcfee1bc99174be6a67558e06dfdd4cae1dc1a644c9d00aa837ee86c1
......@@ -2376,6 +2376,12 @@ namespace vtkvolume
\n }\
\n }\
\n\
\n if (any(greaterThan(startPosTex, in_texMax[0])) ||\
\n any(lessThan(startPosTex, in_texMin[0])))\
\n {\
\n return false;\
\n }\
\n\
\n return true;\
\n}\
\n");
......
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