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