11 #ifndef vtk_m_internal_ConnectivityStructuredInternals_h
12 #define vtk_m_internal_ConnectivityStructuredInternals_h
27 template <vtkm::IdComponent>
28 class ConnectivityStructuredInternals;
32 class ConnectivityStructuredInternals<1>
35 using SchedulingRangeType =
vtkm::Id;
38 void SetPointDimensions(
vtkm::Id dimensions) { this->PointDimensions = dimensions; }
41 void SetGlobalPointDimensions(
vtkm::Id dimensions) { this->GlobalPointDimensions = dimensions; }
44 void SetGlobalPointIndexStart(
vtkm::Id start) { this->GlobalPointIndexStart = start; }
47 vtkm::Id GetPointDimensions()
const {
return this->PointDimensions; }
50 vtkm::Id GetGlobalPointDimensions()
const {
return this->GlobalPointDimensions; }
53 vtkm::Id GetCellDimensions()
const {
return this->PointDimensions - 1; }
56 vtkm::Id GetGlobalCellDimensions()
const {
return this->GlobalPointDimensions - 1; }
61 return this->GetNumberOfCells();
67 return this->GetNumberOfPoints();
71 SchedulingRangeType GetGlobalPointIndexStart()
const {
return this->GlobalPointIndexStart; }
77 vtkm::Id GetNumberOfPoints()
const {
return this->PointDimensions; }
79 vtkm::Id GetNumberOfCells()
const {
return this->PointDimensions - 1; }
85 using CellShapeTag = vtkm::CellShapeTagLine;
94 pointIds[1] = pointIds[0] + 1;
103 if ((pointIndex > 0) && (pointIndex < this->PointDimensions - 1))
123 cellIds.
Append(index - 1);
125 if (index < this->PointDimensions - 1)
135 vtkm::Id FlatToLogicalPointIndex(
vtkm::Id flatPointIndex)
const {
return flatPointIndex; }
138 vtkm::Id LogicalToFlatPointIndex(
vtkm::Id logicalPointIndex)
const {
return logicalPointIndex; }
141 vtkm::Id FlatToLogicalCellIndex(
vtkm::Id flatCellIndex)
const {
return flatCellIndex; }
144 vtkm::Id LogicalToFlatCellIndex(
vtkm::Id logicalCellIndex)
const {
return logicalCellIndex; }
147 void PrintSummary(std::ostream& out)
const
149 out <<
" UniformConnectivity<1> ";
150 out <<
"PointDimensions[" << this->PointDimensions <<
"] ";
151 out <<
"GlobalPointDimensions[" << this->GlobalPointDimensions <<
"] ";
152 out <<
"GlobalPointIndexStart[" << this->GlobalPointIndexStart <<
"] ";
164 class ConnectivityStructuredInternals<2>
170 void SetPointDimensions(
vtkm::Id2 dims) { this->PointDimensions = dims; }
173 void SetGlobalPointDimensions(
vtkm::Id2 dims) { this->GlobalPointDimensions = dims; }
176 void SetGlobalPointIndexStart(
vtkm::Id2 start) { this->GlobalPointIndexStart = start; }
179 const vtkm::Id2& GetPointDimensions()
const {
return this->PointDimensions; }
182 const vtkm::Id2& GetGlobalPointDimensions()
const {
return this->GlobalPointDimensions; }
188 vtkm::Id2 GetGlobalCellDimensions()
const {
return this->GlobalPointDimensions -
vtkm::Id2(1); }
197 return this->GetCellDimensions();
202 return this->GetPointDimensions();
206 const vtkm::Id2& GetGlobalPointIndexStart()
const {
return this->GlobalPointIndexStart; }
218 using CellShapeTag = vtkm::CellShapeTagQuad;
222 const SchedulingRangeType& logicalCellIndex)
const
225 pointIds[0] = this->LogicalToFlatPointIndex(logicalCellIndex);
226 pointIds[1] = pointIds[0] + 1;
227 pointIds[2] = pointIds[1] + this->PointDimensions[0];
228 pointIds[3] = pointIds[2] - 1;
235 return this->GetPointsOfCell(this->FlatToLogicalCellIndex(cellIndex));
244 if ((ij[dim] > 0) && (ij[dim] < this->PointDimensions[dim] - 1))
256 return this->GetNumberOfCellsOnPoint(this->FlatToLogicalPointIndex(pointIndex));
261 const SchedulingRangeType& ij)
const
265 if ((ij[0] > 0) && (ij[1] > 0))
269 if ((ij[0] < this->PointDimensions[0] - 1) && (ij[1] > 0))
273 if ((ij[0] > 0) && (ij[1] < this->PointDimensions[1] - 1))
277 if ((ij[0] < this->PointDimensions[0] - 1) && (ij[1] < this->PointDimensions[1] - 1))
279 cellIds.
Append(this->LogicalToFlatCellIndex(ij));
288 return this->GetCellsOfPoint(this->FlatToLogicalPointIndex(pointIndex));
295 logicalPointIndex[0] = flatPointIndex % this->PointDimensions[0];
296 logicalPointIndex[1] = flatPointIndex / this->PointDimensions[0];
297 return logicalPointIndex;
303 return logicalPointIndex[0] + this->PointDimensions[0] * logicalPointIndex[1];
309 vtkm::Id2 cellDimensions = this->GetCellDimensions();
311 logicalCellIndex[0] = flatCellIndex % cellDimensions[0];
312 logicalCellIndex[1] = flatCellIndex / cellDimensions[0];
313 return logicalCellIndex;
319 vtkm::Id2 cellDimensions = this->GetCellDimensions();
320 return logicalCellIndex[0] + cellDimensions[0] * logicalCellIndex[1];
324 void PrintSummary(std::ostream& out)
const
326 out <<
" UniformConnectivity<2> ";
327 out <<
"PointDimensions[" << this->PointDimensions[0] <<
" " << this->PointDimensions[1]
329 out <<
"GlobalPointDimensions[" << this->GlobalPointDimensions[0] <<
" "
330 << this->GlobalPointDimensions[1] <<
"] ";
331 out <<
"GlobalPointIndexStart[" << this->GlobalPointIndexStart[0] <<
" "
332 << this->GlobalPointIndexStart[1] <<
"] ";
338 vtkm::Id2 GlobalPointDimensions = { 0, 0 };
339 vtkm::Id2 GlobalPointIndexStart = { 0, 0 };
344 class ConnectivityStructuredInternals<3>
352 this->PointDimensions = dims;
353 this->CellDimensions = dims -
vtkm::Id3(1);
354 this->CellDim01 = (dims[0] - 1) * (dims[1] - 1);
358 void SetGlobalPointDimensions(
vtkm::Id3 dims)
360 this->GlobalPointDimensions = dims;
361 this->GlobalCellDimensions = dims -
vtkm::Id3(1);
365 void SetGlobalPointIndexStart(
vtkm::Id3 start) { this->GlobalPointIndexStart = start; }
368 const vtkm::Id3& GetPointDimensions()
const {
return this->PointDimensions; }
371 const vtkm::Id3& GetGlobalPointDimensions()
const {
return this->GlobalPointDimensions; }
374 const vtkm::Id3& GetCellDimensions()
const {
return this->CellDimensions; }
377 const vtkm::Id3& GetGlobalCellDimensions()
const {
return this->GlobalCellDimensions; }
386 return this->GetCellDimensions();
391 return this->GetPointDimensions();
395 const vtkm::Id3& GetGlobalPointIndexStart()
const {
return this->GlobalPointIndexStart; }
407 using CellShapeTag = vtkm::CellShapeTagHexahedron;
413 pointIds[0] = (ijk[2] * this->PointDimensions[1] + ijk[1]) * this->PointDimensions[0] + ijk[0];
414 pointIds[1] = pointIds[0] + 1;
415 pointIds[2] = pointIds[1] + this->PointDimensions[0];
416 pointIds[3] = pointIds[2] - 1;
417 pointIds[4] = pointIds[0] + this->PointDimensions[0] * this->PointDimensions[1];
418 pointIds[5] = pointIds[4] + 1;
419 pointIds[6] = pointIds[5] + this->PointDimensions[0];
420 pointIds[7] = pointIds[6] - 1;
428 return this->GetPointsOfCell(this->FlatToLogicalCellIndex(cellIndex));
437 if ((ijk[dim] > 0) && (ijk[dim] < this->PointDimensions[dim] - 1))
449 return this->GetNumberOfCellsOnPoint(this->FlatToLogicalPointIndex(pointIndex));
454 const SchedulingRangeType& ijk)
const
458 if ((ijk[0] > 0) && (ijk[1] > 0) && (ijk[2] > 0))
460 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(1, 1, 1)));
462 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] > 0) && (ijk[2] > 0))
464 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(0, 1, 1)));
466 if ((ijk[0] > 0) && (ijk[1] < this->PointDimensions[1] - 1) && (ijk[2] > 0))
468 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(1, 0, 1)));
470 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] < this->PointDimensions[1] - 1) &&
473 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(0, 0, 1)));
476 if ((ijk[0] > 0) && (ijk[1] > 0) && (ijk[2] < this->PointDimensions[2] - 1))
478 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(1, 1, 0)));
480 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] > 0) &&
481 (ijk[2] < this->PointDimensions[2] - 1))
483 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(0, 1, 0)));
485 if ((ijk[0] > 0) && (ijk[1] < this->PointDimensions[1] - 1) &&
486 (ijk[2] < this->PointDimensions[2] - 1))
488 cellIds.
Append(this->LogicalToFlatCellIndex(ijk -
vtkm::Id3(1, 0, 0)));
490 if ((ijk[0] < this->PointDimensions[0] - 1) && (ijk[1] < this->PointDimensions[1] - 1) &&
491 (ijk[2] < this->PointDimensions[2] - 1))
493 cellIds.
Append(this->LogicalToFlatCellIndex(ijk));
502 return this->GetCellsOfPoint(this->FlatToLogicalPointIndex(pointIndex));
506 void PrintSummary(std::ostream& out)
const
508 out <<
" UniformConnectivity<3> ";
509 out <<
"PointDimensions[" << this->PointDimensions[0] <<
" " << this->PointDimensions[1] <<
" "
510 << this->PointDimensions[2] <<
"] ";
511 out <<
"GlobalPointDimensions[" << this->GlobalPointDimensions[0] <<
" "
512 << this->GlobalPointDimensions[1] <<
" " << this->GlobalPointDimensions[2] <<
"] ";
513 out <<
"GlobalPointIndexStart[" << this->GlobalPointIndexStart[0] <<
" "
514 << this->GlobalPointIndexStart[1] <<
" " << this->GlobalPointIndexStart[2] <<
"] ";
521 const vtkm::Id pointDims01 = this->PointDimensions[0] * this->PointDimensions[1];
522 const vtkm::Id indexij = flatPointIndex % pointDims01;
524 return vtkm::Id3(indexij % this->PointDimensions[0],
525 indexij / this->PointDimensions[0],
526 flatPointIndex / pointDims01);
532 return logicalPointIndex[0] +
533 this->PointDimensions[0] *
534 (logicalPointIndex[1] + this->PointDimensions[1] * logicalPointIndex[2]);
540 const vtkm::Id indexij = flatCellIndex % this->CellDim01;
541 return vtkm::Id3(indexij % this->CellDimensions[0],
542 indexij / this->CellDimensions[0],
543 flatCellIndex / this->CellDim01);
549 return logicalCellIndex[0] +
550 this->CellDimensions[0] *
551 (logicalCellIndex[1] + this->CellDimensions[1] * logicalCellIndex[2]);
556 vtkm::Id3 GlobalPointDimensions = { 0, 0, 0 };
557 vtkm::Id3 GlobalCellDimensions = { 0, 0, 0 };
558 vtkm::Id3 GlobalPointIndexStart = { 0, 0, 0 };
566 template <
typename VisitTopology,
typename Inc
identTopology, vtkm::IdComponent Dimension>
567 struct ConnectivityStructuredIndexHelper
574 "Missing Specialization for Topologies");
577 template <vtkm::IdComponent Dimension>
578 struct ConnectivityStructuredIndexHelper<
vtkm::TopologyElementTagCell,
582 using ConnectivityType = vtkm::internal::ConnectivityStructuredInternals<Dimension>;
583 using LogicalIndexType =
typename ConnectivityType::SchedulingRangeType;
585 using CellShapeTag =
typename ConnectivityType::CellShapeTag;
591 return connectivity.GetNumberOfCells();
594 template <
typename IndexType>
599 return ConnectivityType::NUM_POINTS_IN_CELL;
602 template <
typename IndexType>
603 VTKM_EXEC_CONT static IndicesType GetIndices(
const ConnectivityType& connectivity,
604 const IndexType& cellIndex)
606 return connectivity.GetPointsOfCell(cellIndex);
610 static LogicalIndexType FlatToLogicalFromIndex(
const ConnectivityType& connectivity,
613 return connectivity.FlatToLogicalPointIndex(flatFromIndex);
617 static vtkm::Id LogicalToFlatFromIndex(
const ConnectivityType& connectivity,
618 const LogicalIndexType& logicalFromIndex)
620 return connectivity.LogicalToFlatPointIndex(logicalFromIndex);
624 static LogicalIndexType FlatToLogicalToIndex(
const ConnectivityType& connectivity,
627 return connectivity.FlatToLogicalCellIndex(flatToIndex);
631 static vtkm::Id LogicalToFlatToIndex(
const ConnectivityType& connectivity,
632 const LogicalIndexType& logicalToIndex)
634 return connectivity.LogicalToFlatCellIndex(logicalToIndex);
638 template <vtkm::IdComponent Dimension>
639 struct ConnectivityStructuredIndexHelper<
vtkm::TopologyElementTagPoint,
643 using ConnectivityType = vtkm::internal::ConnectivityStructuredInternals<Dimension>;
644 using LogicalIndexType =
typename ConnectivityType::SchedulingRangeType;
646 using CellShapeTag = vtkm::CellShapeTagVertex;
652 return connectivity.GetNumberOfPoints();
655 template <
typename IndexType>
657 const IndexType& pointIndex)
659 return connectivity.GetNumberOfCellsOnPoint(pointIndex);
662 template <
typename IndexType>
663 VTKM_EXEC_CONT static IndicesType GetIndices(
const ConnectivityType& connectivity,
664 const IndexType& pointIndex)
666 return connectivity.GetCellsOfPoint(pointIndex);
670 static LogicalIndexType FlatToLogicalFromIndex(
const ConnectivityType& connectivity,
673 return connectivity.FlatToLogicalCellIndex(flatFromIndex);
677 static vtkm::Id LogicalToFlatFromIndex(
const ConnectivityType& connectivity,
678 const LogicalIndexType& logicalFromIndex)
680 return connectivity.LogicalToFlatCellIndex(logicalFromIndex);
684 static LogicalIndexType FlatToLogicalToIndex(
const ConnectivityType& connectivity,
687 return connectivity.FlatToLogicalPointIndex(flatToIndex);
691 static vtkm::Id LogicalToFlatToIndex(
const ConnectivityType& connectivity,
692 const LogicalIndexType& logicalToIndex)
694 return connectivity.LogicalToFlatPointIndex(logicalToIndex);
700 #endif //vtk_m_internal_ConnectivityStructuredInternals_h