Merge topic 'triangle-tetra-filter'

36b48099 Move the processing of scatter cell data to worklet from the filter.
3a1a6aec Added mapping of cell data onto output dataset
984af5a2 Reorganize Triangulate and Tetrahedralize and write filters.

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !732
This commit is contained in:
Patricia Fasel 2017-03-27 14:27:09 +00:00 committed by Kitware Robot
commit 49d897ef9f
24 changed files with 1102 additions and 593 deletions

@ -31,7 +31,6 @@ add_subdirectory(hello_world)
add_subdirectory(isosurface)
add_subdirectory(multi_backend)
add_subdirectory(streamline)
add_subdirectory(tetrahedra)
if(VTKm_ENABLE_RENDERING)
add_subdirectory(rendering)
endif()

@ -47,6 +47,11 @@ if(VTKm_OpenGL_FOUND AND VTKm_GLUT_FOUND)
target_link_libraries(TriangulateUniformGrid_SERIAL PRIVATE ${VTKm_LIBRARIES})
target_compile_options(TriangulateUniformGrid_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
add_executable(TriangulateStructured_SERIAL TriangulateStructured.cxx)
target_include_directories(TriangulateStructured_SERIAL PRIVATE ${VTKm_INCLUDE_DIRS})
target_link_libraries(TriangulateStructured_SERIAL PRIVATE ${VTKm_LIBRARIES})
target_compile_options(TriangulateStructured_SERIAL PRIVATE ${VTKm_COMPILE_OPTIONS})
if(VTKm_CUDA_FOUND)
# Cuda compiles do not respect target_include_directories
cuda_include_directories(${VTKm_INCLUDE_DIRS})

@ -40,7 +40,9 @@ set(headers
ResultBase.h
ResultDataSet.h
ResultField.h
Tetrahedralize.h
Threshold.h
Triangulate.h
VectorMagnitude.h
VertexClustering.h
)
@ -60,7 +62,9 @@ set(header_template_sources
MarchingCubes.hxx
PointAverage.hxx
PointElevation.hxx
Tetrahedralize.hxx
Threshold.hxx
Triangulate.hxx
VectorMagnitude.hxx
VertexClustering.hxx
)

@ -0,0 +1,61 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_Tetrahedralize_h
#define vtk_m_filter_Tetrahedralize_h
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/Tetrahedralize.h>
namespace vtkm {
namespace filter {
class Tetrahedralize : public vtkm::filter::FilterDataSet<Tetrahedralize>
{
public:
VTKM_CONT
Tetrahedralize();
template<typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
vtkm::filter::ResultDataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
// Map new field onto the resulting dataset after running the filter
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
bool DoMapField(vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
private:
vtkm::worklet::Tetrahedralize Worklet;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/Tetrahedralize.hxx>
#endif // vtk_m_filter_Tetrahedralize_h

@ -0,0 +1,105 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm {
namespace filter {
//-----------------------------------------------------------------------------
inline VTKM_CONT
Tetrahedralize::Tetrahedralize():
vtkm::filter::FilterDataSet<Tetrahedralize>(),
Worklet()
{
}
//-----------------------------------------------------------------------------
template<typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
vtkm::filter::ResultDataSet Tetrahedralize::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
{
typedef vtkm::cont::CellSetStructured<3> CellSetStructuredType;
typedef vtkm::cont::CellSetExplicit<> CellSetExplicitType;
const vtkm::cont::DynamicCellSet& cells =
input.GetCellSet(this->GetActiveCellSetIndex());
vtkm::cont::CellSetSingleType<> outCellSet;
if (cells.IsType<CellSetStructuredType>())
{
outCellSet = this->Worklet.Run(cells.Cast<CellSetStructuredType>(),
device);
}
else
{
outCellSet = this->Worklet.Run(cells.Cast<CellSetExplicitType>(),
device);
}
// create the output dataset
vtkm::cont::DataSet output;
output.AddCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()) );
return vtkm::filter::ResultDataSet(output);
}
//-----------------------------------------------------------------------------
template<typename T,
typename StorageType,
typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
bool Tetrahedralize::DoMapField(
vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
{
// point data is copied as is because it was not collapsed
if(fieldMeta.IsPointField())
{
result.GetDataSet().AddField(fieldMeta.AsField(input));
return true;
}
// cell data must be scattered to the cells created per input cell
if(fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T, StorageType> output =
this->Worklet.ProcessField(input, device);
result.GetDataSet().AddField(fieldMeta.AsField(output));
return true;
}
return false;
}
}
}

61
vtkm/filter/Triangulate.h Normal file

@ -0,0 +1,61 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_filter_Triangulate_h
#define vtk_m_filter_Triangulate_h
#include <vtkm/filter/FilterDataSet.h>
#include <vtkm/worklet/Triangulate.h>
namespace vtkm {
namespace filter {
class Triangulate : public vtkm::filter::FilterDataSet<Triangulate>
{
public:
VTKM_CONT
Triangulate();
template<typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
vtkm::filter::ResultDataSet DoExecute(const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
// Map new field onto the resulting dataset after running the filter
template<typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
VTKM_CONT
bool DoMapField(vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
const DeviceAdapter& tag);
private:
vtkm::worklet::Triangulate Worklet;
};
}
} // namespace vtkm::filter
#include <vtkm/filter/Triangulate.hxx>
#endif // vtk_m_filter_Triangulate_h

106
vtkm/filter/Triangulate.hxx Normal file

@ -0,0 +1,106 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/worklet/ScatterCounting.h>
#include <vtkm/worklet/DispatcherMapField.h>
namespace vtkm {
namespace filter {
//-----------------------------------------------------------------------------
inline VTKM_CONT
Triangulate::Triangulate():
vtkm::filter::FilterDataSet<Triangulate>(),
Worklet()
{
}
//-----------------------------------------------------------------------------
template<typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
vtkm::filter::ResultDataSet Triangulate::DoExecute(
const vtkm::cont::DataSet& input,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
{
typedef vtkm::cont::CellSetStructured<2> CellSetStructuredType;
typedef vtkm::cont::CellSetExplicit<> CellSetExplicitType;
const vtkm::cont::DynamicCellSet& cells =
input.GetCellSet(this->GetActiveCellSetIndex());
vtkm::cont::CellSetSingleType<> outCellSet;
if (cells.IsType<CellSetStructuredType>())
{
outCellSet = this->Worklet.Run(cells.Cast<CellSetStructuredType>(),
device);
}
else
{
outCellSet = this->Worklet.Run(cells.Cast<CellSetExplicitType>(),
device);
}
// create the output dataset
vtkm::cont::DataSet output;
output.AddCellSet(outCellSet);
output.AddCoordinateSystem(input.GetCoordinateSystem(this->GetActiveCoordinateSystemIndex()) );
return vtkm::filter::ResultDataSet(output);
}
//-----------------------------------------------------------------------------
template<typename T,
typename StorageType,
typename DerivedPolicy,
typename DeviceAdapter>
inline VTKM_CONT
bool Triangulate::DoMapField(
vtkm::filter::ResultDataSet& result,
const vtkm::cont::ArrayHandle<T, StorageType>& input,
const vtkm::filter::FieldMetadata& fieldMeta,
const vtkm::filter::PolicyBase<DerivedPolicy>&,
const DeviceAdapter& device)
{
// point data is copied as is because it was not collapsed
if(fieldMeta.IsPointField())
{
result.GetDataSet().AddField(fieldMeta.AsField(input));
return true;
}
// cell data must be scattered to the cells created per input cell
if(fieldMeta.IsCellField())
{
vtkm::cont::ArrayHandle<T, StorageType> output =
this->Worklet.ProcessField(input, device);
result.GetDataSet().AddField(fieldMeta.AsField(output));
return true;
}
return false;
}
}
}

@ -30,7 +30,9 @@ set(unit_tests
UnitTestMarchingCubesFilter.cxx
UnitTestPointAverageFilter.cxx
UnitTestPointElevationFilter.cxx
UnitTestTetrahedralizeFilter.cxx
UnitTestThresholdFilter.cxx
UnitTestTriangulateFilter.cxx
UnitTestVectorMagnitudeFilter.cxx
UnitTestVertexClusteringFilter.cxx
)

@ -0,0 +1,85 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/Tetrahedralize.h>
using vtkm::cont::testing::MakeTestDataSet;
namespace {
class TestingTetrahedralize
{
public:
void TestStructured() const
{
std::cout << "Testing tetrahedralize structured" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DUniformDataSet0();
vtkm::filter::ResultDataSet result;
vtkm::filter::Tetrahedralize tetrahedralize;
result = tetrahedralize.Execute(dataset);
tetrahedralize.MapFieldOntoOutput(result, dataset.GetField("pointvar") );
tetrahedralize.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), 20),
"Wrong result for Tetrahedralize");
VTKM_TEST_ASSERT(test_equal(output.GetField("pointvar").GetData().GetNumberOfValues(), 18),
"Wrong number of points for Tetrahedralize");
}
void TestExplicit() const
{
std::cout << "Testing tetrahedralize explicit" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make3DExplicitDataSet5();
vtkm::filter::ResultDataSet result;
vtkm::filter::Tetrahedralize tetrahedralize;
result = tetrahedralize.Execute(dataset);
tetrahedralize.MapFieldOntoOutput(result, dataset.GetField("pointvar") );
tetrahedralize.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), 11),
"Wrong result for Tetrahedralize");
VTKM_TEST_ASSERT(test_equal(output.GetField("pointvar").GetData().GetNumberOfValues(), 11),
"Wrong number of points for Tetrahedralize");
}
void operator()() const
{
this->TestStructured();
this->TestExplicit();
}
};
}
int UnitTestTetrahedralizeFilter(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestingTetrahedralize());
}

