Commit 342ae7ee authored by Sujin Philip's avatar Sujin Philip

Add vtkmTriangleMeshPointNormals filter

parent a12181f9
......@@ -44,6 +44,7 @@ set(headers
vtkmAverageToCells.h
vtkmGradient.h
vtkmPolyDataNormals.h
vtkmTriangleMeshPointNormals.h
)
#implementation of the algorithms for cpu accelerators
......@@ -62,6 +63,7 @@ set(cpu_accelerator_srcs
vtkmConnectivityExec.cxx
vtkmGradient.cxx
vtkmPolyDataNormals.cxx
vtkmTriangleMeshPointNormals.cxx
vtkmlib/Portals.cxx
vtkmlib/ImplicitFunctionConverter.cxx
)
......@@ -82,6 +84,7 @@ set(cuda_accelerator_srcs
vtkmConnectivityExec.cu
vtkmGradient.cu
vtkmPolyDataNormals.cu
vtkmTriangleMeshPointNormals.cu
vtkmlib/Portals.cu
vtkmlib/ImplicitFunctionConverter.cu
)
......
......@@ -15,6 +15,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestVTKMPolyDataNormals.cxx
TestVTKMThreshold.cxx
TestVTKMThreshold2.cxx
TestVTKMTriangleMeshPointNormals.cxx
)
vtk_test_cxx_executable(${vtk-module}CxxTests tests
RENDERING_FACTORY
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestVTKMTriangleMeshPointNormals.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 "vtkActor.h"
#include "vtkArrowSource.h"
#include "vtkCamera.h"
#include "vtkCleanPolyData.h"
#include "vtkGlyph3D.h"
#include "vtkInteractorStyleTrackballCamera.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTesting.h"
#include "vtkTriangleFilter.h"
#include "vtkmTriangleMeshPointNormals.h"
#include "vtkXMLPolyDataReader.h"
int TestVTKMTriangleMeshPointNormals(int argc, char* argv[])
{
vtkSmartPointer<vtkTesting> testHelper =
vtkSmartPointer<vtkTesting>::New();
testHelper->AddArguments(argc, argv);
if (!testHelper->IsFlagSpecified("-D"))
{
std::cerr << "Error: -D /path/to/data was not specified.";
return EXIT_FAILURE;
}
std::string dataRoot = testHelper->GetDataRoot();
std::string fileName = dataRoot + "/Data/cow.vtp";
std::cout << fileName << std::endl;
// reader
vtkNew<vtkXMLPolyDataReader> reader;
reader->SetFileName(fileName.c_str());
// triangle filter
vtkNew<vtkTriangleFilter> triFilter;
triFilter->SetInputConnection(reader->GetOutputPort());
// cleaning filter
vtkNew<vtkCleanPolyData> cleanFilter;
cleanFilter->SetInputConnection(triFilter->GetOutputPort());
// normals
vtkNew<vtkmTriangleMeshPointNormals> normFilter;
normFilter->SetInputConnection(cleanFilter->GetOutputPort());
// mapper, actor
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(normFilter->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
// glyphs
vtkNew<vtkArrowSource> glyphsource;
vtkNew<vtkGlyph3D> glyph;
glyph->SetInputConnection(normFilter->GetOutputPort());
glyph->SetSourceConnection(glyphsource->GetOutputPort());
glyph->SetVectorModeToUseNormal();
glyph->SetColorModeToColorByVector();
glyph->SetScaleModeToScaleByVector();
glyph->SetScaleFactor(0.5);
vtkNew<vtkPolyDataMapper> glyphmapper;
glyphmapper->SetInputConnection(glyph->GetOutputPort());
vtkNew<vtkActor> glyphactor;
glyphactor->SetMapper(glyphmapper.GetPointer());
// renderer
vtkNew<vtkRenderer> renderer;
renderer->AddActor(actor.GetPointer());
renderer->AddActor(glyphactor.GetPointer());
renderer->SetBackground(0.0, 0.0, 0.0);
renderer->ResetCamera();
// renderwindow, interactor
vtkNew<vtkRenderWindow> renWin ;
renWin->AddRenderer(renderer.GetPointer());
renWin->SetSize(300,300);
renWin->SetMultiSamples(0);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renWin.GetPointer());
iren->Initialize();
renWin->Render();
int retVal = vtkRegressionTestImage(renWin.GetPointer());
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
vtkNew<vtkInteractorStyleTrackballCamera> iStyle;
iren->SetInteractorStyle(iStyle.GetPointer());
renWin->SetSize(1000,1000);
iren->Start();
}
return !retVal;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmTriangleMeshPointNormals.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 "vtkmTriangleMeshPointNormals.cxx"
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmTriangleMeshPointNormals.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 "vtkmTriangleMeshPointNormals.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
#include "vtkmlib/ArrayConverters.h"
#include "vtkmlib/PolyDataConverter.h"
#include "vtkmlib/Storage.h"
#include "vtkmCellSetExplicit.h"
#include "vtkmCellSetSingleType.h"
#include "vtkmFilterPolicy.h"
#include "vtkm/filter/SurfaceNormals.h"
namespace {
struct InputFilterPolicy : public vtkmInputFilterPolicy
{
using UnstructuredCellSetList =
vtkm::ListTagBase<vtkm::cont::vtkmCellSetSingleType>;
};
}
vtkStandardNewMacro(vtkmTriangleMeshPointNormals)
//------------------------------------------------------------------------------
void vtkmTriangleMeshPointNormals::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
vtkmTriangleMeshPointNormals::vtkmTriangleMeshPointNormals() = default;
vtkmTriangleMeshPointNormals::~vtkmTriangleMeshPointNormals() = default;
//------------------------------------------------------------------------------
int vtkmTriangleMeshPointNormals::RequestData(
vtkInformation *request,
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
// get the info objects
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkInformation *outInfo = outputVector->GetInformationObject(0);
// get the input and output
vtkPolyData *input = vtkPolyData::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
vtkPolyData *output = vtkPolyData::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
// check if polydata is in supported format
if (input->GetVerts()->GetNumberOfCells() != 0 ||
input->GetLines()->GetNumberOfCells() != 0 ||
input->GetStrips()->GetNumberOfCells() != 0 ||
(input->GetPolys()->GetNumberOfConnectivityEntries() % 4) != 0)
{
vtkErrorMacro(<< "This filter only works with polydata containing just triangles.");
return 0;
}
// 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;
}
vtkm::filter::PolicyBase<InputFilterPolicy> policy;
vtkm::filter::SurfaceNormals filter;
filter.SetGenerateCellNormals(false);
filter.SetGeneratePointNormals(true);
filter.SetPointNormalsName("Normals");
auto result = filter.Execute(in, policy);
if (!result.IsValid())
{
vtkWarningMacro(<< "VTKm SurfaceNormals algorithm failed to run."
<< "Falling back to vtkTriangleMeshPointNormals.");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
if (!fromvtkm::Convert(result.GetDataSet(), output, input))
{
vtkErrorMacro(<< "Unable to convert VTKm DataSet back to VTK");
return 0;
}
vtkSmartPointer<vtkDataArray> pointNormals = output->GetPointData()->GetArray("Normals");
output->GetPointData()->CopyNormalsOff();
output->GetPointData()->PassData(input->GetPointData());
output->GetCellData()->CopyNormalsOff();
output->GetCellData()->PassData(input->GetPointData());
if (pointNormals)
{
output->GetPointData()->SetNormals(pointNormals.GetPointer());
}
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmTriangleMeshPointNormals.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 vtkmTriangleMeshPointNormals_h
#define vtkmTriangleMeshPointNormals_h
#include "vtkTriangleMeshPointNormals.h"
#include "vtkAcceleratorsVTKmModule.h" // for export macro
class VTKACCELERATORSVTKM_EXPORT vtkmTriangleMeshPointNormals
: public vtkTriangleMeshPointNormals
{
public:
vtkTypeMacro(vtkmTriangleMeshPointNormals, vtkTriangleMeshPointNormals)
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
static vtkmTriangleMeshPointNormals* New();
protected:
vtkmTriangleMeshPointNormals();
~vtkmTriangleMeshPointNormals();
int RequestData(vtkInformation*, vtkInformationVector**,
vtkInformationVector*) VTK_OVERRIDE;
private:
vtkmTriangleMeshPointNormals(const vtkmTriangleMeshPointNormals&) VTK_DELETE_FUNCTION;
void operator=(const vtkmTriangleMeshPointNormals&) VTK_DELETE_FUNCTION;
};
#endif // vtkmTriangleMeshPointNormals_h
// VTK-HeaderTest-Exclude: vtkmTriangleMeshPointNormals.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