VTK  9.7.20260714
vtkCellArray.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
235
236#ifndef vtkCellArray_h
237#define vtkCellArray_h
238
239#include "vtkAbstractCellArray.h"
240#include "vtkCommonDataModelModule.h" // For export macro
241#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
242
243#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
244#include "vtkAffineArray.h" // Needed for inline methods
245#include "vtkCell.h" // Needed for inline methods
246#include "vtkDataArrayAccessor.h" // Needed for inline methods
247#include "vtkDataArrayRange.h" // Needed for inline methods
248#include "vtkFeatures.h" // for VTK_USE_MEMKIND
249#include "vtkSmartPointer.h" // For vtkSmartPointer
250#include "vtkTypeInt32Array.h" // Needed for inline methods
251#include "vtkTypeInt64Array.h" // Needed for inline methods
252#include "vtkTypeList.h" // Needed for ArrayList definition
253
254#include <cassert> // Needed for assert
255#include <initializer_list> // Needed for API
256#include <type_traits> // Needed for std::is_same
257#include <utility> // Needed for std::forward
258
279#define VTK_CELL_ARRAY_V2
280
281VTK_ABI_NAMESPACE_BEGIN
283class vtkIdTypeArray;
284
285class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkCellArray : public vtkAbstractCellArray
286{
287public:
292
294
298 static vtkCellArray* New();
300 void PrintSelf(ostream& os, vtkIndent indent) override;
301 void PrintDebug(ostream& os);
303
313 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
314 {
315 return this->AllocateExact(numCells, numCells * maxCellSize);
316 }
317
327 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
328
339 {
340 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
341 }
342
352 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
353
357 void Initialize() override;
358
362 void Reset();
363
369 void Squeeze();
370
381 bool IsValid();
382
386 vtkIdType GetNumberOfCells() const override { return this->Offsets->GetNumberOfValues() - 1; }
387
392 vtkIdType GetNumberOfOffsets() const override { return this->Offsets->GetNumberOfValues(); }
393
398 {
399 return static_cast<vtkIdType>(this->Offsets->GetComponent(cellId, 0));
400 }
401
405 void SetOffset(vtkIdType cellId, vtkIdType offset)
406 {
407 this->Offsets->SetComponent(cellId, 0, static_cast<double>(offset));
408 }
409
414 {
415 return this->Connectivity->GetNumberOfValues();
416 }
417
424
426
439 void SetData(AOSArray32*, AOSArray32* connectivity);
440 void SetData(AOSArray64*, AOSArray64* connectivity);
441 void SetData(AffineArray32*, AOSArray32* connectivity);
442 void SetData(AffineArray64*, AOSArray64* connectivity);
444
459 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
460
478 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
479
488
492 StorageTypes GetStorageType() const noexcept { return this->StorageType; }
493
497 bool IsStorage64Bit() const { return this->StorageType == StorageTypes::Int64; }
498
502 bool IsStorage32Bit() const { return this->StorageType == StorageTypes::Int32; }
503
508
513
518 {
519 return this->IsStorageFixedSize32Bit() || this->IsStorageFixedSize64Bit();
520 }
521
525 bool IsStorageGeneric() const { return this->StorageType == StorageTypes::Generic; }
526
533 bool IsStorageShareable() const override
534 {
535 switch (this->StorageType)
536 {
539 return std::is_same_v<vtkTypeInt32, vtkIdType>;
542 return std::is_same_v<vtkTypeInt64, vtkIdType>;
544 default:
545 return false;
546 }
547 }
548
550
564
566
580 {
581 switch (type)
582 {
584 return this->CanConvertTo32BitStorage();
586 return this->CanConvertTo64BitStorage();
592 default:
593 return true;
594 }
595 }
596
597
599
621 {
622 switch (type)
623 {
625 return this->ConvertTo32BitStorage();
627 return this->ConvertTo64BitStorage();
629 return this->ConvertToFixedSize32BitStorage();
631 return this->ConvertToFixedSize64BitStorage();
633 default:
634 return true;
635 }
636 }
637
638
640
644 vtkDataArray* GetOffsetsArray() const { return this->Offsets; }
655
656
658
672
673
682 vtkIdType IsHomogeneous() const override;
683
693 void InitTraversal();
694
709 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
710
721 int GetNextCell(vtkIdList* pts);
722
733 inline void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
734 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
735 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
736
742 inline void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
743 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
744
752 inline void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
753 VTK_SIZEHINT(cellPoints, cellSize)
754 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
755
759 vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
760 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells())
761 VTK_EXPECTS(0 <= cellPointIndex && cellPointIndex < this->GetCellSize(cellId));
762
766 vtkIdType GetCellSize(vtkIdType cellId) const override;
767
771 inline vtkIdType InsertNextCell(vtkCell* cell);
772
777 inline vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
778
784
792 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
793 {
794 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
795 }
796
803 inline vtkIdType InsertNextCell(int npts);
804
809 void InsertCellPoint(vtkIdType id);
810
815 void UpdateCellCount(int npts);
816
818
827
831 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
832
834
842 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
843 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
845
853 void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
854
862 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
863 {
864 this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
865 }
866
871 int GetMaxCellSize() override;
872
876 void DeepCopy(vtkAbstractCellArray* ca) override;
877
882
886 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
887
899
901
912 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
914
916
926 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
927 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
928 VTK_SIZEHINT(data, len);
930
939 unsigned long GetActualMemorySize() const;
940
941 // The following code is used to support
942
943 // The wrappers get understandably confused by some of the template code below
944#ifndef __VTK_WRAP__
945 /*
946 * Utilities class that every dispatch functor used with Dispatch() must inherit
947 * or optionally use its static methods.
948 */
950 {
951 template <class ArrayT>
953
954 template <class OffsetsT>
955 vtkIdType GetNumberOfCells(OffsetsT* offsets)
956 {
957 return offsets->GetNumberOfValues() - 1;
958 }
959
960 template <class ArrayT>
961 static decltype(vtk::DataArrayValueRange<1, vtkIdType>(std::declval<ArrayT>())) GetRange(
962 ArrayT* array)
963 {
965 }
966
967 template <class OffsetsT>
968 static vtkIdType GetBeginOffset(OffsetsT* offsets, vtkIdType cellId)
969 {
970 return static_cast<vtkIdType>(GetRange(offsets)[cellId]);
971 }
972
973 template <class OffsetsT>
974 static vtkIdType GetEndOffset(OffsetsT* offsets, vtkIdType cellId)
975 {
976 return static_cast<vtkIdType>(GetRange(offsets)[cellId + 1]);
977 }
978
979 template <class OffsetsT>
980 static vtkIdType GetCellSize(OffsetsT* offsets, vtkIdType cellId)
981 {
982 auto offsetsRange = GetRange(offsets);
983 return static_cast<vtkIdType>(offsetsRange[cellId + 1] - offsetsRange[cellId]);
984 }
985
986 template <class OffsetsT, class ConnectivityT>
987 static decltype(vtk::DataArrayValueRange<1, vtkIdType>(std::declval<ConnectivityT>()))
988 GetCellRange(OffsetsT* offsets, ConnectivityT* conn, vtkIdType cellId)
989 {
990 auto offsetsRange = GetRange(offsets);
992 conn, offsetsRange[cellId], offsetsRange[cellId + 1]);
993 }
994 };
995
997
1060 template <typename Functor, typename... Args>
1061 void Dispatch(Functor&& functor, Args&&... args)
1062 {
1063 switch (this->StorageType)
1064 {
1066 functor(static_cast<AOSArray32*>(this->Offsets.Get()),
1067 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1068 break;
1070 functor(static_cast<AOSArray64*>(this->Offsets.Get()),
1071 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1072 break;
1074 functor(static_cast<AffineArray32*>(this->Offsets.Get()),
1075 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1076 break;
1078 functor(static_cast<AffineArray64*>(this->Offsets.Get()),
1079 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1080 break;
1082 default:
1083 functor(this->Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1084 break;
1085 }
1086 }
1087 template <typename Functor, typename... Args>
1088 void Dispatch(Functor&& functor, Args&&... args) const
1089 {
1090 switch (this->StorageType)
1091 {
1093 functor(static_cast<AOSArray32*>(this->Offsets.Get()),
1094 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1095 break;
1097 functor(static_cast<AOSArray64*>(this->Offsets.Get()),
1098 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1099 break;
1101 functor(static_cast<AffineArray32*>(this->Offsets.Get()),
1102 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1103 break;
1105 functor(static_cast<AffineArray64*>(this->Offsets.Get()),
1106 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1107 break;
1109 default:
1110 functor(this->Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1111 break;
1112 }
1113 }
1114
1115
1116 // Holds connectivity and offset arrays of the given ArrayType.
1117 VTK_DEPRECATED_IN_9_8_0("Use DispatchUtilities")
1118 template <typename ArrayT>
1120 {
1121 using ArrayType = ArrayT;
1122 using ValueType = typename ArrayType::ValueType;
1123 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
1124
1125 // We can't just use is_same here, since binary compatible representations
1126 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
1127 // is a signed integer the same size as vtkIdType.
1128 // If this value is true, ValueType pointers may be safely converted to
1129 // vtkIdType pointers via reinterpret cast.
1130 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
1131 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
1132
1133 ArrayType* GetOffsets() { return this->Offsets; }
1134 const ArrayType* GetOffsets() const { return this->Offsets; }
1135
1137 const ArrayType* GetConnectivity() const { return this->Connectivity; }
1138
1140
1141 vtkIdType GetBeginOffset(vtkIdType cellId) const;
1142
1143 vtkIdType GetEndOffset(vtkIdType cellId) const;
1144
1145 vtkIdType GetCellSize(vtkIdType cellId) const;
1146
1147 CellRangeType GetCellRange(vtkIdType cellId);
1148
1149 friend class vtkCellArray;
1150
1151 protected:
1153 {
1156 this->Offsets->InsertNextValue(0);
1158 {
1159 this->IsInMemkind = true;
1160 }
1161 }
1162 ~VisitState() = default;
1163 void* operator new(size_t nSize)
1164 {
1165 void* r;
1166#ifdef VTK_USE_MEMKIND
1168#else
1169 r = malloc(nSize);
1170#endif
1171 return r;
1172 }
1173 void operator delete(void* p)
1174 {
1175#ifdef VTK_USE_MEMKIND
1176 VisitState* a = static_cast<VisitState*>(p);
1177 if (a->IsInMemkind)
1178 {
1180 }
1181 else
1182 {
1183 free(p);
1184 }
1185#else
1186 free(p);
1187#endif
1188 }
1189
1192
1193 private:
1194 VisitState(const VisitState&) = delete;
1195 VisitState& operator=(const VisitState&) = delete;
1196 bool IsInMemkind = false;
1197 };
1198
1199private: // Helpers that allow Visit to return a value:
1200 template <typename Functor, typename... Args>
1201 using GetReturnType = decltype(std::declval<Functor>()(
1202 std::declval<VisitState<AOSArray32>&>(), std::declval<Args>()...));
1203
1204 template <typename Functor, typename... Args>
1205 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1206 {
1207 };
1208#endif // __VTK_WRAP__
1209
1210public:
1212
1220
1222
1223protected:
1225 ~vtkCellArray() override;
1226
1231
1233
1234private:
1235 vtkCellArray(const vtkCellArray&) = delete;
1236 void operator=(const vtkCellArray&) = delete;
1237};
1238
1239template <typename ArrayT>
1241{
1242 return this->Offsets->GetNumberOfValues() - 1;
1243}
1244
1245template <typename ArrayT>
1247{
1248 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1249}
1250
1251template <typename ArrayT>
1253{
1254 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1255}
1256
1257template <typename ArrayT>
1259{
1260 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1261}
1262
1263template <typename ArrayT>
1270VTK_ABI_NAMESPACE_END
1271
1273{
1274VTK_ABI_NAMESPACE_BEGIN
1275
1277{
1278 // Insert full cell
1279 template <class OffsetsT, class ConnectivityT>
1280 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType npts,
1281 const vtkIdType pts[], vtkIdType& cellId)
1282 {
1283 using ValueType = GetAPIType<OffsetsT>;
1284 using OffsetsAccessorType = vtkDataArrayAccessor<OffsetsT>;
1285 using ConnectivityAccessorType = vtkDataArrayAccessor<ConnectivityT>;
1286 OffsetsAccessorType offsetsAccesor(offsets);
1287 ConnectivityAccessorType connAccesor(conn);
1288
1289 cellId = offsets->GetNumberOfValues() - 1;
1290
1291 offsetsAccesor.InsertNext(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1292
1293 for (vtkIdType i = 0; i < npts; ++i)
1294 {
1295 connAccesor.InsertNext(static_cast<ValueType>(pts[i]));
1296 }
1297 }
1298
1299 // Just update offset table (for incremental API)
1300 template <class OffsetsT, class ConnectivityT>
1301 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType npts, vtkIdType& cellId)
1302 {
1303 using ValueType = GetAPIType<OffsetsT>;
1304 using AccessorType = vtkDataArrayAccessor<OffsetsT>;
1305 AccessorType offsetsAccesor(offsets);
1306
1307 cellId = offsets->GetNumberOfValues() - 1;
1308
1309 offsetsAccesor.InsertNext(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1310 }
1311};
1312
1313// for incremental API:
1315{
1316 template <class OffsetsT, class ConnectivityT>
1317 void operator()(OffsetsT* offsets, ConnectivityT* vtkNotUsed(conn), const vtkIdType npts)
1318 {
1319 using ValueType = GetAPIType<OffsetsT>;
1320
1321 auto offsetsRange = GetRange(offsets);
1322 const ValueType cellBegin = offsetsRange[offsets->GetMaxId() - 1];
1323 offsetsRange[offsets->GetMaxId()] = static_cast<ValueType>(cellBegin + npts);
1324 }
1325};
1326
1328{
1329 template <class OffsetsT, class ConnectivityT>
1331 OffsetsT* offsets, ConnectivityT* vtkNotUsed(conn), vtkIdType cellId, vtkIdType& cellSize)
1332 {
1333 cellSize = GetCellSize(offsets, cellId);
1334 }
1335};
1336
1338{
1339 template <class OffsetsT, class ConnectivityT>
1340 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId, vtkIdList* ids)
1341 {
1342 auto offsetsRange = GetRange(offsets);
1343 const auto& beginOffset = offsetsRange[cellId];
1344 const auto& endOffset = offsetsRange[cellId + 1];
1345 const vtkIdType cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1346 const auto cellConnectivity = GetRange(conn).begin() + beginOffset;
1347
1348 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1349 ids->SetNumberOfIds(cellSize);
1350 vtkIdType* idPtr = ids->GetPointer(0);
1351 for (vtkIdType i = 0; i < cellSize; ++i)
1352 {
1353 idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1354 }
1355 }
1356
1357 template <class OffsetsT, class ConnectivityT>
1358 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId,
1359 vtkIdType& cellSize, vtkIdType* cellPoints)
1360 {
1361 auto offsetsRange = GetRange(offsets);
1362 const auto& beginOffset = offsetsRange[cellId];
1363 const auto& endOffset = offsetsRange[cellId + 1];
1364 cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1365 const auto cellConnectivity = GetRange(conn).begin() + beginOffset;
1366
1367 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1368 for (vtkIdType i = 0; i < cellSize; ++i)
1369 {
1370 cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1371 }
1372 }
1373
1374 // SFINAE helper to check if a Functors's connectivity array's memory can be used as a vtkIdType*.
1375 template <typename ConnectivityT>
1377 {
1378 static constexpr bool value =
1379 std::is_base_of_v<vtkAOSDataArrayTemplate<vtkIdType>, ConnectivityT>;
1380 };
1381
1382 template <class OffsetsT, class ConnectivityT>
1383 typename std::enable_if_t<CanShareConnPtr<ConnectivityT>::value, void> operator()(
1384 OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId, vtkIdType& cellSize,
1385 vtkIdType const*& cellPoints, vtkIdList* vtkNotUsed(temp))
1386 {
1387 auto offsetsRange = GetRange(offsets);
1388 const auto& beginOffset = offsetsRange[cellId];
1389 const auto& endOffset = offsetsRange[cellId + 1];
1390 cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1391 // This is safe, see CanShareConnPtr helper above.
1392 cellPoints = conn->GetPointer(beginOffset);
1393 }
1394
1395 template <class OffsetsT, class ConnectivityT>
1396 typename std::enable_if_t<!CanShareConnPtr<ConnectivityT>::value, void> operator()(
1397 OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId, vtkIdType& cellSize,
1398 vtkIdType const*& cellPoints, vtkIdList* temp)
1399 {
1400 auto offsetsRange = GetRange(offsets);
1401 const auto& beginOffset = offsetsRange[cellId];
1402 const auto& endOffset = offsetsRange[cellId + 1];
1403 cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1404 const auto cellConnectivity = GetRange(conn).begin() + beginOffset;
1405
1406 temp->SetNumberOfIds(cellSize);
1407 vtkIdType* tempPtr = temp->GetPointer(0);
1408 for (vtkIdType i = 0; i < cellSize; ++i)
1409 {
1410 tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1411 }
1412
1413 cellPoints = tempPtr;
1414 }
1415};
1416
1418{
1419 template <class OffsetsT, class ConnectivityT>
1420 void operator()(OffsetsT* offsets, ConnectivityT* conn, vtkIdType cellId,
1421 vtkIdType cellPointIndex, vtkIdType& pointId)
1422 {
1423 pointId =
1424 static_cast<vtkIdType>(GetRange(conn)[GetBeginOffset(offsets, cellId) + cellPointIndex]);
1425 }
1426};
1427
1429{
1430 template <class OffsetsT, class ConnectivityT>
1431 void operator()(OffsetsT* offsets, ConnectivityT* conn)
1432 {
1433 using ValueType = GetAPIType<OffsetsT>;
1434 using AccessorType = vtkDataArrayAccessor<OffsetsT>;
1435 offsets->Reset();
1436 conn->Reset();
1437 AccessorType accessor(offsets);
1438 ValueType firstOffset = 0;
1439 accessor.InsertNext(firstOffset);
1440 }
1441};
1442
1444{
1445 template <class OffsetsT, class ConnectivityT>
1446 void operator()(OffsetsT* vtkNotUsed(offsets), ConnectivityT* conn, vtkIdType id)
1447 {
1448 using ValueType = GetAPIType<ConnectivityT>;
1449 using AccessorType = vtkDataArrayAccessor<ConnectivityT>;
1450 AccessorType accessor(conn);
1451 accessor.InsertNext(static_cast<ValueType>(id));
1452 }
1453};
1454
1455VTK_ABI_NAMESPACE_END
1456} // end namespace vtkCellArray_detail
1457
1458VTK_ABI_NAMESPACE_BEGIN
1459//----------------------------------------------------------------------------
1461{
1462 this->TraversalCellId = 0;
1463}
1464
1465//----------------------------------------------------------------------------
1466inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1467{
1468 if (this->TraversalCellId < this->GetNumberOfCells())
1469 {
1470 this->GetCellAtId(this->TraversalCellId, npts, pts);
1471 ++this->TraversalCellId;
1472 return 1;
1473 }
1474
1475 npts = 0;
1476 pts = nullptr;
1477 return 0;
1478}
1479
1480//----------------------------------------------------------------------------
1482{
1484 {
1485 this->GetCellAtId(this->TraversalCellId, pts);
1486 ++this->TraversalCellId;
1487 return 1;
1488 }
1489
1490 pts->Reset();
1491 return 0;
1492}
1493//----------------------------------------------------------------------------
1495{
1496 vtkIdType cellSize;
1497 this->Dispatch(vtkCellArray_detail::GetCellSizeImpl{}, cellId, cellSize);
1498 return cellSize;
1499}
1500
1501//----------------------------------------------------------------------------
1502void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1503 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1504{
1505 this->Dispatch(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1506}
1507
1508//----------------------------------------------------------------------------
1510{
1511 this->Dispatch(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1512}
1513
1514//----------------------------------------------------------------------------
1515void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1516{
1517 this->Dispatch(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1518}
1519
1520//----------------------------------------------------------------------------
1522{
1523 vtkIdType pointId;
1524 this->Dispatch(vtkCellArray_detail::CellPointAtIdImpl{}, cellId, cellPointIndex, pointId);
1525 return pointId;
1526}
1527
1528//----------------------------------------------------------------------------
1530{
1531 vtkIdType cellId;
1532 this->Dispatch(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts, cellId);
1533 return cellId;
1534}
1535
1536//----------------------------------------------------------------------------
1538{
1539 vtkIdType cellId;
1541 return cellId;
1542}
1543
1544//----------------------------------------------------------------------------
1549
1550//----------------------------------------------------------------------------
1552{
1554}
1555
1556//----------------------------------------------------------------------------
1558{
1559 vtkIdType cellId;
1560 this->Dispatch(
1562 return cellId;
1563}
1564
1565//----------------------------------------------------------------------------
1567{
1568 vtkIdList* pts = cell->GetPointIds();
1569 vtkIdType cellId;
1570 this->Dispatch(
1572 return cellId;
1573}
1574
1575//----------------------------------------------------------------------------
1577{
1579}
1580
1581VTK_ABI_NAMESPACE_END
1582#endif // vtkCellArray.h
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.
virtual vtkIdType GetCellSize(vtkIdType cellId) const =0
Return the size of 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.
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)
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.
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.:
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.
void Reset()
Reuse list.
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
Return the array used to store cell offsets.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
vtkIdType TraversalCellId
void UseFixedSize64BitStorage(vtkIdType cellSize)
Initialize internal data structures to use 32- or 64-bit storage.
void InitTraversal()
bool IsStorageShareable() const override
bool IsStorageGeneric() 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.
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.
~vtkCellArray() override
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
Return the array used to store cell offsets.
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
Return the array used to store cell offsets.
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.
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.
bool ConvertToFixedSize32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
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.:
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.
StorageTypes StorageType
int GetMaxCellSize() override
Returns the size of the largest cell.
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
void Dispatch(Functor &&functor, Args &&... args)
AOSArray32 * GetOffsetsAOSArray32() const
Return the array used to store cell offsets.
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.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
void Dispatch(Functor &&functor, Args &&... args) const
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
Definition vtkCell.h:130
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition vtkCell.h:223
static vtkDataArray * FastDownCast(vtkAbstractArray *source)
Perform a fast, safe cast from a vtkAbstractArray to a vtkDataArray.
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 GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:185
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:295
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
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
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
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
typename ArrayType::ValueType ValueType
ArrayType * GetConnectivity()
void operator()(OffsetsT *offsets, ConnectivityT *conn, vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType &pointId)
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdList *ids)
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType *cellPoints)
std::enable_if_t< CanShareConnPtr< ConnectivityT >::value, void > operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
std::enable_if_t<!CanShareConnPtr< ConnectivityT >::value, void > operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
void operator()(OffsetsT *offsets, ConnectivityT *conn, vtkIdType cellId, vtkIdType &cellSize)
void operator()(OffsetsT *offsets, ConnectivityT *conn, vtkIdType id)
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType npts, vtkIdType &cellId)
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType npts, const vtkIdType pts[], vtkIdType &cellId)
void operator()(OffsetsT *offsets, ConnectivityT *conn)
void operator()(OffsetsT *offsets, ConnectivityT *conn, const vtkIdType npts)
Efficient templated access to vtkDataArray.
#define vtkDataArray
STL-compatible iterable ranges that provide access to vtkDataArray elements.
#define VTK_DEPRECATED_IN_9_8_0(reason)
int vtkIdType
Definition vtkType.h:363
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE