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