Commit 1dc7f42b authored by Aashish Chaudhary's avatar Aashish Chaudhary Committed by Code Review

Merge topic 'sample_distance_issue' into master

c2e74059 Add baseline for new sample distance test
d45993bf Changed the noise generator amplitude to 0.1
08e8c63d Fixed bad sampling issues when dealing with large sample distances
703ff1e2 Test for large sample distance in volume mapper
parents aab57b1d c2e74059
......@@ -19,6 +19,7 @@ set (GenericVolumeCxxTests
TestGPURayCastMIPBinaryMask.cxx
TestGPURayCastMIPToComposite.cxx
TestGPURayCastMapperBenchmark.cxx
TestGPURayCastMapperSampleDistance.cxx
TestGPURayCastNearestDataTypesMIP.cxx
TestGPURayCastPerspectiveParallel.cxx
TestGPURayCastVolumeUpdate.cxx
......
/*=========================================================================
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"
//----------------------------------------------------------------------------
int TestGPURayCastMapperSampleDistance(int argc, char* argv[])
{
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());
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));
}
......@@ -941,7 +941,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::UpdateNoiseTexture()
noiseGenerator->SetFrequency(size, 1.0, 1.0);
noiseGenerator->SetPhase(0.0, 0.0, 0.0);
// -0.5 and 0.5 range
noiseGenerator->SetAmplitude(0.5);
noiseGenerator->SetAmplitude(0.1);
int j = 0;
while(j < size)
{
......@@ -949,7 +949,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::UpdateNoiseTexture()
while(i < size)
{
this->NoiseTextureData[j * size + i] =
static_cast<float>(noiseGenerator->EvaluateFunction(i, j, 0.0));
static_cast<float>(noiseGenerator->EvaluateFunction(i, j, 0.0) + 0.1);
++i;
}
++j;
......@@ -960,6 +960,8 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::UpdateNoiseTexture()
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
GLfloat borderColor[4]={0.0,0.0,0.0,0.0};
glTexParameterfv(GL_TEXTURE_2D,GL_TEXTURE_BORDER_COLOR,borderColor);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glActiveTexture(GL_TEXTURE0);
......
......@@ -217,7 +217,7 @@ namespace vtkvolume
\n g_dirStep = (in_inverseTextureDatasetMatrix *\
\n vec4(rayDir, 0.0)).xyz * in_sampleDistance;\
\n\
\n g_dataPos += g_dirStep * texture2D(in_noiseSampler, g_dataPos.xy).x;\
\n g_dataPos += g_dirStep * (texture2D(in_noiseSampler, g_dataPos.xy).x);\
\n\
\n // Flag to deternmine if voxel should be considered for the rendering\
\n bool l_skip = false;");
......
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