VTK-m  2.0
TriangulateExplicit.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_TriangulateExplicit_h
12 #define vtk_m_worklet_TriangulateExplicit_h
13 
14 #include <vtkm/cont/ArrayHandle.h>
17 #include <vtkm/cont/DataSet.h>
18 #include <vtkm/cont/Field.h>
19 
25 
27 
28 namespace vtkm
29 {
30 namespace worklet
31 {
32 
35 {
36 public:
38 
39  //
40  // Worklet to count the number of triangles generated per cell
41  //
43  {
44  public:
45  using ControlSignature = void(CellSetIn cells, ExecObject tables, FieldOut triangleCount);
46  using ExecutionSignature = _3(CellShape, IncidentElementCount, _2);
47  using InputDomain = _1;
48 
49  VTKM_CONT
51 
52  template <typename CellShapeTag>
54  CellShapeTag shape,
55  vtkm::IdComponent numPoints,
56  const vtkm::worklet::internal::TriangulateTablesExecutionObject& tables) const
57  {
58  return tables.GetCount(shape, numPoints);
59  }
60  };
61 
62  //
63  // Worklet to turn cells into triangles
64  // Vertices remain the same and each cell is processed with needing topology
65  //
67  {
68  public:
69  using ControlSignature = void(CellSetIn cellset,
70  ExecObject tables,
71  FieldOutCell connectivityOut);
72  using ExecutionSignature = void(CellShape, PointIndices, _2, _3, VisitIndex);
73  using InputDomain = _1;
74 
76 
77  template <typename CountArrayType>
78  VTKM_CONT static ScatterType MakeScatter(const CountArrayType& countArray)
79  {
80  return ScatterType(countArray);
81  }
82 
83  // Each cell produces triangles and write result at the offset
84  template <typename CellShapeTag, typename ConnectivityInVec, typename ConnectivityOutVec>
86  CellShapeTag shape,
87  const ConnectivityInVec& connectivityIn,
88  const vtkm::worklet::internal::TriangulateTablesExecutionObject& tables,
89  ConnectivityOutVec& connectivityOut,
90  vtkm::IdComponent visitIndex) const
91  {
92  vtkm::IdComponent3 triIndices = tables.GetIndices(shape, visitIndex);
93  connectivityOut[0] = connectivityIn[triIndices[0]];
94  connectivityOut[1] = connectivityIn[triIndices[1]];
95  connectivityOut[2] = connectivityIn[triIndices[2]];
96  }
97  };
98  template <typename CellSetType>
99  vtkm::cont::CellSetSingleType<> Run(const CellSetType& cellSet,
101  {
103 
104  vtkm::cont::Invoker invoke;
105 
106  // Output topology
107  vtkm::cont::ArrayHandle<vtkm::Id> outConnectivity;
108 
109  vtkm::worklet::internal::TriangulateTables tables;
110 
111  // Determine the number of output cells each input cell will generate
112  invoke(TrianglesPerCell{}, cellSet, tables, outCellsPerCell);
113 
114  // Build new cells
115  invoke(TriangulateCell{},
116  TriangulateCell::MakeScatter(outCellsPerCell),
117  cellSet,
118  tables,
119  vtkm::cont::make_ArrayHandleGroupVec<3>(outConnectivity));
120 
121  // Add cells to output cellset
122  outCellSet.Fill(
123  cellSet.GetNumberOfPoints(), vtkm::CellShapeTagTriangle::Id, 3, outConnectivity);
124  return outCellSet;
125  }
126 };
127 
128 }
129 } // namespace vtkm::worklet
130 
131 #endif // vtk_m_worklet_TriangulateExplicit_h
vtkm::cont::ArrayHandle< vtkm::IdComponent >
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm::worklet::TriangulateExplicit::Run
vtkm::cont::CellSetSingleType Run(const CellSetType &cellSet, vtkm::cont::ArrayHandle< vtkm::IdComponent > &outCellsPerCell)
Definition: TriangulateExplicit.h:99
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::TriangulateExplicit
Compute the triangulate cells for an explicit grid data set.
Definition: TriangulateExplicit.h:34
WorkletMapField.h
CellSetExplicit.h
vtkm::worklet::TriangulateExplicit::TriangulateExplicit
TriangulateExplicit()
Definition: TriangulateExplicit.h:37
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::TriangulateExplicit::TrianglesPerCell::TrianglesPerCell
VTKM_CONT TrianglesPerCell()
Definition: TriangulateExplicit.h:50
vtkm::worklet::TriangulateExplicit::TrianglesPerCell::operator()
VTKM_EXEC vtkm::IdComponent operator()(CellShapeTag shape, vtkm::IdComponent numPoints, const vtkm::worklet::internal::TriangulateTablesExecutionObject &tables) const
Definition: TriangulateExplicit.h:53
vtkm::cont::CellSetSingleType
Definition: CastAndCall.h:34
vtkm::worklet::WorkletVisitCellsWithPoints::PointIndices
IncidentElementIndices PointIndices
Definition: WorkletMapTopology.h:269
vtkm::worklet::TriangulateExplicit::TriangulateCell::InputDomain
_1 InputDomain
Definition: TriangulateExplicit.h:73
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
DispatcherMapField.h
ScatterCounting.h
vtkm::worklet::TriangulateExplicit::TriangulateCell
Definition: TriangulateExplicit.h:66
vtkm::worklet::ScatterCounting
A scatter that maps input to some numbers of output.
Definition: ScatterCounting.h:44
vtkm::worklet::TriangulateExplicit::TrianglesPerCell::ControlSignature
void(CellSetIn cells, ExecObject tables, FieldOut triangleCount) ControlSignature
Definition: TriangulateExplicit.h:45
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::TriangulateExplicit::TriangulateCell::operator()
VTKM_EXEC void operator()(CellShapeTag shape, const ConnectivityInVec &connectivityIn, const vtkm::worklet::internal::TriangulateTablesExecutionObject &tables, ConnectivityOutVec &connectivityOut, vtkm::IdComponent visitIndex) const
Definition: TriangulateExplicit.h:85
ArrayHandleGroupVec.h
vtkm::worklet::TriangulateExplicit::TrianglesPerCell::InputDomain
_1 InputDomain
Definition: TriangulateExplicit.h:47
vtkm::Vec
A short fixed-length array.
Definition: Types.h:767
vtkm::worklet::TriangulateExplicit::TriangulateCell::MakeScatter
static VTKM_CONT ScatterType MakeScatter(const CountArrayType &countArray)
Definition: TriangulateExplicit.h:78
Field.h
vtkm::worklet::TriangulateExplicit::TriangulateCell::ExecutionSignature
void(CellShape, PointIndices, _2, _3, VisitIndex) ExecutionSignature
Definition: TriangulateExplicit.h:72
TriangulateTables.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
vtkm::exec::arg::VisitIndex
The ExecutionSignature tag to use to get the visit index.
Definition: VisitIndex.h:43
DispatcherMapTopology.h
WorkletMapTopology.h
vtkm::worklet::TriangulateExplicit::TriangulateCell::ControlSignature
void(CellSetIn cellset, ExecObject tables, FieldOutCell connectivityOut) ControlSignature
Definition: TriangulateExplicit.h:71
vtkm::worklet::TriangulateExplicit::TriangulateCell::ScatterType
vtkm::worklet::ScatterCounting ScatterType
Definition: TriangulateExplicit.h:75
DataSet.h
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOutCell
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263
vtkm::worklet::TriangulateExplicit::TrianglesPerCell
Definition: TriangulateExplicit.h:42
vtkm::worklet::TriangulateExplicit::TrianglesPerCell::ExecutionSignature
_3(CellShape, IncidentElementCount, _2) ExecutionSignature
Definition: TriangulateExplicit.h:46