VTK-m  2.0
TetrahedralizeStructured.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 
11 #ifndef vtk_m_worklet_TetrahedralizeStructured_h
12 #define vtk_m_worklet_TetrahedralizeStructured_h
13 
14 #include <vtkm/cont/ArrayCopy.h>
15 #include <vtkm/cont/ArrayHandle.h>
19 #include <vtkm/cont/DataSet.h>
22 #include <vtkm/cont/Field.h>
23 
27 
28 namespace vtkm
29 {
30 namespace worklet
31 {
32 
33 namespace tetrahedralize
34 {
35 //
36 // Worklet to turn hexahedra into tetrahedra
37 // Vertices remain the same and each cell is processed with needing topology
38 //
40 {
41 public:
42  using ControlSignature = void(CellSetIn cellset, FieldOutCell connectivityOut);
44  using InputDomain = _1;
45 
47 
48  // Each hexahedron cell produces five tetrahedron cells
49  template <typename ConnectivityInVec, typename ConnectivityOutVec, typename ThreadIndicesType>
50  VTKM_EXEC void operator()(const ConnectivityInVec& connectivityIn,
51  ConnectivityOutVec& connectivityOut,
52  const ThreadIndicesType threadIndices) const
53  {
54  VTKM_STATIC_CONSTEXPR_ARRAY vtkm::IdComponent StructuredTetrahedronIndices[2][5][4] = {
55  { { 0, 1, 3, 4 }, { 1, 4, 5, 6 }, { 1, 4, 6, 3 }, { 1, 3, 6, 2 }, { 3, 6, 7, 4 } },
56  { { 2, 1, 5, 0 }, { 0, 2, 3, 7 }, { 2, 5, 6, 7 }, { 0, 7, 4, 5 }, { 0, 2, 7, 5 } }
57  };
58 
59  vtkm::Id3 inputIndex = threadIndices.GetInputIndex3D();
60 
61  // Calculate the type of tetrahedron generated because it alternates
62  vtkm::Id indexType = (inputIndex[0] + inputIndex[1] + inputIndex[2]) % 2;
63 
64  vtkm::IdComponent visitIndex = threadIndices.GetVisitIndex();
65 
66  connectivityOut[0] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][0]];
67  connectivityOut[1] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][1]];
68  connectivityOut[2] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][2]];
69  connectivityOut[3] = connectivityIn[StructuredTetrahedronIndices[indexType][visitIndex][3]];
70  }
71 };
72 }
73 
76 {
77 public:
78  template <typename CellSetType>
79  vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
81  {
84 
86  dispatcher.Invoke(cellSet, vtkm::cont::make_ArrayHandleGroupVec<4>(connectivity));
87 
88  // Fill in array of output cells per input cell
90  vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(5, cellSet.GetNumberOfCells()),
91  outCellsPerCell);
92 
93  // Add cells to output cellset
94  outCellSet.Fill(cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTetra::Id, 4, connectivity);
95  return outCellSet;
96  }
97 };
98 }
99 } // namespace vtkm::worklet
100 
101 #endif // vtk_m_worklet_TetrahedralizeStructured_h
vtkm::cont::ArrayHandle< vtkm::IdComponent >
vtkm::worklet::TetrahedralizeStructured::Run
vtkm::cont::CellSetSingleType Run(const CellSetType &cellSet, vtkm::cont::ArrayHandle< vtkm::IdComponent > &outCellsPerCell)
Definition: TetrahedralizeStructured.h:79
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ScatterUniform.h
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
VTKM_STATIC_CONSTEXPR_ARRAY
#define VTKM_STATIC_CONSTEXPR_ARRAY
Definition: ExportMacros.h:107
vtkm::worklet::TetrahedralizeStructured
Compute the tetrahedralize cells for a uniform grid data set.
Definition: TetrahedralizeStructured.h:75
vtkm::worklet::ScatterUniform
A scatter that maps input to some constant numbers of output.
Definition: ScatterUniform.h:53
vtkm::worklet::contourtree_distributed::indexType
vtkm::Id indexType
Definition: TreeCompiler.h:73
vtkm::cont::CellSetSingleType
Definition: CastAndCall.h:34
vtkm::worklet::WorkletVisitCellsWithPoints::PointIndices
IncidentElementIndices PointIndices
Definition: WorkletMapTopology.h:269
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ArrayCopy.h
DeviceAdapter.h
vtkm::worklet::DispatcherMapTopology
Dispatcher for worklets that inherit from WorkletMapTopology.
Definition: DispatcherMapTopology.h:31
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::worklet::tetrahedralize::TetrahedralizeCell::InputDomain
_1 InputDomain
Definition: TetrahedralizeStructured.h:44
vtkm::exec::arg::ThreadIndices
The ExecutionSignature tag to use to get the thread indices.
Definition: ThreadIndices.h:41
vtkm::worklet::tetrahedralize::TetrahedralizeCell::ExecutionSignature
void(PointIndices, _2, ThreadIndices) ExecutionSignature
Definition: TetrahedralizeStructured.h:43
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
ArrayHandleGroupVec.h
vtkm::worklet::tetrahedralize::TetrahedralizeCell
Definition: TetrahedralizeStructured.h:39
vtkm::worklet::tetrahedralize::TetrahedralizeCell::operator()
VTKM_EXEC void operator()(const ConnectivityInVec &connectivityIn, ConnectivityOutVec &connectivityOut, const ThreadIndicesType threadIndices) const
Definition: TetrahedralizeStructured.h:50
vtkm::Vec< vtkm::Id, 3 >
ErrorBadValue.h
Field.h
CellSetStructured.h
vtkm::cont::CellSetSingleType::Fill
VTKM_CONT void Fill(vtkm::Id numPoints, vtkm::UInt8 shapeId, vtkm::IdComponent numberOfPointsPerCell, const vtkm::cont::ArrayHandle< vtkm::Id, ConnectivityStorageTag > &connectivity)
Definition: CellSetSingleType.h:186
CellSetSingleType.h
vtkm::worklet::tetrahedralize::TetrahedralizeCell::ControlSignature
void(CellSetIn cellset, FieldOutCell connectivityOut) ControlSignature
Definition: TetrahedralizeStructured.h:42
DispatcherMapTopology.h
WorkletMapTopology.h
DataSet.h
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOutCell
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263