VTK-m  2.0
Quadralizer.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 #ifndef vtk_m_rendering_Quadralizer_h
11 #define vtk_m_rendering_Quadralizer_h
12 
13 #include <typeinfo>
14 #include <vtkm/cont/Algorithm.h>
17 #include <vtkm/cont/DataSet.h>
23 
24 
25 #define QUAD_PER_CSS 6
26 
27 namespace vtkm
28 {
29 namespace rendering
30 {
31 
33 {
34 public:
36  {
37  public:
38  VTKM_CONT
40  typedef void ControlSignature(CellSetIn cellset, FieldOut);
41  typedef void ExecutionSignature(CellShape, _2);
42 
43  VTKM_EXEC
44  void operator()(vtkm::CellShapeTagGeneric shapeType, vtkm::Id& quads) const
45  {
46  if (shapeType.Id == vtkm::CELL_SHAPE_QUAD)
47  quads = 1;
48  else if (shapeType.Id == CELL_SHAPE_HEXAHEDRON)
49  quads = 6;
50  else if (shapeType.Id == vtkm::CELL_SHAPE_WEDGE)
51  quads = 3;
52  else if (shapeType.Id == vtkm::CELL_SHAPE_PYRAMID)
53  quads = 1;
54 
55  else
56  quads = 0;
57  }
58 
59  VTKM_EXEC
60  void operator()(vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType), vtkm::Id& quads) const
61  {
62  quads = 6;
63  }
64 
65  VTKM_EXEC
66  void operator()(vtkm::CellShapeTagQuad shapeType, vtkm::Id& quads) const
67  {
68  if (shapeType.Id == vtkm::CELL_SHAPE_QUAD)
69  quads = 1;
70  else
71  quads = 0;
72  }
73  VTKM_EXEC
74  void operator()(vtkm::CellShapeTagWedge vtkmNotUsed(shapeType), vtkm::Id& quads) const
75  {
76  quads = 3;
77  }
78  }; //class CountQuads
79 
80  template <int DIM>
82  {
83 
84  public:
85  typedef void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut);
86  typedef void ExecutionSignature(IncidentElementIndices, _2, _3);
87  //typedef _1 InputDomain;
88  VTKM_CONT
90 
91 #if defined(VTKM_MSVC)
92 #pragma warning(push)
93 #pragma warning(disable : 4127) //conditional expression is constant
94 #endif
95  template <typename CellNodeVecType, typename OutIndicesPortal>
97  vtkm::Vec<Id, 5>& quad,
98  const vtkm::Id offset,
99  const CellNodeVecType& cellIndices,
100  OutIndicesPortal& outputIndices) const
101  {
102 
103  quad[1] = cellIndices[vtkm::IdComponent(idx[0])];
104  quad[2] = cellIndices[vtkm::IdComponent(idx[1])];
105  quad[3] = cellIndices[vtkm::IdComponent(idx[2])];
106  quad[4] = cellIndices[vtkm::IdComponent(idx[3])];
107  outputIndices.Set(offset, quad);
108  }
109 
110  template <typename CellNodeVecType, typename OutIndicesPortal>
111  VTKM_EXEC void operator()(const CellNodeVecType& cellIndices,
112  const vtkm::Id& cellIndex,
113  OutIndicesPortal& outputIndices) const
114  {
115  if (DIM == 2)
116  {
117  outputIndices.Set(
118  cellIndex, { cellIndex, cellIndices[0], cellIndices[1], cellIndices[2], cellIndices[3] });
119  }
120  else if (DIM == 3)
121  {
122  vtkm::Id offset = cellIndex * QUAD_PER_CSS;
124  quad[0] = cellIndex;
125  vtkm::Id4 idx;
126  idx[0] = 0;
127  idx[1] = 1;
128  idx[2] = 5;
129  idx[3] = 4;
130  cell2quad(idx, quad, offset, cellIndices, outputIndices);
131 
132  idx[0] = 1;
133  idx[1] = 2;
134  idx[2] = 6;
135  idx[3] = 5;
136  offset++;
137  cell2quad(idx, quad, offset, cellIndices, outputIndices);
138 
139  idx[0] = 3;
140  idx[1] = 7;
141  idx[2] = 6;
142  idx[3] = 2;
143  offset++;
144  cell2quad(idx, quad, offset, cellIndices, outputIndices);
145 
146  idx[0] = 0;
147  idx[1] = 4;
148  idx[2] = 7;
149  idx[3] = 3;
150  offset++;
151  cell2quad(idx, quad, offset, cellIndices, outputIndices);
152 
153  idx[0] = 0;
154  idx[1] = 3;
155  idx[2] = 2;
156  idx[3] = 1;
157  offset++;
158  cell2quad(idx, quad, offset, cellIndices, outputIndices);
159 
160  idx[0] = 4;
161  idx[1] = 5;
162  idx[2] = 6;
163  idx[3] = 7;
164  offset++;
165  cell2quad(idx, quad, offset, cellIndices, outputIndices);
166  }
167  }
168 #if defined(VTKM_MSVC)
169 #pragma warning(pop)
170 #endif
171  };
172 
173 
175  {
176 
177  public:
178  VTKM_CONT
180  typedef void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut);
181  typedef void ExecutionSignature(_2, CellShape, PointIndices, WorkIndex, _3);
182 
183  template <typename VecType, typename OutputPortal>
185  const VecType& cellIndices,
186  const vtkm::Id& cellId,
187  const vtkm::Id Id0,
188  const vtkm::Id Id1,
189  const vtkm::Id Id2,
190  const vtkm::Id Id3,
191  OutputPortal& outputIndices) const
192  {
194  quad[0] = cellId;
195  quad[1] = static_cast<vtkm::Id>(cellIndices[vtkm::IdComponent(Id0)]);
196  quad[2] = static_cast<vtkm::Id>(cellIndices[vtkm::IdComponent(Id1)]);
197  quad[3] = static_cast<vtkm::Id>(cellIndices[vtkm::IdComponent(Id2)]);
198  quad[4] = static_cast<vtkm::Id>(cellIndices[vtkm::IdComponent(Id3)]);
199  outputIndices.Set(offset++, quad);
200  }
201 
202  template <typename VecType, typename OutputPortal>
203  VTKM_EXEC void operator()(const vtkm::Id& pointOffset,
204  vtkm::CellShapeTagWedge vtkmNotUsed(shapeType),
205  const VecType& cellIndices,
206  const vtkm::Id& cellId,
207  OutputPortal& outputIndices) const
208  {
209  vtkm::Id offset = pointOffset;
210 
211  cell2quad(offset, cellIndices, cellId, 3, 0, 2, 5, outputIndices);
212  cell2quad(offset, cellIndices, cellId, 1, 4, 5, 2, outputIndices);
213  cell2quad(offset, cellIndices, cellId, 0, 3, 4, 1, outputIndices);
214  }
215  template <typename VecType, typename OutputPortal>
216  VTKM_EXEC void operator()(const vtkm::Id& offset,
217  vtkm::CellShapeTagQuad shapeType,
218  const VecType& cellIndices,
219  const vtkm::Id& cellId,
220  OutputPortal& outputIndices) const
221  {
222  if (shapeType.Id == vtkm::CELL_SHAPE_QUAD)
223  {
225  quad[0] = cellId;
226  quad[1] = static_cast<vtkm::Id>(cellIndices[0]);
227  quad[2] = static_cast<vtkm::Id>(cellIndices[1]);
228  quad[3] = static_cast<vtkm::Id>(cellIndices[2]);
229  quad[4] = static_cast<vtkm::Id>(cellIndices[3]);
230  outputIndices.Set(offset, quad);
231  }
232  }
233 
234  template <typename VecType, typename OutputPortal>
235  VTKM_EXEC void operator()(const vtkm::Id& pointOffset,
236  vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType),
237  const VecType& cellIndices,
238  const vtkm::Id& cellId,
239  OutputPortal& outputIndices) const
240 
241  {
242  vtkm::Id offset = pointOffset;
243  cell2quad(offset, cellIndices, cellId, 0, 1, 5, 4, outputIndices);
244  cell2quad(offset, cellIndices, cellId, 1, 2, 6, 5, outputIndices);
245  cell2quad(offset, cellIndices, cellId, 3, 7, 6, 2, outputIndices);
246  cell2quad(offset, cellIndices, cellId, 0, 4, 7, 3, outputIndices);
247  cell2quad(offset, cellIndices, cellId, 0, 3, 2, 1, outputIndices);
248  cell2quad(offset, cellIndices, cellId, 4, 5, 6, 7, outputIndices);
249  }
250 
251  template <typename VecType, typename OutputPortal>
252  VTKM_EXEC void operator()(const vtkm::Id& pointOffset,
253  vtkm::CellShapeTagGeneric shapeType,
254  const VecType& cellIndices,
255  const vtkm::Id& cellId,
256  OutputPortal& outputIndices) const
257  {
258 
259  if (shapeType.Id == vtkm::CELL_SHAPE_QUAD)
260  {
262  quad[0] = cellId;
263  quad[1] = cellIndices[0];
264  quad[2] = cellIndices[1];
265  quad[3] = cellIndices[2];
266  quad[4] = cellIndices[3];
267  outputIndices.Set(pointOffset, quad);
268  }
269  if (shapeType.Id == vtkm::CELL_SHAPE_HEXAHEDRON)
270  {
271  vtkm::Id offset = pointOffset;
272  cell2quad(offset, cellIndices, cellId, 0, 1, 5, 4, outputIndices);
273  cell2quad(offset, cellIndices, cellId, 1, 2, 6, 5, outputIndices);
274  cell2quad(offset, cellIndices, cellId, 3, 7, 6, 2, outputIndices);
275  cell2quad(offset, cellIndices, cellId, 0, 4, 7, 3, outputIndices);
276  cell2quad(offset, cellIndices, cellId, 0, 3, 2, 1, outputIndices);
277  cell2quad(offset, cellIndices, cellId, 4, 5, 6, 7, outputIndices);
278  }
279  if (shapeType.Id == vtkm::CELL_SHAPE_WEDGE)
280  {
281  vtkm::Id offset = pointOffset;
282 
283  cell2quad(offset, cellIndices, cellId, 3, 0, 2, 5, outputIndices);
284  cell2quad(offset, cellIndices, cellId, 1, 4, 5, 2, outputIndices);
285  cell2quad(offset, cellIndices, cellId, 0, 3, 4, 1, outputIndices);
286  }
287  if (shapeType.Id == vtkm::CELL_SHAPE_PYRAMID)
288  {
289  vtkm::Id offset = pointOffset;
290 
291  cell2quad(offset, cellIndices, cellId, 3, 2, 1, 0, outputIndices);
292  }
293  }
294 
295  }; //class Quadralize
296 
297 public:
298  VTKM_CONT
300 
301  VTKM_CONT
302  void Run(const vtkm::cont::UnknownCellSet& cellset,
304  vtkm::Id& output)
305  {
306  vtkm::cont::Invoker invoke;
307 
309  {
310  vtkm::cont::CellSetStructured<3> cellSetStructured3D =
312  const vtkm::Id numCells = cellSetStructured3D.GetNumberOfCells();
313 
314  vtkm::cont::ArrayHandleIndex cellIdxs(numCells);
315  outputIndices.Allocate(numCells * QUAD_PER_CSS);
316  invoke(SegmentedStructured<3>{}, cellSetStructured3D, cellIdxs, outputIndices);
317 
318  output = numCells * QUAD_PER_CSS;
319  }
320  else if (cellset.CanConvert<vtkm::cont::CellSetStructured<2>>())
321  {
322  vtkm::cont::CellSetStructured<2> cellSetStructured2D =
324  const vtkm::Id numCells = cellSetStructured2D.GetNumberOfCells();
325 
326  vtkm::cont::ArrayHandleIndex cellIdxs(numCells);
327  outputIndices.Allocate(numCells);
328  invoke(SegmentedStructured<2>{}, cellSetStructured2D, cellIdxs, outputIndices);
329 
330  output = numCells;
331  }
332  else
333  {
334  auto cellSetUnstructured =
335  cellset.ResetCellSetList(VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED{});
337  invoke(CountQuads{}, cellSetUnstructured, quadsPerCell);
338 
339  vtkm::Id total = 0;
340  total = vtkm::cont::Algorithm::Reduce(quadsPerCell, vtkm::Id(0));
341 
343  vtkm::cont::Algorithm::ScanExclusive(quadsPerCell, cellOffsets);
344  outputIndices.Allocate(total);
345 
346  invoke(Quadralize{}, cellSetUnstructured, cellOffsets, outputIndices);
347 
348  output = total;
349  }
350  }
351 };
352 }
353 }
354 #endif
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
vtkm::rendering::Quadralizer::CountQuads::CountQuads
VTKM_CONT CountQuads()
Definition: Quadralizer.h:39
vtkm::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
Definition: CellShape.h:49
vtkm::cont::CellSetStructured::GetNumberOfCells
vtkm::Id GetNumberOfCells() const override
Definition: CellSetStructured.h:38
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::rendering::Quadralizer::CountQuads::ExecutionSignature
void ExecutionSignature(CellShape, _2)
Definition: Quadralizer.h:41
vtkm::rendering::Quadralizer::Quadralize::operator()
VTKM_EXEC void operator()(const vtkm::Id &pointOffset, vtkm::CellShapeTagGeneric shapeType, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:252
WorkletMapField.h
vtkm::cont::UnknownCellSet::CanConvert
VTKM_CONT bool CanConvert() const
Returns true if this cell set can be retrieved as the given type.
Definition: UnknownCellSet.h:161
vtkm::rendering::Quadralizer::Quadralize::operator()
VTKM_EXEC void operator()(const vtkm::Id &pointOffset, vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType), const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:235
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::cont::CellSetStructured< 3 >
vtkm::rendering::Quadralizer::SegmentedStructured::ControlSignature
void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut)
Definition: Quadralizer.h:85
vtkm::cont::UnknownCellSet::ResetCellSetList
VTKM_CONT vtkm::cont::UncertainCellSet< CellSetList > ResetCellSetList(CellSetList) const
Assigns potential cell set types.
vtkm::rendering::Quadralizer::SegmentedStructured::ExecutionSignature
void ExecutionSignature(IncidentElementIndices, _2, _3)
Definition: Quadralizer.h:86
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
UncertainCellSet.h
vtkm::rendering::Quadralizer::Quadralize::cell2quad
VTKM_EXEC void cell2quad(vtkm::Id &offset, const VecType &cellIndices, const vtkm::Id &cellId, const vtkm::Id Id0, const vtkm::Id Id1, const vtkm::Id Id2, const vtkm::Id Id3, OutputPortal &outputIndices) const
Definition: Quadralizer.h:184
vtkm::worklet::WorkletVisitCellsWithPoints::PointIndices
IncidentElementIndices PointIndices
Definition: WorkletMapTopology.h:269
vtkm::rendering::Quadralizer::Quadralize::Quadralize
VTKM_CONT Quadralize()
Definition: Quadralizer.h:179
vtkm::rendering::Quadralizer::Quadralizer
VTKM_CONT Quadralizer()
Definition: Quadralizer.h:299
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::rendering::Quadralizer::SegmentedStructured::operator()
VTKM_EXEC void operator()(const CellNodeVecType &cellIndices, const vtkm::Id &cellIndex, OutIndicesPortal &outputIndices) const
Definition: Quadralizer.h:111
MeshConnectivityBuilder.h
vtkm::rendering::Quadralizer::SegmentedStructured
Definition: Quadralizer.h:81
QUAD_PER_CSS
#define QUAD_PER_CSS
Definition: Quadralizer.h:25
vtkm::cont::UnknownCellSet::AsCellSet
VTKM_CONT void AsCellSet(CellSetType &cellSet) const
Get the cell set as a known type.
Definition: UnknownCellSet.h:178
vtkm::rendering::Quadralizer::CountQuads
Definition: Quadralizer.h:35
Algorithm.h
vtkm::cont::Algorithm::ScanExclusive
static VTKM_CONT T ScanExclusive(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:816
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::rendering::Quadralizer::CountQuads::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagWedge vtkmNotUsed(shapeType), vtkm::Id &quads) const
Definition: Quadralizer.h:74
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::rendering::Quadralizer::Quadralize::operator()
VTKM_EXEC void operator()(const vtkm::Id &offset, vtkm::CellShapeTagQuad shapeType, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:216
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
Definition: CellShape.h:48
vtkm::rendering::Quadralizer::Quadralize
Definition: Quadralizer.h:174
vtkm::rendering::Quadralizer::Quadralize::operator()
VTKM_EXEC void operator()(const vtkm::Id &pointOffset, vtkm::CellShapeTagWedge vtkmNotUsed(shapeType), const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:203
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
CellSetPermutation.h
vtkm::rendering::Quadralizer
Definition: Quadralizer.h:32
vtkm::rendering::Quadralizer::Quadralize::ControlSignature
void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut)
Definition: Quadralizer.h:180
vtkm::Vec< vtkm::Id, 4 >
vtkm::rendering::Quadralizer::CountQuads::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagGeneric shapeType, vtkm::Id &quads) const
Definition: Quadralizer.h:44
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
Definition: CellShape.h:160
vtkm::cont::Algorithm::Reduce
static VTKM_CONT U Reduce(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Definition: Algorithm.h:656
ArrayHandleCounting.h
vtkm::rendering::Quadralizer::CountQuads::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType), vtkm::Id &quads) const
Definition: Quadralizer.h:60
vtkm::rendering::Quadralizer::Quadralize::ExecutionSignature
void ExecutionSignature(_2, CellShape, PointIndices, WorkIndex, _3)
Definition: Quadralizer.h:181
vtkm::rendering::Quadralizer::CountQuads::ControlSignature
void ControlSignature(CellSetIn cellset, FieldOut)
Definition: Quadralizer.h:40
vtkm::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:152
vtkm::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
Definition: CellShape.h:50
vtkm::rendering::Quadralizer::CountQuads::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagQuad shapeType, vtkm::Id &quads) const
Definition: Quadralizer.h:66
vtkm::rendering::Quadralizer::SegmentedStructured::SegmentedStructured
VTKM_CONT SegmentedStructured()
Definition: Quadralizer.h:89
DispatcherMapTopology.h
WorkletMapTopology.h
vtkm::rendering::Quadralizer::Run
VTKM_CONT void Run(const vtkm::cont::UnknownCellSet &cellset, vtkm::cont::ArrayHandle< vtkm::Vec< vtkm::Id, 5 >> &outputIndices, vtkm::Id &output)
Definition: Quadralizer.h:302
DataSet.h
vtkm::worklet::WorkletVisitCellsWithPoints::FieldInCell
FieldInVisit FieldInCell
Definition: WorkletMapTopology.h:261
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:54
vtkm::rendering::Quadralizer::SegmentedStructured::cell2quad
VTKM_EXEC void cell2quad(vtkm::Id4 idx, vtkm::Vec< Id, 5 > &quad, const vtkm::Id offset, const CellNodeVecType &cellIndices, OutIndicesPortal &outputIndices) const
Definition: Quadralizer.h:96
vtkm::exec::arg::WorkIndex
The ExecutionSignature tag to use to get the work index.
Definition: WorkIndex.h:39
vtkm::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
Definition: CellShape.h:45