10 #ifndef vtk_m_rendering_Triangulator_h
11 #define vtk_m_rendering_Triangulator_h
92 #if defined(VTKM_MSVC)
94 #pragma warning(disable : 4127) //conditional expression is constant
96 template <
typename CellNodeVecType,
typename OutIndicesPortal>
99 OutIndicesPortal& outputIndices)
const
104 const vtkm::Id triangleOffset = cellIndex * 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);
112 triangle[2] = cellIndices[3];
113 outputIndices.Set(triangleOffset + 1, triangle);
117 const vtkm::Id triangleOffset = cellIndex * 12;
119 triangle[1] = cellIndices[0];
120 triangle[2] = cellIndices[1];
121 triangle[3] = cellIndices[5];
122 triangle[0] = cellIndex;
123 outputIndices.Set(triangleOffset, triangle);
125 triangle[1] = cellIndices[0];
126 triangle[2] = cellIndices[5];
127 triangle[3] = cellIndices[4];
128 outputIndices.Set(triangleOffset + 1, triangle);
130 triangle[1] = cellIndices[1];
131 triangle[2] = cellIndices[2];
132 triangle[3] = cellIndices[6];
133 outputIndices.Set(triangleOffset + 2, triangle);
135 triangle[1] = cellIndices[1];
136 triangle[2] = cellIndices[6];
137 triangle[3] = cellIndices[5];
138 outputIndices.Set(triangleOffset + 3, triangle);
140 triangle[1] = cellIndices[3];
141 triangle[2] = cellIndices[7];
142 triangle[3] = cellIndices[6];
143 outputIndices.Set(triangleOffset + 4, triangle);
145 triangle[1] = cellIndices[3];
146 triangle[2] = cellIndices[6];
147 triangle[3] = cellIndices[2];
148 outputIndices.Set(triangleOffset + 5, triangle);
150 triangle[1] = cellIndices[0];
151 triangle[2] = cellIndices[4];
152 triangle[3] = cellIndices[7];
153 outputIndices.Set(triangleOffset + 6, triangle);
155 triangle[1] = cellIndices[0];
156 triangle[2] = cellIndices[7];
157 triangle[3] = cellIndices[3];
158 outputIndices.Set(triangleOffset + 7, triangle);
160 triangle[1] = cellIndices[0];
161 triangle[2] = cellIndices[3];
162 triangle[3] = cellIndices[2];
163 outputIndices.Set(triangleOffset + 8, triangle);
165 triangle[1] = cellIndices[0];
166 triangle[2] = cellIndices[2];
167 triangle[3] = cellIndices[1];
168 outputIndices.Set(triangleOffset + 9, triangle);
170 triangle[1] = cellIndices[4];
171 triangle[2] = cellIndices[5];
172 triangle[3] = cellIndices[6];
173 outputIndices.Set(triangleOffset + 10, triangle);
175 triangle[1] = cellIndices[4];
176 triangle[2] = cellIndices[6];
177 triangle[3] = cellIndices[7];
178 outputIndices.Set(triangleOffset + 11, triangle);
181 #if defined(VTKM_MSVC)
200 if (triangleIndices[1] > triangleIndices[3])
202 temp = triangleIndices[1];
203 triangleIndices[1] = triangleIndices[3];
204 triangleIndices[3] = temp;
206 if (triangleIndices[1] > triangleIndices[2])
208 temp = triangleIndices[1];
209 triangleIndices[1] = triangleIndices[2];
210 triangleIndices[2] = temp;
212 if (triangleIndices[2] > triangleIndices[3])
214 temp = triangleIndices[2];
215 triangleIndices[2] = triangleIndices[3];
216 triangleIndices[3] = temp;
252 return (a[1] == b[1] && a[2] == b[2] && a[3] == b[3]);
255 template <
typename IndicesPortalType,
typename OutputFlagsPortalType>
257 OutputFlagsPortalType& outputFlags,
263 if (
IsTwin(indices.Get(index), indices.Get(index - 1)))
265 outputFlags.Set(index, 0);
266 outputFlags.Set(index - 1, 0);
280 template <
typename VecType,
typename OutputPortal>
283 const VecType& cellIndices,
285 OutputPortal& outputIndices)
const
289 triangle[1] = cellIndices[0];
290 triangle[2] = cellIndices[1];
291 triangle[3] = cellIndices[2];
292 triangle[0] = cellId;
293 outputIndices.Set(triangleOffset, triangle);
295 triangle[1] = cellIndices[3];
296 triangle[2] = cellIndices[5];
297 triangle[3] = cellIndices[4];
298 outputIndices.Set(triangleOffset + 1, triangle);
300 triangle[1] = cellIndices[3];
301 triangle[2] = cellIndices[0];
302 triangle[3] = cellIndices[2];
303 outputIndices.Set(triangleOffset + 2, triangle);
305 triangle[1] = cellIndices[3];
306 triangle[2] = cellIndices[2];
307 triangle[3] = cellIndices[5];
308 outputIndices.Set(triangleOffset + 3, triangle);
310 triangle[1] = cellIndices[1];
311 triangle[2] = cellIndices[4];
312 triangle[3] = cellIndices[5];
313 outputIndices.Set(triangleOffset + 4, triangle);
315 triangle[1] = cellIndices[1];
316 triangle[2] = cellIndices[5];
317 triangle[3] = cellIndices[2];
318 outputIndices.Set(triangleOffset + 5, triangle);
320 triangle[1] = cellIndices[0];
321 triangle[2] = cellIndices[3];
322 triangle[3] = cellIndices[4];
323 outputIndices.Set(triangleOffset + 6, triangle);
325 triangle[1] = cellIndices[0];
326 triangle[2] = cellIndices[4];
327 triangle[3] = cellIndices[1];
328 outputIndices.Set(triangleOffset + 7, triangle);
330 template <
typename VecType,
typename OutputPortal>
333 const VecType& cellIndices,
335 OutputPortal& outputIndices)
const
340 triangle[1] = cellIndices[0];
341 triangle[2] = cellIndices[1];
342 triangle[3] = cellIndices[2];
343 triangle[0] = cellId;
344 outputIndices.Set(triangleOffset, triangle);
346 triangle[2] = cellIndices[3];
347 outputIndices.Set(triangleOffset + 1, triangle);
350 template <
typename VecType,
typename OutputPortal>
352 vtkm::CellShapeTagHexahedron
vtkmNotUsed(shapeType),
353 const VecType& cellIndices,
355 OutputPortal& outputIndices)
const
359 triangle[1] = cellIndices[0];
360 triangle[2] = cellIndices[1];
361 triangle[3] = cellIndices[5];
362 triangle[0] = cellId;
363 outputIndices.Set(triangleOffset, triangle);
365 triangle[1] = cellIndices[0];
366 triangle[2] = cellIndices[5];
367 triangle[3] = cellIndices[4];
368 outputIndices.Set(triangleOffset + 1, triangle);
370 triangle[1] = cellIndices[1];
371 triangle[2] = cellIndices[2];
372 triangle[3] = cellIndices[6];
373 outputIndices.Set(triangleOffset + 2, triangle);
375 triangle[1] = cellIndices[1];
376 triangle[2] = cellIndices[6];
377 triangle[3] = cellIndices[5];
378 outputIndices.Set(triangleOffset + 3, triangle);
380 triangle[1] = cellIndices[3];
381 triangle[2] = cellIndices[7];
382 triangle[3] = cellIndices[6];
383 outputIndices.Set(triangleOffset + 4, triangle);
385 triangle[1] = cellIndices[3];
386 triangle[2] = cellIndices[6];
387 triangle[3] = cellIndices[2];
388 outputIndices.Set(triangleOffset + 5, triangle);
390 triangle[1] = cellIndices[0];
391 triangle[2] = cellIndices[4];
392 triangle[3] = cellIndices[7];
393 outputIndices.Set(triangleOffset + 6, triangle);
395 triangle[1] = cellIndices[0];
396 triangle[2] = cellIndices[7];
397 triangle[3] = cellIndices[3];
398 outputIndices.Set(triangleOffset + 7, triangle);
400 triangle[1] = cellIndices[0];
401 triangle[2] = cellIndices[3];
402 triangle[3] = cellIndices[2];
403 outputIndices.Set(triangleOffset + 8, triangle);
405 triangle[1] = cellIndices[0];
406 triangle[2] = cellIndices[2];
407 triangle[3] = cellIndices[1];
408 outputIndices.Set(triangleOffset + 9, triangle);
410 triangle[1] = cellIndices[4];
411 triangle[2] = cellIndices[5];
412 triangle[3] = cellIndices[6];
413 outputIndices.Set(triangleOffset + 10, triangle);
415 triangle[1] = cellIndices[4];
416 triangle[2] = cellIndices[6];
417 triangle[3] = cellIndices[7];
418 outputIndices.Set(triangleOffset + 11, triangle);
421 template <
typename VecType,
typename OutputPortal>
424 const VecType& cellIndices,
426 OutputPortal& outputIndices)
const
433 triangle[1] = cellIndices[0];
434 triangle[2] = cellIndices[1];
435 triangle[3] = cellIndices[2];
436 triangle[0] = cellId;
437 outputIndices.Set(triangleOffset, triangle);
442 triangle[1] = cellIndices[0];
443 triangle[2] = cellIndices[1];
444 triangle[3] = cellIndices[2];
445 triangle[0] = cellId;
446 outputIndices.Set(triangleOffset, triangle);
448 triangle[2] = cellIndices[3];
449 outputIndices.Set(triangleOffset + 1, triangle);
453 triangle[1] = cellIndices[0];
454 triangle[2] = cellIndices[3];
455 triangle[3] = cellIndices[1];
456 triangle[0] = cellId;
457 outputIndices.Set(triangleOffset, triangle);
459 triangle[1] = cellIndices[1];
460 triangle[2] = cellIndices[2];
461 triangle[3] = cellIndices[3];
462 outputIndices.Set(triangleOffset + 1, triangle);
464 triangle[1] = cellIndices[0];
465 triangle[2] = cellIndices[2];
466 triangle[3] = cellIndices[3];
467 outputIndices.Set(triangleOffset + 2, triangle);
469 triangle[1] = cellIndices[0];
470 triangle[2] = cellIndices[2];
471 triangle[3] = cellIndices[1];
472 outputIndices.Set(triangleOffset + 3, triangle);
476 triangle[1] = cellIndices[0];
477 triangle[2] = cellIndices[1];
478 triangle[3] = cellIndices[5];
479 triangle[0] = cellId;
480 outputIndices.Set(triangleOffset, triangle);
482 triangle[1] = cellIndices[0];
483 triangle[2] = cellIndices[5];
484 triangle[3] = cellIndices[4];
485 outputIndices.Set(triangleOffset + 1, triangle);
487 triangle[1] = cellIndices[1];
488 triangle[2] = cellIndices[2];
489 triangle[3] = cellIndices[6];
490 outputIndices.Set(triangleOffset + 2, triangle);
492 triangle[1] = cellIndices[1];
493 triangle[2] = cellIndices[6];
494 triangle[3] = cellIndices[5];
495 outputIndices.Set(triangleOffset + 3, triangle);
497 triangle[1] = cellIndices[3];
498 triangle[2] = cellIndices[7];
499 triangle[3] = cellIndices[6];
500 outputIndices.Set(triangleOffset + 4, triangle);
502 triangle[1] = cellIndices[3];
503 triangle[2] = cellIndices[6];
504 triangle[3] = cellIndices[2];
505 outputIndices.Set(triangleOffset + 5, triangle);
507 triangle[1] = cellIndices[0];
508 triangle[2] = cellIndices[4];
509 triangle[3] = cellIndices[7];
510 outputIndices.Set(triangleOffset + 6, triangle);
512 triangle[1] = cellIndices[0];
513 triangle[2] = cellIndices[7];
514 triangle[3] = cellIndices[3];
515 outputIndices.Set(triangleOffset + 7, triangle);
517 triangle[1] = cellIndices[0];
518 triangle[2] = cellIndices[3];
519 triangle[3] = cellIndices[2];
520 outputIndices.Set(triangleOffset + 8, triangle);
522 triangle[1] = cellIndices[0];
523 triangle[2] = cellIndices[2];
524 triangle[3] = cellIndices[1];
525 outputIndices.Set(triangleOffset + 9, triangle);
527 triangle[1] = cellIndices[4];
528 triangle[2] = cellIndices[5];
529 triangle[3] = cellIndices[6];
530 outputIndices.Set(triangleOffset + 10, triangle);
532 triangle[1] = cellIndices[4];
533 triangle[2] = cellIndices[6];
534 triangle[3] = cellIndices[7];
535 outputIndices.Set(triangleOffset + 11, triangle);
539 triangle[1] = cellIndices[0];
540 triangle[2] = cellIndices[1];
541 triangle[3] = cellIndices[2];
542 triangle[0] = cellId;
543 outputIndices.Set(triangleOffset, triangle);
545 triangle[1] = cellIndices[3];
546 triangle[2] = cellIndices[5];
547 triangle[3] = cellIndices[4];
548 outputIndices.Set(triangleOffset + 1, triangle);
550 triangle[1] = cellIndices[3];
551 triangle[2] = cellIndices[0];
552 triangle[3] = cellIndices[2];
553 outputIndices.Set(triangleOffset + 2, triangle);
555 triangle[1] = cellIndices[3];
556 triangle[2] = cellIndices[2];
557 triangle[3] = cellIndices[5];
558 outputIndices.Set(triangleOffset + 3, triangle);
560 triangle[1] = cellIndices[1];
561 triangle[2] = cellIndices[4];
562 triangle[3] = cellIndices[5];
563 outputIndices.Set(triangleOffset + 4, triangle);
565 triangle[1] = cellIndices[1];
566 triangle[2] = cellIndices[5];
567 triangle[3] = cellIndices[2];
568 outputIndices.Set(triangleOffset + 5, triangle);
570 triangle[1] = cellIndices[0];
571 triangle[2] = cellIndices[3];
572 triangle[3] = cellIndices[4];
573 outputIndices.Set(triangleOffset + 6, triangle);
575 triangle[1] = cellIndices[0];
576 triangle[2] = cellIndices[4];
577 triangle[3] = cellIndices[1];
578 outputIndices.Set(triangleOffset + 7, triangle);
582 triangle[1] = cellIndices[0];
583 triangle[2] = cellIndices[4];
584 triangle[3] = cellIndices[1];
585 triangle[0] = cellId;
586 outputIndices.Set(triangleOffset, triangle);
588 triangle[1] = cellIndices[1];
589 triangle[2] = cellIndices[2];
590 triangle[3] = cellIndices[4];
591 outputIndices.Set(triangleOffset + 1, triangle);
593 triangle[1] = cellIndices[2];
594 triangle[2] = cellIndices[3];
595 triangle[3] = cellIndices[4];
596 outputIndices.Set(triangleOffset + 2, triangle);
598 triangle[1] = cellIndices[0];
599 triangle[2] = cellIndices[4];
600 triangle[3] = cellIndices[3];
601 outputIndices.Set(triangleOffset + 3, triangle);
603 triangle[1] = cellIndices[3];
604 triangle[2] = cellIndices[2];
605 triangle[3] = cellIndices[1];
606 outputIndices.Set(triangleOffset + 4, triangle);
608 triangle[1] = cellIndices[3];
609 triangle[2] = cellIndices[1];
610 triangle[3] = cellIndices[0];
611 outputIndices.Set(triangleOffset + 5, triangle);
626 sortInvoker.Invoke(outputIndices);
639 outputIndices = subset;
648 bool fastPath =
false;
663 outputIndices.
Allocate(numCells * 12);
665 .Invoke(cellSetStructured3D, cellIdxs, outputIndices);
667 outputTriangles = numCells * 12;
676 outputIndices.
Allocate(numCells * 2);
678 .Invoke(cellSetStructured2D, cellIdxs, outputIndices);
680 outputTriangles = numCells * 2;
686 auto cellSetUnstructured =
690 .Invoke(cellSetUnstructured, trianglesPerCell);
697 outputIndices.
Allocate(totalTriangles);
700 .Invoke(cellSetUnstructured, cellOffsets, outputIndices);
702 outputTriangles = totalTriangles;
714 #endif //vtk_m_rendering_Triangulator_h