@ -0,0 +1,101 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
#include <vtkm/filter/Triangulate.h>
using vtkm::cont::testing::MakeTestDataSet;
namespace {
class TestingTriangulate
{
public:
void TestStructured() const
{
std::cout << "Testing triangulate structured" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DUniformDataSet1();
vtkm::filter::ResultDataSet result;
vtkm::filter::Triangulate triangulate;
result = triangulate.Execute(dataset);
triangulate.MapFieldOntoOutput(result, dataset.GetField("pointvar") );
triangulate.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), 32),
"Wrong result for Triangulate");
VTKM_TEST_ASSERT(test_equal(output.GetField("pointvar").GetData().GetNumberOfValues(), 25),
"Wrong number of points for Triangulate");
vtkm::cont::ArrayHandle<vtkm::Float32> outData =
output.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32> >();
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(2) == 1.f, "Wrong cell field data");
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(3) == 1.f, "Wrong cell field data");
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(30) == 15.f, "Wrong cell field data");
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(31) == 15.f, "Wrong cell field data");
}
void TestExplicit() const
{
std::cout << "Testing triangulate explicit" << std::endl;
vtkm::cont::DataSet dataset = MakeTestDataSet().Make2DExplicitDataSet0();
vtkm::filter::ResultDataSet result;
vtkm::filter::Triangulate triangulate;
result = triangulate.Execute(dataset);
triangulate.MapFieldOntoOutput(result, dataset.GetField("pointvar") );
triangulate.MapFieldOntoOutput(result, dataset.GetField("cellvar") );
vtkm::cont::DataSet output = result.GetDataSet();
VTKM_TEST_ASSERT(test_equal(output.GetCellSet().GetNumberOfCells(), 14),
"Wrong result for Triangulate");
VTKM_TEST_ASSERT(test_equal(output.GetField("pointvar").GetData().GetNumberOfValues(), 16),
"Wrong number of points for Triangulate");
vtkm::cont::ArrayHandle<vtkm::Float32> outData =
output.GetField("cellvar").GetData().Cast<vtkm::cont::ArrayHandle<vtkm::Float32> >();
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(1) == 1.f, "Wrong cell field data");
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(2) == 1.f, "Wrong cell field data");
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(5) == 3.f, "Wrong cell field data");
VTKM_TEST_ASSERT(outData.GetPortalConstControl().Get(6) == 3.f, "Wrong cell field data");
}
void operator()() const
{
this->TestStructured();
this->TestExplicit();
}
};
}
int UnitTestTriangulateFilter(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestingTriangulate());
}

