Commit a12181f9 authored by Sujin Philip's avatar Sujin Philip

Add vtkmPolyDataNormals filter

parent 55aee9b9
......@@ -43,6 +43,7 @@ set(headers
vtkmLevelOfDetail.h
vtkmAverageToCells.h
vtkmGradient.h
vtkmPolyDataNormals.h
)
#implementation of the algorithms for cpu accelerators
......@@ -60,6 +61,7 @@ set(cpu_accelerator_srcs
vtkmCellSetSingleType.cxx
vtkmConnectivityExec.cxx
vtkmGradient.cxx
vtkmPolyDataNormals.cxx
vtkmlib/Portals.cxx
vtkmlib/ImplicitFunctionConverter.cxx
)
......@@ -79,6 +81,7 @@ set(cuda_accelerator_srcs
vtkmCellSetSingleType.cu
vtkmConnectivityExec.cu
vtkmGradient.cu
vtkmPolyDataNormals.cu
vtkmlib/Portals.cu
vtkmlib/ImplicitFunctionConverter.cu
)
......
......@@ -12,6 +12,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestVTKMLevelOfDetail.cxx
TestVTKMMarchingCubes.cxx
TestVTKMMarchingCubes2.cxx
TestVTKMPolyDataNormals.cxx
TestVTKMThreshold.cxx
TestVTKMThreshold2.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 "vtkmPolyDataNormals.h"
#include "vtkActor.h"
#include "vtkArrowSource.h"
#include "vtkCamera.h"
#include "vtkCellCenters.h"
#include "vtkCellData.h"
#include "vtkCleanPolyData.h"
#include "vtkCylinderSource.h"
#include "vtkGlyph3D.h"
#include "vtkNew.h"
#include "vtkPointData.h"
#include "vtkPolyDataMapper.h"
#include "vtkProperty.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkTriangleFilter.h"
namespace
{
void MakeInputDataSet(vtkPolyData *ds)
{
vtkNew<vtkCylinderSource> cylinder;
cylinder->SetRadius(1.0);
cylinder->SetResolution(8);
cylinder->CappingOn();
vtkNew<vtkTriangleFilter> triangle;
triangle->SetInputConnection(cylinder->GetOutputPort());
vtkNew<vtkCleanPolyData> clean;
clean->SetInputConnection(triangle->GetOutputPort());
clean->Update();
ds->ShallowCopy(clean->GetOutput());
ds->GetPointData()->Initialize();
ds->GetCellData()->Initialize();
}
}
int TestVTKMPolyDataNormals(int argc, char* argv[])
{
vtkNew<vtkPolyData> input;
MakeInputDataSet(input.GetPointer());
vtkNew<vtkmPolyDataNormals> normals;
normals->SetInputData(input.GetPointer());
normals->ComputePointNormalsOn();
normals->ComputeCellNormalsOn();
// cylinder mapper and actor
vtkNew<vtkPolyDataMapper> cylinderMapper;
cylinderMapper->SetInputData(input.GetPointer());
vtkNew<vtkActor> cylinderActor;
cylinderActor->SetMapper(cylinderMapper.GetPointer());
vtkSmartPointer<vtkProperty> cylinderProperty;
cylinderProperty.TakeReference(cylinderActor->MakeProperty());
cylinderProperty->SetRepresentationToWireframe();
cylinderProperty->SetColor(0.3, 0.3, 0.3);
cylinderActor->SetProperty(cylinderProperty.GetPointer());
vtkNew<vtkArrowSource> arrow;
// point normals
vtkNew<vtkGlyph3D> pnGlyphs;
pnGlyphs->SetInputConnection(normals->GetOutputPort());
pnGlyphs->SetSourceConnection(arrow->GetOutputPort());
pnGlyphs->SetScaleFactor(0.5);
pnGlyphs->OrientOn();
pnGlyphs->SetVectorModeToUseNormal();
vtkNew<vtkPolyDataMapper> pnMapper;
pnMapper->SetInputConnection(pnGlyphs->GetOutputPort());
vtkNew<vtkActor> pnActor;
pnActor->SetMapper(pnMapper.GetPointer());
vtkNew<vtkRenderer> pnRenderer;
pnRenderer->AddActor(cylinderActor.GetPointer());
pnRenderer->AddActor(pnActor.GetPointer());
pnRenderer->ResetCamera();
pnRenderer->GetActiveCamera()->SetPosition(0.0, 4.5, 7.5);
// cell normals
vtkNew<vtkCellCenters> cells;
cells->SetInputConnection(normals->GetOutputPort());
vtkNew<vtkGlyph3D> cnGlyphs;
cnGlyphs->SetInputConnection(cells->GetOutputPort());
cnGlyphs->SetSourceConnection(arrow->GetOutputPort());
cnGlyphs->SetScaleFactor(0.5);
cnGlyphs->OrientOn();
cnGlyphs->SetVectorModeToUseNormal();
vtkNew<vtkPolyDataMapper> cnMapper;
cnMapper->SetInputConnection(cnGlyphs->GetOutputPort());
vtkNew<vtkActor> cnActor;
cnActor->SetMapper(cnMapper.GetPointer());
vtkNew<vtkRenderer> cnRenderer;
cnRenderer->AddActor(cylinderActor.GetPointer());
cnRenderer->AddActor(cnActor.GetPointer());
cnRenderer->ResetCamera();
cnRenderer->GetActiveCamera()->SetPosition(0.0, 8.0, 0.1);
// render
vtkNew<vtkRenderWindow> renWin;
renWin->SetSize(600, 300);
pnRenderer->SetViewport(0.0, 0.0, 0.5, 1.0);
renWin->AddRenderer(pnRenderer.GetPointer());
cnRenderer->SetViewport(0.5, 0.0, 1.0, 1.0);
renWin->AddRenderer(cnRenderer.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;
}
......@@ -203,6 +203,7 @@ struct CellListUnstructuredInVTK
struct CellListUnstructuredOutVTK
: vtkm::ListTagBase<
vtkm::cont::CellSetExplicit<>, vtkm::cont::CellSetSingleType<>,
vtkm::cont::vtkmCellSetExplicitAOS, vtkm::cont::vtkmCellSetSingleType,
vtkm::cont::CellSetPermutation<vtkm::cont::vtkmCellSetExplicitAOS>,
vtkm::cont::CellSetPermutation<vtkm::cont::vtkmCellSetSingleType>>
{
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmPolyDataNormals.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 "vtkmPolyDataNormals.cxx"
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmPolyDataNormals.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 "vtkmPolyDataNormals.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"
vtkStandardNewMacro(vtkmPolyDataNormals)
//------------------------------------------------------------------------------
void vtkmPolyDataNormals::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//------------------------------------------------------------------------------
vtkmPolyDataNormals::vtkmPolyDataNormals()
{
// change defaults from parent
this->Splitting = 0;
this->Consistency = 0;
this->FlipNormals = 0;
this->ComputePointNormals = 1;
this->ComputeCellNormals = 0;
this->AutoOrientNormals = 0;
}
//------------------------------------------------------------------------------
vtkmPolyDataNormals::~vtkmPolyDataNormals() = default;
//------------------------------------------------------------------------------
int vtkmPolyDataNormals::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()));
// 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;
}
vtkmInputFilterPolicy policy;
vtkm::cont::DataSet out;
// check for flags that vtkm filter cannot handle
bool unsupported = this->Splitting || this->Consistency || this->FlipNormals;
bool vtkmSuccess = false;
if (!unsupported)
{
vtkm::filter::SurfaceNormals filter;
filter.SetGenerateCellNormals(this->ComputeCellNormals);
filter.SetCellNormalsName("Normals");
filter.SetGeneratePointNormals(this->ComputePointNormals);
filter.SetPointNormalsName("Normals");
auto result = filter.Execute(in, policy);
if (result.IsValid())
{
out = result.GetDataSet();
vtkmSuccess = true;
}
}
if (!vtkmSuccess)
{
vtkWarningMacro(<< "VTKm SurfaceNormals algorithm failed to run"
<< (unsupported ? ": unsupported settings." : ".")
<< "Falling back to vtkPolyDataNormals.");
return this->Superclass::RequestData(request, inputVector, outputVector);
}
if (!fromvtkm::Convert(out, output, input))
{
vtkErrorMacro(<< "Unable to convert VTKm DataSet back to VTK");
return 0;
}
vtkSmartPointer<vtkDataArray> pointNormals = output->GetPointData()->GetArray("Normals");
vtkSmartPointer<vtkDataArray> cellNormals = output->GetCellData()->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());
}
if (cellNormals)
{
output->GetCellData()->SetNormals(cellNormals.GetPointer());
}
return 1;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkmPolyDataNormals.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 vtkmPolyDataNormals_h
#define vtkmPolyDataNormals_h
#include "vtkPolyDataNormals.h"
#include "vtkAcceleratorsVTKmModule.h" // for export macro
class VTKACCELERATORSVTKM_EXPORT vtkmPolyDataNormals : public vtkPolyDataNormals
{
public:
vtkTypeMacro(vtkmPolyDataNormals, vtkPolyDataNormals)
void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
static vtkmPolyDataNormals* New();
protected:
vtkmPolyDataNormals();
~vtkmPolyDataNormals();
int RequestData(vtkInformation*, vtkInformationVector**,
vtkInformationVector*) VTK_OVERRIDE;
private:
vtkmPolyDataNormals(const vtkmPolyDataNormals&) VTK_DELETE_FUNCTION;
void operator=(const vtkmPolyDataNormals&) VTK_DELETE_FUNCTION;
};
#endif // vtkmPolyDataNormals_h
// VTK-HeaderTest-Exclude: vtkmPolyDataNormals.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