238#ifndef vtkCellArray_h
239#define vtkCellArray_h
242#include "vtkCommonDataModelModule.h"
248#include "vtkFeatures.h"
250#include "vtkTypeInt32Array.h"
251#include "vtkTypeInt64Array.h"
255#include <initializer_list>
256#include <type_traits>
279#define VTK_CELL_ARRAY_V2
281VTK_ABI_NAMESPACE_BEGIN
334 return this->AllocateExact(sz, sz) ? 1 : 0;
348 return this->AllocateExact(numCells, numCells * maxCellSize);
502 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
503 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
616 return this->GetOffsetsArray64();
620 return this->GetOffsetsArray32();
637 return this->GetConnectivityArray64();
641 return this->GetConnectivityArray32();
667 void InitTraversal();
760 return this->InsertNextCell(
static_cast<vtkIdType>(cell.size()), cell.begin());
781 void UpdateCellCount(
int npts);
830 return this->ReplaceCellAtId(cellId,
static_cast<vtkIdType>(cell.size()), cell.begin());
905 unsigned long GetActualMemorySize() const;
913 template <
typename ArrayT>
918 using CellRangeType =
decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
925 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
951 this->Offsets->InsertNextValue(0);
954 this->IsInMemkind =
true;
958 void*
operator new(
size_t nSize)
961#ifdef VTK_USE_MEMKIND
968 void operator delete(
void* p)
970#ifdef VTK_USE_MEMKIND
991 bool IsInMemkind =
false;
995 template <
typename Functor,
typename... Args>
996 using GetReturnType =
decltype(
997 std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
999 template <
typename Functor,
typename... Args>
1000 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1074 template <
typename Functor,
typename... Args,
1075 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1076 void Visit(Functor&& functor, Args&&... args)
1094 template <
typename Functor,
typename... Args,
1095 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1096 void Visit(Functor&& functor, Args&&... args)
const
1114 template <
typename Functor,
typename... Args,
1115 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1116 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
1133 template <
typename Functor,
typename... Args,
1134 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1135 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
const
1228 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1323#ifdef VTK_USE_MEMKIND
1334 this->StorageIs64Bit =
true;
1339 this->StorageIs64Bit =
false;
1342#ifdef VTK_USE_MEMKIND
1345 this->IsInMemkind =
true;
1348 (void)this->IsInMemkind;
1354 if (this->StorageIs64Bit)
1356 this->Arrays->Int64->~VisitState();
1357 delete this->Arrays->Int64;
1361 this->Arrays->Int32->~VisitState();
1362 delete this->Arrays->Int32;
1364#ifdef VTK_USE_MEMKIND
1365 if (this->IsInMemkind)
1374 delete this->Arrays;
1382 if (!this->StorageIs64Bit)
1387 this->Arrays->Int64->~VisitState();
1388 delete this->Arrays->Int64;
1390 this->StorageIs64Bit =
false;
1399 if (this->StorageIs64Bit)
1404 this->Arrays->Int32->~VisitState();
1405 delete this->Arrays->Int32;
1407 this->StorageIs64Bit =
true;
1413 bool Is64Bit()
const {
return this->StorageIs64Bit; }
1418 assert(!this->StorageIs64Bit);
1419 return *this->Arrays->Int32;
1424 assert(!this->StorageIs64Bit);
1425 return *this->Arrays->Int32;
1431 assert(this->StorageIs64Bit);
1432 return *this->Arrays->Int64;
1437 assert(this->StorageIs64Bit);
1438 return *this->Arrays->Int64;
1444 ArraySwitch* Arrays;
1445 bool StorageIs64Bit;
1446 bool IsInMemkind =
false;
1461template <
typename ArrayT>
1464 return this->Offsets->GetNumberOfValues() - 1;
1467template <
typename ArrayT>
1470 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1473template <
typename ArrayT>
1476 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1479template <
typename ArrayT>
1482 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1485template <
typename ArrayT>
1489 return vtk::DataArrayValueRange<1>(
1490 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1492VTK_ABI_NAMESPACE_END
1496VTK_ABI_NAMESPACE_BEGIN
1501 template <
typename CellStateT>
1504 using ValueType =
typename CellStateT::ValueType;
1505 auto* conn = state.GetConnectivity();
1506 auto* offsets = state.GetOffsets();
1508 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1510 offsets->InsertNextValue(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1514 conn->InsertNextValue(
static_cast<ValueType
>(pts[i]));
1521 template <
typename CellStateT>
1524 using ValueType =
typename CellStateT::ValueType;
1525 auto* conn = state.GetConnectivity();
1526 auto* offsets = state.GetOffsets();
1528 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1530 offsets->InsertNextValue(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1539 template <
typename CellStateT>
1542 using ValueType =
typename CellStateT::ValueType;
1544 auto* offsets = state.GetOffsets();
1545 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1546 offsets->SetValue(offsets->GetMaxId(),
static_cast<ValueType
>(cellBegin + npts));
1552 template <
typename CellStateT>
1555 return state.GetCellSize(cellId);
1561 template <
typename CellStateT>
1564 using ValueType =
typename CellStateT::ValueType;
1566 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1567 const vtkIdType endOffset = state.GetEndOffset(cellId);
1568 const vtkIdType cellSize = endOffset - beginOffset;
1569 const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1574 for (ValueType i = 0; i < cellSize; ++i)
1576 idPtr[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1580 template <
typename CellStateT>
1584 using ValueType =
typename CellStateT::ValueType;
1586 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1587 const vtkIdType endOffset = state.GetEndOffset(cellId);
1588 cellSize = endOffset - beginOffset;
1589 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1592 for (
vtkIdType i = 0; i < cellSize; ++i)
1594 cellPoints[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1600 template <
typename CellStateT>
1604 using ValueType =
typename CellStateT::ValueType;
1605 using ArrayType =
typename CellStateT::ArrayType;
1607 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1608 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1611 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1614 template <
typename CellStateT>
1615 typename std::enable_if<CanShareConnPtr<CellStateT>::value,
void>::type
operator()(
1619 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1620 const vtkIdType endOffset = state.GetEndOffset(cellId);
1621 cellSize = endOffset - beginOffset;
1623 cellPoints =
reinterpret_cast<vtkIdType*
>(state.GetConnectivity()->GetPointer(beginOffset));
1626 template <
typename CellStateT>
1627 typename std::enable_if<!CanShareConnPtr<CellStateT>::value,
void>::type
operator()(
1631 using ValueType =
typename CellStateT::ValueType;
1633 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1634 const vtkIdType endOffset = state.GetEndOffset(cellId);
1635 cellSize = endOffset - beginOffset;
1636 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1641 for (
vtkIdType i = 0; i < cellSize; ++i)
1643 tempPtr[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1652 template <
typename CellStateT>
1655 state.GetOffsets()->Reset();
1656 state.GetConnectivity()->Reset();
1657 state.GetOffsets()->InsertNextValue(0);
1661VTK_ABI_NAMESPACE_END
1664VTK_ABI_NAMESPACE_BEGIN
1674 if (this->TraversalCellId < this->GetNumberOfCells())
1676 this->GetCellAtId(this->TraversalCellId, npts, pts);
1677 ++this->TraversalCellId;
1742 using ValueType =
typename ArrayType64::ValueType;
1747 using ValueType =
typename ArrayType32::ValueType;
1779VTK_ABI_NAMESPACE_END
Array-Of-Structs implementation of vtkGenericDataArray.
abstract object to represent cell connectivity
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.
virtual vtkIdType GetCellSize(vtkIdType cellId) const =0
Return the size of the cell at cellId.
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
vtkIdType GetCellSize(vtkIdType cellId) const override
Return the size of the cell at cellId.
void SetData(vtkAOSDataArrayTemplate< int > *offsets, vtkAOSDataArrayTemplate< int > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)
vtkIdType IsHomogeneous() override
Check if all cells have the same number of vertices.
vtkIdType GetOffset(vtkIdType cellId) override
Get the offset (into the connectivity) for a specified cell id.
vtkIdType GetNumberOfConnectivityEntries()
Return the size of the array that would be returned from ExportLegacyFormat().
void SetData(vtkTypeInt32Array *offsets, vtkTypeInt32Array *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
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.
void AppendLegacyFormat(vtkIdTypeArray *data, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
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.
void AppendLegacyFormat(const vtkIdType *data, vtkIdType len, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
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.
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
vtkIdType GetNumberOfConnectivityIds() const override
Get the size of the connectivity array that stores the point ids.
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
void SetData(vtkAOSDataArrayTemplate< long long > *offsets, vtkAOSDataArrayTemplate< long long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
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...
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
vtkTypeInt64Array ArrayType64
vtkIdType TraversalCellId
bool IsStorageShareable() const override
void Use64BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
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.
static bool DefaultStorageIs64Bit
void GetCell(vtkIdType loc, vtkIdType &npts, const vtkIdType *&pts)
Internal method used to retrieve a cell given a legacy offset location.
bool CanConvertTo32BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *ptIds) override
Return the point ids for the cell at cellId.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
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 ReverseCellAtId(vtkIdType cellId)
Reverses the order of the point ids for the specified cell.
bool SetData(vtkDataArray *offsets, vtkDataArray *connectivity)
Sets the internal 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.
void SetData(vtkIdTypeArray *offsets, vtkIdTypeArray *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool ConvertTo32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
void Visit(Functor &&functor, Args &&... args) const
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
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 SetData(vtkAOSDataArrayTemplate< long > *offsets, vtkAOSDataArrayTemplate< long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
void ImportLegacyFormat(const vtkIdType *data, vtkIdType len)
Import an array of data with the legacy vtkCellArray layout, e.g.:
void ImportLegacyFormat(vtkIdTypeArray *data)
Import an array of data with the legacy vtkCellArray layout, e.g.:
void Use32BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > > >::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
void SetTraversalCellId(vtkIdType cellId)
Get/Set the current cellId for traversal.
void SetData(vtkTypeInt64Array *offsets, vtkTypeInt64Array *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
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.
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
vtkNew< vtkIdTypeArray > LegacyData
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.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
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.
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.
abstract superclass for arrays of numeric data
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
Allocate and hold a VTK object.
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.
VisitState< ArrayType64 > & GetArrays64()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType32 > & GetArrays32()
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
vtkSmartPointer< ArrayType > Connectivity
const ArrayType * GetOffsets() const
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
typename ArrayType::ValueType ValueType
ArrayType * GetConnectivity()
std::enable_if<!CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
std::enable_if< CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *vtkNotUsed(temp))
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType *cellPoints)
vtkIdType operator()(CellStateT &state, vtkIdType cellId)
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
void operator()(CellStateT &state)
void operator()(CellStateT &state, const vtkIdType npts)
Remove all duplicate types from TypeList TList, storing the new list in Result.
VisitState< ArrayType32 > * Int32
VisitState< ArrayType64 > * Int64
STL-compatible iterable ranges that provide access to vtkDataArray elements.
#define VTK_SIZEHINT(...)
#define VTK_MARSHALMANUAL