243#ifndef vtkCellArray_h
244#define vtkCellArray_h
247#include "vtkCommonDataModelModule.h"
255#include "vtkFeatures.h"
257#include "vtkTypeInt32Array.h"
258#include "vtkTypeInt64Array.h"
262#include <initializer_list>
263#include <type_traits>
286#define VTK_CELL_ARRAY_V2
288VTK_ABI_NAMESPACE_BEGIN
322 return this->
AllocateExact(numCells, numCells * maxCellSize);
414 this->
Offsets->SetComponent(cellId, 0,
static_cast<double>(offset));
546 return std::is_same_v<vtkTypeInt32, vtkIdType>;
549 return std::is_same_v<vtkTypeInt64, vtkIdType>;
666 bool EnsureStorageForCellSize(
vtkIdType cellSize);
831 inline vtkIdType InsertNextCell(
int npts);
843 void UpdateCellCount(
int npts);
985 template <
class ArrayT>
988 template <
class OffsetsT>
991 return offsets->GetNumberOfValues() - 1;
994 template <
class ArrayT>
1001 template <
class OffsetsT>
1007 template <
class OffsetsT>
1013 template <
class OffsetsT>
1016 auto offsetsRange =
GetRange(offsets);
1017 return static_cast<vtkIdType>(offsetsRange[cellId + 1] - offsetsRange[cellId]);
1020 template <
class OffsetsT,
class ConnectivityT>
1024 auto offsetsRange =
GetRange(offsets);
1026 conn, offsetsRange[cellId], offsetsRange[cellId + 1]);
1033 template <
typename Functor,
typename... Args>
1034 using GetDispatchReturnType =
decltype(std::declval<Functor>()(
1035 std::declval<AOSArray32*>(), std::declval<AOSArray32*>(), std::declval<Args>()...));
1037 template <
typename Functor,
typename... Args>
1038 struct DispatchReturnsVoid : std::is_same<GetDispatchReturnType<Functor, Args...>, void>
1112 template <
typename Functor,
typename... Args,
1113 typename =
typename std::enable_if<DispatchReturnsVoid<Functor, Args...>::value>::type>
1120 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1124 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1128 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1132 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1136 functor(this->
Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1140 template <
typename Functor,
typename... Args,
1141 typename =
typename std::enable_if<DispatchReturnsVoid<Functor, Args...>::value>::type>
1148 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1152 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1156 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1160 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1164 functor(this->
Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1168 template <
typename Functor,
typename... Args,
1169 typename =
typename std::enable_if<!DispatchReturnsVoid<Functor, Args...>::value>::type>
1170 GetDispatchReturnType<Functor, Args...>
Dispatch(Functor&& functor, Args&&... args)
1176 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1179 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1182 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1185 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1188 return functor(this->
Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1191 template <
typename Functor,
typename... Args,
1192 typename =
typename std::enable_if<!DispatchReturnsVoid<Functor, Args...>::value>::type>
1193 GetDispatchReturnType<Functor, Args...>
Dispatch(Functor&& functor, Args&&... args)
const
1199 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1202 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1205 static_cast<AOSArray32*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1208 static_cast<AOSArray64*
>(this->Connectivity.Get()), std::forward<Args>(args)...);
1211 return functor(this->
Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1217 template <
typename ArrayT>
1219 "Use Dispatch with a struct that inherits from DispatchUtilities ")
VisitState
1269 this->
Offsets->InsertNextValue(0);
1272 this->IsInMemkind =
true;
1276 void*
operator new(
size_t nSize)
1279#ifdef VTK_USE_MEMKIND
1286 void operator delete(
void* p)
1288#ifdef VTK_USE_MEMKIND
1309 bool IsInMemkind =
false;
1341VTK_ABI_NAMESPACE_END
1345VTK_ABI_NAMESPACE_BEGIN
1350 template <
class OffsetsT,
class ConnectivityT>
1357 OffsetsAccessorType offsetsAccesor(offsets);
1358 ConnectivityAccessorType connAccesor(conn);
1360 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1362 offsetsAccesor.InsertNext(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1366 connAccesor.InsertNext(
static_cast<ValueType
>(pts[i]));
1373 template <
class OffsetsT,
class ConnectivityT>
1378 AccessorType offsetsAccesor(offsets);
1380 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1382 offsetsAccesor.InsertNext(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1391 template <
class OffsetsT,
class ConnectivityT>
1396 auto offsetsRange =
GetRange(offsets);
1397 const ValueType cellBegin = offsetsRange[offsets->GetMaxId() - 1];
1398 offsetsRange[offsets->GetMaxId()] =
static_cast<ValueType
>(cellBegin + npts);
1404 template <
class OffsetsT,
class ConnectivityT>
1413 template <
class OffsetsT,
class ConnectivityT>
1416 auto offsetsRange =
GetRange(offsets);
1417 const auto& beginOffset = offsetsRange[cellId];
1418 const auto& endOffset = offsetsRange[cellId + 1];
1420 const auto cellConnectivity =
GetRange(conn).begin() + beginOffset;
1425 for (
vtkIdType i = 0; i < cellSize; ++i)
1427 idPtr[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1432 template <
class OffsetsT,
class ConnectivityT>
1434 OffsetsT* offsets, ConnectivityT* conn,
const vtkIdType cellId,
vtkIdType* cellPoints)
1436 auto offsetsRange =
GetRange(offsets);
1437 const auto& beginOffset = offsetsRange[cellId];
1438 const auto& endOffset = offsetsRange[cellId + 1];
1440 const auto cellConnectivity =
GetRange(conn).begin() + beginOffset;
1443 for (
vtkIdType i = 0; i < cellSize; ++i)
1445 cellPoints[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1452 template <
typename ConnectivityT>
1456 std::is_base_of_v<vtkAOSDataArrayTemplate<vtkIdType>, ConnectivityT>;
1460 template <
class OffsetsT,
class ConnectivityT>
1465 auto offsetsRange =
GetRange(offsets);
1466 const auto& beginOffset = offsetsRange[cellId];
1467 const auto& endOffset = offsetsRange[cellId + 1];
1469 cellPoints = conn->GetPointer(beginOffset);
1470 return static_cast<vtkIdType>(endOffset - beginOffset);
1473 template <
class OffsetsT,
class ConnectivityT>
1477 auto offsetsRange =
GetRange(offsets);
1478 const auto& beginOffset = offsetsRange[cellId];
1479 const auto& endOffset = offsetsRange[cellId + 1];
1481 const auto cellConnectivity =
GetRange(conn).begin() + beginOffset;
1485 for (
vtkIdType i = 0; i < cellSize; ++i)
1487 tempPtr[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1490 cellPoints = tempPtr;
1497 template <
class OffsetsT,
class ConnectivityT>
1507 template <
class OffsetsT,
class ConnectivityT>
1514 AccessorType accessor(offsets);
1515 ValueType firstOffset = 0;
1516 accessor.InsertNext(firstOffset);
1522 template <
class OffsetsT,
class ConnectivityT>
1527 AccessorType accessor(conn);
1528 accessor.InsertNext(
static_cast<ValueType
>(
id));
1532VTK_ABI_NAMESPACE_END
1535VTK_ABI_NAMESPACE_BEGIN
1673VTK_ABI_NAMESPACE_END
Array-Of-Structs implementation of vtkGenericDataArray.
virtual vtkIdType GetNumberOfCells() const =0
Get the number of cells in the array.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
A utility array for wrapping affine functions in implicit arrays.
static vtkAffineArray< ValueType > * FastDownCast(vtkAbstractArray *source)
Encapsulate traversal logic for vtkCellArray.
bool AppendLegacyFormat(vtkIdTypeArray *data, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
vtkIdType GetCellSize(vtkIdType cellId) const override
Return the size of the cell at cellId.
vtkDataArray * GetOffsetsArray() const
Return the array used to store cell offsets.
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)
GetDispatchReturnType< Functor, Args... > Dispatch(Functor &&functor, Args &&... args) const
void UseFixedSizeDefaultStorage(vtkIdType cellSize)
Initialize internal data structures to use 32- or 64-bit storage.
vtkIdType GetOffset(vtkIdType cellId) override
Get the offset (into the connectivity) for a specified cell id.
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
static void SetDefaultStorageIs64Bit(bool val)
Control the default internal storage size.
void DeepCopy(vtkAbstractCellArray *ca) override
Perform a deep copy (no reference counting) of the given cell array.
bool IsValid()
Check that internal storage is consistent and in a valid state.
friend class vtkCellArrayIterator
bool SetData(vtkIdType cellSize, vtkDataArray *connectivity)
Sets the internal arrays to the supported connectivity array with an offsets array automatically gene...
void ShallowCopy(vtkAbstractCellArray *ca) override
Shallow copy ca into this cell array.
vtkIdType GetNumberOfOffsets() const override
Get the number of elements in the offsets array.
bool CanConvertToFixedSize64BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void SetData(AOSArray64 *, AOSArray64 *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
vtkAOSDataArrayTemplate< vtkTypeInt32 > AOSArray32
bool CanConvertToFixedSizeDefaultStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
vtkIdType GetNumberOfConnectivityIds() const override
Get the size of the connectivity array that stores the point ids.
vtkAOSDataArrayTemplate< vtkTypeInt64 > AOSArray64
bool CanConvertToStorageType(StorageTypes type) const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
void SetData(AffineArray32 *, AOSArray32 *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool ConvertToFixedSize64BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
vtkAffineArray< vtkTypeInt64 > AffineArray64
bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize)
Pre-allocate memory in internal data structures.
bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize)
ResizeExact() resizes the internal structures to hold numCells total cell offsets and connectivitySiz...
AOSArray64 * GetOffsetsAOSArray64() const
Ensure that a cell of size cellSize can be safely inserted or appended.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
bool ImportLegacyFormat(const vtkIdType *data, vtkIdType len)
Import an array of data with the legacy vtkCellArray layout, e.g.:
vtkIdType TraversalCellId
void UseFixedSize64BitStorage(vtkIdType cellSize)
Initialize internal data structures to use 32- or 64-bit storage.
bool IsStorageShareable() const override
bool IsStorageGeneric() const
void Dispatch(Functor &&functor, Args &&... args) const
void Use64BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
vtkSmartPointer< vtkDataArray > Offsets
vtkDataArray * GetConnectivityArray() const
Return the array used to store the point ids that define the cells' connectivity.
bool ConvertToDefaultStorage()
Convert internal data structures to use 32- or 64-bit storage.
bool CanConvertToDefaultStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
GetDispatchReturnType< Functor, Args... > Dispatch(Functor &&functor, Args &&... args)
static bool DefaultStorageIs64Bit
bool CanConvertTo32BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *ptIds) override
Return the point ids for the cell at cellId.
void SetData(AffineArray64 *, AOSArray64 *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
unsigned long GetActualMemorySize() const
Return the memory in kibibytes (1024 bytes) consumed by this cell array.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
void ReplaceCellAtId(vtkIdType cellId, vtkIdList *list)
Replaces the point ids for the specified cell with the supplied list.
void UseFixedSize32BitStorage(vtkIdType cellSize)
Initialize internal data structures to use 32- or 64-bit storage.
void ReverseCellAtId(vtkIdType cellId)
Reverses the order of the point ids for the specified cell.
bool IsStorage32Bit() const
bool SetData(vtkDataArray *offsets, vtkDataArray *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
void Initialize() override
Free any memory and reset to an empty state.
void Squeeze()
Reclaim any extra memory while preserving data.
vtkSmartPointer< vtkDataArray > Connectivity
bool IsStorageFixedSize32Bit() const
bool ConvertTo32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
AffineArray64 * GetOffsetsAffineArray64() const
Ensure that a cell of size cellSize can be safely inserted or appended.
bool ImportLegacyFormat(vtkIdTypeArray *data)
Import an array of data with the legacy vtkCellArray layout, e.g.:
bool ConvertToFixedSizeDefaultStorage()
Convert internal data structures to use 32- or 64-bit storage.
void SetData(AOSArray32 *, AOSArray32 *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool ConvertToStorageType(StorageTypes type)
Convert internal data structures to use 32- or 64-bit storage.
AffineArray32 * GetOffsetsAffineArray32() const
Ensure that a cell of size cellSize can be safely inserted or appended.
void SetOffset(vtkIdType cellId, vtkIdType offset)
Set the offset (into the connectivity) for a specified cell id.
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
bool AppendLegacyFormat(const vtkIdType *data, vtkIdType len, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
void ExportLegacyFormat(vtkIdTypeArray *data)
Fill data with the old-style vtkCellArray data layout, e.g.
bool ConvertTo64BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
void Dispatch(Functor &&functor, Args &&... args)
bool ConvertToFixedSize32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
vtkAffineArray< vtkTypeInt32 > AffineArray32
void Use32BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
Return the point id at cellPointIndex for the cell at cellId.
void SetTraversalCellId(vtkIdType cellId)
Get/Set the current cellId for traversal.
bool IsStorageFixedSize64Bit() const
static bool GetDefaultStorageIs64Bit()
Control the default internal storage size.
int GetMaxCellSize() override
Returns the size of the largest cell.
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
AOSArray32 * GetOffsetsAOSArray32() const
Ensure that a cell of size cellSize can be safely inserted or appended.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
void PrintDebug(ostream &os)
Standard methods for instantiation, type information, and printing.
vtkIdType IsHomogeneous() const override
Check if all cells have the same number of vertices.
bool EnsureStorageForCellSize(vtkIdType cellSize)
Ensure that a cell of size cellSize can be safely inserted or appended.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
bool IsStorageFixedSize() const
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
StorageTypes GetStorageType() const noexcept
void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId)
Replaces the pointId at cellPointIndex of a cell with newPointId.
bool CanConvertToFixedSize32BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
AOSArray32 * GetConnectivityAOSArray32() const
Return the array used to store the point ids that define the cells' connectivity.
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
bool IsStorage64Bit() const
void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType *cellPoints)
Replaces the point ids for the specified cell with the supplied list.
AOSArray64 * GetConnectivityAOSArray64() const
Return the array used to store the point ids that define the cells' connectivity.
bool CanConvertTo64BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
abstract class to specify cell behavior
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
list of point or cell ids
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
void Reset()
Reset to an empty state but retain previously allocated memory.
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
static vtkMallocingFunction GetCurrentMallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
typename detail::GetAPITypeImpl< ArrayType, ForceValueTypeForVtkDataArray >::APIType GetAPIType
VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr &array, ValueIdType start=-1, ValueIdType end=-1) -> typename detail::SelectValueRange< ArrayTypePtr, TupleSize, ForceValueTypeForVtkDataArray >::type
Generate an stl and for-range compatible range of flat AOS iterators from a vtkDataArray.
vtkIdType GetNumberOfCells(OffsetsT *offsets)
static vtkIdType GetCellSize(OffsetsT *offsets, vtkIdType cellId)
static vtkIdType GetEndOffset(OffsetsT *offsets, vtkIdType cellId)
static decltype(vtk::DataArrayValueRange< 1, vtkIdType >(std::declval< ConnectivityT >())) GetCellRange(OffsetsT *offsets, ConnectivityT *conn, vtkIdType cellId)
static vtkIdType GetBeginOffset(OffsetsT *offsets, vtkIdType cellId)
static decltype(vtk::DataArrayValueRange< 1, vtkIdType >(std::declval< ArrayT >())) GetRange(ArrayT *array)
vtk::GetAPIType< ArrayT, vtkIdType > GetAPIType
vtkIdType GetNumberOfCells() const
CellRangeType GetCellRange(vtkIdType cellId)
friend class vtkCellArray
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
vtkSmartPointer< ArrayType > Connectivity
static constexpr bool ValueTypeIsSameAsIdType
const ArrayType * GetOffsets() const
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
typename ArrayType::ValueType ValueType
ArrayType * GetConnectivity()
vtkIdType operator()(OffsetsT *offsets, ConnectivityT *conn, vtkIdType cellId, vtkIdType cellPointIndex)
static constexpr bool value
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdList *ids)
std::enable_if_t<!CanShareConnPtr< ConnectivityT >::value, vtkIdType > operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdType const *&cellPoints, vtkIdList *temp)
std::enable_if_t< CanShareConnPtr< ConnectivityT >::value, vtkIdType > operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdType const *&cellPoints, vtkIdList *temp)
vtkIdType operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdType *cellPoints)
vtkIdType operator()(OffsetsT *offsets, ConnectivityT *conn, vtkIdType cellId)
void operator()(OffsetsT *offsets, ConnectivityT *conn, vtkIdType id)
vtkIdType operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType npts, const vtkIdType pts[])
vtkIdType operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType npts)
void operator()(OffsetsT *offsets, ConnectivityT *conn)
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType npts)
Efficient templated access to vtkDataArray.
STL-compatible iterable ranges that provide access to vtkDataArray elements.
#define VTK_DEPRECATED_IN_9_8_0(reason)
#define VTK_SIZEHINT(...)
#define VTK_MARSHALMANUAL