Viskores  1.0
Quadralizer.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_rendering_Quadralizer_h
19 #define viskores_rendering_Quadralizer_h
20 
21 #include <typeinfo>
25 #include <viskores/cont/DataSet.h>
27 #include <viskores/rendering/raytracing/MeshConnectivityBuilder.h>
31 
32 
33 #define QUAD_PER_CSS 6
34 
35 namespace viskores
36 {
37 namespace rendering
38 {
39 
41 {
42 public:
44  {
45  public:
48  typedef void ControlSignature(CellSetIn cellset, FieldOut);
49  typedef void ExecutionSignature(CellShape, _2);
50 
53  {
54  if (shapeType.Id == viskores::CELL_SHAPE_QUAD)
55  quads = 1;
56  else if (shapeType.Id == CELL_SHAPE_HEXAHEDRON)
57  quads = 6;
58  else if (shapeType.Id == viskores::CELL_SHAPE_WEDGE)
59  quads = 3;
60  else if (shapeType.Id == viskores::CELL_SHAPE_PYRAMID)
61  quads = 1;
62 
63  else
64  quads = 0;
65  }
66 
69  viskores::Id& quads) const
70  {
71  quads = 6;
72  }
73 
75  void operator()(viskores::CellShapeTagQuad shapeType, viskores::Id& quads) const
76  {
77  if (shapeType.Id == viskores::CELL_SHAPE_QUAD)
78  quads = 1;
79  else
80  quads = 0;
81  }
84  viskores::Id& quads) const
85  {
86  quads = 3;
87  }
88  }; //class CountQuads
89 
90  template <int DIM>
92  {
93 
94  public:
95  typedef void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut);
96  typedef void ExecutionSignature(IncidentElementIndices, _2, _3);
97  //typedef _1 InputDomain;
100 
101 #if defined(VISKORES_MSVC)
102 #pragma warning(push)
103 #pragma warning(disable : 4127) //conditional expression is constant
104 #endif
105  template <typename CellNodeVecType, typename OutIndicesPortal>
107  viskores::Vec<Id, 5>& quad,
108  const viskores::Id offset,
109  const CellNodeVecType& cellIndices,
110  OutIndicesPortal& outputIndices) const
111  {
112 
113  quad[1] = cellIndices[viskores::IdComponent(idx[0])];
114  quad[2] = cellIndices[viskores::IdComponent(idx[1])];
115  quad[3] = cellIndices[viskores::IdComponent(idx[2])];
116  quad[4] = cellIndices[viskores::IdComponent(idx[3])];
117  outputIndices.Set(offset, quad);
118  }
119 
120  template <typename CellNodeVecType, typename OutIndicesPortal>
121  VISKORES_EXEC void operator()(const CellNodeVecType& cellIndices,
122  const viskores::Id& cellIndex,
123  OutIndicesPortal& outputIndices) const
124  {
125  if (DIM == 2)
126  {
127  outputIndices.Set(
128  cellIndex, { cellIndex, cellIndices[0], cellIndices[1], cellIndices[2], cellIndices[3] });
129  }
130  else if (DIM == 3)
131  {
132  viskores::Id offset = cellIndex * QUAD_PER_CSS;
134  quad[0] = cellIndex;
135  viskores::Id4 idx;
136  idx[0] = 0;
137  idx[1] = 1;
138  idx[2] = 5;
139  idx[3] = 4;
140  cell2quad(idx, quad, offset, cellIndices, outputIndices);
141 
142  idx[0] = 1;
143  idx[1] = 2;
144  idx[2] = 6;
145  idx[3] = 5;
146  offset++;
147  cell2quad(idx, quad, offset, cellIndices, outputIndices);
148 
149  idx[0] = 3;
150  idx[1] = 7;
151  idx[2] = 6;
152  idx[3] = 2;
153  offset++;
154  cell2quad(idx, quad, offset, cellIndices, outputIndices);
155 
156  idx[0] = 0;
157  idx[1] = 4;
158  idx[2] = 7;
159  idx[3] = 3;
160  offset++;
161  cell2quad(idx, quad, offset, cellIndices, outputIndices);
162 
163  idx[0] = 0;
164  idx[1] = 3;
165  idx[2] = 2;
166  idx[3] = 1;
167  offset++;
168  cell2quad(idx, quad, offset, cellIndices, outputIndices);
169 
170  idx[0] = 4;
171  idx[1] = 5;
172  idx[2] = 6;
173  idx[3] = 7;
174  offset++;
175  cell2quad(idx, quad, offset, cellIndices, outputIndices);
176  }
177  }
178 #if defined(VISKORES_MSVC)
179 #pragma warning(pop)
180 #endif
181  };
182 
183 
185  {
186 
187  public:
190  typedef void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut);
192 
193  template <typename VecType, typename OutputPortal>
195  const VecType& cellIndices,
196  const viskores::Id& cellId,
197  const viskores::Id Id0,
198  const viskores::Id Id1,
199  const viskores::Id Id2,
200  const viskores::Id Id3,
201  OutputPortal& outputIndices) const
202  {
204  quad[0] = cellId;
205  quad[1] = static_cast<viskores::Id>(cellIndices[viskores::IdComponent(Id0)]);
206  quad[2] = static_cast<viskores::Id>(cellIndices[viskores::IdComponent(Id1)]);
207  quad[3] = static_cast<viskores::Id>(cellIndices[viskores::IdComponent(Id2)]);
208  quad[4] = static_cast<viskores::Id>(cellIndices[viskores::IdComponent(Id3)]);
209  outputIndices.Set(offset++, quad);
210  }
211 
212  template <typename VecType, typename OutputPortal>
213  VISKORES_EXEC void operator()(const viskores::Id& pointOffset,
215  const VecType& cellIndices,
216  const viskores::Id& cellId,
217  OutputPortal& outputIndices) const
218  {
219  viskores::Id offset = pointOffset;
220 
221  cell2quad(offset, cellIndices, cellId, 3, 0, 2, 5, outputIndices);
222  cell2quad(offset, cellIndices, cellId, 1, 4, 5, 2, outputIndices);
223  cell2quad(offset, cellIndices, cellId, 0, 3, 4, 1, outputIndices);
224  }
225  template <typename VecType, typename OutputPortal>
227  viskores::CellShapeTagQuad shapeType,
228  const VecType& cellIndices,
229  const viskores::Id& cellId,
230  OutputPortal& outputIndices) const
231  {
232  if (shapeType.Id == viskores::CELL_SHAPE_QUAD)
233  {
235  quad[0] = cellId;
236  quad[1] = static_cast<viskores::Id>(cellIndices[0]);
237  quad[2] = static_cast<viskores::Id>(cellIndices[1]);
238  quad[3] = static_cast<viskores::Id>(cellIndices[2]);
239  quad[4] = static_cast<viskores::Id>(cellIndices[3]);
240  outputIndices.Set(offset, quad);
241  }
242  }
243 
244  template <typename VecType, typename OutputPortal>
245  VISKORES_EXEC void operator()(const viskores::Id& pointOffset,
247  const VecType& cellIndices,
248  const viskores::Id& cellId,
249  OutputPortal& outputIndices) const
250 
251  {
252  viskores::Id offset = pointOffset;
253  cell2quad(offset, cellIndices, cellId, 0, 1, 5, 4, outputIndices);
254  cell2quad(offset, cellIndices, cellId, 1, 2, 6, 5, outputIndices);
255  cell2quad(offset, cellIndices, cellId, 3, 7, 6, 2, outputIndices);
256  cell2quad(offset, cellIndices, cellId, 0, 4, 7, 3, outputIndices);
257  cell2quad(offset, cellIndices, cellId, 0, 3, 2, 1, outputIndices);
258  cell2quad(offset, cellIndices, cellId, 4, 5, 6, 7, outputIndices);
259  }
260 
261  template <typename VecType, typename OutputPortal>
262  VISKORES_EXEC void operator()(const viskores::Id& pointOffset,
264  const VecType& cellIndices,
265  const viskores::Id& cellId,
266  OutputPortal& outputIndices) const
267  {
268 
269  if (shapeType.Id == viskores::CELL_SHAPE_QUAD)
270  {
272  quad[0] = cellId;
273  quad[1] = cellIndices[0];
274  quad[2] = cellIndices[1];
275  quad[3] = cellIndices[2];
276  quad[4] = cellIndices[3];
277  outputIndices.Set(pointOffset, quad);
278  }
279  if (shapeType.Id == viskores::CELL_SHAPE_HEXAHEDRON)
280  {
281  viskores::Id offset = pointOffset;
282  cell2quad(offset, cellIndices, cellId, 0, 1, 5, 4, outputIndices);
283  cell2quad(offset, cellIndices, cellId, 1, 2, 6, 5, outputIndices);
284  cell2quad(offset, cellIndices, cellId, 3, 7, 6, 2, outputIndices);
285  cell2quad(offset, cellIndices, cellId, 0, 4, 7, 3, outputIndices);
286  cell2quad(offset, cellIndices, cellId, 0, 3, 2, 1, outputIndices);
287  cell2quad(offset, cellIndices, cellId, 4, 5, 6, 7, outputIndices);
288  }
289  if (shapeType.Id == viskores::CELL_SHAPE_WEDGE)
290  {
291  viskores::Id offset = pointOffset;
292 
293  cell2quad(offset, cellIndices, cellId, 3, 0, 2, 5, outputIndices);
294  cell2quad(offset, cellIndices, cellId, 1, 4, 5, 2, outputIndices);
295  cell2quad(offset, cellIndices, cellId, 0, 3, 4, 1, outputIndices);
296  }
297  if (shapeType.Id == viskores::CELL_SHAPE_PYRAMID)
298  {
299  viskores::Id offset = pointOffset;
300 
301  cell2quad(offset, cellIndices, cellId, 3, 2, 1, 0, outputIndices);
302  }
303  }
304 
305  }; //class Quadralize
306 
307 public:
310 
312  void Run(const viskores::cont::UnknownCellSet& cellset,
314  viskores::Id& output)
315  {
317 
319  {
320  viskores::cont::CellSetStructured<3> cellSetStructured3D =
322  const viskores::Id numCells = cellSetStructured3D.GetNumberOfCells();
323 
324  viskores::cont::ArrayHandleIndex cellIdxs(numCells);
325  outputIndices.Allocate(numCells * QUAD_PER_CSS);
326  invoke(SegmentedStructured<3>{}, cellSetStructured3D, cellIdxs, outputIndices);
327 
328  output = numCells * QUAD_PER_CSS;
329  }
331  {
332  viskores::cont::CellSetStructured<2> cellSetStructured2D =
334  const viskores::Id numCells = cellSetStructured2D.GetNumberOfCells();
335 
336  viskores::cont::ArrayHandleIndex cellIdxs(numCells);
337  outputIndices.Allocate(numCells);
338  invoke(SegmentedStructured<2>{}, cellSetStructured2D, cellIdxs, outputIndices);
339 
340  output = numCells;
341  }
342  else
343  {
344  auto cellSetUnstructured =
347  invoke(CountQuads{}, cellSetUnstructured, quadsPerCell);
348 
349  viskores::Id total = 0;
350  total = viskores::cont::Algorithm::Reduce(quadsPerCell, viskores::Id(0));
351 
353  viskores::cont::Algorithm::ScanExclusive(quadsPerCell, cellOffsets);
354  outputIndices.Allocate(total);
355 
356  invoke(Quadralize{}, cellSetUnstructured, cellOffsets, outputIndices);
357 
358  output = total;
359  }
360  }
361 };
362 }
363 }
364 #endif
viskores::worklet::WorkletVisitCellsWithPoints::FieldInCell
A control signature tag for input fields on the cells of the topology.
Definition: WorkletMapTopology.h:299
viskores::CELL_SHAPE_PYRAMID
@ CELL_SHAPE_PYRAMID
A pyramid with a quadrilateral base and four triangular faces.0.
Definition: CellShape.h:76
viskores::CellShapeTagGeneric::Id
viskores::UInt8 Id
An identifier that corresponds to one of the CELL_SHAPE_* identifiers.
Definition: CellShape.h:188
viskores::rendering::Quadralizer::SegmentedStructured
Definition: Quadralizer.h:91
viskores::rendering::Quadralizer::CountQuads::CountQuads
CountQuads()
Definition: Quadralizer.h:47
viskores::rendering::Quadralizer::SegmentedStructured::ExecutionSignature
void ExecutionSignature(IncidentElementIndices, _2, _3)
Definition: Quadralizer.h:96
WorkletMapField.h
viskores::worklet::WorkletVisitCellsWithPoints::CellSetIn
A control signature tag for input connectivity.
Definition: WorkletMapTopology.h:289
viskores::CellShapeTagHexahedron
Definition: CellShape.h:167
viskores::rendering::Quadralizer::Quadralize::cell2quad
void cell2quad(viskores::Id &offset, const VecType &cellIndices, const viskores::Id &cellId, const viskores::Id Id0, const viskores::Id Id1, const viskores::Id Id2, const viskores::Id Id3, OutputPortal &outputIndices) const
Definition: Quadralizer.h:194
viskoresNotUsed
#define viskoresNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:136
viskores::cont::Algorithm::Reduce
static U Reduce(viskores::cont::DeviceAdapterId devId, const viskores::cont::ArrayHandle< T, CIn > &input, U initialValue)
Definition: Algorithm.h:672
viskores::cont::Algorithm::ScanExclusive
static T ScanExclusive(viskores::cont::DeviceAdapterId devId, const viskores::cont::ArrayHandle< T, CIn > &input, viskores::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:836
viskores::rendering::Quadralizer::Run
void Run(const viskores::cont::UnknownCellSet &cellset, viskores::cont::ArrayHandle< viskores::Vec< viskores::Id, 5 >> &outputIndices, viskores::Id &output)
Definition: Quadralizer.h:312
viskores::rendering::Quadralizer
Definition: Quadralizer.h:40
viskores::worklet::WorkletVisitCellsWithPoints::CellShape
An execution signature tag to get the shape of the visited cell.
Definition: WorkletMapTopology.h:406
viskores::rendering::Quadralizer::SegmentedStructured::operator()
void operator()(const CellNodeVecType &cellIndices, const viskores::Id &cellIndex, OutIndicesPortal &outputIndices) const
Definition: Quadralizer.h:121
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::rendering::Quadralizer::Quadralize::Quadralize
Quadralize()
Definition: Quadralizer.h:189
viskores::worklet::WorkletVisitCellsWithPoints::FieldOut
A control signature tag for output fields.
Definition: WorkletMapTopology.h:339
VISKORES_DEFAULT_CELL_SET_LIST_UNSTRUCTURED
#define VISKORES_DEFAULT_CELL_SET_LIST_UNSTRUCTURED
Definition: DefaultTypes.h:68
viskores::IdComponent
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
viskores::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
A hexahedron.
Definition: CellShape.h:70
UncertainCellSet.h
viskores::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:265
viskores::rendering::Quadralizer::CountQuads::operator()
void operator()(viskores::CellShapeTagHexahedron, viskores::Id &quads) const
Definition: Quadralizer.h:68
viskores::CellShapeTagGeneric
A special cell shape tag that holds a cell shape that is not known at compile time.
Definition: CellShape.h:178
viskores::rendering::Quadralizer::CountQuads::ExecutionSignature
void ExecutionSignature(CellShape, _2)
Definition: Quadralizer.h:49
viskores::worklet::WorkletVisitCellsWithPoints::PointIndices
An execution signature tag to get the indices of the incident points.
Definition: WorkletMapTopology.h:426
viskores::rendering::Quadralizer::Quadralize::ControlSignature
void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut)
Definition: Quadralizer.h:190
viskores::CellShapeTagWedge
Definition: CellShape.h:168
QUAD_PER_CSS
#define QUAD_PER_CSS
Definition: Quadralizer.h:33
viskores::rendering::Quadralizer::CountQuads::operator()
void operator()(viskores::CellShapeTagGeneric shapeType, viskores::Id &quads) const
Definition: Quadralizer.h:52
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
A wedge.
Definition: CellShape.h:74
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::cont::UnknownCellSet::ResetCellSetList
viskores::cont::UncertainCellSet< CellSetList > ResetCellSetList(CellSetList) const
Assigns potential cell set types.
viskores::rendering::Quadralizer::Quadralizer
Quadralizer()
Definition: Quadralizer.h:309
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Algorithm.h
viskores::rendering::Quadralizer::CountQuads::operator()
void operator()(viskores::CellShapeTagWedge, viskores::Id &quads) const
Definition: Quadralizer.h:83
viskores::rendering::Quadralizer::CountQuads::operator()
void operator()(viskores::CellShapeTagQuad shapeType, viskores::Id &quads) const
Definition: Quadralizer.h:75
viskores::CellShapeTagQuad
Definition: CellShape.h:164
viskores::rendering::Quadralizer::SegmentedStructured::ControlSignature
void ControlSignature(CellSetIn cellset, FieldInCell, WholeArrayOut)
Definition: Quadralizer.h:95
viskores::rendering::Quadralizer::Quadralize::operator()
void operator()(const viskores::Id &pointOffset, viskores::CellShapeTagHexahedron, const VecType &cellIndices, const viskores::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:245
viskores::rendering::Quadralizer::CountQuads
Definition: Quadralizer.h:43
CellSetPermutation.h
viskores::rendering::Quadralizer::CountQuads::ControlSignature
void ControlSignature(CellSetIn cellset, FieldOut)
Definition: Quadralizer.h:48
viskores::rendering::Quadralizer::Quadralize
Definition: Quadralizer.h:184
viskores::cont::CellSetStructured
Defines a 1-, 2-, or 3-dimensional structured grid of points.
Definition: CastAndCall.h:40
viskores::cont::UnknownCellSet::CanConvert
bool CanConvert() const
Returns true if this cell set can be retrieved as the given type.
Definition: UnknownCellSet.h:172
viskores::cont::CellSetStructured::GetNumberOfCells
viskores::Id GetNumberOfCells() const override
Get the number of cells in the topology.
Definition: CellSetStructured.h:53
viskores::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:56
viskores::CELL_SHAPE_QUAD
@ CELL_SHAPE_QUAD
A four-sided polygon.
Definition: CellShape.h:64
ArrayHandleCounting.h
viskores::rendering::Quadralizer::SegmentedStructured::cell2quad
void cell2quad(viskores::Id4 idx, viskores::Vec< Id, 5 > &quad, const viskores::Id offset, const CellNodeVecType &cellIndices, OutIndicesPortal &outputIndices) const
Definition: Quadralizer.h:106
viskores::rendering::Quadralizer::SegmentedStructured::SegmentedStructured
SegmentedStructured()
Definition: Quadralizer.h:99
viskores::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:49
viskores::CellShapeTagQuad::Id
static constexpr viskores::UInt8 Id
Definition: CellShape.h:164
viskores::rendering::Quadralizer::Quadralize::operator()
void operator()(const viskores::Id &pointOffset, viskores::CellShapeTagWedge, const VecType &cellIndices, const viskores::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:213
viskores::rendering::Quadralizer::Quadralize::operator()
void operator()(const viskores::Id &offset, viskores::CellShapeTagQuad shapeType, const VecType &cellIndices, const viskores::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:226
DispatcherMapTopology.h
WorkletMapTopology.h
viskores::Vec
A short fixed-length array.
Definition: Types.h:365
viskores::cont::UnknownCellSet::AsCellSet
void AsCellSet(CellSetType &cellSet) const
Get the cell set as a known type.
Definition: UnknownCellSet.h:189
VISKORES_EXEC
#define VISKORES_EXEC
Definition: ExportMacros.h:59
viskores::rendering::Quadralizer::Quadralize::ExecutionSignature
void ExecutionSignature(_2, CellShape, PointIndices, WorkIndex, _3)
Definition: Quadralizer.h:191
DataSet.h
viskores::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:64
viskores::rendering::Quadralizer::Quadralize::operator()
void operator()(const viskores::Id &pointOffset, viskores::CellShapeTagGeneric shapeType, const VecType &cellIndices, const viskores::Id &cellId, OutputPortal &outputIndices) const
Definition: Quadralizer.h:262
viskores::exec::arg::WorkIndex
The ExecutionSignature tag to use to get the work index.
Definition: WorkIndex.h:47