Commit 15dda152 authored by Sankhesh Jhaveri's avatar Sankhesh Jhaveri 💬 Committed by Kitware Robot
Browse files

Merge topic 'clipped_voxel_intensity'

3c245fa0 Added test for volume clipped intensity
1ac72fd2

 Introduce volume API to specify intensity for clipped voxels
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Aashish Chaudhary's avatarAashish Chaudhary <aashish.chaudhary@kitware.com>
Merge-request: !4627
parents 6ef84697 3c245fa0
......@@ -33,6 +33,9 @@ vtkVolumeProperty::vtkVolumeProperty()
this->InterpolationType = VTK_NEAREST_INTERPOLATION;
this->UseClippedVoxelIntensity = 0;
this->ClippedVoxelIntensity = VTK_DOUBLE_MIN;
for ( int i = 0; i < VTK_MAX_VRCOMP; i++ )
{
this->ColorChannels[i] = 1;
......@@ -106,6 +109,8 @@ void vtkVolumeProperty::DeepCopy(vtkVolumeProperty *p)
this->SetIndependentComponents(p->GetIndependentComponents());
this->SetInterpolationType(p->GetInterpolationType());
this->SetUseClippedVoxelIntensity(p->GetUseClippedVoxelIntensity());
this->SetClippedVoxelIntensity(p->GetClippedVoxelIntensity());
for (int i = 0; i < VTK_MAX_VRCOMP; i++)
{
......@@ -698,6 +703,11 @@ void vtkVolumeProperty::PrintSelf(ostream& os, vtkIndent indent)
os << indent << "Interpolation Type: "
<< this->GetInterpolationTypeAsString() << "\n";
os << indent << "Use Clipped Voxel Intensity: " <<
(this->UseClippedVoxelIntensity ? "On\n" : "Off\n");
os << indent << "Clipped Voxel Intensity: "
<< this->GetClippedVoxelIntensity() << "\n";
for ( int i = 0; i < VTK_MAX_VRCOMP; i++ )
{
os << indent << "Properties for material " << i << endl;
......
......@@ -435,6 +435,36 @@ public:
vtkTimeStamp GetGrayTransferFunctionMTime()
{ return this->GetGrayTransferFunctionMTime(0); }
//@{
/**
* Set/Get whether to use a fixed intensity value for voxels in the clipped
* space for gradient calculations. When UseClippedVoxelIntensity is
* enabled, the ClippedVoxelIntensity value will be used as intensity of
* clipped voxels. By default, this is false.
*
* \note This property is only used by the vtkGPUVolumeRayCastMapper for now.
* \sa SetClippedVoxelIntensity
*/
vtkSetMacro(UseClippedVoxelIntensity, int);
vtkGetMacro(UseClippedVoxelIntensity, int);
vtkBooleanMacro(UseClippedVoxelIntensity, int);
//@}
//@{
/**
* Set/Get the intensity value for voxels in the clipped space for gradient
* computations (for shading and gradient based opacity modulation).
* By default, this is set to VTK_DOUBLE_MIN.
*
* \note This value is only used when UseClippedVoxelIntensity is true.
* \note This property is only used by the vtkGPUVolumeRayCastMapper for now.
* \sa SetUseClippedVoxelIntensity
*/
vtkSetMacro(ClippedVoxelIntensity, double);
vtkGetMacro(ClippedVoxelIntensity, double);
//@}
protected:
vtkVolumeProperty();
~vtkVolumeProperty() override;
......@@ -484,6 +514,9 @@ protected:
double Specular[VTK_MAX_VRCOMP];
double SpecularPower[VTK_MAX_VRCOMP];
double ClippedVoxelIntensity;
int UseClippedVoxelIntensity;
/**
* Contour values for isosurface blend mode
*/
......
......@@ -50,6 +50,7 @@ set (VolumeCxxTests
TestGPURayCastRenderDepthToImage.cxx
TestGPURayCastRenderDepthToImage2.cxx
TestGPURayCastRenderToTexture.cxx
TestGPURayCastShadedClipping.cxx
TestGPURayCastThreeComponentsAdditive.cxx
TestGPURayCastThreeComponentsIndependent.cxx
TestGPURayCastTransfer2D.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestGPURayCastShadedClipping.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.
=========================================================================*/
// Description
// This test covers volume shading with clipping
#include <vtkCamera.h>
#include <vtkColorTransferFunction.h>
#include <vtkGPUVolumeRayCastMapper.h>
#include <vtkImageData.h>
#include <vtkNew.h>
#include <vtkPiecewiseFunction.h>
#include <vtkPlane.h>
#include <vtkPlaneCollection.h>
#include <vtkRegressionTestImage.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkTestUtilities.h>
#include <vtkVolume16Reader.h>
#include <vtkVolumeProperty.h>
void CreateVolumeShadedClippingPipeline(vtkImageData* data,
vtkVolume* volume,
int UseClippedVoxelIntensity)
{
vtkNew<vtkGPUVolumeRayCastMapper> volumeMapper;
volumeMapper->SetInputData(data);
volumeMapper->SetBlendModeToComposite();
vtkNew<vtkPiecewiseFunction> scalarOpacity;
scalarOpacity->AddPoint( 70.0, 0.0);
scalarOpacity->AddPoint( 1200, .2);
scalarOpacity->AddPoint( 1300, .3);
scalarOpacity->AddPoint( 2000, .3);
scalarOpacity->AddPoint( 4095.0, 1.0);
vtkNew<vtkVolumeProperty> volumeProperty;
volumeProperty->ShadeOn();
volumeProperty->SetInterpolationType(VTK_LINEAR_INTERPOLATION);
volumeProperty->SetScalarOpacity(scalarOpacity);
volumeProperty->SetClippedVoxelIntensity(-1000.0);
volumeProperty->SetUseClippedVoxelIntensity(UseClippedVoxelIntensity);
vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction =
volumeProperty->GetRGBTransferFunction(0);
colorTransferFunction->AddRGBPoint( 0.0, 0.5 , 0.0 , 0.0);
colorTransferFunction->AddRGBPoint( 600.0, 1.0 , 0.5 , 0.5);
colorTransferFunction->AddRGBPoint( 1280.0, 0.9 , 0.2 , 0.3);
colorTransferFunction->AddRGBPoint( 1960.0, 0.81, 0.27, 0.1);
colorTransferFunction->AddRGBPoint( 4095.0, 0.5 , 0.5 , 0.5);
// Test cropping now
const double* bounds = data->GetBounds();
vtkNew<vtkPlane> clipPlane1;
clipPlane1->SetOrigin(0.45 * (bounds[0] + bounds[1]), 0.0, 0.0);
clipPlane1->SetNormal(0.8, 0.0, 0.0);
vtkNew<vtkPlane> clipPlane2;
clipPlane2->SetOrigin(
0.45 * (bounds[0] + bounds[1]), 0.35 * (bounds[2] + bounds[3]), 0.0);
clipPlane2->SetNormal(0.2, -0.2, 0.0);
vtkNew<vtkPlaneCollection> clipPlaneCollection;
clipPlaneCollection->AddItem(clipPlane1);
volumeMapper->SetClippingPlanes(clipPlaneCollection);
// Setup volume actor
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
}
int TestGPURayCastShadedClipping(int argc, char* argv[])
{
cout << "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)" << endl;
char* fname =
vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/headsq/quarter");
vtkSmartPointer<vtkVolume16Reader> reader =
vtkSmartPointer<vtkVolume16Reader>::New();
reader->SetDataDimensions(64, 64);
reader->SetDataByteOrderToLittleEndian();
reader->SetImageRange(1, 93);
reader->SetDataSpacing(3.2, 3.2, 1.5);
reader->SetFilePrefix(fname);
reader->SetDataMask(0x7fff);
reader->Update();
delete[] fname;
vtkImageData* input = reader->GetOutput();
// Testing prefers image comparison with small images
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(400, 400);
vtkNew<vtkRenderer> lren;
lren->SetViewport(0, 0, 0.5, 1);
renWin->AddRenderer(lren);
vtkNew<vtkRenderer> rren;
rren->SetViewport(0.5, 0, 1, 1);
renWin->AddRenderer(rren);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkVolume> lvolume;
CreateVolumeShadedClippingPipeline(input, lvolume, 0);
vtkNew<vtkVolume> rvolume;
CreateVolumeShadedClippingPipeline(input, rvolume, 1);
lren->AddViewProp(lvolume);
lren->GetActiveCamera()->Azimuth(-40);
lren->GetActiveCamera()->Pitch(-60);
lren->ResetCamera();
lren->GetActiveCamera()->Zoom(1.8);
rren->AddViewProp(rvolume);
rren->GetActiveCamera()->Azimuth(-40);
rren->GetActiveCamera()->Pitch(-60);
rren->ResetCamera();
rren->GetActiveCamera()->Zoom(1.8);
renWin->Render();
iren->Initialize();
int retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
d56faa95f1d8a57c98ade1e8b5373bbaa96a39ccb415d61145aed8a08d0738d91c72f3e2d2d291c0e83e4d19d68e3088daba8f2161d57e0b213d9b0cb92a8f29
......@@ -56,6 +56,8 @@ float g_terminatePointMax;
//VTK::Cropping::Dec
//VTK::Clipping::Dec
//VTK::Shading::Dec
//VTK::BinaryMask::Dec
......@@ -87,8 +89,6 @@ float g_terminatePointMax;
uniform float in_scale;
uniform float in_bias;
//VTK::Clipping::Dec
//////////////////////////////////////////////////////////////////////////////
///
/// Helper functions
......
......@@ -1300,7 +1300,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::SetCroppingRegions(
//----------------------------------------------------------------------------
void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::SetClippingPlanes(
vtkRenderer* vtkNotUsed(ren), vtkShaderProgram* prog,
vtkVolume* vtkNotUsed(vol))
vtkVolume* vol)
{
if (this->Parent->GetClippingPlanes())
{
......@@ -1331,6 +1331,9 @@ void vtkOpenGLGPUVolumeRayCastMapper::vtkInternal::SetClippingPlanes(
prog->SetUniform1fv("in_clippingPlanes",
static_cast<int>(clippingPlanes.size()),
&clippingPlanes[0]);
float clippedVoxelIntensity =
static_cast<float>(vol->GetProperty()->GetClippedVoxelIntensity());
prog->SetUniformf("in_clippedVoxelIntensity", clippedVoxelIntensity);
}
}
......@@ -2574,7 +2577,7 @@ void vtkOpenGLGPUVolumeRayCastMapper::ReplaceShaderCompute(
vtkShaderProgram::Substitute(fragmentShader,
"//VTK::ComputeGradient::Dec",
vtkvolume::ComputeGradientDeclaration(this->AssembledInputs));
vtkvolume::ComputeGradientDeclaration(this, this->AssembledInputs));
if (this->Impl->MultiVolume)
{
......
......@@ -53,6 +53,22 @@ namespace {
return false;
}
bool UseClippedVoxelIntensity(
vtkOpenGLGPUVolumeRayCastMapper::VolumeInputMap& inputs)
{
for (auto& item : inputs)
{
vtkVolumeProperty* volProp = item.second.Volume->GetProperty();
const bool useClippedVoxelIntensity =
volProp->GetUseClippedVoxelIntensity() == 1;
if (useClippedVoxelIntensity)
{
return true;
}
}
return false;
}
const std::string ArrayBaseName(const std::string& arrayName)
{
const std::string base = arrayName.substr(0, arrayName.length() - 3);
......@@ -450,6 +466,7 @@ namespace vtkvolume
//--------------------------------------------------------------------------
std::string ComputeGradientDeclaration(
vtkOpenGLGPUVolumeRayCastMapper* mapper,
vtkOpenGLGPUVolumeRayCastMapper::VolumeInputMap& inputs)
{
const bool hasLighting = HasLighting(inputs);
......@@ -468,13 +485,62 @@ namespace vtkvolume
" vec3 xvec = vec3(in_cellStep[index].x, 0.0, 0.0);\n"
" vec3 yvec = vec3(0.0, in_cellStep[index].y, 0.0);\n"
" vec3 zvec = vec3(0.0, 0.0, in_cellStep[index].z);\n"
" g1.x = texture3D(volume, vec3(texPos + xvec))[c];\n"
" g1.y = texture3D(volume, vec3(texPos + yvec))[c];\n"
" g1.z = texture3D(volume, vec3(texPos + zvec))[c];\n"
" g2.x = texture3D(volume, vec3(texPos - xvec))[c];\n"
" g2.y = texture3D(volume, vec3(texPos - yvec))[c];\n"
" g2.z = texture3D(volume, vec3(texPos - zvec))[c];\n"
"\n"
" vec3 texPosPvec[3];\n"
" texPosPvec[0] = texPos + xvec;\n"
" texPosPvec[1] = texPos + yvec;\n"
" texPosPvec[2] = texPos + zvec;\n"
" vec3 texPosNvec[3];\n"
" texPosNvec[0] = texPos - xvec;\n"
" texPosNvec[1] = texPos - yvec;\n"
" texPosNvec[2] = texPos - zvec;\n"
" g1.x = texture3D(volume, vec3(texPosPvec[0]))[c];\n"
" g1.y = texture3D(volume, vec3(texPosPvec[1]))[c];\n"
" g1.z = texture3D(volume, vec3(texPosPvec[2]))[c];\n"
" g2.x = texture3D(volume, vec3(texPosNvec[0]))[c];\n"
" g2.y = texture3D(volume, vec3(texPosNvec[1]))[c];\n"
" g2.z = texture3D(volume, vec3(texPosNvec[2]))[c];\n"
"\n");
if (UseClippedVoxelIntensity(inputs) && mapper->GetClippingPlanes())
{
shaderStr += std::string(
" vec4 g1ObjDataPos[3], g2ObjDataPos[3];\n"
" for (int i = 0; i < 3; ++i)\n"
" {\n"
" g1ObjDataPos[i] = clip_texToObjMat * vec4(texPosPvec[i], 1.0);\n"
" if (g1ObjDataPos[i].w != 0.0)\n"
" {\n"
" g1ObjDataPos[i] /= g1ObjDataPos[i].w;\n"
" }\n"
" g2ObjDataPos[i] = clip_texToObjMat * vec4(texPosNvec[i], 1.0);\n"
" if (g2ObjDataPos[i].w != 0.0)\n"
" {\n"
" g2ObjDataPos[i] /= g2ObjDataPos[i].w;\n"
" }\n"
" }\n"
"\n"
" for (int i = 0; i < clip_numPlanes && !g_skip; i = i + 6)\n"
" {\n"
" vec3 planeOrigin = vec3(in_clippingPlanes[i + 1],\n"
" in_clippingPlanes[i + 2],\n"
" in_clippingPlanes[i + 3]);\n"
" vec3 planeNormal = normalize(vec3(in_clippingPlanes[i + 4],\n"
" in_clippingPlanes[i + 5],\n"
" in_clippingPlanes[i + 6]));\n"
" for (int j = 0; j < 3; ++j)\n"
" {\n"
" if (dot(vec3(planeOrigin - g1ObjDataPos[j].xyz), planeNormal) > 0)\n"
" {\n"
" g1[j] = in_clippedVoxelIntensity;\n"
" }\n"
" if (dot(vec3(planeOrigin - g2ObjDataPos[j].xyz), planeNormal) > 0)\n"
" {\n"
" g2[j] = in_clippedVoxelIntensity;\n"
" }\n"
" }\n"
" }\n"
"\n");
}
shaderStr += std::string(
" // Apply scale and bias to the fetched values.\n"
" g1 = g1 * in_volume_scale[index][c] + in_volume_bias[index][c];\n"
" g2 = g2 * in_volume_scale[index][c] + in_volume_bias[index][c];\n"
......@@ -2272,6 +2338,7 @@ namespace vtkvolume
\n /// The first value is the size of the data array for clipping\
\n /// planes (origin, normal)\
\n uniform float in_clippingPlanes[49];\
\n uniform float in_clippedVoxelIntensity;\
\n\
\n int clip_numPlanes;\
\n vec3 clip_rayDirObj;\
......
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