@ -44,11 +44,9 @@ set(headers
ScatterIdentity.h
ScatterUniform.h
StreamLineUniformGrid.h
TetrahedralizeExplicitGrid.h
TetrahedralizeUniformGrid.h
Tetrahedralize.h
Threshold.h
TriangulateExplicitGrid.h
TriangulateUniformGrid.h
Triangulate.h
VertexClustering.h
WaveletCompressor.h
WorkletMapField.h
@ -60,6 +58,8 @@ set(headers
add_subdirectory(internal)
add_subdirectory(contourtree)
add_subdirectory(splatkernels)
add_subdirectory(tetrahedralize)
add_subdirectory(triangulate)
add_subdirectory(wavelets)
vtkm_declare_headers(${headers})

@ -0,0 +1,107 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtkm_m_worklet_Tetrahedralize_h
#define vtkm_m_worklet_Tetrahedralize_h
#include <vtkm/worklet/tetrahedralize/TetrahedralizeExplicit.h>
#include <vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h>
namespace vtkm {
namespace worklet {
//
// Distribute multiple copies of cell data depending on cells create from original
//
struct DistributeCellData : public vtkm::worklet::WorkletMapField
{
typedef void ControlSignature(FieldIn<> inIndices,
FieldOut<> outIndices);
typedef void ExecutionSignature(_1, _2);
typedef vtkm::worklet::ScatterCounting ScatterType;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename DeviceAdapter>
VTKM_CONT
DistributeCellData(const CountArrayType &countArray,
DeviceAdapter device) :
Scatter(countArray, device) { }
template <typename T>
VTKM_EXEC
void operator()(T inputIndex,
T &outputIndex) const
{
outputIndex = inputIndex;
}
private:
ScatterType Scatter;
};
class Tetrahedralize
{
public:
Tetrahedralize() : OutCellsPerCell() {}
// Tetrahedralize explicit data set, save number of tetra cells per input
template <typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetExplicit<> &cellSet,
const DeviceAdapter&)
{
TetrahedralizeExplicit<DeviceAdapter> worklet;
return worklet.Run(cellSet, this->OutCellsPerCell);
}
// Tetrahedralize structured data set, save number of tetra cells per input
template <typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<3> &cellSet,
const DeviceAdapter&)
{
TetrahedralizeStructured<DeviceAdapter> worklet;
return worklet.Run(cellSet, this->OutCellsPerCell);
}
// Using the saved input to output cells, expand cell data
template <typename T,
typename StorageType,
typename DeviceAdapter>
vtkm::cont::ArrayHandle<T, StorageType> ProcessField(
const vtkm::cont::ArrayHandle<T, StorageType> &input,
const DeviceAdapter& device)
{
vtkm::cont::ArrayHandle<T, StorageType> output;
DistributeCellData distribute(this->OutCellsPerCell, device);
vtkm::worklet::DispatcherMapField<DistributeCellData, DeviceAdapter> dispatcher(distribute);
dispatcher.Invoke(input, output);
return output;
}
private:
vtkm::cont::ArrayHandle<vtkm::IdComponent> OutCellsPerCell;
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_Tetrahedralize_h

107
vtkm/worklet/Triangulate.h Normal file

@ -0,0 +1,107 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtkm_m_worklet_Triangulate_h
#define vtkm_m_worklet_Triangulate_h
#include <vtkm/worklet/triangulate/TriangulateExplicit.h>
#include <vtkm/worklet/triangulate/TriangulateStructured.h>
namespace vtkm {
namespace worklet {
//
// Distribute multiple copies of cell data depending on cells create from original
//
struct DistributeCellData : public vtkm::worklet::WorkletMapField
{
typedef void ControlSignature(FieldIn<> inIndices,
FieldOut<> outIndices);
typedef void ExecutionSignature(_1, _2);
typedef vtkm::worklet::ScatterCounting ScatterType;
VTKM_CONT
ScatterType GetScatter() const { return this->Scatter; }
template <typename CountArrayType, typename DeviceAdapter>
VTKM_CONT
DistributeCellData(const CountArrayType &countArray,
DeviceAdapter device) :
Scatter(countArray, device) { }
template <typename T>
VTKM_EXEC
void operator()(T inputIndex,
T &outputIndex) const
{
outputIndex = inputIndex;
}
private:
ScatterType Scatter;
};
class Triangulate
{
public:
Triangulate() : OutCellsPerCell() {}
// Triangulate explicit data set, save number of triangulated cells per input
template <typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetExplicit<> &cellSet,
const DeviceAdapter&)
{
TriangulateExplicit<DeviceAdapter> worklet;
return worklet.Run(cellSet, this->OutCellsPerCell);
}
// Triangulate structured data set, save number of triangulated cells per input
template <typename DeviceAdapter>
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<2> &cellSet,
const DeviceAdapter&)
{
TriangulateStructured<DeviceAdapter> worklet;
return worklet.Run(cellSet, this->OutCellsPerCell);
}
// Using the saved input to output cells, expand cell data
template <typename T,
typename StorageType,
typename DeviceAdapter>
vtkm::cont::ArrayHandle<T, StorageType> ProcessField(
const vtkm::cont::ArrayHandle<T, StorageType> &input,
const DeviceAdapter& device)
{
vtkm::cont::ArrayHandle<T, StorageType> output;
DistributeCellData distribute(this->OutCellsPerCell, device);
vtkm::worklet::DispatcherMapField<DistributeCellData, DeviceAdapter> dispatcher(distribute);
dispatcher.Invoke(input, output);
return output;
}
private:
vtkm::cont::ArrayHandle<vtkm::IdComponent> OutCellsPerCell;
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_Triangulate_h

@ -37,9 +37,9 @@ set(unit_tests
UnitTestSplatKernels.cxx
UnitTestStreamingSine.cxx
UnitTestStreamLineUniformGrid.cxx
UnitTestTetrahedralizeExplicitGrid.cxx
UnitTestTetrahedralizeUniformGrid.cxx
UnitTestTetrahedralize.cxx
UnitTestThreshold.cxx
UnitTestTriangulate.cxx
UnitTestWorkletMapField.cxx
UnitTestWorkletMapFieldExecArg.cxx
UnitTestWorkletMapFieldWholeArray.cxx

@ -0,0 +1,106 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/worklet/Tetrahedralize.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
using vtkm::cont::testing::MakeTestDataSet;
template <typename DeviceAdapter>
class TestingTetrahedralize
{
public:
//
// Create a uniform 3D structured cell set as input
// Add a field which is the index type which is (i+j+k) % 2 to alternate tetrahedralization pattern
// Points are all the same, but each hexahedron cell becomes 5 tetrahedral cells
//
void TestStructured() const
{
std::cout << "Testing TetrahedralizeStructured" << std::endl;
typedef vtkm::cont::CellSetStructured<3> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DUniformDataSet0();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
// Convert uniform hexahedra to tetrahedra
vtkm::worklet::Tetrahedralize tetrahedralize;
OutCellSetType outCellSet = tetrahedralize.Run(cellSet,
DeviceAdapter());
// Create the output dataset with same coordinate system
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), cellSet.GetNumberOfCells() * 5),
"Wrong result for Tetrahedralize filter");
}
//
// Create an explicit 3D cell set as input and fill
// Points are all the same, but each cell becomes tetrahedra
//
void TestExplicit() const
{
std::cout << "Testing TetrahedralizeExplicit" << std::endl;
typedef vtkm::cont::CellSetExplicit<> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Create the input explicit cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make3DExplicitDataSet5();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::ArrayHandle<vtkm::IdComponent> outCellsPerCell;
// Convert explicit cells to tetrahedra
vtkm::worklet::Tetrahedralize tetrahedralize;
OutCellSetType outCellSet = tetrahedralize.Run(cellSet,
DeviceAdapter());
// Create the output dataset explicit cell set with same coordinate system
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 11),
"Wrong result for Tetrahedralize filter");
}
void operator()() const
{
TestStructured();
TestExplicit();
}
};
int UnitTestTetrahedralize(int, char *[])
{
return vtkm::cont::testing::Testing::Run(
TestingTetrahedralize<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>());
}

