mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Reorganize Triangulate and Tetrahedralize and write filters.
This commit is contained in:
parent
2481dd6248
commit
984af5a2b4
@ -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
|
||||
)
|
||||
|
58
vtkm/filter/Tetrahedralize.h
Normal file
58
vtkm/filter/Tetrahedralize.h
Normal file
@ -0,0 +1,58 @@
|
||||
//============================================================================
|
||||
// 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);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::filter
|
||||
|
||||
|
||||
#include <vtkm/filter/Tetrahedralize.hxx>
|
||||
|
||||
#endif // vtk_m_filter_Tetrahedralize_h
|
96
vtkm/filter/Tetrahedralize.hxx
Normal file
96
vtkm/filter/Tetrahedralize.hxx
Normal file
@ -0,0 +1,96 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
namespace vtkm {
|
||||
namespace filter {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
inline VTKM_CONT
|
||||
Tetrahedralize::Tetrahedralize():
|
||||
vtkm::filter::FilterDataSet<Tetrahedralize>()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template<typename DerivedPolicy,
|
||||
typename DeviceAdapter>
|
||||
inline VTKM_CONT
|
||||
vtkm::filter::ResultDataSet Tetrahedralize::DoExecute(
|
||||
const vtkm::cont::DataSet& input,
|
||||
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
|
||||
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;
|
||||
vtkm::worklet::Tetrahedralize<DeviceAdapter> worklet;
|
||||
|
||||
if (cells.IsType<CellSetStructuredType>())
|
||||
{
|
||||
outCellSet = worklet.Run(cells.Cast<CellSetStructuredType>());
|
||||
}
|
||||
else
|
||||
{
|
||||
outCellSet = worklet.Run(cells.Cast<CellSetExplicitType>());
|
||||
}
|
||||
|
||||
// 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>& policy,
|
||||
const DeviceAdapter&)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if(fieldMeta.IsPointField())
|
||||
{
|
||||
result.GetDataSet().AddField(fieldMeta.AsField(input));
|
||||
return true;
|
||||
}
|
||||
|
||||
// cell data for structured will be ScatterIndex(2) because every cell became two
|
||||
if(fieldMeta.IsCellField())
|
||||
{
|
||||
result.GetDataSet().AddField(fieldMeta.AsField(input));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
58
vtkm/filter/Triangulate.h
Normal file
58
vtkm/filter/Triangulate.h
Normal file
@ -0,0 +1,58 @@
|
||||
//============================================================================
|
||||
// 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);
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::filter
|
||||
|
||||
|
||||
#include <vtkm/filter/Triangulate.hxx>
|
||||
|
||||
#endif // vtk_m_filter_Triangulate_h
|
96
vtkm/filter/Triangulate.hxx
Normal file
96
vtkm/filter/Triangulate.hxx
Normal file
@ -0,0 +1,96 @@
|
||||
//============================================================================
|
||||
// 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.
|
||||
//============================================================================
|
||||
|
||||
namespace vtkm {
|
||||
namespace filter {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
inline VTKM_CONT
|
||||
Triangulate::Triangulate():
|
||||
vtkm::filter::FilterDataSet<Triangulate>()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template<typename DerivedPolicy,
|
||||
typename DeviceAdapter>
|
||||
inline VTKM_CONT
|
||||
vtkm::filter::ResultDataSet Triangulate::DoExecute(
|
||||
const vtkm::cont::DataSet& input,
|
||||
const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
|
||||
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;
|
||||
vtkm::worklet::Triangulate<DeviceAdapter> worklet;
|
||||
|
||||
if (cells.IsType<CellSetStructuredType>())
|
||||
{
|
||||
outCellSet = worklet.Run(cells.Cast<CellSetStructuredType>());
|
||||
}
|
||||
else
|
||||
{
|
||||
outCellSet = worklet.Run(cells.Cast<CellSetExplicitType>());
|
||||
}
|
||||
|
||||
// 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>& policy,
|
||||
const DeviceAdapter&)
|
||||
{
|
||||
// point data is copied as is because it was not collapsed
|
||||
if(fieldMeta.IsPointField())
|
||||
{
|
||||
result.GetDataSet().AddField(fieldMeta.AsField(input));
|
||||
return true;
|
||||
}
|
||||
|
||||
// cell data for structured will be ScatterIndex(2) because every cell became two
|
||||
if(fieldMeta.IsCellField())
|
||||
{
|
||||
result.GetDataSet().AddField(fieldMeta.AsField(input));
|
||||
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
|
||||
)
|
||||
|
85
vtkm/filter/testing/UnitTestTetrahedralizeFilter.cxx
Normal file
85
vtkm/filter/testing/UnitTestTetrahedralizeFilter.cxx
Normal file
@ -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());
|
||||
}
|
85
vtkm/filter/testing/UnitTestTriangulateFilter.cxx
Normal file
85
vtkm/filter/testing/UnitTestTriangulateFilter.cxx
Normal file
@ -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/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");
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
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})
|
||||
|
51
vtkm/worklet/Tetrahedralize.h
Normal file
51
vtkm/worklet/Tetrahedralize.h
Normal file
@ -0,0 +1,51 @@
|
||||
//============================================================================
|
||||
// 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 {
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class Tetrahedralize
|
||||
{
|
||||
public:
|
||||
Tetrahedralize() {}
|
||||
|
||||
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetExplicit<> &cellSet)
|
||||
{
|
||||
TetrahedralizeExplicit<DeviceAdapter> worklet;
|
||||
return worklet.Run(cellSet);
|
||||
}
|
||||
|
||||
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<3> &cellSet)
|
||||
{
|
||||
TetrahedralizeStructured<DeviceAdapter> worklet;
|
||||
return worklet.Run(cellSet);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace vtkm::worklet
|
||||
|
||||
#endif // vtkm_m_worklet_Tetrahedralize_h
|
51
vtkm/worklet/Triangulate.h
Normal file
51
vtkm/worklet/Triangulate.h
Normal file
@ -0,0 +1,51 @@
|
||||
//============================================================================
|
||||
// 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 {
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
class Triangulate
|
||||
{
|
||||
public:
|
||||
Triangulate() {}
|
||||
|
||||
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetExplicit<> &cellSet)
|
||||
{
|
||||
TriangulateExplicit<DeviceAdapter> worklet;
|
||||
return worklet.Run(cellSet);
|
||||
}
|
||||
|
||||
vtkm::cont::CellSetSingleType<> Run(const vtkm::cont::CellSetStructured<2> &cellSet)
|
||||
{
|
||||
TriangulateStructured<DeviceAdapter> worklet;
|
||||
return worklet.Run(cellSet);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // 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
|
||||
|
103
vtkm/worklet/testing/UnitTestTetrahedralize.cxx
Normal file
103
vtkm/worklet/testing/UnitTestTetrahedralize.cxx
Normal file
@ -0,0 +1,103 @@
|
||||
//============================================================================
|
||||
// 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<DeviceAdapter> tetrahedralize;
|
||||
OutCellSetType outCellSet = tetrahedralize.Run(cellSet);
|
||||
|
||||
// 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);
|
||||
|
||||
// Convert explicit cells to tetrahedra
|
||||
vtkm::worklet::Tetrahedralize<DeviceAdapter> tetrahedralize;
|
||||
OutCellSetType outCellSet = tetrahedralize.Run(cellSet);
|
||||
|
||||
// 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);
|
||||
}
|
94
vtkm/worklet/testing/UnitTestTriangulate.cxx
Normal file
94
vtkm/worklet/testing/UnitTestTriangulate.cxx
Normal file
@ -0,0 +1,94 @@
|
||||
//============================================================================
|
||||
// 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<DeviceAdapter> triangulate;
|
||||
OutCellSetType outCellSet = triangulate.Run(cellSet);
|
||||
|
||||
// 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);
|
||||
|
||||
// Convert explicit cells to triangles
|
||||
vtkm::worklet::Triangulate<DeviceAdapter> triangulate;
|
||||
OutCellSetType outCellSet = triangulate.Run(cellSet);
|
||||
|
||||
// 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>());
|
||||
}
|
27
vtkm/worklet/tetrahedralize/CMakeLists.txt
Normal file
27
vtkm/worklet/tetrahedralize/CMakeLists.txt
Normal file
@ -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,18 @@ 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)
|
||||
{
|
||||
// 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,7 +141,7 @@ public:
|
||||
// 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);
|
||||
@ -164,22 +149,21 @@ public:
|
||||
// Build new cells
|
||||
TetrahedralizeCell tetrahedralizeWorklet(numOutCellArray);
|
||||
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
|
46
vtkm/worklet/TetrahedralizeUniformGrid.h → vtkm/worklet/tetrahedralize/TetrahedralizeStructured.h
46
vtkm/worklet/TetrahedralizeUniformGrid.h → vtkm/worklet/tetrahedralize/TetrahedralizeStructured.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,27 @@ 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::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<> >();
|
||||
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));
|
||||
|
||||
// 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
|
27
vtkm/worklet/triangulate/CMakeLists.txt
Normal file
27
vtkm/worklet/triangulate/CMakeLists.txt
Normal file
@ -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,18 @@ 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)
|
||||
{
|
||||
// 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;
|
||||
@ -158,7 +143,7 @@ public:
|
||||
// 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()),
|
||||
@ -167,22 +152,21 @@ public:
|
||||
// Build new cells
|
||||
TriangulateCell triangulateWorklet(numOutCellArray);
|
||||
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,28 @@ 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::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<> >();
|
||||
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));
|
||||
|
||||
// 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
|
Loading…
Reference in New Issue
Block a user