10 #ifndef vtk_m_rendering_Triangulator_h
11 #define vtk_m_rendering_Triangulator_h
19 #include <vtkm/rendering/raytracing/MeshConnectivityBuilder.h>
75 template <
typename ghostlArrayType>
77 ghostlArrayType& ghostField,
81 if (
int(ghostField) != 0)
99 template <
typename ghostlArrayType>
101 ghostlArrayType& ghostField,
105 if (
int(ghostField) != 0)
111 template <
typename ghostlArrayType>
113 ghostlArrayType& ghostField,
116 if (
int(ghostField) != 0)
122 template <
typename ghostlArrayType>
124 ghostlArrayType& ghostField,
127 if (
int(ghostField) != 0)
144 #if defined(VTKM_MSVC)
145 #pragma warning(push)
146 #pragma warning(disable : 4127) //conditional expression is constant
148 template <
typename CellNodeVecType,
typename OutIndicesPortal>
151 OutIndicesPortal& outputIndices)
const
156 const vtkm::Id triangleOffset = cellIndex * 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);
164 triangle[2] = cellIndices[3];
165 outputIndices.Set(triangleOffset + 1, triangle);
169 const vtkm::Id triangleOffset = cellIndex * 12;
171 triangle[1] = cellIndices[0];
172 triangle[2] = cellIndices[1];
173 triangle[3] = cellIndices[5];
174 triangle[0] = cellIndex;
175 outputIndices.Set(triangleOffset, triangle);
177 triangle[1] = cellIndices[0];
178 triangle[2] = cellIndices[5];
179 triangle[3] = cellIndices[4];
180 outputIndices.Set(triangleOffset + 1, triangle);
182 triangle[1] = cellIndices[1];
183 triangle[2] = cellIndices[2];
184 triangle[3] = cellIndices[6];
185 outputIndices.Set(triangleOffset + 2, triangle);
187 triangle[1] = cellIndices[1];
188 triangle[2] = cellIndices[6];
189 triangle[3] = cellIndices[5];
190 outputIndices.Set(triangleOffset + 3, triangle);
192 triangle[1] = cellIndices[3];
193 triangle[2] = cellIndices[7];
194 triangle[3] = cellIndices[6];
195 outputIndices.Set(triangleOffset + 4, triangle);
197 triangle[1] = cellIndices[3];
198 triangle[2] = cellIndices[6];
199 triangle[3] = cellIndices[2];
200 outputIndices.Set(triangleOffset + 5, triangle);
202 triangle[1] = cellIndices[0];
203 triangle[2] = cellIndices[4];
204 triangle[3] = cellIndices[7];
205 outputIndices.Set(triangleOffset + 6, triangle);
207 triangle[1] = cellIndices[0];
208 triangle[2] = cellIndices[7];
209 triangle[3] = cellIndices[3];
210 outputIndices.Set(triangleOffset + 7, triangle);
212 triangle[1] = cellIndices[0];
213 triangle[2] = cellIndices[3];
214 triangle[3] = cellIndices[2];
215 outputIndices.Set(triangleOffset + 8, triangle);
217 triangle[1] = cellIndices[0];
218 triangle[2] = cellIndices[2];
219 triangle[3] = cellIndices[1];
220 outputIndices.Set(triangleOffset + 9, triangle);
222 triangle[1] = cellIndices[4];
223 triangle[2] = cellIndices[5];
224 triangle[3] = cellIndices[6];
225 outputIndices.Set(triangleOffset + 10, triangle);
227 triangle[1] = cellIndices[4];
228 triangle[2] = cellIndices[6];
229 triangle[3] = cellIndices[7];
230 outputIndices.Set(triangleOffset + 11, triangle);
233 #if defined(VTKM_MSVC)
252 if (triangleIndices[1] > triangleIndices[3])
254 temp = triangleIndices[1];
255 triangleIndices[1] = triangleIndices[3];
256 triangleIndices[3] = temp;
258 if (triangleIndices[1] > triangleIndices[2])
260 temp = triangleIndices[1];
261 triangleIndices[1] = triangleIndices[2];
262 triangleIndices[2] = temp;
264 if (triangleIndices[2] > triangleIndices[3])
266 temp = triangleIndices[2];
267 triangleIndices[2] = triangleIndices[3];
268 triangleIndices[3] = temp;
304 return (a[1] == b[1] && a[2] == b[2] && a[3] == b[3]);
307 template <
typename IndicesPortalType,
typename OutputFlagsPortalType>
309 OutputFlagsPortalType& outputFlags,
315 if (
IsTwin(indices.Get(index), indices.Get(index - 1)))
317 outputFlags.Set(index, 0);
318 outputFlags.Set(index - 1, 0);
332 template <
typename VecType,
typename OutputPortal>
335 const VecType& cellIndices,
337 OutputPortal& outputIndices)
const
341 triangle[1] = cellIndices[0];
342 triangle[2] = cellIndices[1];
343 triangle[3] = cellIndices[2];
344 triangle[0] = cellId;
345 outputIndices.Set(triangleOffset, triangle);
347 triangle[1] = cellIndices[3];
348 triangle[2] = cellIndices[5];
349 triangle[3] = cellIndices[4];
350 outputIndices.Set(triangleOffset + 1, triangle);
352 triangle[1] = cellIndices[3];
353 triangle[2] = cellIndices[0];
354 triangle[3] = cellIndices[2];
355 outputIndices.Set(triangleOffset + 2, triangle);
357 triangle[1] = cellIndices[3];
358 triangle[2] = cellIndices[2];
359 triangle[3] = cellIndices[5];
360 outputIndices.Set(triangleOffset + 3, triangle);
362 triangle[1] = cellIndices[1];
363 triangle[2] = cellIndices[4];
364 triangle[3] = cellIndices[5];
365 outputIndices.Set(triangleOffset + 4, triangle);
367 triangle[1] = cellIndices[1];
368 triangle[2] = cellIndices[5];
369 triangle[3] = cellIndices[2];
370 outputIndices.Set(triangleOffset + 5, triangle);
372 triangle[1] = cellIndices[0];
373 triangle[2] = cellIndices[3];
374 triangle[3] = cellIndices[4];
375 outputIndices.Set(triangleOffset + 6, triangle);
377 triangle[1] = cellIndices[0];
378 triangle[2] = cellIndices[4];
379 triangle[3] = cellIndices[1];
380 outputIndices.Set(triangleOffset + 7, triangle);
382 template <
typename VecType,
typename OutputPortal>
385 const VecType& cellIndices,
387 OutputPortal& outputIndices)
const
392 triangle[1] = cellIndices[0];
393 triangle[2] = cellIndices[1];
394 triangle[3] = cellIndices[2];
395 triangle[0] = cellId;
396 outputIndices.Set(triangleOffset, triangle);
398 triangle[2] = cellIndices[3];
399 outputIndices.Set(triangleOffset + 1, triangle);
402 template <
typename VecType,
typename OutputPortal>
405 const VecType& cellIndices,
407 OutputPortal& outputIndices)
const
411 triangle[1] = cellIndices[0];
412 triangle[2] = cellIndices[1];
413 triangle[3] = cellIndices[5];
414 triangle[0] = cellId;
415 outputIndices.Set(triangleOffset, triangle);
417 triangle[1] = cellIndices[0];
418 triangle[2] = cellIndices[5];
419 triangle[3] = cellIndices[4];
420 outputIndices.Set(triangleOffset + 1, triangle);
422 triangle[1] = cellIndices[1];
423 triangle[2] = cellIndices[2];
424 triangle[3] = cellIndices[6];
425 outputIndices.Set(triangleOffset + 2, triangle);
427 triangle[1] = cellIndices[1];
428 triangle[2] = cellIndices[6];
429 triangle[3] = cellIndices[5];
430 outputIndices.Set(triangleOffset + 3, triangle);
432 triangle[1] = cellIndices[3];
433 triangle[2] = cellIndices[7];
434 triangle[3] = cellIndices[6];
435 outputIndices.Set(triangleOffset + 4, triangle);
437 triangle[1] = cellIndices[3];
438 triangle[2] = cellIndices[6];
439 triangle[3] = cellIndices[2];
440 outputIndices.Set(triangleOffset + 5, triangle);
442 triangle[1] = cellIndices[0];
443 triangle[2] = cellIndices[4];
444 triangle[3] = cellIndices[7];
445 outputIndices.Set(triangleOffset + 6, triangle);
447 triangle[1] = cellIndices[0];
448 triangle[2] = cellIndices[7];
449 triangle[3] = cellIndices[3];
450 outputIndices.Set(triangleOffset + 7, triangle);
452 triangle[1] = cellIndices[0];
453 triangle[2] = cellIndices[3];
454 triangle[3] = cellIndices[2];
455 outputIndices.Set(triangleOffset + 8, triangle);
457 triangle[1] = cellIndices[0];
458 triangle[2] = cellIndices[2];
459 triangle[3] = cellIndices[1];
460 outputIndices.Set(triangleOffset + 9, triangle);
462 triangle[1] = cellIndices[4];
463 triangle[2] = cellIndices[5];
464 triangle[3] = cellIndices[6];
465 outputIndices.Set(triangleOffset + 10, triangle);
467 triangle[1] = cellIndices[4];
468 triangle[2] = cellIndices[6];
469 triangle[3] = cellIndices[7];
470 outputIndices.Set(triangleOffset + 11, triangle);
473 template <
typename VecType,
typename OutputPortal>
476 const VecType& cellIndices,
478 OutputPortal& outputIndices)
const
485 triangle[1] = cellIndices[0];
486 triangle[2] = cellIndices[1];
487 triangle[3] = cellIndices[2];
488 triangle[0] = cellId;
489 outputIndices.Set(triangleOffset, triangle);
494 triangle[1] = cellIndices[0];
495 triangle[2] = cellIndices[1];
496 triangle[3] = cellIndices[2];
497 triangle[0] = cellId;
498 outputIndices.Set(triangleOffset, triangle);
500 triangle[2] = cellIndices[3];
501 outputIndices.Set(triangleOffset + 1, triangle);
505 triangle[1] = cellIndices[0];
506 triangle[2] = cellIndices[3];
507 triangle[3] = cellIndices[1];
508 triangle[0] = cellId;
509 outputIndices.Set(triangleOffset, triangle);
511 triangle[1] = cellIndices[1];
512 triangle[2] = cellIndices[2];
513 triangle[3] = cellIndices[3];
514 outputIndices.Set(triangleOffset + 1, triangle);
516 triangle[1] = cellIndices[0];
517 triangle[2] = cellIndices[2];
518 triangle[3] = cellIndices[3];
519 outputIndices.Set(triangleOffset + 2, triangle);
521 triangle[1] = cellIndices[0];
522 triangle[2] = cellIndices[2];
523 triangle[3] = cellIndices[1];
524 outputIndices.Set(triangleOffset + 3, triangle);
528 triangle[1] = cellIndices[0];
529 triangle[2] = cellIndices[1];
530 triangle[3] = cellIndices[5];
531 triangle[0] = cellId;
532 outputIndices.Set(triangleOffset, triangle);
534 triangle[1] = cellIndices[0];
535 triangle[2] = cellIndices[5];
536 triangle[3] = cellIndices[4];
537 outputIndices.Set(triangleOffset + 1, triangle);
539 triangle[1] = cellIndices[1];
540 triangle[2] = cellIndices[2];
541 triangle[3] = cellIndices[6];
542 outputIndices.Set(triangleOffset + 2, triangle);
544 triangle[1] = cellIndices[1];
545 triangle[2] = cellIndices[6];
546 triangle[3] = cellIndices[5];
547 outputIndices.Set(triangleOffset + 3, triangle);
549 triangle[1] = cellIndices[3];
550 triangle[2] = cellIndices[7];
551 triangle[3] = cellIndices[6];
552 outputIndices.Set(triangleOffset + 4, triangle);
554 triangle[1] = cellIndices[3];
555 triangle[2] = cellIndices[6];
556 triangle[3] = cellIndices[2];
557 outputIndices.Set(triangleOffset + 5, triangle);
559 triangle[1] = cellIndices[0];
560 triangle[2] = cellIndices[4];
561 triangle[3] = cellIndices[7];
562 outputIndices.Set(triangleOffset + 6, triangle);
564 triangle[1] = cellIndices[0];
565 triangle[2] = cellIndices[7];
566 triangle[3] = cellIndices[3];
567 outputIndices.Set(triangleOffset + 7, triangle);
569 triangle[1] = cellIndices[0];
570 triangle[2] = cellIndices[3];
571 triangle[3] = cellIndices[2];
572 outputIndices.Set(triangleOffset + 8, triangle);
574 triangle[1] = cellIndices[0];
575 triangle[2] = cellIndices[2];
576 triangle[3] = cellIndices[1];
577 outputIndices.Set(triangleOffset + 9, triangle);
579 triangle[1] = cellIndices[4];
580 triangle[2] = cellIndices[5];
581 triangle[3] = cellIndices[6];
582 outputIndices.Set(triangleOffset + 10, triangle);
584 triangle[1] = cellIndices[4];
585 triangle[2] = cellIndices[6];
586 triangle[3] = cellIndices[7];
587 outputIndices.Set(triangleOffset + 11, triangle);
591 triangle[1] = cellIndices[0];
592 triangle[2] = cellIndices[1];
593 triangle[3] = cellIndices[2];
594 triangle[0] = cellId;
595 outputIndices.Set(triangleOffset, triangle);
597 triangle[1] = cellIndices[3];
598 triangle[2] = cellIndices[5];
599 triangle[3] = cellIndices[4];
600 outputIndices.Set(triangleOffset + 1, triangle);
602 triangle[1] = cellIndices[3];
603 triangle[2] = cellIndices[0];
604 triangle[3] = cellIndices[2];
605 outputIndices.Set(triangleOffset + 2, triangle);
607 triangle[1] = cellIndices[3];
608 triangle[2] = cellIndices[2];
609 triangle[3] = cellIndices[5];
610 outputIndices.Set(triangleOffset + 3, triangle);
612 triangle[1] = cellIndices[1];
613 triangle[2] = cellIndices[4];
614 triangle[3] = cellIndices[5];
615 outputIndices.Set(triangleOffset + 4, triangle);
617 triangle[1] = cellIndices[1];
618 triangle[2] = cellIndices[5];
619 triangle[3] = cellIndices[2];
620 outputIndices.Set(triangleOffset + 5, triangle);
622 triangle[1] = cellIndices[0];
623 triangle[2] = cellIndices[3];
624 triangle[3] = cellIndices[4];
625 outputIndices.Set(triangleOffset + 6, triangle);
627 triangle[1] = cellIndices[0];
628 triangle[2] = cellIndices[4];
629 triangle[3] = cellIndices[1];
630 outputIndices.Set(triangleOffset + 7, triangle);
634 triangle[1] = cellIndices[0];
635 triangle[2] = cellIndices[4];
636 triangle[3] = cellIndices[1];
637 triangle[0] = cellId;
638 outputIndices.Set(triangleOffset, triangle);
640 triangle[1] = cellIndices[1];
641 triangle[2] = cellIndices[2];
642 triangle[3] = cellIndices[4];
643 outputIndices.Set(triangleOffset + 1, triangle);
645 triangle[1] = cellIndices[2];
646 triangle[2] = cellIndices[3];
647 triangle[3] = cellIndices[4];
648 outputIndices.Set(triangleOffset + 2, triangle);
650 triangle[1] = cellIndices[0];
651 triangle[2] = cellIndices[4];
652 triangle[3] = cellIndices[3];
653 outputIndices.Set(triangleOffset + 3, triangle);
655 triangle[1] = cellIndices[3];
656 triangle[2] = cellIndices[2];
657 triangle[3] = cellIndices[1];
658 outputIndices.Set(triangleOffset + 4, triangle);
660 triangle[1] = cellIndices[3];
661 triangle[2] = cellIndices[1];
662 triangle[3] = cellIndices[0];
663 outputIndices.Set(triangleOffset + 5, triangle);
678 sortInvoker.Invoke(outputIndices);
691 outputIndices = subset;
701 bool fastPath =
false;
716 outputIndices.
Allocate(numCells * 12);
718 .Invoke(cellSetStructured3D, cellIdxs, outputIndices);
720 outputTriangles = numCells * 12;
726 .Invoke(ghostField.GetData().ExtractComponent<
vtkm::UInt8>(0), triangleGhostArrayHandle);
731 outputIndices = nonGhostTriangles;
740 outputIndices.
Allocate(numCells * 2);
742 .Invoke(cellSetStructured2D, cellIdxs, outputIndices);
744 outputTriangles = numCells * 2;
750 .Invoke(ghostField.GetData().ExtractComponent<
vtkm::UInt8>(0), triangleGhostArrayHandle);
755 outputIndices = nonGhostTriangles;
762 auto cellSetUnstructured =
767 .Invoke(cellSetUnstructured,
768 ghostField.GetData().ExtractComponent<
vtkm::UInt8>(0),
776 outputIndices.
Allocate(totalTriangles);
779 .Invoke(cellSetUnstructured, cellOffsets, outputIndices);
781 outputTriangles = totalTriangles;
793 #endif //vtk_m_rendering_Triangulator_h