Commit 8f45e32a authored by Sujin Philip's avatar Sujin Philip

Add vtkmExtractVOI filter

parent d6469a86
......@@ -27,6 +27,7 @@ set(lib_srcs
vtkmlib/ArrayConverters.cxx
vtkmlib/CellSetConverters.cxx
vtkmlib/DataSetConverters.cxx
vtkmlib/ImageDataConverter.cxx
vtkmlib/Storage.cxx
)
......@@ -37,6 +38,7 @@ set(headers
vtkmClip.h
vtkmContour.h
vtkmExternalFaces.h
vtkmExtractVOI.h
vtkmThreshold.h
vtkmLevelOfDetail.h
vtkmAverageToCells.h
......@@ -50,6 +52,7 @@ set(cpu_accelerator_srcs
vtkmClip.cxx
vtkmContour.cxx
vtkmExternalFaces.cxx
vtkmExtractVOI.cxx
vtkmThreshold.cxx
vtkmLevelOfDetail.cxx
vtkmAverageToCells.cxx
......@@ -68,6 +71,7 @@ set(cuda_accelerator_srcs
vtkmClip.cu
vtkmContour.cu
vtkmExternalFaces.cu
vtkmExtractVOI.cu
vtkmThreshold.cu
vtkmLevelOfDetail.cu
vtkmAverageToCells.cu
......@@ -91,6 +95,7 @@ set_source_files_properties(
vtkmlib/ArrayConverters
vtkmlib/CellSetConverters
vtkmlib/DataSetConverters
vtkmlib/ImageDataConverter
vtkmlib/Storage
vtkmlib/Portals
vtkmlib/ImplicitFunctionConverter
......@@ -150,7 +155,7 @@ if(VTKm_CUDA_FOUND)
if(PRIVATE IN_LIST CUDA_LIBRARIES)
set(cache_cuda_libs ${CUDA_LIBRARIES})
set(cache_devrt_libs ${CUDA_cudadevrt_LIBRARY})
set(CUDA_LIBRARIES ${CUDA_LIBRARIES} vtkFiltersGeneral)
set(CUDA_LIBRARIES ${CUDA_LIBRARIES} ${vtkAcceleratorsVTKm_DEPENDS})
set(CUDA_cudadevrt_LIBRARY PRIVATE ${CUDA_cudadevrt_LIBRARY})
endif()
......
......@@ -8,6 +8,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestVTKMClipWithImplicitFunction.cxx
# TestVTKMGradientAndVorticity.cxx,NO_VALID
TestVTKMExternalFaces.cxx
TestVTKMExtractVOI.cxx
TestVTKMLevelOfDetail.cxx
TestVTKMMarchingCubes.cxx
TestVTKMMarchingCubes2.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestVTKMExtractVOI.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.
=========================================================================*/
#include "vtkmExtractVOI.h"
#include "vtkActor.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRTAnalyticSource.h"
#include "vtkSphereSource.h"
#include "vtkTriangleFilter.h"
#include "vtkImageData.h"
int TestVTKMExtractVOI(int argc, char* argv[])
{
vtkNew<vtkSphereSource> sphere;
sphere->SetRadius(2.0);
vtkNew<vtkPolyDataMapper> sphereMapper;
sphereMapper->SetInputConnection(sphere->GetOutputPort());
sphereMapper->ImmediateModeRenderingOn();
vtkNew<vtkActor> sphereActor;
sphereActor->SetMapper(sphereMapper.GetPointer());
vtkNew<vtkRTAnalyticSource> rt;
rt->SetWholeExtent(-50, 50, -50, 50, 0, 0);
vtkNew<vtkmExtractVOI> voi;
voi->SetInputConnection(rt->GetOutputPort());
voi->SetVOI(-11, 39, 5, 45, 0, 0);
voi->SetSampleRate(5, 5, 1);
// Get rid of ambiguous triagulation issues.
vtkNew<vtkDataSetSurfaceFilter> surf;
surf->SetInputConnection(voi->GetOutputPort());
vtkNew<vtkTriangleFilter> tris;
tris->SetInputConnection(surf->GetOutputPort());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(tris->GetOutputPort());
mapper->ImmediateModeRenderingOn();
mapper->SetScalarRange(130, 280);
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor.GetPointer());
renderer->AddActor(sphereActor.GetPointer());
renderer->ResetCamera();
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(renderer.GetPointer());
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin.GetPointer());
iren->Initialize();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
return !retVal;
}
......@@ -6,6 +6,7 @@ vtk_module(vtkAcceleratorsVTKm
vtkCommonExecutionModel
vtkFiltersGeneral
vtkFiltersGeometry
vtkImagingCore
TEST_DEPENDS
vtkTestingCore
vtkTestingRendering
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractVOI.cu
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.
=========================================================================*/
#include "vtkmExtractVOI.cxx"
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractVOI.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.
=========================================================================*/
#include "vtkmExtractVOI.h"
#include "vtkCellData.h"
#include "vtkExtractStructuredGridHelper.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointData.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/ImageDataConverter.h"
#include "vtkmlib/Storage.h"
#include "vtkmCellSetExplicit.h"
#include "vtkmCellSetSingleType.h"
#include "vtkmFilterPolicy.h"
#include "vtkm/filter/ExtractStructured.h"
namespace {
struct InputFilterPolicy : public vtkmInputFilterPolicy
{
using StructuredCellSetList =
vtkm::ListTagBase<vtkm::cont::CellSetStructured<1>,
vtkm::cont::CellSetStructured<2>,
vtkm::cont::CellSetStructured<3>>;
};
}
vtkStandardNewMacro(vtkmExtractVOI)
//------------------------------------------------------------------------------
void vtkmExtractVOI::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
vtkmExtractVOI::vtkmExtractVOI() = default;
vtkmExtractVOI::~vtkmExtractVOI() = default;
//------------------------------------------------------------------------------
int vtkmExtractVOI::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkImageData* input =
vtkImageData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkImageData* output =
vtkImageData::SafeDownCast(outInfo->Get(vtkDataObject::DATA_OBJECT()));
// convert the input dataset to a vtkm::cont::DataSet
vtkm::cont::DataSet in = tovtkm::Convert(input);
if (in.GetNumberOfCoordinateSystems() <= 0 || in.GetNumberOfCellSets() <= 0)
{
vtkErrorMacro(<< "Could not convert vtk dataset to vtkm dataset");
return 0;
}
// transform VOI
int inExtents[6], voi[6];
input->GetExtent(inExtents);
for (int i = 0; i < 6; i += 2)
{
voi[i] = this->VOI[i] - inExtents[i];
voi[i + 1] = this->VOI[i + 1] - inExtents[i] + 1;
}
vtkm::filter::PolicyBase<InputFilterPolicy> policy;
// apply the filter
vtkm::filter::ExtractStructured filter;
filter.SetVOI(voi[0], voi[1], voi[2], voi[3], voi[4], voi[5]);
filter.SetSampleRate(this->SampleRate[0], this->SampleRate[1], this->SampleRate[2]);
filter.SetIncludeBoundary(this->IncludeBoundary);
vtkm::filter::ResultDataSet result = filter.Execute(in, policy);
if (!result.IsValid())
{
vtkWarningMacro(<< "VTKm ExtractStructured algorithm failed to run."
<< "Falling back to vtkExtractVOI.");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
vtkDataSetAttributes *attr[2] = { input->GetPointData(), input->GetCellData() };
int assoc[2] = { vtkDataObject::FIELD_ASSOCIATION_POINTS,
vtkDataObject::FIELD_ASSOCIATION_CELLS };
for (int i = 0; i < 2; ++i)
{
for (vtkIdType j = 0; j < attr[i]->GetNumberOfArrays(); ++j)
{
vtkDataArray* array = attr[i]->GetArray(j);
if (array == NULL)
{
continue;
}
vtkm::cont::Field pfield = tovtkm::Convert(array, assoc[i]);
try
{
filter.MapFieldOntoOutput(result, pfield, policy);
}
catch (vtkm::cont::Error&)
{
vtkWarningMacro(<< "Unable to use VTKm to convert field ("
<< array->GetName() << ") to the output");
}
}
}
// convert back to vtkImageData
int outExtents[6];
this->Internal->GetOutputWholeExtent(outExtents);
if (!fromvtkm::Convert(result.GetDataSet(), outExtents, output, input))
{
vtkErrorMacro(<< "Unable to convert VTKm DataSet back to VTK");
return 0;
}
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkExtractVOI.h
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.
=========================================================================*/
#ifndef vtkmExtractVOI_h
#define vtkmExtractVOI_h
#include "vtkExtractVOI.h"
#include "vtkAcceleratorsVTKmModule.h" // for export macro
class VTKACCELERATORSVTKM_EXPORT vtkmExtractVOI : public vtkExtractVOI
{
public:
vtkTypeMacro(vtkmExtractVOI, vtkExtractVOI)
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
static vtkmExtractVOI* New();
protected:
vtkmExtractVOI();
~vtkmExtractVOI();
int RequestData(vtkInformation*, vtkInformationVector**,
vtkInformationVector*) VTK_OVERRIDE;
private:
vtkmExtractVOI(const vtkmExtractVOI&) VTK_DELETE_FUNCTION;
void operator=(const vtkmExtractVOI&) VTK_DELETE_FUNCTION;
};
#endif // vtkmExtractVOI_h
// VTK-HeaderTest-Exclude: vtkmExtractVOI.h
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