VTK-m  2.0
Triangulator.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_Triangulator_h
11 #define vtk_m_rendering_Triangulator_h
12 
13 #include <typeinfo>
14 #include <vtkm/cont/Algorithm.h>
17 #include <vtkm/cont/DataSet.h>
24 namespace vtkm
25 {
26 namespace rendering
27 {
35 {
36 public:
38  {
39  public:
40  VTKM_CONT
42  using ControlSignature = void(CellSetIn cellset, FieldOut);
43  using ExecutionSignature = void(CellShape, _2);
44 
45  VTKM_EXEC
46  void operator()(vtkm::CellShapeTagGeneric shapeType, vtkm::Id& triangles) const
47  {
48  if (shapeType.Id == vtkm::CELL_SHAPE_TRIANGLE)
49  triangles = 1;
50  else if (shapeType.Id == vtkm::CELL_SHAPE_QUAD)
51  triangles = 2;
52  else if (shapeType.Id == vtkm::CELL_SHAPE_TETRA)
53  triangles = 4;
54  else if (shapeType.Id == vtkm::CELL_SHAPE_HEXAHEDRON)
55  triangles = 12;
56  else if (shapeType.Id == vtkm::CELL_SHAPE_WEDGE)
57  triangles = 8;
58  else if (shapeType.Id == vtkm::CELL_SHAPE_PYRAMID)
59  triangles = 6;
60  else
61  triangles = 0;
62  }
63 
64  VTKM_EXEC
65  void operator()(vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType), vtkm::Id& triangles) const
66  {
67  triangles = 12;
68  }
69 
70  VTKM_EXEC
71  void operator()(vtkm::CellShapeTagQuad vtkmNotUsed(shapeType), vtkm::Id& triangles) const
72  {
73  triangles = 2;
74  }
75  VTKM_EXEC
76  void operator()(vtkm::CellShapeTagWedge vtkmNotUsed(shapeType), vtkm::Id& triangles) const
77  {
78  triangles = 8;
79  }
80  }; //class CountTriangles
81 
82  template <int DIM>
84  {
85 
86  public:
87  using ControlSignature = void(CellSetIn cellset, FieldInCell, WholeArrayOut);
88  using ExecutionSignature = void(IncidentElementIndices, _2, _3);
89  VTKM_CONT
91 
92 #if defined(VTKM_MSVC)
93 #pragma warning(push)
94 #pragma warning(disable : 4127) //conditional expression is constant
95 #endif
96  template <typename CellNodeVecType, typename OutIndicesPortal>
97  VTKM_EXEC void operator()(const CellNodeVecType& cellIndices,
98  const vtkm::Id& cellIndex,
99  OutIndicesPortal& outputIndices) const
100  {
101  vtkm::Id4 triangle;
102  if (DIM == 2)
103  {
104  const vtkm::Id triangleOffset = cellIndex * 2;
105  // 0-1-2
106  triangle[1] = cellIndices[0];
107  triangle[2] = cellIndices[1];
108  triangle[3] = cellIndices[2];
109  triangle[0] = cellIndex;
110  outputIndices.Set(triangleOffset, triangle);
111  // 0-3-2
112  triangle[2] = cellIndices[3];
113  outputIndices.Set(triangleOffset + 1, triangle);
114  }
115  else if (DIM == 3)
116  {
117  const vtkm::Id triangleOffset = cellIndex * 12;
118 
119  triangle[1] = cellIndices[0];
120  triangle[2] = cellIndices[1];
121  triangle[3] = cellIndices[5];
122  triangle[0] = cellIndex;
123  outputIndices.Set(triangleOffset, triangle);
124 
125  triangle[1] = cellIndices[0];
126  triangle[2] = cellIndices[5];
127  triangle[3] = cellIndices[4];
128  outputIndices.Set(triangleOffset + 1, triangle);
129 
130  triangle[1] = cellIndices[1];
131  triangle[2] = cellIndices[2];
132  triangle[3] = cellIndices[6];
133  outputIndices.Set(triangleOffset + 2, triangle);
134 
135  triangle[1] = cellIndices[1];
136  triangle[2] = cellIndices[6];
137  triangle[3] = cellIndices[5];
138  outputIndices.Set(triangleOffset + 3, triangle);
139 
140  triangle[1] = cellIndices[3];
141  triangle[2] = cellIndices[7];
142  triangle[3] = cellIndices[6];
143  outputIndices.Set(triangleOffset + 4, triangle);
144 
145  triangle[1] = cellIndices[3];
146  triangle[2] = cellIndices[6];
147  triangle[3] = cellIndices[2];
148  outputIndices.Set(triangleOffset + 5, triangle);
149 
150  triangle[1] = cellIndices[0];
151  triangle[2] = cellIndices[4];
152  triangle[3] = cellIndices[7];
153  outputIndices.Set(triangleOffset + 6, triangle);
154 
155  triangle[1] = cellIndices[0];
156  triangle[2] = cellIndices[7];
157  triangle[3] = cellIndices[3];
158  outputIndices.Set(triangleOffset + 7, triangle);
159 
160  triangle[1] = cellIndices[0];
161  triangle[2] = cellIndices[3];
162  triangle[3] = cellIndices[2];
163  outputIndices.Set(triangleOffset + 8, triangle);
164 
165  triangle[1] = cellIndices[0];
166  triangle[2] = cellIndices[2];
167  triangle[3] = cellIndices[1];
168  outputIndices.Set(triangleOffset + 9, triangle);
169 
170  triangle[1] = cellIndices[4];
171  triangle[2] = cellIndices[5];
172  triangle[3] = cellIndices[6];
173  outputIndices.Set(triangleOffset + 10, triangle);
174 
175  triangle[1] = cellIndices[4];
176  triangle[2] = cellIndices[6];
177  triangle[3] = cellIndices[7];
178  outputIndices.Set(triangleOffset + 11, triangle);
179  }
180  }
181 #if defined(VTKM_MSVC)
182 #pragma warning(pop)
183 #endif
184  };
185 
186 
188  {
189  public:
190  VTKM_CONT
193  using ExecutionSignature = void(_1);
194  VTKM_EXEC
195  void operator()(vtkm::Id4& triangleIndices) const
196  {
197  // first field contains the id of the cell the
198  // trianlge belongs to
199  vtkm::Id temp;
200  if (triangleIndices[1] > triangleIndices[3])
201  {
202  temp = triangleIndices[1];
203  triangleIndices[1] = triangleIndices[3];
204  triangleIndices[3] = temp;
205  }
206  if (triangleIndices[1] > triangleIndices[2])
207  {
208  temp = triangleIndices[1];
209  triangleIndices[1] = triangleIndices[2];
210  triangleIndices[2] = temp;
211  }
212  if (triangleIndices[2] > triangleIndices[3])
213  {
214  temp = triangleIndices[2];
215  triangleIndices[2] = triangleIndices[3];
216  triangleIndices[3] = temp;
217  }
218  }
219  }; //class IndicesSort
220 
222  {
224  bool operator()(const vtkm::Id4& a, const vtkm::Id4& b) const
225  {
226  if (a[1] < b[1])
227  return true;
228  if (a[1] > b[1])
229  return false;
230  if (a[2] < b[2])
231  return true;
232  if (a[2] > b[2])
233  return false;
234  if (a[3] < b[3])
235  return true;
236  return false;
237  }
238  };
239 
241  {
242  public:
243  VTKM_CONT
245 
246  using ControlSignature = void(WholeArrayIn, WholeArrayOut);
247  using ExecutionSignature = void(_1, _2, WorkIndex);
248 
249  VTKM_EXEC
250  bool IsTwin(const vtkm::Id4& a, const vtkm::Id4& b) const
251  {
252  return (a[1] == b[1] && a[2] == b[2] && a[3] == b[3]);
253  }
254 
255  template <typename IndicesPortalType, typename OutputFlagsPortalType>
256  VTKM_EXEC void operator()(const IndicesPortalType& indices,
257  OutputFlagsPortalType& outputFlags,
258  const vtkm::Id& index) const
259  {
260  if (index == 0)
261  return;
262  //if we are a shared face, mark ourself and neighbor for destruction
263  if (IsTwin(indices.Get(index), indices.Get(index - 1)))
264  {
265  outputFlags.Set(index, 0);
266  outputFlags.Set(index - 1, 0);
267  }
268  }
269  }; //class UniqueTriangles
270 
272  {
273 
274  public:
275  VTKM_CONT
277  using ControlSignature = void(CellSetIn cellset, FieldInCell, WholeArrayOut);
278  using ExecutionSignature = void(_2, CellShape, PointIndices, WorkIndex, _3);
279 
280  template <typename VecType, typename OutputPortal>
281  VTKM_EXEC void operator()(const vtkm::Id& triangleOffset,
282  vtkm::CellShapeTagWedge vtkmNotUsed(shapeType),
283  const VecType& cellIndices,
284  const vtkm::Id& cellId,
285  OutputPortal& outputIndices) const
286  {
287  vtkm::Id4 triangle;
288 
289  triangle[1] = cellIndices[0];
290  triangle[2] = cellIndices[1];
291  triangle[3] = cellIndices[2];
292  triangle[0] = cellId;
293  outputIndices.Set(triangleOffset, triangle);
294 
295  triangle[1] = cellIndices[3];
296  triangle[2] = cellIndices[5];
297  triangle[3] = cellIndices[4];
298  outputIndices.Set(triangleOffset + 1, triangle);
299 
300  triangle[1] = cellIndices[3];
301  triangle[2] = cellIndices[0];
302  triangle[3] = cellIndices[2];
303  outputIndices.Set(triangleOffset + 2, triangle);
304 
305  triangle[1] = cellIndices[3];
306  triangle[2] = cellIndices[2];
307  triangle[3] = cellIndices[5];
308  outputIndices.Set(triangleOffset + 3, triangle);
309 
310  triangle[1] = cellIndices[1];
311  triangle[2] = cellIndices[4];
312  triangle[3] = cellIndices[5];
313  outputIndices.Set(triangleOffset + 4, triangle);
314 
315  triangle[1] = cellIndices[1];
316  triangle[2] = cellIndices[5];
317  triangle[3] = cellIndices[2];
318  outputIndices.Set(triangleOffset + 5, triangle);
319 
320  triangle[1] = cellIndices[0];
321  triangle[2] = cellIndices[3];
322  triangle[3] = cellIndices[4];
323  outputIndices.Set(triangleOffset + 6, triangle);
324 
325  triangle[1] = cellIndices[0];
326  triangle[2] = cellIndices[4];
327  triangle[3] = cellIndices[1];
328  outputIndices.Set(triangleOffset + 7, triangle);
329  }
330  template <typename VecType, typename OutputPortal>
331  VTKM_EXEC void operator()(const vtkm::Id& triangleOffset,
332  vtkm::CellShapeTagQuad vtkmNotUsed(shapeType),
333  const VecType& cellIndices,
334  const vtkm::Id& cellId,
335  OutputPortal& outputIndices) const
336  {
337  vtkm::Id4 triangle;
338 
339 
340  triangle[1] = cellIndices[0];
341  triangle[2] = cellIndices[1];
342  triangle[3] = cellIndices[2];
343  triangle[0] = cellId;
344  outputIndices.Set(triangleOffset, triangle);
345 
346  triangle[2] = cellIndices[3];
347  outputIndices.Set(triangleOffset + 1, triangle);
348  }
349 
350  template <typename VecType, typename OutputPortal>
351  VTKM_EXEC void operator()(const vtkm::Id& triangleOffset,
352  vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType),
353  const VecType& cellIndices,
354  const vtkm::Id& cellId,
355  OutputPortal& outputIndices) const
356  {
357  vtkm::Id4 triangle;
358 
359  triangle[1] = cellIndices[0];
360  triangle[2] = cellIndices[1];
361  triangle[3] = cellIndices[5];
362  triangle[0] = cellId;
363  outputIndices.Set(triangleOffset, triangle);
364 
365  triangle[1] = cellIndices[0];
366  triangle[2] = cellIndices[5];
367  triangle[3] = cellIndices[4];
368  outputIndices.Set(triangleOffset + 1, triangle);
369 
370  triangle[1] = cellIndices[1];
371  triangle[2] = cellIndices[2];
372  triangle[3] = cellIndices[6];
373  outputIndices.Set(triangleOffset + 2, triangle);
374 
375  triangle[1] = cellIndices[1];
376  triangle[2] = cellIndices[6];
377  triangle[3] = cellIndices[5];
378  outputIndices.Set(triangleOffset + 3, triangle);
379 
380  triangle[1] = cellIndices[3];
381  triangle[2] = cellIndices[7];
382  triangle[3] = cellIndices[6];
383  outputIndices.Set(triangleOffset + 4, triangle);
384 
385  triangle[1] = cellIndices[3];
386  triangle[2] = cellIndices[6];
387  triangle[3] = cellIndices[2];
388  outputIndices.Set(triangleOffset + 5, triangle);
389 
390  triangle[1] = cellIndices[0];
391  triangle[2] = cellIndices[4];
392  triangle[3] = cellIndices[7];
393  outputIndices.Set(triangleOffset + 6, triangle);
394 
395  triangle[1] = cellIndices[0];
396  triangle[2] = cellIndices[7];
397  triangle[3] = cellIndices[3];
398  outputIndices.Set(triangleOffset + 7, triangle);
399 
400  triangle[1] = cellIndices[0];
401  triangle[2] = cellIndices[3];
402  triangle[3] = cellIndices[2];
403  outputIndices.Set(triangleOffset + 8, triangle);
404 
405  triangle[1] = cellIndices[0];
406  triangle[2] = cellIndices[2];
407  triangle[3] = cellIndices[1];
408  outputIndices.Set(triangleOffset + 9, triangle);
409 
410  triangle[1] = cellIndices[4];
411  triangle[2] = cellIndices[5];
412  triangle[3] = cellIndices[6];
413  outputIndices.Set(triangleOffset + 10, triangle);
414 
415  triangle[1] = cellIndices[4];
416  triangle[2] = cellIndices[6];
417  triangle[3] = cellIndices[7];
418  outputIndices.Set(triangleOffset + 11, triangle);
419  }
420 
421  template <typename VecType, typename OutputPortal>
422  VTKM_EXEC void operator()(const vtkm::Id& triangleOffset,
423  vtkm::CellShapeTagGeneric shapeType,
424  const VecType& cellIndices,
425  const vtkm::Id& cellId,
426  OutputPortal& outputIndices) const
427  {
428  vtkm::Id4 triangle;
429 
430  if (shapeType.Id == vtkm::CELL_SHAPE_TRIANGLE)
431  {
432 
433  triangle[1] = cellIndices[0];
434  triangle[2] = cellIndices[1];
435  triangle[3] = cellIndices[2];
436  triangle[0] = cellId;
437  outputIndices.Set(triangleOffset, triangle);
438  }
439  if (shapeType.Id == vtkm::CELL_SHAPE_QUAD)
440  {
441 
442  triangle[1] = cellIndices[0];
443  triangle[2] = cellIndices[1];
444  triangle[3] = cellIndices[2];
445  triangle[0] = cellId;
446  outputIndices.Set(triangleOffset, triangle);
447 
448  triangle[2] = cellIndices[3];
449  outputIndices.Set(triangleOffset + 1, triangle);
450  }
451  if (shapeType.Id == vtkm::CELL_SHAPE_TETRA)
452  {
453  triangle[1] = cellIndices[0];
454  triangle[2] = cellIndices[3];
455  triangle[3] = cellIndices[1];
456  triangle[0] = cellId;
457  outputIndices.Set(triangleOffset, triangle);
458 
459  triangle[1] = cellIndices[1];
460  triangle[2] = cellIndices[2];
461  triangle[3] = cellIndices[3];
462  outputIndices.Set(triangleOffset + 1, triangle);
463 
464  triangle[1] = cellIndices[0];
465  triangle[2] = cellIndices[2];
466  triangle[3] = cellIndices[3];
467  outputIndices.Set(triangleOffset + 2, triangle);
468 
469  triangle[1] = cellIndices[0];
470  triangle[2] = cellIndices[2];
471  triangle[3] = cellIndices[1];
472  outputIndices.Set(triangleOffset + 3, triangle);
473  }
474  if (shapeType.Id == vtkm::CELL_SHAPE_HEXAHEDRON)
475  {
476  triangle[1] = cellIndices[0];
477  triangle[2] = cellIndices[1];
478  triangle[3] = cellIndices[5];
479  triangle[0] = cellId;
480  outputIndices.Set(triangleOffset, triangle);
481 
482  triangle[1] = cellIndices[0];
483  triangle[2] = cellIndices[5];
484  triangle[3] = cellIndices[4];
485  outputIndices.Set(triangleOffset + 1, triangle);
486 
487  triangle[1] = cellIndices[1];
488  triangle[2] = cellIndices[2];
489  triangle[3] = cellIndices[6];
490  outputIndices.Set(triangleOffset + 2, triangle);
491 
492  triangle[1] = cellIndices[1];
493  triangle[2] = cellIndices[6];
494  triangle[3] = cellIndices[5];
495  outputIndices.Set(triangleOffset + 3, triangle);
496 
497  triangle[1] = cellIndices[3];
498  triangle[2] = cellIndices[7];
499  triangle[3] = cellIndices[6];
500  outputIndices.Set(triangleOffset + 4, triangle);
501 
502  triangle[1] = cellIndices[3];
503  triangle[2] = cellIndices[6];
504  triangle[3] = cellIndices[2];
505  outputIndices.Set(triangleOffset + 5, triangle);
506 
507  triangle[1] = cellIndices[0];
508  triangle[2] = cellIndices[4];
509  triangle[3] = cellIndices[7];
510  outputIndices.Set(triangleOffset + 6, triangle);
511 
512  triangle[1] = cellIndices[0];
513  triangle[2] = cellIndices[7];
514  triangle[3] = cellIndices[3];
515  outputIndices.Set(triangleOffset + 7, triangle);
516 
517  triangle[1] = cellIndices[0];
518  triangle[2] = cellIndices[3];
519  triangle[3] = cellIndices[2];
520  outputIndices.Set(triangleOffset + 8, triangle);
521 
522  triangle[1] = cellIndices[0];
523  triangle[2] = cellIndices[2];
524  triangle[3] = cellIndices[1];
525  outputIndices.Set(triangleOffset + 9, triangle);
526 
527  triangle[1] = cellIndices[4];
528  triangle[2] = cellIndices[5];
529  triangle[3] = cellIndices[6];
530  outputIndices.Set(triangleOffset + 10, triangle);
531 
532  triangle[1] = cellIndices[4];
533  triangle[2] = cellIndices[6];
534  triangle[3] = cellIndices[7];
535  outputIndices.Set(triangleOffset + 11, triangle);
536  }
537  if (shapeType.Id == vtkm::CELL_SHAPE_WEDGE)
538  {
539  triangle[1] = cellIndices[0];
540  triangle[2] = cellIndices[1];
541  triangle[3] = cellIndices[2];
542  triangle[0] = cellId;
543  outputIndices.Set(triangleOffset, triangle);
544 
545  triangle[1] = cellIndices[3];
546  triangle[2] = cellIndices[5];
547  triangle[3] = cellIndices[4];
548  outputIndices.Set(triangleOffset + 1, triangle);
549 
550  triangle[1] = cellIndices[3];
551  triangle[2] = cellIndices[0];
552  triangle[3] = cellIndices[2];
553  outputIndices.Set(triangleOffset + 2, triangle);
554 
555  triangle[1] = cellIndices[3];
556  triangle[2] = cellIndices[2];
557  triangle[3] = cellIndices[5];
558  outputIndices.Set(triangleOffset + 3, triangle);
559 
560  triangle[1] = cellIndices[1];
561  triangle[2] = cellIndices[4];
562  triangle[3] = cellIndices[5];
563  outputIndices.Set(triangleOffset + 4, triangle);
564 
565  triangle[1] = cellIndices[1];
566  triangle[2] = cellIndices[5];
567  triangle[3] = cellIndices[2];
568  outputIndices.Set(triangleOffset + 5, triangle);
569 
570  triangle[1] = cellIndices[0];
571  triangle[2] = cellIndices[3];
572  triangle[3] = cellIndices[4];
573  outputIndices.Set(triangleOffset + 6, triangle);
574 
575  triangle[1] = cellIndices[0];
576  triangle[2] = cellIndices[4];
577  triangle[3] = cellIndices[1];
578  outputIndices.Set(triangleOffset + 7, triangle);
579  }
580  if (shapeType.Id == vtkm::CELL_SHAPE_PYRAMID)
581  {
582  triangle[1] = cellIndices[0];
583  triangle[2] = cellIndices[4];
584  triangle[3] = cellIndices[1];
585  triangle[0] = cellId;
586  outputIndices.Set(triangleOffset, triangle);
587 
588  triangle[1] = cellIndices[1];
589  triangle[2] = cellIndices[2];
590  triangle[3] = cellIndices[4];
591  outputIndices.Set(triangleOffset + 1, triangle);
592 
593  triangle[1] = cellIndices[2];
594  triangle[2] = cellIndices[3];
595  triangle[3] = cellIndices[4];
596  outputIndices.Set(triangleOffset + 2, triangle);
597 
598  triangle[1] = cellIndices[0];
599  triangle[2] = cellIndices[4];
600  triangle[3] = cellIndices[3];
601  outputIndices.Set(triangleOffset + 3, triangle);
602 
603  triangle[1] = cellIndices[3];
604  triangle[2] = cellIndices[2];
605  triangle[3] = cellIndices[1];
606  outputIndices.Set(triangleOffset + 4, triangle);
607 
608  triangle[1] = cellIndices[3];
609  triangle[2] = cellIndices[1];
610  triangle[3] = cellIndices[0];
611  outputIndices.Set(triangleOffset + 5, triangle);
612  }
613  }
614  }; //class Triangulate
615 
616 public:
617  VTKM_CONT
619 
620  VTKM_CONT
622  vtkm::Id& outputTriangles)
623  {
624  //Eliminate unseen triangles
626  sortInvoker.Invoke(outputIndices);
627 
630  flags.Allocate(outputTriangles);
631 
632  vtkm::cont::ArrayHandleConstant<vtkm::Id> one(1, outputTriangles);
633  vtkm::cont::Algorithm::Copy(one, flags);
634  //Unique triangles will have a flag = 1
635  vtkm::worklet::DispatcherMapField<UniqueTriangles>().Invoke(outputIndices, flags);
636 
638  vtkm::cont::Algorithm::CopyIf(outputIndices, flags, subset);
639  outputIndices = subset;
640  outputTriangles = subset.GetNumberOfValues();
641  }
642 
643  VTKM_CONT
644  void Run(const vtkm::cont::UnknownCellSet& cellset,
645  vtkm::cont::ArrayHandle<vtkm::Id4>& outputIndices,
646  vtkm::Id& outputTriangles)
647  {
648  bool fastPath = false;
650  {
651  //vtkm::cont::CellSetStructured<3> cellSetStructured3D =
652  // cellset.Cast<vtkm::cont::CellSetStructured<3>>();
653 
654  //raytracing::MeshConnectivityBuilder<Device> builder;
655  //outputIndices = builder.ExternalTrianglesStructured(cellSetStructured3D);
656  //outputTriangles = outputIndices.GetNumberOfValues();
657  //fastPath = true;
658  vtkm::cont::CellSetStructured<3> cellSetStructured3D =
660  const vtkm::Id numCells = cellSetStructured3D.GetNumberOfCells();
661 
662  vtkm::cont::ArrayHandleCounting<vtkm::Id> cellIdxs(0, 1, numCells);
663  outputIndices.Allocate(numCells * 12);
665  .Invoke(cellSetStructured3D, cellIdxs, outputIndices);
666 
667  outputTriangles = numCells * 12;
668  }
669  else if (cellset.CanConvert<vtkm::cont::CellSetStructured<2>>())
670  {
671  vtkm::cont::CellSetStructured<2> cellSetStructured2D =
673  const vtkm::Id numCells = cellSetStructured2D.GetNumberOfCells();
674 
675  vtkm::cont::ArrayHandleCounting<vtkm::Id> cellIdxs(0, 1, numCells);
676  outputIndices.Allocate(numCells * 2);
678  .Invoke(cellSetStructured2D, cellIdxs, outputIndices);
679 
680  outputTriangles = numCells * 2;
681  // no need to do external faces on 2D cell set
682  fastPath = true;
683  }
684  else
685  {
686  auto cellSetUnstructured =
687  cellset.ResetCellSetList(VTKM_DEFAULT_CELL_SET_LIST_UNSTRUCTURED{});
688  vtkm::cont::ArrayHandle<vtkm::Id> trianglesPerCell;
690  .Invoke(cellSetUnstructured, trianglesPerCell);
691 
692  vtkm::Id totalTriangles = 0;
693  totalTriangles = vtkm::cont::Algorithm::Reduce(trianglesPerCell, vtkm::Id(0));
694 
696  vtkm::cont::Algorithm::ScanExclusive(trianglesPerCell, cellOffsets);
697  outputIndices.Allocate(totalTriangles);
698 
700  .Invoke(cellSetUnstructured, cellOffsets, outputIndices);
701 
702  outputTriangles = totalTriangles;
703  }
704 
705  //get rid of any triagles we cannot see
706  if (!fastPath)
707  {
708  ExternalTriangles(outputIndices, outputTriangles);
709  }
710  }
711 }; // class Triangulator
712 }
713 } //namespace vtkm::rendering
714 #endif //vtk_m_rendering_Triangulator_h
vtkm::rendering::Triangulator::CountTriangles::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType), vtkm::Id &triangles) const
Definition: Triangulator.h:65
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle< vtkm::Id4 >
vtkm::rendering::Triangulator::Triangulate::operator()
VTKM_EXEC void operator()(const vtkm::Id &triangleOffset, vtkm::CellShapeTagGeneric shapeType, const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Triangulator.h:422
vtkm::CELL_SHAPE_WEDGE
@ CELL_SHAPE_WEDGE
Definition: CellShape.h:49
vtkm::rendering::Triangulator::IndicesSort::ControlSignature
void(FieldInOut) ControlSignature
Definition: Triangulator.h:192
vtkm::cont::CellSetStructured::GetNumberOfCells
vtkm::Id GetNumberOfCells() const override
Definition: CellSetStructured.h:38
vtkm::rendering::Triangulator::UniqueTriangles::operator()
VTKM_EXEC void operator()(const IndicesPortalType &indices, OutputFlagsPortalType &outputFlags, const vtkm::Id &index) const
Definition: Triangulator.h:256
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
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_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:465
vtkm::cont::CellSetStructured< 3 >
vtkm::rendering::Triangulator::TriangulateStructured::ControlSignature
void(CellSetIn cellset, FieldInCell, WholeArrayOut) ControlSignature
Definition: Triangulator.h:87
vtkm::rendering::Triangulator::TriangulateStructured::operator()
VTKM_EXEC void operator()(const CellNodeVecType &cellIndices, const vtkm::Id &cellIndex, OutIndicesPortal &outputIndices) const
Definition: Triangulator.h:97
vtkm::rendering::Triangulator::CountTriangles::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagQuad vtkmNotUsed(shapeType), vtkm::Id &triangles) const
Definition: Triangulator.h:71
vtkm::rendering::Triangulator::UniqueTriangles
Definition: Triangulator.h:240
vtkm::cont::UnknownCellSet::ResetCellSetList
VTKM_CONT vtkm::cont::UncertainCellSet< CellSetList > ResetCellSetList(CellSetList) const
Assigns potential cell set types.
vtkm::cont::Algorithm::Sort
static VTKM_CONT void Sort(vtkm::cont::DeviceAdapterId devId, vtkm::cont::ArrayHandle< T, Storage > &values)
Definition: Algorithm.h:965
vtkm::rendering::Triangulator::IndicesSort::ExecutionSignature
void(_1) ExecutionSignature
Definition: Triangulator.h:193
vtkm::cont::Algorithm::Copy
static VTKM_CONT bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:410
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
UncertainCellSet.h
vtkm::worklet::WorkletVisitCellsWithPoints::PointIndices
IncidentElementIndices PointIndices
Definition: WorkletMapTopology.h:269
vtkm::rendering::Triangulator::CountTriangles::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagGeneric shapeType, vtkm::Id &triangles) const
Definition: Triangulator.h:46
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
MeshConnectivityBuilder.h
DispatcherMapField.h
vtkm::rendering::Triangulator::Triangulate::operator()
VTKM_EXEC void operator()(const vtkm::Id &triangleOffset, vtkm::CellShapeTagQuad vtkmNotUsed(shapeType), const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Triangulator.h:331
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::Triangulator::TriangulateStructured
Definition: Triangulator.h:83
vtkm::rendering::Triangulator::Triangulator
VTKM_CONT Triangulator()
Definition: Triangulator.h:618
vtkm::rendering::Triangulator::TriangulateStructured::TriangulateStructured
VTKM_CONT TriangulateStructured()
Definition: Triangulator.h:90
vtkm::worklet::DispatcherMapField
Dispatcher for worklets that inherit from WorkletMapField.
Definition: DispatcherMapField.h:25
vtkm::rendering::Triangulator::CountTriangles::ExecutionSignature
void(CellShape, _2) ExecutionSignature
Definition: Triangulator.h:43
Algorithm.h
vtkm::worklet::DispatcherMapTopology
Dispatcher for worklets that inherit from WorkletMapTopology.
Definition: DispatcherMapTopology.h:31
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::rendering::Triangulator::Run
VTKM_CONT void Run(const vtkm::cont::UnknownCellSet &cellset, vtkm::cont::ArrayHandle< vtkm::Id4 > &outputIndices, vtkm::Id &outputTriangles)
Definition: Triangulator.h:644
vtkm::cont::ArrayHandleCounting< vtkm::Id >
vtkm::CELL_SHAPE_TETRA
@ CELL_SHAPE_TETRA
Definition: CellShape.h:46
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
vtkm::rendering::Triangulator::TriangulateStructured::ExecutionSignature
void(IncidentElementIndices, _2, _3) ExecutionSignature
Definition: Triangulator.h:88
vtkm::rendering::Triangulator::UniqueTriangles::IsTwin
VTKM_EXEC bool IsTwin(const vtkm::Id4 &a, const vtkm::Id4 &b) const
Definition: Triangulator.h:250
vtkm::cont::Algorithm::CopyIf
static VTKM_CONT void CopyIf(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< U, CStencil > &stencil, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:435
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::WorkletMapField::FieldInOut
A control signature tag for input-output (in-place) fields.
Definition: WorkletMapField.h:71
vtkm::rendering::Triangulator::Triangulate::ExecutionSignature
void(_2, CellShape, PointIndices, WorkIndex, _3) ExecutionSignature
Definition: Triangulator.h:278
vtkm::rendering::Triangulator::Triangulate::operator()
VTKM_EXEC void operator()(const vtkm::Id &triangleOffset, vtkm::CellShapeTagHexahedron vtkmNotUsed(shapeType), const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Triangulator.h:351
vtkm::CELL_SHAPE_HEXAHEDRON
@ CELL_SHAPE_HEXAHEDRON
Definition: CellShape.h:48
vtkm::rendering::Triangulator::Triangulate::operator()
VTKM_EXEC void operator()(const vtkm::Id &triangleOffset, vtkm::CellShapeTagWedge vtkmNotUsed(shapeType), const VecType &cellIndices, const vtkm::Id &cellId, OutputPortal &outputIndices) const
Definition: Triangulator.h:281
vtkm::rendering::Triangulator::UniqueTriangles::ExecutionSignature
void(_1, _2, WorkIndex) ExecutionSignature
Definition: Triangulator.h:247
vtkm::rendering::Triangulator::Triangulate::Triangulate
VTKM_CONT Triangulate()
Definition: Triangulator.h:276
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
vtkm::rendering::Triangulator::Triangulate
Definition: Triangulator.h:271
vtkmNotUsed
#define vtkmNotUsed(parameter_name)
Simple macro to identify a parameter as unused.
Definition: ExportMacros.h:128
vtkm::CELL_SHAPE_TRIANGLE
@ CELL_SHAPE_TRIANGLE
Definition: CellShape.h:41
CellSetPermutation.h
vtkm::rendering::Triangulator
Triangulator creates a minimal set of triangles from a cell set.
Definition: Triangulator.h:34
vtkm::rendering::Triangulator::CountTriangles::CountTriangles
VTKM_CONT CountTriangles()
Definition: Triangulator.h:41
vtkm::Vec< vtkm::Id, 4 >
vtkm::rendering::Triangulator::Triangulate::ControlSignature
void(CellSetIn cellset, FieldInCell, WholeArrayOut) ControlSignature
Definition: Triangulator.h:277
vtkm::CellShapeTagGeneric::Id
vtkm::UInt8 Id
Definition: CellShape.h:160
vtkm::rendering::Triangulator::CountTriangles::operator()
VTKM_EXEC void operator()(vtkm::CellShapeTagWedge vtkmNotUsed(shapeType), vtkm::Id &triangles) const
Definition: Triangulator.h:76
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
vtkm::rendering::Triangulator::IndicesSort
Definition: Triangulator.h:187
ArrayHandleCounting.h
vtkm::rendering::Triangulator::CountTriangles::ControlSignature
void(CellSetIn cellset, FieldOut) ControlSignature
Definition: Triangulator.h:42
vtkm::rendering::Triangulator::IndicesLessThan
Definition: Triangulator.h:221
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::Triangulator::CountTriangles
Definition: Triangulator.h:37
vtkm::rendering::Triangulator::IndicesLessThan::operator()
VTKM_EXEC_CONT bool operator()(const vtkm::Id4 &a, const vtkm::Id4 &b) const
Definition: Triangulator.h:224
DispatcherMapTopology.h
WorkletMapTopology.h
vtkm::rendering::Triangulator::UniqueTriangles::UniqueTriangles
VTKM_CONT UniqueTriangles()
Definition: Triangulator.h:244
vtkm::rendering::Triangulator::ExternalTriangles
VTKM_CONT void ExternalTriangles(vtkm::cont::ArrayHandle< vtkm::Id4 > &outputIndices, vtkm::Id &outputTriangles)
Definition: Triangulator.h:621
vtkm::rendering::Triangulator::IndicesSort::operator()
VTKM_EXEC void operator()(vtkm::Id4 &triangleIndices) const
Definition: Triangulator.h:195
vtkm::rendering::Triangulator::IndicesSort::IndicesSort
VTKM_CONT IndicesSort()
Definition: Triangulator.h:191
DataSet.h
vtkm::rendering::Triangulator::UniqueTriangles::ControlSignature
void(WholeArrayIn, WholeArrayOut) ControlSignature
Definition: Triangulator.h:246
vtkm::worklet::WorkletVisitCellsWithPoints::FieldInCell
FieldInVisit FieldInCell
Definition: WorkletMapTopology.h:261
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
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