250 #ifndef vtkCellArray_h
251 #define vtkCellArray_h
253 #include "vtkCommonDataModelModule.h"
259 #include "vtkFeatures.h"
261 #include "vtkTypeInt32Array.h"
262 #include "vtkTypeInt64Array.h"
266 #include <initializer_list>
267 #include <type_traits>
290 #define VTK_CELL_ARRAY_V2
292 VTK_ABI_NAMESPACE_BEGIN
345 return this->AllocateExact(sz, sz) ? 1 : 0;
359 return this->AllocateExact(numCells, numCells * maxCellSize);
509 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
510 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
629 return this->GetOffsetsArray64();
633 return this->GetOffsetsArray32();
650 return this->GetConnectivityArray64();
654 return this->GetConnectivityArray32();
680 void InitTraversal();
742 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
775 return this->InsertNextCell(
static_cast<vtkIdType>(cell.size()), cell.begin());
796 void UpdateCellCount(
int npts);
845 return this->ReplaceCellAtId(cellId,
static_cast<vtkIdType>(cell.size()), cell.begin());
920 unsigned long GetActualMemorySize() const;
928 template <
typename ArrayT>
933 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
966 this->Offsets->InsertNextValue(0);
969 this->IsInMemkind =
true;
973 void*
operator new(
size_t nSize)
976 #ifdef VTK_USE_MEMKIND
983 void operator delete(
void* p)
985 #ifdef VTK_USE_MEMKIND
1006 bool IsInMemkind =
false;
1010 template <
typename Functor,
typename... Args>
1011 using GetReturnType = decltype(
1014 template <
typename Functor,
typename... Args>
1015 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1089 template <
typename Functor,
typename... Args,
1090 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>
::value>
::type>
1091 void Visit(Functor&& functor, Args&&... args)
1109 template <
typename Functor,
typename... Args,
1110 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>
::value>
::type>
1111 void Visit(Functor&& functor, Args&&... args)
const
1129 template <
typename Functor,
typename... Args,
1130 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>
::value>
::type>
1131 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
1148 template <
typename Functor,
typename... Args,
1149 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>
::value>
::type>
1150 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
const
1233 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1328 #ifdef VTK_USE_MEMKIND
1336 #ifdef VTK_USE_64BIT_IDS
1339 this->StorageIs64Bit =
true;
1344 this->StorageIs64Bit =
false;
1347 #ifdef VTK_USE_MEMKIND
1350 this->IsInMemkind =
true;
1353 (void)this->IsInMemkind;
1359 if (this->StorageIs64Bit)
1361 this->Arrays->Int64->~VisitState();
1362 delete this->Arrays->Int64;
1366 this->Arrays->Int32->~VisitState();
1367 delete this->Arrays->Int32;
1369 #ifdef VTK_USE_MEMKIND
1370 if (this->IsInMemkind)
1379 delete this->Arrays;
1387 if (!this->StorageIs64Bit)
1392 this->Arrays->Int64->~VisitState();
1393 delete this->Arrays->Int64;
1395 this->StorageIs64Bit =
false;
1404 if (this->StorageIs64Bit)
1409 this->Arrays->Int32->~VisitState();
1410 delete this->Arrays->Int32;
1412 this->StorageIs64Bit =
true;
1418 bool Is64Bit()
const {
return this->StorageIs64Bit; }
1423 assert(!this->StorageIs64Bit);
1424 return *this->Arrays->Int32;
1429 assert(!this->StorageIs64Bit);
1430 return *this->Arrays->Int32;
1436 assert(this->StorageIs64Bit);
1437 return *this->Arrays->Int64;
1442 assert(this->StorageIs64Bit);
1443 return *this->Arrays->Int64;
1449 ArraySwitch* Arrays;
1450 bool StorageIs64Bit;
1451 bool IsInMemkind =
false;
1465 template <
typename ArrayT>
1468 return this->Offsets->GetNumberOfValues() - 1;
1471 template <
typename ArrayT>
1474 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1477 template <
typename ArrayT>
1480 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1483 template <
typename ArrayT>
1486 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1489 template <
typename ArrayT>
1493 return vtk::DataArrayValueRange<1>(
1494 this->
GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1496 VTK_ABI_NAMESPACE_END
1500 VTK_ABI_NAMESPACE_BEGIN
1505 template <
typename CellStateT>
1508 using ValueType =
typename CellStateT::ValueType;
1509 auto* conn = state.GetConnectivity();
1510 auto* offsets = state.GetOffsets();
1512 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1514 offsets->InsertNextValue(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1518 conn->InsertNextValue(
static_cast<ValueType
>(pts[i]));
1525 template <
typename CellStateT>
1528 using ValueType =
typename CellStateT::ValueType;
1529 auto* conn = state.GetConnectivity();
1530 auto* offsets = state.GetOffsets();
1532 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1534 offsets->InsertNextValue(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1543 template <
typename CellStateT>
1546 using ValueType =
typename CellStateT::ValueType;
1548 auto* offsets = state.GetOffsets();
1549 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1550 offsets->SetValue(offsets->GetMaxId(),
static_cast<ValueType
>(cellBegin + npts));
1556 template <
typename CellStateT>
1559 return state.GetCellSize(cellId);
1565 template <
typename CellStateT>
1568 using ValueType =
typename CellStateT::ValueType;
1570 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1571 const vtkIdType endOffset = state.GetEndOffset(cellId);
1572 const vtkIdType cellSize = endOffset - beginOffset;
1573 const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1578 for (ValueType i = 0; i < cellSize; ++i)
1580 idPtr[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1586 template <
typename CellStateT>
1590 using ValueType =
typename CellStateT::ValueType;
1591 using ArrayType =
typename CellStateT::ArrayType;
1593 static constexpr
bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1597 static constexpr
bool value = ValueTypeCompat && ArrayTypeCompat;
1600 template <
typename CellStateT>
1605 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1606 const vtkIdType endOffset = state.GetEndOffset(cellId);
1607 cellSize = endOffset - beginOffset;
1609 cellPoints =
reinterpret_cast<vtkIdType*
>(state.GetConnectivity()->GetPointer(beginOffset));
1612 template <
typename CellStateT>
1617 using ValueType =
typename CellStateT::ValueType;
1619 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1620 const vtkIdType endOffset = state.GetEndOffset(cellId);
1621 cellSize = endOffset - beginOffset;
1622 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1627 for (
vtkIdType i = 0; i < cellSize; ++i)
1629 tempPtr[i] =
static_cast<vtkIdType>(cellConnectivity[i]);
1638 template <
typename CellStateT>
1641 state.GetOffsets()->Reset();
1642 state.GetConnectivity()->Reset();
1643 state.GetOffsets()->InsertNextValue(0);
1647 VTK_ABI_NAMESPACE_END
1650 VTK_ABI_NAMESPACE_BEGIN
1660 if (this->TraversalCellId < this->GetNumberOfCells())
1662 this->GetCellAtId(this->TraversalCellId, npts, pts);
1663 ++this->TraversalCellId;
1729 using ValueType =
typename ArrayType64::ValueType;
1734 using ValueType =
typename ArrayType32::ValueType;
1766 VTK_ABI_NAMESPACE_END
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
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 GetNumberOfConnectivityEntries()
Return the size of the array that would be returned from ExportLegacyFormat().
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
vtkIdType GetOffset(vtkIdType cellId)
Get the offset (into the connectivity) for a specified cell id.
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.
bool IsStorageShareable() const
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
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.
bool SetData(vtkIdType cellSize, vtkDataArray *connectivity)
Sets the internal arrays to the supported connectivity array with an offsets array automatically gene...
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
void SetData(vtkAOSDataArrayTemplate< long long > *offsets, vtkAOSDataArrayTemplate< long long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
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.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
vtkTypeInt64Array ArrayType64
vtkIdType TraversalCellId
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.
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.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
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 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.
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
bool ConvertTo32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
vtkIdType IsHomogeneous()
Check if all cells have the same number of vertices.
void Visit(Functor &&functor, Args &&... args) const
int GetMaxCellSize()
Returns the size of the largest cell.
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
void ShallowCopy(vtkCellArray *ca)
Shallow copy ca into this cell array.
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.
void Initialize()
Free any memory and reset to an empty state.
void DeepCopy(vtkCellArray *ca)
Perform a deep copy (no reference counting) of the given cell array.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > >>::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
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.
vtkIdType GetNumberOfCells() const
Get the number of cells in the array.
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
vtkIdType GetNumberOfConnectivityIds() const
Get the size of the connectivity array that stores the point ids.
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.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
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) const
vtkNew< vtkIdList > TempCell
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
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.
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
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
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
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.
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
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...
abstract base class for most VTK objects
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
VisitState< ArrayType32 > & GetArrays32()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType64 > & GetArrays64()
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
vtkSmartPointer< ArrayType > Connectivity
static constexpr bool ValueTypeIsSameAsIdType
ArrayType * GetConnectivity()
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
CellRangeType GetCellRange(vtkIdType cellId)
const ArrayType * GetOffsets() const
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
typename ArrayType::ValueType ValueType
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
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))
vtkIdType operator()(CellStateT &state, const 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(...)