@ -1,250 +0,0 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/worklet/TetrahedralizeExplicitGrid.h>
#include <vtkm/worklet/TriangulateExplicitGrid.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/Testing.h>
namespace {
//
// Test 2D explicit dataset
//
vtkm::cont::DataSet MakeTriangulateExplicitDataSet()
{
vtkm::cont::DataSetBuilderExplicitIterative builder;
builder.Begin();
builder.AddPoint(0, 0, 0); // 0
builder.AddPoint(1, 0, 0); // 1
builder.AddPoint(2, 0, 0); // 2
builder.AddPoint(3, 0, 0); // 3
builder.AddPoint(0, 1, 0); // 4
builder.AddPoint(1, 1, 0); // 5
builder.AddPoint(2, 1, 0); // 6
builder.AddPoint(3, 1, 0); // 7
builder.AddPoint(0, 2, 0); // 8
builder.AddPoint(1, 2, 0); // 9
builder.AddPoint(2, 2, 0); // 10
builder.AddPoint(3, 2, 0); // 11
builder.AddPoint(0, 3, 0); // 12
builder.AddPoint(3, 3, 0); // 13
builder.AddPoint(1, 4, 0); // 14
builder.AddPoint(2, 4, 0); // 15
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
builder.AddCellPoint(0);
builder.AddCellPoint(1);
builder.AddCellPoint(5);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(1);
builder.AddCellPoint(2);
builder.AddCellPoint(6);
builder.AddCellPoint(5);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(5);
builder.AddCellPoint(6);
builder.AddCellPoint(10);
builder.AddCellPoint(9);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(4);
builder.AddCellPoint(5);
builder.AddCellPoint(9);
builder.AddCellPoint(8);
builder.AddCell(vtkm::CELL_SHAPE_TRIANGLE);
builder.AddCellPoint(2);
builder.AddCellPoint(3);
builder.AddCellPoint(7);
builder.AddCell(vtkm::CELL_SHAPE_QUAD);
builder.AddCellPoint(6);
builder.AddCellPoint(7);
builder.AddCellPoint(11);
builder.AddCellPoint(10);
builder.AddCell(vtkm::CELL_SHAPE_POLYGON);
builder.AddCellPoint(9);
builder.AddCellPoint(10);
builder.AddCellPoint(13);
builder.AddCellPoint(15);
builder.AddCellPoint(14);
builder.AddCellPoint(12);
return builder.Create();
}
//
// Test 3D explicit dataset
//
vtkm::cont::DataSet MakeTetrahedralizeExplicitDataSet()
{
vtkm::cont::DataSetBuilderExplicitIterative builder;
builder.Begin();
builder.AddPoint(0, 0, 0);
builder.AddPoint(1, 0, 0);
builder.AddPoint(2, 0, 0);
builder.AddPoint(3, 0, 0);
builder.AddPoint(0, 1, 0);
builder.AddPoint(1, 1, 0);
builder.AddPoint(2, 1, 0);
builder.AddPoint(2.5, 1.0, 0.0);
builder.AddPoint(0, 2, 0);
builder.AddPoint(1, 2, 0);
builder.AddPoint(0.5, 0.5, 1.0);
builder.AddPoint(1, 0, 1);
builder.AddPoint(2, 0, 1);
builder.AddPoint(3, 0, 1);
builder.AddPoint(1, 1, 1);
builder.AddPoint(2, 1, 1);
builder.AddPoint(2.5, 1.0, 1.0);
builder.AddPoint(0.5, 1.5, 1.0);
builder.AddCell(vtkm::CELL_SHAPE_TETRA);
builder.AddCellPoint(0);
builder.AddCellPoint(1);
builder.AddCellPoint(5);
builder.AddCellPoint(10);
builder.AddCell(vtkm::CELL_SHAPE_HEXAHEDRON);
builder.AddCellPoint(1);
builder.AddCellPoint(2);
builder.AddCellPoint(6);
builder.AddCellPoint(5);
builder.AddCellPoint(11);
builder.AddCellPoint(12);
builder.AddCellPoint(15);
builder.AddCellPoint(14);
builder.AddCell(vtkm::CELL_SHAPE_WEDGE);
builder.AddCellPoint(2);
builder.AddCellPoint(3);
builder.AddCellPoint(7);
builder.AddCellPoint(12);
builder.AddCellPoint(13);
builder.AddCellPoint(16);
builder.AddCell(vtkm::CELL_SHAPE_PYRAMID);
builder.AddCellPoint(4);
builder.AddCellPoint(5);
builder.AddCellPoint(9);
builder.AddCellPoint(8);
builder.AddCellPoint(17);
return builder.Create();
}
}
//
// Create an explicit 2D cell set as input and fill
// Create an explicit 2D cell set as output
// Points are all the same, but each cell becomes triangle cells
//
void TestExplicitGrid2D()
{
std::cout << "Testing TriangulateExplicitGrid Filter" << std::endl;
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
// Create the input uniform cell set
vtkm::cont::DataSet inDataSet = MakeTriangulateExplicitDataSet();
// Create the output dataset explicit cell set with same coordinate system
vtkm::cont::DataSet outDataSet;
vtkm::cont::CellSetSingleType<> outCellSet("cells");
outDataSet.AddCellSet(outCellSet);
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert explicit cells to triangles
vtkm::worklet::TriangulateFilterExplicitGrid<DeviceAdapter>
triangulateFilter(inDataSet, outDataSet);
triangulateFilter.Run();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData();
std::cout << "Number of output triangles " << cellSet.GetNumberOfCells() << std::endl;
std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl;
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::Bounds bounds = coordinates.GetBounds();
std::cout << "Bounds " << bounds << std::endl;
VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), 14), "Wrong result for Triangulate filter");
}
//
// Create an explicit 3D cell set as input and fill
// Create an explicit 3D cell set as output
// Points are all the same, but each cell becomes tetrahedra
//
void TestExplicitGrid3D()
{
std::cout << "Testing TetrahedralizeExplicitGrid Filter" << std::endl;
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
// Create the input uniform cell set
vtkm::cont::DataSet inDataSet = MakeTetrahedralizeExplicitDataSet();
// Create the output dataset explicit cell set with same coordinate system
vtkm::cont::DataSet outDataSet;
vtkm::cont::CellSetSingleType<> outCellSet("cells");
outDataSet.AddCellSet(outCellSet);
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert explicit cells to triangles
vtkm::worklet::TetrahedralizeFilterExplicitGrid<DeviceAdapter>
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem coordArray = coordinates.GetData();
std::cout << "Number of output tetrahedra " << cellSet.GetNumberOfCells() << std::endl;
std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl;
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::Bounds bounds = coordinates.GetBounds();
std::cout << "Bounds " << bounds << std::endl;
VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), 11), "Wrong result for Tetrahedralize filter");
}
void TestTetrahedralizeExplicitGrid()
{
TestExplicitGrid2D();
TestExplicitGrid3D();
}
int UnitTestTetrahedralizeExplicitGrid(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestTetrahedralizeExplicitGrid);
}

