VTK-m  2.2
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>
19 #include <vtkm/rendering/raytracing/MeshConnectivityBuilder.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
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);
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,
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,
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 =
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::CellShapeTagQuad
Definition: CellShape.h:156
vtkm::rendering::Quadralizer::Quadralize::operator()
void operator()(const vtkm::Id &pointOffset, vtkm::CellShapeTagWedge, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:203
vtkm::cont::UnknownCellSet::ResetCellSetList
vtkm::cont::UncertainCellSet< CellSetList > ResetCellSetList(CellSetList) const
Assigns potential cell set types.
vtkm::worklet::WorkletVisitCellsWithPoints::CellShape
An execution signature tag to get the shape of the visited cell.
Definition: WorkletMapTopology.h:396
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:300
vtkm::rendering::Quadralizer::SegmentedStructured::cell2quad
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::cont::Algorithm::ScanExclusive
static T ScanExclusive(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:817
vtkm::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
A wedge.
Definition: CellShape.h:66
vtkm::cont::UnknownCellSet::CanConvert
bool CanConvert() const
Returns true if this cell set can be retrieved as the given type.
Definition: UnknownCellSet.h:161
vtkm::cont::CellSetStructured::GetNumberOfCells
vtkm::Id GetNumberOfCells() const override
Get the number of cells in the topology.
Definition: CellSetStructured.h:45
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
WorkletMapField.h
vtkm::IdComponent
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
vtkm::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:32
vtkm::rendering::Quadralizer::SegmentedStructured::ControlSignature
void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut)
Definition: Quadralizer.h:85
vtkm::rendering::Quadralizer::Quadralize::operator()
void operator()(const vtkm::Id &pointOffset, vtkm::CellShapeTagHexahedron, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:235
vtkm::rendering::Quadralizer::Quadralize::operator()
void operator()(const vtkm::Id &offset, vtkm::CellShapeTagQuad shapeType, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:216
vtkm::rendering::Quadralizer::CountQuads::operator()
void operator()(vtkm::CellShapeTagQuad shapeType, vtkm::Id &quads) const
Definition: Quadralizer.h:66
vtkm::rendering::Quadralizer::SegmentedStructured::ExecutionSignature
void ExecutionSignature(IncidentElementIndices, _2, _3)
Definition: Quadralizer.h:86
vtkm::worklet::WorkletVisitCellsWithPoints::CellSetIn
A control signature tag for input connectivity.
Definition: WorkletMapTopology.h:280
vtkm::cont::Algorithm::Reduce
static U Reduce(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, U initialValue)
Definition: Algorithm.h:657
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::cont::UnknownCellSet::AsCellSet
void AsCellSet(CellSetType &cellSet) const
Get the cell set as a known type.
Definition: UnknownCellSet.h:178
UncertainCellSet.h
vtkm::rendering::Quadralizer::Quadralize::Quadralize
Quadralize()
Definition: Quadralizer.h:179
vtkm::worklet::WorkletVisitCellsWithPoints::FieldInCell
A control signature tag for input fields on the cells of the topology.
Definition: WorkletMapTopology.h:290
vtkm::rendering::Quadralizer::CountQuads::operator()
void operator()(vtkm::CellShapeTagGeneric shapeType, vtkm::Id &quads) const
Definition: Quadralizer.h:44
vtkm::rendering::Quadralizer::SegmentedStructured
Definition: Quadralizer.h:81
QUAD_PER_CSS
#define QUAD_PER_CSS
Definition: Quadralizer.h:25
vtkm::rendering::Quadralizer::CountQuads
Definition: Quadralizer.h:35
Algorithm.h
vtkm::CellShapeTagQuad::Id
static constexpr vtkm::UInt8 Id
Definition: CellShape.h:156
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:256
vtkm::rendering::Quadralizer::Quadralizer
Quadralizer()
Definition: Quadralizer.h:299
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOut
A control signature tag for output fields.
Definition: WorkletMapTopology.h:329
vtkm::rendering::Quadralizer::CountQuads::CountQuads
CountQuads()
Definition: Quadralizer.h:39
vtkm::rendering::Quadralizer::SegmentedStructured::operator()
void operator()(const CellNodeVecType &cellIndices, const vtkm::Id &cellIndex, OutIndicesPortal &outputIndices) const
Definition: Quadralizer.h:111
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Id
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
A hexahedron.
Definition: CellShape.h:62
vtkm::rendering::Quadralizer::Quadralize
Definition: Quadralizer.h:174
vtkm::rendering::Quadralizer::Quadralize::operator()
void operator()(const vtkm::Id &pointOffset, vtkm::CellShapeTagGeneric shapeType, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:252
vtkm::CellShapeTagHexahedron
Definition: CellShape.h:159
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
CellSetPermutation.h
vtkm::rendering::Quadralizer::Run
void Run(const vtkm::cont::UnknownCellSet &cellset, vtkm::cont::ArrayHandle< vtkm::Vec< vtkm::Id, 5 >> &outputIndices, vtkm::Id &output)
Definition: Quadralizer.h:302
vtkm::rendering::Quadralizer
Definition: Quadralizer.h:32
vtkm::rendering::Quadralizer::Quadralize::ControlSignature
void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut)
Definition: Quadralizer.h:180
vtkm::Vec
A short fixed-length array.
Definition: Types.h:357
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:180
ArrayHandleCounting.h
VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED
#define VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED
Definition: DefaultTypes.h:60
vtkm::rendering::Quadralizer::SegmentedStructured::SegmentedStructured
SegmentedStructured()
Definition: Quadralizer.h:89
vtkm::CellShapeTagWedge
Definition: CellShape.h:160
vtkm::rendering::Quadralizer::CountQuads::operator()
void operator()(vtkm::CellShapeTagWedge, vtkm::Id &quads) const
Definition: Quadralizer.h:74
vtkm::rendering::Quadralizer::CountQuads::operator()
void operator()(vtkm::CellShapeTagHexahedron, 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:170
vtkm::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
A pyramid with a quadrilateral base and four triangular faces.0.
Definition: CellShape.h:68
DispatcherMapTopology.h
WorkletMapTopology.h
vtkm::rendering::Quadralizer::Quadralize::cell2quad
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
DataSet.h
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:55
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
A four-sided polygon.
Definition: CellShape.h:56
vtkm::worklet::WorkletVisitCellsWithPoints::PointIndices
An execution signature tag to get the indices of the incident points.
Definition: WorkletMapTopology.h:416