VTK  9.7.20261025
vtkPolyhedronCellArray.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
98
99#ifndef vtkPolyhedronCellArray_h
100#define vtkPolyhedronCellArray_h
101
102#include "vtkCommonDataModelModule.h" // For export macro
103#include "vtkObject.h"
104
105#include "vtkCellArray.h" // Needed for inline methods
106#include "vtkIdList.h" // Needed for inline methods
107#include "vtkSmartPointer.h" // For vtkSmartPointer
108#include "vtkWrappingHints.h" // For VTK_EXPECTS, VTK_MARSHALMANUAL, VTK_WRAPEXCLUDE
109
110#include <type_traits> // Needed for std::is_base_of_v
111#include <utility> // Needed for std::forward
112
113VTK_ABI_NAMESPACE_BEGIN
114class vtkIdTypeArray;
115
116class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkPolyhedronCellArray : public vtkObject
117{
118public:
125
127
132 void PrintSelf(ostream& os, vtkIndent indent) override;
134
140 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxFacesPerCell, vtkIdType maxFacePoints);
141
146
150 void Reset();
151
155 void Squeeze();
156
161 unsigned long GetActualMemorySize() const;
162
168
174
179 void SetData(vtkCellArray* faces, vtkCellArray* faceLocations);
180
182
187 vtkCellArray* GetFaces() const { return this->Faces; }
188 vtkCellArray* GetFaceLocations() const { return this->FaceLocations; }
190
195
197
200 vtkIdType GetNumberOfCells() const { return this->FaceLocations->GetNumberOfCells(); }
201 vtkIdType GetNumberOfFaces() const { return this->Faces->GetNumberOfCells(); }
203
207 int GetMaxCellNumberOfFaces() const { return this->FaceLocations->GetMaxCellSize(); }
208
212 int GetMaxFaceSize() const { return this->Faces->GetMaxCellSize(); }
213
219 {
220 const StorageTypes storageType = this->Faces->GetStorageType();
221 return storageType == this->FaceLocations->GetStorageType() ? storageType
222 : StorageTypes::Generic;
223 }
224
229 bool IsStorageShareable() const { return this->Faces->IsStorageShareable(); }
230
232
242
246 int GetCellNumberOfFaces(vtkIdType cellId) const
247 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
248
252 vtkIdType GetFaceId(vtkIdType cellId, int face) const
253 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
254
258 vtkIdType GetFaceSize(vtkIdType cellId, int face) const
259 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
260
266 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
267
275 void GetFacePoints(vtkIdType cellId, int face, vtkIdType& npts,
276 vtkIdType const*& pts VTK_SIZEHINT(npts), vtkIdList* tempIds) const
277 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
278
282 void GetFacePoints(vtkIdType cellId, int face, vtkIdList* pts) const
283 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
284
290 void GetFaceStream(vtkIdType cellId, vtkIdList* faceStream) const
291 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
292
296 void GetCellFaces(vtkIdType cellId, vtkCellArray* faces) const
297 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
298
304
310
317
324
341
343
353 bool ImportLegacyFormat(const vtkIdType* faces, vtkIdType facesLength,
354 const vtkIdType* faceLocations, vtkIdType numberOfCells) VTK_SIZEHINT(faces, facesLength)
355 VTK_SIZEHINT(faceLocations, numberOfCells);
357
359
369 vtkIdTypeArray* faces, vtkIdTypeArray* faceLocations, vtkIdType ptOffset = 0);
370 bool AppendLegacyFormat(const vtkIdType* faces, vtkIdType facesLength,
371 const vtkIdType* faceLocations, vtkIdType numberOfCells, vtkIdType ptOffset = 0)
372 VTK_SIZEHINT(faces, facesLength) VTK_SIZEHINT(faceLocations, numberOfCells);
374
418 template <typename Functor, typename... Args>
419 decltype(auto) Dispatch(Functor&& functor, Args&&... args) const
420 {
421 return this->Dispatch(
422 std::forward<Functor>(functor), this->GetStorageType(), std::forward<Args>(args)...);
423 }
424 template <typename Functor, typename... Args>
425 decltype(auto) Dispatch(Functor&& functor, StorageTypes storageType, Args&&... args) const
426 {
427 vtkCellArray* faces = this->Faces;
428 vtkCellArray* locations = this->FaceLocations;
429 switch (storageType)
430 {
431 case StorageTypes::Int32:
432 return functor(static_cast<AOSArray32*>(faces->GetOffsetsArray()),
433 static_cast<AOSArray32*>(faces->GetConnectivityArray()),
434 static_cast<AOSArray32*>(locations->GetOffsetsArray()),
435 static_cast<AOSArray32*>(locations->GetConnectivityArray()), std::forward<Args>(args)...);
436 case StorageTypes::Int64:
437 return functor(static_cast<AOSArray64*>(faces->GetOffsetsArray()),
438 static_cast<AOSArray64*>(faces->GetConnectivityArray()),
439 static_cast<AOSArray64*>(locations->GetOffsetsArray()),
440 static_cast<AOSArray64*>(locations->GetConnectivityArray()), std::forward<Args>(args)...);
441 case StorageTypes::FixedSizeInt32:
442 return functor(static_cast<AffineArray32*>(faces->GetOffsetsArray()),
443 static_cast<AOSArray32*>(faces->GetConnectivityArray()),
444 static_cast<AffineArray32*>(locations->GetOffsetsArray()),
445 static_cast<AOSArray32*>(locations->GetConnectivityArray()), std::forward<Args>(args)...);
446 case StorageTypes::FixedSizeInt64:
447 return functor(static_cast<AffineArray64*>(faces->GetOffsetsArray()),
448 static_cast<AOSArray64*>(faces->GetConnectivityArray()),
449 static_cast<AffineArray64*>(locations->GetOffsetsArray()),
450 static_cast<AOSArray64*>(locations->GetConnectivityArray()), std::forward<Args>(args)...);
451 case StorageTypes::Generic:
452 default:
453 return functor(faces->GetOffsetsArray(), faces->GetConnectivityArray(),
454 locations->GetOffsetsArray(), locations->GetConnectivityArray(),
455 std::forward<Args>(args)...);
456 }
457 }
458
459protected:
462
463private:
465 void operator=(const vtkPolyhedronCellArray&) = delete;
466
468 vtkSmartPointer<vtkCellArray> FaceLocations;
469};
470VTK_ABI_NAMESPACE_END
471
473{
474VTK_ABI_NAMESPACE_BEGIN
476{
477 template <class FaceOffsetsT, class FaceConnectivityT, class LocationOffsetsT,
478 class LocationConnectivityT>
479 int operator()(FaceOffsetsT*, FaceConnectivityT*, LocationOffsetsT* locationOffsets,
480 LocationConnectivityT*, vtkIdType cellId) const
481 {
482 return static_cast<int>(
483 GetEndOffset(locationOffsets, cellId) - GetBeginOffset(locationOffsets, cellId));
484 }
485};
486
487// The id, in Faces, of the face `face` of the cell cellId.
488template <class LocationOffsetsT, class LocationConnectivityT>
489vtkIdType GetFaceId(LocationOffsetsT* locationOffsets, LocationConnectivityT* locationConnectivity,
490 vtkIdType cellId, int face)
491{
493 return static_cast<vtkIdType>(Utilities::GetRange(
494 locationConnectivity)[Utilities::GetBeginOffset(locationOffsets, cellId) + face]);
495}
496
498{
499 template <class FaceOffsetsT, class FaceConnectivityT, class LocationOffsetsT,
500 class LocationConnectivityT>
501 vtkIdType operator()(FaceOffsetsT*, FaceConnectivityT*, LocationOffsetsT* locationOffsets,
502 LocationConnectivityT* locationConnectivity, vtkIdType cellId, int face) const
503 {
504 return GetFaceId(locationOffsets, locationConnectivity, cellId, face);
505 }
506};
507
509{
510 template <class FaceOffsetsT, class FaceConnectivityT, class LocationOffsetsT,
511 class LocationConnectivityT>
512 vtkIdType operator()(FaceOffsetsT* faceOffsets, FaceConnectivityT*,
513 LocationOffsetsT* locationOffsets, LocationConnectivityT* locationConnectivity,
514 vtkIdType cellId, int face) const
515 {
516 const vtkIdType faceId = GetFaceId(locationOffsets, locationConnectivity, cellId, face);
517 return GetEndOffset(faceOffsets, faceId) - GetBeginOffset(faceOffsets, faceId);
518 }
519};
520
522{
523 // Points pts at the points of the face, copied into tempIds unless they are shared, and returns
524 // their number.
525 template <class FaceOffsetsT, class FaceConnectivityT, class LocationOffsetsT,
526 class LocationConnectivityT>
527 vtkIdType operator()(FaceOffsetsT* faceOffsets, FaceConnectivityT* faceConnectivity,
528 LocationOffsetsT* locationOffsets, LocationConnectivityT* locationConnectivity,
529 vtkIdType cellId, int face, vtkIdType const*& pts, vtkIdList* tempIds) const
530 {
531 const vtkIdType faceId = GetFaceId(locationOffsets, locationConnectivity, cellId, face);
532 const vtkIdType begin = GetBeginOffset(faceOffsets, faceId);
533 const vtkIdType npts = GetEndOffset(faceOffsets, faceId) - begin;
534 if constexpr (std::is_base_of_v<vtkAOSDataArrayTemplate<vtkIdType>, FaceConnectivityT>)
535 {
536 // The points are shared, as by vtkCellArray::GetCellAtId().
537 pts = faceConnectivity->GetPointer(begin);
538 }
539 else
540 {
541 tempIds->SetNumberOfIds(npts);
542 vtkIdType* ids = tempIds->GetPointer(0);
543 const auto facePoints = GetRange(faceConnectivity).begin() + begin;
544 for (vtkIdType i = 0; i < npts; ++i)
545 {
546 ids[i] = static_cast<vtkIdType>(facePoints[i]);
547 }
548 pts = ids;
549 }
550 return npts;
551 }
552};
553VTK_ABI_NAMESPACE_END
554} // namespace vtkPolyhedronCellArray_detail
555
556VTK_ABI_NAMESPACE_BEGIN
557
558//----------------------------------------------------------------------------
563
564//----------------------------------------------------------------------------
566{
567 return this->Dispatch(vtkPolyhedronCellArray_detail::GetFaceIdImpl{}, cellId, face);
568}
569
570//----------------------------------------------------------------------------
572{
573 return this->Dispatch(vtkPolyhedronCellArray_detail::GetFaceSizeImpl{}, cellId, face);
574}
575
576//----------------------------------------------------------------------------
578 vtkIdType cellId, int face, vtkIdType& npts, vtkIdType const*& pts, vtkIdList* tempIds) const
579{
580 npts =
581 this->Dispatch(vtkPolyhedronCellArray_detail::GetFacePointsImpl{}, cellId, face, pts, tempIds);
582}
583
584VTK_ABI_NAMESPACE_END
585#endif // vtkPolyhedronCellArray_h
object to represent cell connectivity
vtkDataArray * GetOffsetsArray() const
Return the array used to store cell offsets.
vtkAOSDataArrayTemplate< vtkTypeInt32 > AOSArray32
vtkAOSDataArrayTemplate< vtkTypeInt64 > AOSArray64
vtkAffineArray< vtkTypeInt64 > AffineArray64
vtkDataArray * GetConnectivityArray() const
Return the array used to store the point ids that define the cells' connectivity.
vtkAffineArray< vtkTypeInt32 > AffineArray32
list of point or cell ids
Definition vtkIdList.h:135
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:259
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:108
int GetMaxCellNumberOfFaces() const
Return the number of faces of the cell with the most faces.
void Initialize()
Free any memory and reset to an empty state.
vtkIdType GetNumberOfCells() const
Get the number of cells, and the number of faces of all the cells.
int GetCellNumberOfFaces(vtkIdType cellId) const
Return the number of faces of the cell cellId.
bool ConvertToSmallestStorage()
Convert the storage of Faces and FaceLocations, see vtkCellArray.
vtkIdType GetCellNumberOfFacePoints(vtkIdType cellId) const
Return the number of points of all the faces of the cell cellId, as listed in its faces: a point of s...
vtkCellArray::AffineArray64 AffineArray64
vtkCellArray::StorageTypes StorageTypes
StorageTypes GetStorageType() const noexcept
Return the storage type of the arrays: the one of Faces and FaceLocations if they have the same,...
vtkIdType InsertEmptyCells(vtkIdType numCells)
Insert numCells cells without face, e.g., the cells of a vtkUnstructuredGrid that are not polyhedral.
void Append(vtkPolyhedronCellArray *source, vtkIdType pointOffset=0)
Append the cells of source into this, as vtkCellArray::Append(): the point ids of its faces are offse...
bool IsStorageShareable() const
Return true if the points of the faces are stored as vtkIdType, so that GetFacePoints() returns a poi...
bool ConvertTo64BitStorage()
Convert the storage of Faces and FaceLocations, see vtkCellArray.
void Reset()
Reuse the list without freeing memory.
void DeepCopy(vtkPolyhedronCellArray *other)
Perform a deep copy (no reference counting) of the given polyhedron cell array.
decltype(auto) Dispatch(Functor &&functor, StorageTypes storageType, Args &&... args) const
~vtkPolyhedronCellArray() override
bool ImportLegacyFormat(const vtkIdType *faces, vtkIdType facesLength, const vtkIdType *faceLocations, vtkIdType numberOfCells)
Import arrays of data with the legacy layout of the faces of the cells, see ExportLegacyFormat(): fac...
void GetFaceStream(vtkIdType cellId, vtkIdList *faceStream) const
Copy the faces of the cell cellId into faceStream, as a face stream preceded by the number of faces: ...
bool AppendLegacyFormat(vtkIdTypeArray *faces, vtkIdTypeArray *faceLocations, vtkIdType ptOffset=0)
Append arrays of data with the legacy layout of the faces of the cells, see ExportLegacyFormat() and ...
VTK_WRAPEXCLUDE vtkIdType InsertNextCell(vtkIdType numFaces, const vtkIdType *faceStream)
Insert a cell given by its numFaces faces, as a face stream: (numFace0Pts, id1, id2,...
bool ImportLegacyFormat(vtkIdTypeArray *faces, vtkIdTypeArray *faceLocations)
Import arrays of data with the legacy layout of the faces of the cells, see ExportLegacyFormat(): fac...
void GetFacePoints(vtkIdType cellId, int face, vtkIdType &npts, vtkIdType const *&pts, vtkIdList *tempIds) const
Return the npts point ids pts of the face face of the cell cellId, as vtkCellArray::GetCellAtId(): pt...
int GetMaxFaceSize() const
Return the size of the largest face, i.e., its number of points.
vtkCellArray * GetFaces() const
Return the vtkCellArray of the faces, whose cells are the point ids of the faces, and the vtkCellArra...
vtkIdType InsertNextCell(vtkCellArray *faces)
Insert a cell given by its faces, one cell of faces per face.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxFacesPerCell, vtkIdType maxFacePoints)
Pre-allocate memory to store numCells cells of at most maxFacesPerCell faces of at most maxFacePoints...
vtkIdType GetNumberOfFaces() const
Get the number of cells, and the number of faces of all the cells.
vtkCellArray::AOSArray32 AOSArray32
static vtkPolyhedronCellArray * New()
Standard methods for instantiation, type information, and printing.
void GetFacePoints(vtkIdType cellId, int face, vtkIdList *pts) const
Copy the point ids of the face face of the cell cellId into pts.
bool ConvertToDefaultStorage()
Convert the storage of Faces and FaceLocations, see vtkCellArray.
vtkCellArray::AOSArray64 AOSArray64
bool ConvertTo32BitStorage()
Convert the storage of Faces and FaceLocations, see vtkCellArray.
bool AppendLegacyFormat(const vtkIdType *faces, vtkIdType facesLength, const vtkIdType *faceLocations, vtkIdType numberOfCells, vtkIdType ptOffset=0)
Append arrays of data with the legacy layout of the faces of the cells, see ExportLegacyFormat() and ...
void SetData(vtkCellArray *faces, vtkCellArray *faceLocations)
Set the internal data arrays to the supplied faces and face locations, which are referenced,...
void GetCellFaces(vtkIdType cellId, vtkCellArray *faces) const
Copy the faces of the cell cellId into faces, one cell per face.
vtkCellArray * GetFaceLocations() const
Return the vtkCellArray of the faces, whose cells are the point ids of the faces, and the vtkCellArra...
unsigned long GetActualMemorySize() const
Return the size, in kibibytes (1024 bytes), of the memory used by this object.
vtkMTimeType GetMTime() override
Return the modification time of this object and of its arrays.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
decltype(auto) Dispatch(Functor &&functor, Args &&... args) const
vtkCellArray::DispatchUtilities DispatchUtilities
vtkIdType GetFaceId(vtkIdType cellId, int face) const
Return the id, in Faces, of the face face of the cell cellId.
void Squeeze()
Reclaim any extra memory while preserving data.
void ShallowCopy(vtkPolyhedronCellArray *other)
Shallow copy the given polyhedron cell array: its Faces and FaceLocations are shared.
void ExportLegacyFormat(vtkIdTypeArray *faces, vtkIdTypeArray *faceLocations)
Fill faces and faceLocations with the legacy layout of the faces of the cells, the two vtkIdTypeArray...
vtkCellArray::AffineArray32 AffineArray32
vtkIdType GetFaceSize(vtkIdType cellId, int face) const
Return the number of points of the face face of the cell cellId.
Hold a reference to a vtkObjectBase instance.
vtkIdType GetFaceId(LocationOffsetsT *locationOffsets, LocationConnectivityT *locationConnectivity, vtkIdType cellId, int face)
static vtkIdType GetEndOffset(OffsetsT *offsets, vtkIdType cellId)
static vtkIdType GetBeginOffset(OffsetsT *offsets, vtkIdType cellId)
static decltype(vtk::DataArrayValueRange< 1, vtkIdType >(std::declval< ArrayT >())) GetRange(ArrayT *array)
int operator()(FaceOffsetsT *, FaceConnectivityT *, LocationOffsetsT *locationOffsets, LocationConnectivityT *, vtkIdType cellId) const
vtkIdType operator()(FaceOffsetsT *, FaceConnectivityT *, LocationOffsetsT *locationOffsets, LocationConnectivityT *locationConnectivity, vtkIdType cellId, int face) const
vtkIdType operator()(FaceOffsetsT *faceOffsets, FaceConnectivityT *faceConnectivity, LocationOffsetsT *locationOffsets, LocationConnectivityT *locationConnectivity, vtkIdType cellId, int face, vtkIdType const *&pts, vtkIdList *tempIds) const
vtkIdType operator()(FaceOffsetsT *faceOffsets, FaceConnectivityT *, LocationOffsetsT *locationOffsets, LocationConnectivityT *locationConnectivity, vtkIdType cellId, int face) const
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition vtkType.h:363
vtkTypeUInt32 vtkMTimeType
Definition vtkType.h:318
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_WRAPEXCLUDE