@ -1,189 +0,0 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/worklet/TetrahedralizeUniformGrid.h>
#include <vtkm/worklet/TriangulateUniformGrid.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/testing/Testing.h>
namespace {
//
// Test 2D regular dataset
//
vtkm::cont::DataSet MakeTriangulateTestDataSet(vtkm::Id2 dims)
{
vtkm::cont::DataSet dataSet;
const vtkm::Id3 vdims(dims[0] + 1, dims[1] + 1, 1);
const vtkm::Vec<vtkm::Float32, 3> origin = vtkm::make_Vec(0.0f, 0.0f, 0.0f);
const vtkm::Vec<vtkm::Float32, 3> spacing = vtkm::make_Vec(
1.0f/static_cast<vtkm::Float32>(dims[0]),
1.0f/static_cast<vtkm::Float32>(dims[1]),
1.0f);
vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vdims, origin, spacing);
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates));
static const vtkm::IdComponent ndim = 2;
vtkm::cont::CellSetStructured<ndim> cellSet("cells");
cellSet.SetPointDimensions(vtkm::make_Vec(dims[0] + 1, dims[1] + 1));
dataSet.AddCellSet(cellSet);
return dataSet;
}
//
// Test 3D regular dataset
//
vtkm::cont::DataSet MakeTetrahedralizeTestDataSet(vtkm::Id3 dims)
{
vtkm::cont::DataSet dataSet;
const vtkm::Id3 vdims(dims[0] + 1, dims[1] + 1, dims[2] + 1);
const vtkm::Vec<vtkm::Float32, 3> origin = vtkm::make_Vec(0.0f, 0.0f, 0.0f);
const vtkm::Vec<vtkm::Float32, 3> spacing = vtkm::make_Vec(
1.0f/static_cast<vtkm::Float32>(dims[0]),
1.0f/static_cast<vtkm::Float32>(dims[1]),
1.0f/static_cast<vtkm::Float32>(dims[2]));
vtkm::cont::ArrayHandleUniformPointCoordinates coordinates(vdims, origin, spacing);
dataSet.AddCoordinateSystem(
vtkm::cont::CoordinateSystem("coordinates", coordinates));
static const vtkm::IdComponent ndim = 3;
vtkm::cont::CellSetStructured<ndim> cellSet("cells");
cellSet.SetPointDimensions(vdims);
dataSet.AddCellSet(cellSet);
return dataSet;
}
}
//
// Create a uniform 2D structured cell set as input
// Add a field which is the index type which is (i+j) % 2 to alternate triangulation pattern
// Create an unstructured cell set explicit as output
// Points are all the same, but each quad cell becomes 2 triangle cells
//
void TestUniformGrid2D()
{
std::cout << "Testing TriangulationUniformGrid Filter" << std::endl;
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
// Create the input uniform cell set
vtkm::Id2 dims(4,4);
vtkm::cont::DataSet inDataSet = MakeTriangulateTestDataSet(dims);
// Set number of cells and vertices in input dataset
vtkm::Id numberOfCells = dims[0] * dims[1];
vtkm::Id numberOfVertices = (dims[0] + 1) * (dims[1] + 1);
std::cout << "Number of input quads " << numberOfCells << std::endl;
std::cout << "Number of input vertices " << numberOfVertices << std::endl;
// Create the output dataset explicit cell set with same coordinate system
vtkm::cont::DataSet outDataSet;
vtkm::cont::CellSetSingleType<> outCellSet("cells");
outDataSet.AddCellSet(outCellSet);
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert uniform quadrilaterals to triangles
vtkm::worklet::TriangulateFilterUniformGrid<DeviceAdapter>
triangulateFilter(inDataSet, outDataSet);
triangulateFilter.Run();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = coordinates.GetData();
std::cout << "Number of output triangles " << cellSet.GetNumberOfCells() << std::endl;
std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl;
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::Bounds bounds = coordinates.GetBounds();
std::cout << "Bounds " << bounds << std::endl;
// Two triangles are created for every quad cell
VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), numberOfCells * 2),
"Wrong result for Triangulate filter");
}
//
// Create a uniform 3D structured cell set as input
// Add a field which is the index type which is (i+j+k) % 2 to alternate tetrahedralization pattern
// Create an unstructured cell set explicit as output
// Points are all the same, but each hexahedron cell becomes 5 tetrahedral cells
//
void TestUniformGrid3D()
{
std::cout << "Testing TetrahedralizeUniformGrid Filter" << std::endl;
typedef VTKM_DEFAULT_DEVICE_ADAPTER_TAG DeviceAdapter;
// Create the input uniform cell set
vtkm::Id3 dims(4,4,4);
vtkm::cont::DataSet inDataSet = MakeTetrahedralizeTestDataSet(dims);
// Set number of cells and vertices in input dataset
vtkm::Id numberOfCells = dims[0] * dims[1] * dims[2];
vtkm::Id numberOfVertices = (dims[0] + 1) * (dims[1] + 1) * (dims[2] + 1);
std::cout << "Number of input hexahedra " << numberOfCells << std::endl;
std::cout << "Number of input vertices " << numberOfVertices << std::endl;
// Create the output dataset explicit cell set with same coordinate system
vtkm::cont::DataSet outDataSet;
vtkm::cont::CellSetSingleType<> outCellSet("cells");
outDataSet.AddCellSet(outCellSet);
outDataSet.AddCoordinateSystem(inDataSet.GetCoordinateSystem(0));
// Convert uniform hexahedra to tetrahedra
vtkm::worklet::TetrahedralizeFilterUniformGrid<DeviceAdapter>
tetrahedralizeFilter(inDataSet, outDataSet);
tetrahedralizeFilter.Run();
vtkm::cont::CellSetSingleType<> cellSet;
outDataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::CoordinateSystem coordinates = outDataSet.GetCoordinateSystem(0);
const vtkm::cont::DynamicArrayHandleCoordinateSystem &coordArray = coordinates.GetData();
std::cout << "Number of output tetrahedra " << cellSet.GetNumberOfCells() << std::endl;
std::cout << "Number of output vertices " << coordArray.GetNumberOfValues() << std::endl;
std::cout << "Number of output components " << coordArray.GetNumberOfComponents() << std::endl;
vtkm::Bounds bounds = coordinates.GetBounds();
std::cout << "Bounds " << bounds << std::endl;
// Five tets are created for every hex cell
VTKM_TEST_ASSERT(test_equal(cellSet.GetNumberOfCells(), numberOfCells * 5),
"Wrong result for Tetrahedralize filter");
}
void TestTetrahedralizeUniformGrid()
{
TestUniformGrid3D();
TestUniformGrid2D();
}
int UnitTestTetrahedralizeUniformGrid(int, char *[])
{
return vtkm::cont::testing::Testing::Run(TestTetrahedralizeUniformGrid);
}

