141 #ifndef vtkCellArray_h
142 #define vtkCellArray_h
144 #include "vtkCommonDataModelModule.h"
150 #include "vtkFeatures.h"
152 #include "vtkTypeInt32Array.h"
153 #include "vtkTypeInt64Array.h"
157 #include <initializer_list>
158 #include <type_traits>
181 #define VTK_CELL_ARRAY_V2
200 void PrintDebug(ostream& os);
235 return this->AllocateExact(sz, sz) ? 1 : 0;
249 return this->AllocateExact(numCells, numCells * maxCellSize);
388 #ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
399 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
400 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
407 #endif // __VTK_WRAP__
470 void Use32BitStorage();
471 void Use64BitStorage();
472 void UseDefaultStorage();
483 bool CanConvertTo32BitStorage()
const;
484 bool CanConvertTo64BitStorage()
const;
485 bool CanConvertToDefaultStorage()
const;
504 bool ConvertTo32BitStorage();
505 bool ConvertTo64BitStorage();
506 bool ConvertToDefaultStorage();
507 bool ConvertToSmallestStorage();
519 return this->GetOffsetsArray64();
523 return this->GetOffsetsArray32();
540 return this->GetConnectivityArray64();
544 return this->GetConnectivityArray32();
570 void InitTraversal();
632 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
665 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
686 void UpdateCellCount(
int npts);
696 void SetTraversalCellId(
vtkIdType cellId);
726 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
733 int GetMaxCellSize();
801 unsigned long GetActualMemorySize() const;
809 template <
typename ArrayT>
814 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
838 CellRangeType GetCellRange(
vtkIdType cellId);
847 this->Offsets->InsertNextValue(0);
850 this->IsInMemkind =
true;
854 void*
operator new(
size_t nSize)
857 #ifdef VTK_USE_MEMKIND
864 void operator delete(
void* p)
866 #ifdef VTK_USE_MEMKIND
887 bool IsInMemkind =
false;
891 template <
typename Functor,
typename... Args>
892 using GetReturnType = decltype(
895 template <
typename Functor,
typename... Args>
896 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
970 template <
typename Functor,
typename... Args,
971 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>
::value>
::type>
972 void Visit(Functor&& functor, Args&&... args)
990 template <
typename Functor,
typename... Args,
991 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>
::value>
::type>
992 void Visit(Functor&& functor, Args&&... args)
const
1010 template <
typename Functor,
typename... Args,
1011 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>
::value>
::type>
1012 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
1029 template <
typename Functor,
typename... Args,
1030 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>
::value>
::type>
1031 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
const
1051 #endif // __VTK_WRAP__
1062 virtual void SetNumberOfCells(
vtkIdType);
1093 vtkIdType GetNumberOfConnectivityEntries();
1114 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1133 void SetTraversalLocation(
vtkIdType loc);
1143 void ReverseCell(
vtkIdType loc)
VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1193 ~vtkCellArray() override;
1209 #ifdef VTK_USE_MEMKIND
1217 #ifdef VTK_USE_64BIT_IDS
1220 this->StorageIs64Bit =
true;
1222 #else // VTK_USE_64BIT_IDS
1225 this->StorageIs64Bit =
false;
1227 #endif // VTK_USE_64BIT_IDS
1228 #ifdef VTK_USE_MEMKIND
1231 this->IsInMemkind =
true;
1234 (void)this->IsInMemkind;
1240 if (this->StorageIs64Bit)
1242 this->Arrays->Int64->~VisitState();
1243 delete this->Arrays->Int64;
1247 this->Arrays->Int32->~VisitState();
1248 delete this->Arrays->Int32;
1250 #ifdef VTK_USE_MEMKIND
1251 if (this->IsInMemkind)
1260 delete this->Arrays;
1268 if (!this->StorageIs64Bit)
1273 this->Arrays->Int64->~VisitState();
1274 delete this->Arrays->Int64;
1276 this->StorageIs64Bit =
false;
1285 if (this->StorageIs64Bit)
1290 this->Arrays->Int32->~VisitState();
1291 delete this->Arrays->Int32;
1293 this->StorageIs64Bit =
true;
1299 bool Is64Bit()
const {
return this->StorageIs64Bit; }
1304 assert(!this->StorageIs64Bit);
1305 return *this->Arrays->Int32;
1310 assert(!this->StorageIs64Bit);
1311 return *this->Arrays->Int32;
1317 assert(this->StorageIs64Bit);
1318 return *this->Arrays->Int64;
1323 assert(this->StorageIs64Bit);
1324 return *this->Arrays->Int64;
1330 ArraySwitch* Arrays;
1331 bool StorageIs64Bit;
1332 bool IsInMemkind =
false;
1346 template <
typename ArrayT>
1349 return this->Offsets->GetNumberOfValues() - 1;
1352 template <
typename ArrayT>
1355 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1358 template <
typename ArrayT>
1361 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1364 template <
typename ArrayT>
1367 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1370 template <
typename ArrayT>
1374 return vtk::DataArrayValueRange<1>(
1375 this->
GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1384 template <
typename CellStateT>
1387 using ValueType =
typename CellStateT::ValueType;
1388 auto* conn = state.GetConnectivity();
1389 auto* offsets = state.GetOffsets();
1391 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1393 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1397 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1404 template <
typename CellStateT>
1407 using ValueType =
typename CellStateT::ValueType;
1408 auto* conn = state.GetConnectivity();
1409 auto* offsets = state.GetOffsets();
1411 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1413 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1422 template <
typename CellStateT>
1425 using ValueType =
typename CellStateT::ValueType;
1427 auto* offsets = state.GetOffsets();
1428 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1429 offsets->SetValue(offsets->GetMaxId(),
static_cast<ValueType
>(cellBegin + npts));
1435 template <
typename CellStateT>
1438 return state.GetCellSize(cellId);
1444 template <
typename CellStateT>
1447 using ValueType =
typename CellStateT::ValueType;
1449 const auto cellPts = state.GetCellRange(cellId);
1454 for (ValueType ptId : cellPts)
1456 *idPtr++ =
static_cast<vtkIdType>(ptId);
1462 template <
typename CellStateT>
1466 using ValueType =
typename CellStateT::ValueType;
1467 using ArrayType =
typename CellStateT::ArrayType;
1469 static constexpr
bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1473 static constexpr
bool value = ValueTypeCompat && ArrayTypeCompat;
1476 template <
typename CellStateT>
1481 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1482 const vtkIdType endOffset = state.GetEndOffset(cellId);
1483 cellSize = endOffset - beginOffset;
1485 cellPoints =
reinterpret_cast<vtkIdType*
>(state.GetConnectivity()->GetPointer(beginOffset));
1488 template <
typename CellStateT>
1493 using ValueType =
typename CellStateT::ValueType;
1495 const auto cellPts = state.GetCellRange(cellId);
1496 cellSize = cellPts.size();
1502 for (ValueType ptId : cellPts)
1504 *tempPtr++ =
static_cast<vtkIdType>(ptId);
1513 template <
typename CellStateT>
1516 state.GetOffsets()->Reset();
1517 state.GetConnectivity()->Reset();
1518 state.GetOffsets()->InsertNextValue(0);
1533 if (this->TraversalCellId < this->GetNumberOfCells())
1535 this->GetCellAtId(this->TraversalCellId, npts, pts);
1536 ++this->TraversalCellId;
1602 using ValueType =
typename ArrayType64::ValueType;
1607 using ValueType =
typename ArrayType32::ValueType;
1639 #endif // vtkCellArray.h
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity. ...
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity. ...
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity. ...
static vtkFreeingFunction GetAlternateFreeFunction()
ArrayType * GetConnectivity()
abstract base class for most VTK objects
Remove all duplicate types from TypeList TList, storing the new list in Result.
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetNumberOfCells() const
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells...
bool IsStorageShareable() const
vtkIdType operator()(CellStateT &state, const vtkIdType cellId)
void operator()(CellStateT &state)
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&...args)
vtkNew< vtkIdTypeArray > LegacyData
vtkIdType GetNumberOfCells() const
Get the number of cells in the array.
void Reset()
Reset to an empty state but retain previously allocated memory.
vtkSmartPointer< ArrayType > Connectivity
const ArrayType * GetOffsets() const
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
dynamic, self-adjusting array of vtkIdType
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
vtkIdType TraversalCellId
const ArrayType * GetConnectivity() const
typename vtkTypeList::detail::CreateImpl< Ts... >::type Create
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray...
vtkNew< vtkIdList > TempCell
abstract class to specify cell behavior
static constexpr bool ValueTypeIsSameAsIdType
void operator()(CellStateT &state, const vtkIdType npts)
a simple class to control print indentation
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
list of point or cell ids
vtkIdType GetOffset(vtkIdType cellId)
Get the offset (into the connectivity) for a specified cell id.
abstract superclass for arrays of numeric data
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long >>>::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
vtkIdType GetNumberOfConnectivityIds() const
Get the size of the connectivity array that stores the point ids.
vtkTypeInt64Array ArrayType64
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
vtkIdType GetEndOffset(vtkIdType cellId) const
#define VTK_SIZEHINT(...)
bool IsStorage64Bit() const
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.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
std::enable_if< CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *vtkNotUsed(temp))
vtkSmartPointer< ArrayType > Offsets
void Visit(Functor &&functor, Args &&...args)
VisitState< ArrayType64 > & GetArrays64()
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
object to represent cell connectivity
vtkTypeInt32Array ArrayType32
typename ArrayType::ValueType ValueType
vtkIdType GetCellSize(vtkIdType cellId) const
std::enable_if<!CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
VisitState< ArrayType32 > * Int32
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&...args) const
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
VisitState< ArrayType32 > & GetArrays32()
static vtkMallocingFunction GetCurrentMallocFunction()
VisitState< ArrayType64 > * Int64
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
vtkIdType GetBeginOffset(vtkIdType cellId) const
const VisitState< ArrayType32 > & GetArrays32() const
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
Encapsulate traversal logic for vtkCellArray.
void Visit(Functor &&functor, Args &&...args) const
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
STL-compatible iterable ranges that provide access to vtkDataArray elements.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)
const VisitState< ArrayType64 > & GetArrays64() const