10 #ifndef vtk_m_cont_CellSetPermutation_h
11 #define vtk_m_cont_CellSetPermutation_h
31 #ifndef VTKM_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG
32 #define VTKM_DEFAULT_CELLSET_PERMUTATION_STORAGE_TAG VTKM_DEFAULT_STORAGE_TAG
48 class RConnTableHelpers
53 using ControlSignature = void(CellSetIn cellset, FieldOutCell numIndices);
54 using ExecutionSignature = void(PointCount, _2);
55 using InputDomain = _1;
59 numIndices = pointCount;
65 using ControlSignature = void(CellSetIn cellset, FieldOutCell connectivity);
66 using ExecutionSignature = void(PointCount, PointIndices, _2);
67 using InputDomain = _1;
69 template <
typename Po
intIndicesType,
typename OutConnectivityType>
71 const PointIndicesType& pointIndices,
72 OutConnectivityType& connectivity)
const
76 connectivity[i] = pointIndices[i];
82 template <
typename CellSetPermutationType>
84 const CellSetPermutationType& cs,
92 template <
typename NumIndicesStorageType>
98 return vtkm::cont::internal::ConvertNumComponentsToOffsetsTemplate(numIndices,
102 template <
typename CellSetPermutationType,
typename OffsetsStorageType>
104 const CellSetPermutationType& cs,
110 connectivity.
Allocate(connectivityLength);
119 template <
typename ConnectivityStorageTag = VTKM_DEFAULT_STORAGE_TAG,
120 typename OffsetsStorageTag = VTKM_DEFAULT_STORAGE_TAG,
121 typename NumIndicesStorageTag = VTKM_DEFAULT_STORAGE_TAG>
122 struct RConnBuilderInputData
128 ConnectivityArrayType Connectivity;
129 OffsetsArrayType Offsets;
130 NumIndicesArrayType NumIndices;
134 template <
typename CellSetPermutationType>
135 class RConnBuilderInput
138 using ConnectivityArrays = vtkm::cont::internal::RConnBuilderInputData<>;
140 static ConnectivityArrays
Get(
const CellSetPermutationType& cellset,
143 using Helper = RConnTableHelpers;
144 ConnectivityArrays conn;
147 conn.NumIndices = Helper::GetNumIndicesArray(cellset, device);
148 conn.Offsets = Helper::GetOffsetsArray(conn.NumIndices, connectivityLength, device);
150 Helper::GetConnectivityArray(cellset, conn.Offsets, connectivityLength, device);
157 template <
typename InShapesST,
159 typename InOffsetsST,
160 typename PermutationArrayHandleType>
161 class RConnBuilderInput<CellSetPermutation<CellSetExplicit<InShapesST, InConnST, InOffsetsST>,
162 PermutationArrayHandleType>>
165 using BaseCellSetType = CellSetExplicit<InShapesST, InConnST, InOffsetsST>;
166 using CellSetPermutationType = CellSetPermutation<BaseCellSetType, PermutationArrayHandleType>;
168 using InShapesArrayType =
typename BaseCellSetType::ShapesArrayType;
169 using InNumIndicesArrayType =
typename BaseCellSetType::NumIndicesArrayType;
173 using NumIndicesStorageTag =
175 InNumIndicesArrayType>::StorageTag;
179 using ConnectivityArrays = vtkm::cont::internal::
180 RConnBuilderInputData<ConnectivityStorageTag, OffsetsStorageTag, NumIndicesStorageTag>;
182 static ConnectivityArrays
Get(
const CellSetPermutationType& cellset,
185 using Helper = RConnTableHelpers;
190 auto fullCellSet = cellset.GetFullCellSet();
193 ConnectivityArrays conn;
195 fullCellSet.GetOffsetsArray(cell, point);
200 cellset.GetValidCellIds(), fullCellSet.GetNumIndicesArray(cell, point));
204 conn.Offsets = Helper::GetOffsetsArray(conn.NumIndices, connectivityLength, device);
211 Helper::GetConnectivityArray(cellset, conn.Offsets, connectivityLength, device);
218 template <vtkm::IdComponent DIMENSION,
typename PermutationArrayHandleType>
219 class RConnBuilderInput<
220 CellSetPermutation<CellSetStructured<DIMENSION>, PermutationArrayHandleType>>
223 using CellSetPermutationType =
224 CellSetPermutation<CellSetStructured<DIMENSION>, PermutationArrayHandleType>;
227 using ConnectivityArrays = vtkm::cont::internal::RConnBuilderInputData<
228 VTKM_DEFAULT_STORAGE_TAG,
232 static ConnectivityArrays
Get(
const CellSetPermutationType& cellset,
235 vtkm::Id numberOfCells = cellset.GetNumberOfCells();
237 vtkm::internal::ConnectivityStructuredInternals<DIMENSION>::NUM_POINTS_IN_CELL;
238 vtkm::Id connectivityLength = numberOfCells * numPointsInCell;
240 ConnectivityArrays conn;
242 conn.Offsets = ArrayHandleCounting<vtkm::Id>(0, numPointsInCell, numberOfCells + 1);
244 RConnTableHelpers::GetConnectivityArray(cellset, conn.Offsets, connectivityLength, device);
250 template <
typename CellSetPermutationType>
251 struct CellSetPermutationTraits;
253 template <
typename OriginalCellSet_,
typename PermutationArrayHandleType_>
254 struct CellSetPermutationTraits<CellSetPermutation<OriginalCellSet_, PermutationArrayHandleType_>>
256 using OriginalCellSet = OriginalCellSet_;
257 using PermutationArrayHandleType = PermutationArrayHandleType_;
260 template <
typename OriginalCellSet_,
261 typename OriginalPermutationArrayHandleType,
262 typename PermutationArrayHandleType_>
263 struct CellSetPermutationTraits<
264 CellSetPermutation<CellSetPermutation<OriginalCellSet_, OriginalPermutationArrayHandleType>,
265 PermutationArrayHandleType_>>
267 using PreviousCellSet = CellSetPermutation<OriginalCellSet_, OriginalPermutationArrayHandleType>;
269 PermutationArrayHandleType_,
270 typename CellSetPermutationTraits<PreviousCellSet>::PermutationArrayHandleType>;
271 using OriginalCellSet =
typename CellSetPermutationTraits<PreviousCellSet>::OriginalCellSet;
272 using Superclass = CellSetPermutation<OriginalCellSet, PermutationArrayHandleType>;
275 template <
typename VisitTopology,
276 typename IncidentTopology,
277 typename OriginalCellSetType,
278 typename PermutationArrayHandleType>
279 struct CellSetPermutationConnectivityChooser;
281 template <
typename OriginalCellSetType,
typename PermutationArrayHandleType>
282 struct CellSetPermutationConnectivityChooser<
vtkm::TopologyElementTagCell,
285 PermutationArrayHandleType>
287 using ExecPortalType =
typename PermutationArrayHandleType::ReadPortalType;
288 using OrigExecObjectType =
292 using ExecConnectivityType =
296 template <
typename OriginalCellSetType,
typename PermutationArrayHandleType>
297 struct CellSetPermutationConnectivityChooser<
vtkm::TopologyElementTagPoint,
300 PermutationArrayHandleType>
306 using ExecConnectivityType =
312 template <
typename OriginalCellSetType_,
313 typename PermutationArrayHandleType_ =
315 class CellSetPermutation :
public CellSet
320 (std::is_same<vtkm::Id, typename PermutationArrayHandleType_::ValueType>::value),
321 "Must use ArrayHandle with value type of Id for permutation array.");
396 "Calling GetCellShape(cellid) is a performance bug. Call ShapesReadPortal() "
397 "and loop over the Get.")
412 std::shared_ptr<CellSet> NewInstance()
const override
414 return std::make_shared<CellSetPermutation>();
417 void DeepCopy(
const CellSet* src)
override
425 this->
FullCellSet.DeepCopy(&(other->GetFullCellSet()));
448 template <
typename VisitTopology,
typename Inc
identTopology>
461 using ConnectivityType =
463 return ConnectivityType(
465 this->FullCellSet.PrepareForInput(device, visitTopology, incidentTopology, token));
468 VTKM_CONT ExecConnectivityType<vtkm::TopologyElementTagPoint, vtkm::TopologyElementTagCell>
477 internal::ComputeRConnTable(
481 using ConnectivityType =
484 this->VisitPointsWithCells.Offsets.PrepareForInput(device, token));
490 out <<
"CellSetPermutation of: " << std::endl;
492 out <<
"Permutation Array: " << std::endl;
505 template <
typename CellSetType,
506 typename PermutationArrayHandleType1,
507 typename PermutationArrayHandleType2>
509 PermutationArrayHandleType2>
510 :
public internal::CellSetPermutationTraits<
511 CellSetPermutation<CellSetPermutation<CellSetType, PermutationArrayHandleType1>,
515 using Superclass =
typename internal::CellSetPermutationTraits<CellSetPermutation>::Superclass;
535 void Fill(
const PermutationArrayHandleType2& validCellIds,
544 return std::make_shared<CellSetPermutation>();
548 template <
typename OriginalCellSet,
typename PermutationArrayHandleType>
550 const PermutationArrayHandleType& cellIndexMap,
551 const OriginalCellSet& cellSet)
570 template <
typename CSType,
typename AHVal
idCellIds>
571 struct SerializableTypeString<
vtkm::cont::CellSetPermutation<CSType, AHValidCellIds>>
586 template <
typename CSType,
typename AHVal
idCellIds>
587 struct Serialization<
vtkm::cont::CellSetPermutation<CSType, AHValidCellIds>>
593 static VTKM_CONT void save(BinaryBuffer& bb,
const Type& cs)
595 vtkmdiy::save(bb, cs.GetFullCellSet());
596 vtkmdiy::save(bb, cs.GetValidCellIds());
603 AHValidCellIds validCellIds;
613 #endif //vtk_m_cont_CellSetPermutation_h