@ -0,0 +1,97 @@
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt 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.
//
// Copyright 2014 Sandia Corporation.
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/worklet/Triangulate.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DataSetBuilderExplicit.h>
#include <vtkm/cont/testing/MakeTestDataSet.h>
#include <vtkm/cont/testing/Testing.h>
using vtkm::cont::testing::MakeTestDataSet;
template <typename DeviceAdapter>
class TestingTriangulate
{
public:
void TestStructured() const
{
std::cout << "Testing TriangulateStructured:" << std::endl;
typedef vtkm::cont::CellSetStructured<2> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DUniformDataSet1();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
// Convert uniform quadrilaterals to triangles
vtkm::worklet::Triangulate triangulate;
OutCellSetType outCellSet = triangulate.Run(cellSet,
DeviceAdapter());
// Create the output dataset and assign the input coordinate system
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
outDataSet.AddCellSet(outCellSet);
// Two triangles are created for every quad cell
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), cellSet.GetNumberOfCells() * 2),
"Wrong result for Triangulate filter");
}
void TestExplicit() const
{
std::cout << "Testing TriangulateExplicit:" << std::endl;
typedef vtkm::cont::CellSetExplicit<> CellSetType;
typedef vtkm::cont::CellSetSingleType<> OutCellSetType;
// Create the input uniform cell set
vtkm::cont::DataSet dataSet = MakeTestDataSet().Make2DExplicitDataSet0();
CellSetType cellSet;
dataSet.GetCellSet(0).CopyTo(cellSet);
vtkm::cont::ArrayHandle<vtkm::IdComponent> outCellsPerCell;
// Convert explicit cells to triangles
vtkm::worklet::Triangulate triangulate;
OutCellSetType outCellSet = triangulate.Run(cellSet,
DeviceAdapter());
// Create the output dataset explicit cell set with same coordinate system
vtkm::cont::DataSet outDataSet;
outDataSet.AddCoordinateSystem(dataSet.GetCoordinateSystem(0));
outDataSet.AddCellSet(outCellSet);
VTKM_TEST_ASSERT(test_equal(outCellSet.GetNumberOfCells(), 14), "Wrong result for Triangulate filter");
}
void operator()() const
{
TestStructured();
TestExplicit();
}
};
int UnitTestTriangulate(int, char *[])
{
return vtkm::cont::testing::Testing::Run(
TestingTriangulate<VTKM_DEFAULT_DEVICE_ADAPTER_TAG>());
}

@ -0,0 +1,27 @@
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt 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.
##
## Copyright 2016 Sandia Corporation.
## Copyright 2016 UT-Battelle, LLC.
## Copyright 2016 Los Alamos National Security.
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
set(headers
TetrahedralizeExplicit.h
TetrahedralizeStructured.h
)
#-----------------------------------------------------------------------------
vtkm_declare_headers(${headers})

