Updates will be applied - 3:30pm EDT (UTC -400). No downtime expected.

Commit c383966b authored by Cory Quammen's avatar Cory Quammen

Support rectilinear grids in vtkMultiBlockVolumeMapper

Add test for the support as well.
parent 1b84a44d
......@@ -75,6 +75,7 @@ set (VolumeCxxTests
TestGPUVolumeRayCastMapper.cxx
TestMinIntensityRendering.cxx
TestMultiBlockMapper.cxx
TestMultiBlockMapperRectilinearGrid.cxx
TestProjectedTetrahedra.cxx
TestProjectedTetrahedraOffscreen.cxx
TestProjectedTetrahedraTransform.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestMultiBlockMapper.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.
=========================================================================*/
/**
* \brief Tests vtkMultiBlockDataSet rendering. Uses the exposed VectorMode
* API of vtkSmartVolumeMapper to render component X of the array data.
*
*/
#include "vtkCamera.h"
#include "vtkColorTransferFunction.h"
#include "vtkCompositeDataSet.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkMultiBlockDataGroupFilter.h"
#include "vtkMultiBlockVolumeMapper.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
#include "vtkRectilinearGridReader.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkStructuredPointsReader.h"
#include "vtkTestUtilities.h"
#include "vtkTesting.h"
#include "vtkUnstructuredGrid.h"
#include "vtkVolume.h"
#include "vtkVolumeProperty.h"
#include "vtkXMLMultiBlockDataReader.h"
#include "vtkXMLPUnstructuredGridReader.h"
int TestMultiBlockMapperRectilinearGrid(int argc, char* argv[])
{
vtkNew<vtkRectilinearGridReader> reader;
const char* fileName = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/RectGrid2.vtk");
reader->SetFileName(fileName);
reader->Update();
delete[] fileName;
vtkNew<vtkMultiBlockDataGroupFilter> grouper;
grouper->AddInputConnection(reader->GetOutputPort());
vtkNew<vtkMultiBlockVolumeMapper> mapper;
mapper->SetInputConnection(grouper->GetOutputPort());
// mapper->SetScalarMode(VTK_SCALAR_MODE_USE_POINT_FIELD_DATA);
vtkNew<vtkColorTransferFunction> ctf;
ctf->AddRGBPoint(0, 0.53, 0.53, 0.83);
ctf->AddRGBPoint(1.77, 0, 0, 1);
ctf->AddRGBPoint(3.53, 0, 1, 1);
ctf->AddRGBPoint(5.2, 0, 1, 0);
ctf->AddRGBPoint(6.97, 1, 1, 0);
ctf->AddRGBPoint(8.73, 1, 0, 0);
ctf->AddRGBPoint(10.39, 0.88, 0, 1);
vtkNew<vtkPiecewiseFunction> pf;
pf->AddPoint(0, 0);
pf->AddPoint(0.2, 1);
pf->AddPoint(3, 0.5);
pf->AddPoint(10.39, 1);
vtkNew<vtkVolumeProperty> volumeProperty;
volumeProperty->SetInterpolationTypeToLinear();
volumeProperty->SetColor(ctf);
volumeProperty->SetScalarOpacity(pf);
vtkNew<vtkVolume> volume;
volume->SetMapper(mapper);
volume->SetProperty(volumeProperty);
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(401, 400);
renWin->SetMultiSamples(0);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin);
vtkNew<vtkInteractorStyleTrackballCamera> style;
iren->SetInteractorStyle(style);
vtkNew<vtkRenderer> ren;
renWin->AddRenderer(ren);
ren->AddVolume(volume);
ren->ResetCamera();
ren->GetActiveCamera()->Azimuth(0);
ren->GetActiveCamera()->Roll(-65);
ren->GetActiveCamera()->Elevation(-45);
ren->GetActiveCamera()->Zoom(1.2);
renWin->Render();
// initialize render loop
int const retVal = vtkRegressionTestImage(renWin);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Initialize();
iren->Start();
}
return !retVal;
}
b77b28286a9a9981f159b7d334acf512404a8dd2f114d017b97ed61da01f8ed431b8cfe7481de9557a13b0f10bb7105c7a358429d8ab38c537902e19c8661862
......@@ -29,6 +29,7 @@
#include "vtkObjectFactory.h"
#include "vtkOpenGLGPUVolumeRayCastMapper.h"
#include "vtkPerlinNoise.h"
#include "vtkRectilinearGrid.h"
#include "vtkRenderWindow.h"
#include "vtkSmartVolumeMapper.h"
......@@ -226,6 +227,12 @@ void vtkMultiBlockVolumeMapper::LoadDataSet(vtkRenderer* ren, vtkVolume* vol)
mapper->SetInputData(inputImage);
this->Mappers.push_back(mapper);
}
else if (auto inputRectGrid = vtkRectilinearGrid::SafeDownCast(input))
{
vtkSmartVolumeMapper* mapper = this->CreateMapper();
mapper->SetInputData(inputRectGrid);
this->Mappers.push_back(mapper);
}
else
{
vtkErrorMacro(
......@@ -246,10 +253,11 @@ void vtkMultiBlockVolumeMapper::CreateMappers(
while (!it->IsDoneWithTraversal())
{
vtkImageData* currentIm = vtkImageData::SafeDownCast(it->GetCurrentDataObject());
if (!warnedOnce && !currentIm)
vtkRectilinearGrid* currentRect = vtkRectilinearGrid::SafeDownCast(it->GetCurrentDataObject());
if (!warnedOnce && !currentIm && !currentRect)
{
vtkErrorMacro("At least one block in the data object is not of type"
" vtkImageData. These blocks will be ignored.");
" vtkImageData or vtkRectilinearGrid. These blocks will be ignored.");
warnedOnce = true;
it->GoToNextItem();
continue;
......@@ -258,9 +266,18 @@ void vtkMultiBlockVolumeMapper::CreateMappers(
vtkSmartVolumeMapper* mapper = this->CreateMapper();
this->Mappers.push_back(mapper);
vtkImageData* im = vtkImageData::New();
im->ShallowCopy(currentIm);
mapper->SetInputData(im);
if (currentIm)
{
vtkNew<vtkImageData> im;
im->ShallowCopy(currentIm);
mapper->SetInputData(im);
}
else if (currentRect)
{
vtkNew<vtkRectilinearGrid> rg;
rg->ShallowCopy(currentRect);
mapper->SetInputData(rg);
}
// Try allocating GPU memory only while succeeding
if (allBlocksLoaded)
......@@ -268,7 +285,7 @@ void vtkMultiBlockVolumeMapper::CreateMappers(
vtkOpenGLGPUVolumeRayCastMapper* glMapper =
vtkOpenGLGPUVolumeRayCastMapper::SafeDownCast(mapper->GetGPUMapper());
if (glMapper)
if (glMapper && currentIm)
{
vtkImageData* imageInternal = vtkImageData::New();
imageInternal->ShallowCopy(currentIm);
......@@ -283,7 +300,6 @@ void vtkMultiBlockVolumeMapper::CreateMappers(
imageInternal->Delete();
}
}
im->Delete();
it->GoToNextItem();
}
it->Delete();
......
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