@ -18,8 +18,8 @@
// this software.
//============================================================================
#ifndef vtk_m_worklet_TetrahedralizeExplicitGrid_h
#define vtk_m_worklet_TetrahedralizeExplicitGrid_h
#ifndef vtk_m_worklet_TetrahedralizeExplicit_h
#define vtk_m_worklet_TetrahedralizeExplicit_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleGroupVec.h>
@ -42,9 +42,10 @@ namespace worklet {
/// \brief Compute the tetrahedralize cells for an explicit grid data set
template <typename DeviceAdapter>
class TetrahedralizeFilterExplicitGrid
class TetrahedralizeExplicit
{
public:
TetrahedralizeExplicit() {}
//
// Worklet to count the number of tetrahedra generated per cell
@ -119,34 +120,19 @@ public:
ScatterType Scatter;
};
//
// Construct the filter to tetrahedralize explicit grid
//
TetrahedralizeFilterExplicitGrid(const vtkm::cont::DataSet &inDataSet,
vtkm::cont::DataSet &outDataSet) :
InDataSet(inDataSet),
OutDataSet(outDataSet)
{}
vtkm::cont::DataSet InDataSet; // input dataset with structured cell set
vtkm::cont::DataSet OutDataSet; // output dataset with explicit cell set
//
// Populate the output dataset with tetrahedra based on input explicit dataset
//
void Run()
template <typename CellSetType>
vtkm::cont::CellSetSingleType<> Run(const CellSetType &cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent> &outCellsPerCell)
{
// Cell sets belonging to input and output datasets
vtkm::cont::CellSetExplicit<> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::cont::CellSetSingleType<> &cellSet =
this->OutDataSet.GetCellSet(0).template Cast<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
// Input topology
vtkm::cont::ArrayHandle<vtkm::UInt8> inShapes = inCellSet.GetShapesArray(
vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::IdComponent> inNumIndices = inCellSet.GetNumIndicesArray(
vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::UInt8> inShapes =
cellSet.GetShapesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::IdComponent> inNumIndices =
cellSet.GetNumIndicesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell());
// Output topology
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
@ -154,32 +140,30 @@ public:
vtkm::worklet::internal::TetrahedralizeTables tables;
// Determine the number of output cells each input cell will generate
vtkm::cont::ArrayHandle<vtkm::IdComponent> numOutCellArray;
vtkm::worklet::DispatcherMapField<TetrahedraPerCell,DeviceAdapter>
tetPerCellDispatcher;
tetPerCellDispatcher;
tetPerCellDispatcher.Invoke(inShapes,
tables.PrepareForInput(DeviceAdapter()),
numOutCellArray);
outCellsPerCell);
// Build new cells
TetrahedralizeCell tetrahedralizeWorklet(numOutCellArray);
TetrahedralizeCell tetrahedralizeWorklet(outCellsPerCell);
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell,DeviceAdapter>
tetrahedralizeDispatcher(tetrahedralizeWorklet);
tetrahedralizeDispatcher.Invoke(
inCellSet,
tables.PrepareForInput(DeviceAdapter()),
vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity));
tetrahedralizeDispatcher(tetrahedralizeWorklet);
tetrahedralizeDispatcher.Invoke(cellSet,
tables.PrepareForInput(DeviceAdapter()),
vtkm::cont::make_ArrayHandleGroupVec<4>(outConnectivity));
// Add cells to output cellset
cellSet.Fill(
this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(),
vtkm::CellShapeTagTetra::Id,
4,
outConnectivity);
outCellSet.Fill(cellSet.GetNumberOfPoints(),
vtkm::CellShapeTagTetra::Id,
4,
outConnectivity);
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_TetrahedralizeExplicitGrid_h
#endif // vtk_m_worklet_TetrahedralizeExplicit_h

@ -18,8 +18,8 @@
// this software.
//============================================================================
#ifndef vtk_m_worklet_TetrahedralizeUniformGrid_h
#define vtk_m_worklet_TetrahedralizeUniformGrid_h
#ifndef vtk_m_worklet_TetrahedralizeStructured_h
#define vtk_m_worklet_TetrahedralizeStructured_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleGroupVec.h>
@ -62,9 +62,10 @@ const static vtkm::IdComponent StructuredTetrahedronIndices[2][5][4] = {
/// \brief Compute the tetrahedralize cells for a uniform grid data set
template <typename DeviceAdapter>
class TetrahedralizeFilterUniformGrid
class TetrahedralizeStructured
{
public:
TetrahedralizeStructured() {}
//
// Worklet to turn hexahedra into tetrahedra
@ -112,46 +113,34 @@ public:
}
};
//
// Construct the filter to tetrahedralize uniform grid
//
TetrahedralizeFilterUniformGrid(const vtkm::cont::DataSet &inDataSet,
vtkm::cont::DataSet &outDataSet) :
InDataSet(inDataSet),
OutDataSet(outDataSet)
template <typename CellSetType>
vtkm::cont::CellSetSingleType<> Run(const CellSetType &cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent> &outCellsPerCell)
{
}
vtkm::cont::DataSet InDataSet; // input dataset with structured cell set
vtkm::cont::DataSet OutDataSet; // output dataset with explicit cell set
//
// Populate the output dataset with tetrahedra based on input uniform dataset
//
void Run()
{
// Get the cell set from the output data set
vtkm::cont::CellSetSingleType<> &cellSet =
this->OutDataSet.GetCellSet(0).template Cast<vtkm::cont::CellSetSingleType<> >();
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
vtkm::cont::CellSetStructured<3> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::worklet::DispatcherMapTopology<TetrahedralizeCell,DeviceAdapter> dispatcher;
dispatcher.Invoke(inCellSet,
dispatcher.Invoke(cellSet,
vtkm::cont::make_ArrayHandleGroupVec<4>(connectivity));
// Fill in array of output cells per input cell
DeviceAlgorithm::Copy(
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(5, cellSet.GetNumberOfCells()),
outCellsPerCell);
// Add cells to output cellset
cellSet.Fill(
this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(),
vtkm::CellShapeTagTetra::Id,
4,
connectivity);
outCellSet.Fill(cellSet.GetNumberOfPoints(),
vtkm::CellShapeTagTetra::Id,
4,
connectivity);
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_TetrahedralizeUniformGrid_h
#endif // vtk_m_worklet_TetrahedralizeStructured_h

@ -0,0 +1,27 @@
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt 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.
##
## Copyright 2016 Sandia Corporation.
## Copyright 2016 UT-Battelle, LLC.
## Copyright 2016 Los Alamos National Security.
##
## Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
set(headers
TriangulateExplicit.h
TriangulateStructured.h
)
#-----------------------------------------------------------------------------
vtkm_declare_headers(${headers})

@ -18,8 +18,8 @@
// this software.
//============================================================================
#ifndef vtk_m_worklet_TriangulateExplicitGrid_h
#define vtk_m_worklet_TriangulateExplicitGrid_h
#ifndef vtk_m_worklet_TriangulateExplicit_h
#define vtk_m_worklet_TriangulateExplicit_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleGroupVec.h>
@ -42,9 +42,10 @@ namespace worklet {
/// \brief Compute the triangulate cells for an explicit grid data set
template <typename DeviceAdapter>
class TriangulateFilterExplicitGrid
class TriangulateExplicit
{
public:
TriangulateExplicit() {}
//
// Worklet to count the number of triangles generated per cell
@ -121,34 +122,19 @@ public:
ScatterType Scatter;
};
//
// Construct the filter to triangulate explicit grid
//
TriangulateFilterExplicitGrid(const vtkm::cont::DataSet &inDataSet,
vtkm::cont::DataSet &outDataSet) :
InDataSet(inDataSet),
OutDataSet(outDataSet)
{}
vtkm::cont::DataSet InDataSet; // input dataset with structured cell set
vtkm::cont::DataSet OutDataSet; // output dataset with explicit cell set
//
// Populate the output dataset with triangles based on input explicit dataset
//
void Run()
template <typename CellSetType>
vtkm::cont::CellSetSingleType<> Run(const CellSetType &cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent> &outCellsPerCell)
{
// Cell sets belonging to input and output datasets
vtkm::cont::CellSetExplicit<> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::cont::CellSetSingleType<> &cellSet =
this->OutDataSet.GetCellSet(0).template Cast<vtkm::cont::CellSetSingleType<> >();
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
// Input topology
vtkm::cont::ArrayHandle<vtkm::UInt8> inShapes = inCellSet.GetShapesArray(
vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::IdComponent> inNumIndices = inCellSet.GetNumIndicesArray(
vtkm::TopologyElementTagPoint(), vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::UInt8> inShapes =
cellSet.GetShapesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell());
vtkm::cont::ArrayHandle<vtkm::IdComponent> inNumIndices =
cellSet.GetNumIndicesArray(vtkm::TopologyElementTagPoint(),
vtkm::TopologyElementTagCell());
// Output topology
vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
@ -156,33 +142,31 @@ public:
vtkm::worklet::internal::TriangulateTables tables;
// Determine the number of output cells each input cell will generate
vtkm::cont::ArrayHandle<vtkm::IdComponent> numOutCellArray;
vtkm::worklet::DispatcherMapField<TrianglesPerCell,DeviceAdapter>
triPerCellDispatcher;
triPerCellDispatcher;
triPerCellDispatcher.Invoke(inShapes,
inNumIndices,
tables.PrepareForInput(DeviceAdapter()),
numOutCellArray);
outCellsPerCell);
// Build new cells
TriangulateCell triangulateWorklet(numOutCellArray);
TriangulateCell triangulateWorklet(outCellsPerCell);
vtkm::worklet::DispatcherMapTopology<TriangulateCell,DeviceAdapter>
triangulateDispatcher(triangulateWorklet);
triangulateDispatcher.Invoke(
inCellSet,
tables.PrepareForInput(DeviceAdapter()),
vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity));
triangulateDispatcher(triangulateWorklet);
triangulateDispatcher.Invoke(cellSet,
tables.PrepareForInput(DeviceAdapter()),
vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity));
// Add cells to output cellset
cellSet.Fill(
this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(),
vtkm::CellShapeTagTriangle::Id,
3,
outConnectivity);
outCellSet.Fill(cellSet.GetNumberOfPoints(),
vtkm::CellShapeTagTriangle::Id,
3,
outConnectivity);
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_TriangulateExplicitGrid_h
#endif // vtk_m_worklet_TriangulateExplicit_h

@ -18,8 +18,8 @@
// this software.
//============================================================================
#ifndef vtk_m_worklet_TriangulateUniformGrid_h
#define vtk_m_worklet_TriangulateUniformGrid_h
#ifndef vtk_m_worklet_TriangulateStructured_h
#define vtk_m_worklet_TriangulateStructured_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleGroupVec.h>
@ -50,9 +50,10 @@ const static vtkm::IdComponent StructuredTriangleIndices[2][3] = {
/// \brief Compute the triangulate cells for a uniform grid data set
template <typename DeviceAdapter>
class TriangulateFilterUniformGrid
class TriangulateStructured
{
public:
TriangulateStructured() {}
//
// Worklet to turn quads into triangles
@ -90,46 +91,36 @@ public:
}
};
//
// Construct the filter to triangulate uniform grid
//
TriangulateFilterUniformGrid(const vtkm::cont::DataSet &inDataSet,
vtkm::cont::DataSet &outDataSet) :
InDataSet(inDataSet),
OutDataSet(outDataSet)
template <typename CellSetType>
vtkm::cont::CellSetSingleType<> Run(const CellSetType &cellSet,
vtkm::cont::ArrayHandle<vtkm::IdComponent> &outCellsPerCell)
{
}
vtkm::cont::DataSet InDataSet; // input dataset with structured cell set
vtkm::cont::DataSet OutDataSet; // output dataset with explicit cell set
//
// Populate the output dataset with triangles based on input uniform dataset
//
void Run()
{
// Get the cell set from the output data set
vtkm::cont::CellSetSingleType<> &cellSet =
this->OutDataSet.GetCellSet(0).template Cast<vtkm::cont::CellSetSingleType<> >();
typedef vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
vtkm::cont::CellSetSingleType<> outCellSet(cellSet.GetName());
vtkm::cont::ArrayHandle<vtkm::Id> connectivity;
vtkm::cont::CellSetStructured<2> inCellSet;
InDataSet.GetCellSet(0).CopyTo(inCellSet);
vtkm::worklet::DispatcherMapTopology<TriangulateCell,DeviceAdapter> dispatcher;
dispatcher.Invoke(inCellSet,
dispatcher.Invoke(cellSet,
vtkm::cont::make_ArrayHandleGroupVec<3>(connectivity));
// Fill in array of output cells per input cell
DeviceAlgorithm::Copy(
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(2, cellSet.GetNumberOfCells()),
outCellsPerCell);
// Add cells to output cellset
cellSet.Fill(
this->OutDataSet.GetCoordinateSystem().GetData().GetNumberOfValues(),
outCellSet.Fill(
cellSet.GetNumberOfPoints(),
vtkm::CellShapeTagTriangle::Id,
3,
connectivity);
return outCellSet;
}
};
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_TriangulateUniformGrid_h
#endif // vtk_m_worklet_TriangulateStructured_h