VTK  9.7.20260823
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
242
243#ifndef vtkCellArray_h
244#define vtkCellArray_h
245
246#include "vtkAbstractCellArray.h"
247#include "vtkCommonDataModelModule.h" // For export macro
248#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
249
250#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
251#include "vtkAffineArray.h" // Needed for inline methods
252#include "vtkCell.h" // Needed for inline methods
253#include "vtkDataArrayAccessor.h" // Needed for inline methods
254#include "vtkDataArrayRange.h" // Needed for inline methods
255#include "vtkFeatures.h" // for VTK_USE_MEMKIND
256#include "vtkSmartPointer.h" // For vtkSmartPointer
257#include "vtkTypeInt32Array.h" // Needed for inline methods
258#include "vtkTypeInt64Array.h" // Needed for inline methods
259#include "vtkTypeList.h" // Needed for ArrayList definition
260
261#include <cassert> // Needed for assert
262#include <initializer_list> // Needed for API
263#include <type_traits> // Needed for std::is_same
264#include <utility> // Needed for std::forward
265
286#define VTK_CELL_ARRAY_V2
287
288VTK_ABI_NAMESPACE_BEGIN
290class vtkIdTypeArray;
291
292class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkCellArray : public vtkAbstractCellArray
293{
294public:
299
301
305 static vtkCellArray* New();
307 void PrintSelf(ostream& os, vtkIndent indent) override;
308 void PrintDebug(ostream& os);
310
320 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
321 {
322 return this->AllocateExact(numCells, numCells * maxCellSize);
323 }
324
334 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
335
346 {
347 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
348 }
349
359 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
360
364 void Initialize() override;
365
369 void Reset();
370
376 void Squeeze();
377
388 bool IsValid();
389
393 vtkIdType GetNumberOfCells() const override { return this->Offsets->GetNumberOfValues() - 1; }
394
399 vtkIdType GetNumberOfOffsets() const override { return this->Offsets->GetNumberOfValues(); }
400
405 {
406 return static_cast<vtkIdType>(this->Offsets->GetComponent(cellId, 0));
407 }
408
412 void SetOffset(vtkIdType cellId, vtkIdType offset)
413 {
414 this->Offsets->SetComponent(cellId, 0, static_cast<double>(offset));
415 }
416
421 {
422 return this->Connectivity->GetNumberOfValues();
423 }
424
431
433
446 void SetData(AOSArray32*, AOSArray32* connectivity);
447 void SetData(AOSArray64*, AOSArray64* connectivity);
448 void SetData(AffineArray32*, AOSArray32* connectivity);
449 void SetData(AffineArray64*, AOSArray64* connectivity);
451
466 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
467
485 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
486
495
499 StorageTypes GetStorageType() const noexcept { return this->StorageType; }
500
504 bool IsStorage64Bit() const { return this->StorageType == StorageTypes::Int64; }
505
509 bool IsStorage32Bit() const { return this->StorageType == StorageTypes::Int32; }
510
515
520
525 {
526 return this->IsStorageFixedSize32Bit() || this->IsStorageFixedSize64Bit();
527 }
528
532 bool IsStorageGeneric() const { return this->StorageType == StorageTypes::Generic; }
533
540 bool IsStorageShareable() const override
541 {
542 switch (this->StorageType)
543 {
546 return std::is_same_v<vtkTypeInt32, vtkIdType>;
549 return std::is_same_v<vtkTypeInt64, vtkIdType>;
551 default:
552 return false;
553 }
554 }
555
557
571
573
587 {
588 switch (type)
589 {
591 return this->CanConvertTo32BitStorage();
593 return this->CanConvertTo64BitStorage();
599 default:
600 return true;
601 }
602 }
603
604
606
628 {
629 switch (type)
630 {
632 return this->ConvertTo32BitStorage();
634 return this->ConvertTo64BitStorage();
636 return this->ConvertToFixedSize32BitStorage();
638 return this->ConvertToFixedSize64BitStorage();
640 default:
641 return true;
642 }
643 }
644
645
647
666 bool EnsureStorageForCellSize(vtkIdType cellSize);
667
672 vtkDataArray* GetOffsetsArray() const { return this->Offsets; }
683
684
686
700
701
710 vtkIdType IsHomogeneous() const override;
711
721 void InitTraversal();
722
737 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
738
749 int GetNextCell(vtkIdList* pts);
750
761 inline void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
762 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
763 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
764
770 inline void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
771 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
772
780 inline void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
781 VTK_SIZEHINT(cellPoints, cellSize)
782 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
783
787 vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
788 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells())
789 VTK_EXPECTS(0 <= cellPointIndex && cellPointIndex < this->GetCellSize(cellId));
790
794 vtkIdType GetCellSize(vtkIdType cellId) const override;
795
799 inline vtkIdType InsertNextCell(vtkCell* cell);
800
805 inline vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
806
812
820 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
821 {
822 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
823 }
824
831 inline vtkIdType InsertNextCell(int npts);
832
837 void InsertCellPoint(vtkIdType id);
838
843 void UpdateCellCount(int npts);
844
846
855
859 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
860
862
870 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
871 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
873
881 void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
882
890 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
891 {
892 this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
893 }
894
899 int GetMaxCellSize() override;
900
904 void DeepCopy(vtkAbstractCellArray* ca) override;
905
910
914 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
915
927
929
943 bool ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
945
947
960 bool AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
961 bool AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
962 VTK_SIZEHINT(data, len);
964
973 unsigned long GetActualMemorySize() const;
974
975 // The following code is used to support
976
977 // The wrappers get understandably confused by some of the template code below
978#ifndef __VTK_WRAP__
979 /*
980 * Utilities class that every dispatch functor used with Dispatch() must inherit
981 * or optionally use its static methods.
982 */
984 {
985 template <class ArrayT>
987
988 template <class OffsetsT>
989 vtkIdType GetNumberOfCells(OffsetsT* offsets)
990 {
991 return offsets->GetNumberOfValues() - 1;
992 }
993
994 template <class ArrayT>
995 static decltype(vtk::DataArrayValueRange<1, vtkIdType>(std::declval<ArrayT>())) GetRange(
996 ArrayT* array)
997 {
999 }
1000
1001 template <class OffsetsT>
1002 static vtkIdType GetBeginOffset(OffsetsT* offsets, vtkIdType cellId)
1003 {
1004 return static_cast<vtkIdType>(GetRange(offsets)[cellId]);
1005 }
1006
1007 template <class OffsetsT>
1008 static vtkIdType GetEndOffset(OffsetsT* offsets, vtkIdType cellId)
1009 {
1010 return static_cast<vtkIdType>(GetRange(offsets)[cellId + 1]);
1011 }
1012
1013 template <class OffsetsT>
1014 static vtkIdType GetCellSize(OffsetsT* offsets, vtkIdType cellId)
1015 {
1016 auto offsetsRange = GetRange(offsets);
1017 return static_cast<vtkIdType>(offsetsRange[cellId + 1] - offsetsRange[cellId]);
1018 }
1019
1020 template <class OffsetsT, class ConnectivityT>
1021 static decltype(vtk::DataArrayValueRange<1, vtkIdType>(std::declval<ConnectivityT>()))
1022 GetCellRange(OffsetsT* offsets, ConnectivityT* conn, vtkIdType cellId)
1023 {
1024 auto offsetsRange = GetRange(offsets);
1026 conn, offsetsRange[cellId], offsetsRange[cellId + 1]);
1027 }
1028 };
1029
1031
1094 template <typename Functor, typename... Args>
1095 void Dispatch(Functor&& functor, Args&&... args)
1096 {
1097 switch (this->StorageType)
1098 {
1100 functor(static_cast<AOSArray32*>(this->Offsets.Get()),
1101 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1102 break;
1104 functor(static_cast<AOSArray64*>(this->Offsets.Get()),
1105 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1106 break;
1108 functor(static_cast<AffineArray32*>(this->Offsets.Get()),
1109 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1110 break;
1112 functor(static_cast<AffineArray64*>(this->Offsets.Get()),
1113 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1114 break;
1116 default:
1117 functor(this->Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1118 break;
1119 }
1120 }
1121 template <typename Functor, typename... Args>
1122 void Dispatch(Functor&& functor, Args&&... args) const
1123 {
1124 switch (this->StorageType)
1125 {
1127 functor(static_cast<AOSArray32*>(this->Offsets.Get()),
1128 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1129 break;
1131 functor(static_cast<AOSArray64*>(this->Offsets.Get()),
1132 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1133 break;
1135 functor(static_cast<AffineArray32*>(this->Offsets.Get()),
1136 static_cast<AOSArray32*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1137 break;
1139 functor(static_cast<AffineArray64*>(this->Offsets.Get()),
1140 static_cast<AOSArray64*>(this->Connectivity.Get()), std::forward<Args>(args)...);
1141 break;
1143 default:
1144 functor(this->Offsets.Get(), this->Connectivity.Get(), std::forward<Args>(args)...);
1145 break;
1146 }
1147 }
1148
1149
1150 // Holds connectivity and offset arrays of the given ArrayType.
1151 template <typename ArrayT>
1152 struct VTK_DEPRECATED_IN_9_8_0("Use DispatchUtilities") VisitState
1153 {
1154 using ArrayType = ArrayT;
1155 using ValueType = typename ArrayType::ValueType;
1156 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
1157
1158 // We can't just use is_same here, since binary compatible representations
1159 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
1160 // is a signed integer the same size as vtkIdType.
1161 // If this value is true, ValueType pointers may be safely converted to
1162 // vtkIdType pointers via reinterpret cast.
1163 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
1164 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
1165
1166 ArrayType* GetOffsets() { return this->Offsets; }
1167 const ArrayType* GetOffsets() const { return this->Offsets; }
1168
1170 const ArrayType* GetConnectivity() const { return this->Connectivity; }
1171
1173
1174 vtkIdType GetBeginOffset(vtkIdType cellId) const;
1175
1176 vtkIdType GetEndOffset(vtkIdType cellId) const;
1177
1178 vtkIdType GetCellSize(vtkIdType cellId) const;
1179
1180 CellRangeType GetCellRange(vtkIdType cellId);
1181
1182 friend class vtkCellArray;
1183
1184 protected:
1186 {
1189 this->Offsets->InsertNextValue(0);
1191 {
1192 this->IsInMemkind = true;
1193 }
1194 }
1195 ~VisitState() = default;
1196 void* operator new(size_t nSize)
1197 {
1198 void* r;
1199#ifdef VTK_USE_MEMKIND
1201#else
1202 r = malloc(nSize);
1203#endif
1204 return r;
1205 }
1206 void operator delete(void* p)
1207 {
1208#ifdef VTK_USE_MEMKIND
1209 VisitState* a = static_cast<VisitState*>(p);
1210 if (a->IsInMemkind)
1211 {
1213 }
1214 else
1215 {
1216 free(p);
1217 }
1218#else
1219 free(p);
1220#endif
1221 }
1222
1225
1226 private:
1227 VisitState(const VisitState&) = delete;
1228 VisitState& operator=(const VisitState&) = delete;
1229 bool IsInMemkind = false;
1230 };
1231
1232private: // Helpers that allow Visit to return a value:
1233 template <typename Functor, typename... Args>
1234 using GetReturnType = decltype(std::declval<Functor>()(
1235 std::declval<VisitState<AOSArray32>&>(), std::declval<Args>()...));
1236
1237 template <typename Functor, typename... Args>
1238 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1239 {
1240 };
1241#endif // __VTK_WRAP__
1242
1243public:
1245
1253
1255
1256protected:
1258 ~vtkCellArray() override;
1259
1264
1266
1267private:
1268 vtkCellArray(const vtkCellArray&) = delete;
1269 void operator=(const vtkCellArray&) = delete;
1270};
1271
1272template <typename ArrayT>
1274{
1275 return this->Offsets->GetNumberOfValues() - 1;
1276}
1277
1278template <typename ArrayT>
1280{
1281 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1282}
1283
1284template <typename ArrayT>
1286{
1287 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1288}
1289
1290template <typename ArrayT>
1292{
1293 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1294}
1295
1296template <typename ArrayT>
1303VTK_ABI_NAMESPACE_END
1304
1306{
1307VTK_ABI_NAMESPACE_BEGIN
1308
1310{
1311 // Insert full cell
1312 template <class OffsetsT, class ConnectivityT>
1313 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType npts,
1314 const vtkIdType pts[], vtkIdType& cellId)
1315 {
1316 using ValueType = GetAPIType<OffsetsT>;
1317 using OffsetsAccessorType = vtkDataArrayAccessor<OffsetsT>;
1318 using ConnectivityAccessorType = vtkDataArrayAccessor<ConnectivityT>;
1319 OffsetsAccessorType offsetsAccesor(offsets);
1320 ConnectivityAccessorType connAccesor(conn);
1321
1322 cellId = offsets->GetNumberOfValues() - 1;
1323
1324 offsetsAccesor.InsertNext(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1325
1326 for (vtkIdType i = 0; i < npts; ++i)
1327 {
1328 connAccesor.InsertNext(static_cast<ValueType>(pts[i]));
1329 }
1330 }
1331
1332 // Just update offset table (for incremental API)
1333 template <class OffsetsT, class ConnectivityT>
1334 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType npts, vtkIdType& cellId)
1335 {
1336 using ValueType = GetAPIType<OffsetsT>;
1337 using AccessorType = vtkDataArrayAccessor<OffsetsT>;
1338 AccessorType offsetsAccesor(offsets);
1339
1340 cellId = offsets->GetNumberOfValues() - 1;
1341
1342 offsetsAccesor.InsertNext(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1343 }
1344};
1345
1346// for incremental API:
1348{
1349 template <class OffsetsT, class ConnectivityT>
1350 void operator()(OffsetsT* offsets, ConnectivityT* vtkNotUsed(conn), const vtkIdType npts)
1351 {
1352 using ValueType = GetAPIType<OffsetsT>;
1353
1354 auto offsetsRange = GetRange(offsets);
1355 const ValueType cellBegin = offsetsRange[offsets->GetMaxId() - 1];
1356 offsetsRange[offsets->GetMaxId()] = static_cast<ValueType>(cellBegin + npts);
1357 }
1358};
1359
1361{
1362 template <class OffsetsT, class ConnectivityT>
1364 OffsetsT* offsets, ConnectivityT* vtkNotUsed(conn), vtkIdType cellId, vtkIdType& cellSize)
1365 {
1366 cellSize = GetCellSize(offsets, cellId);
1367 }
1368};
1369
1371{
1372 template <class OffsetsT, class ConnectivityT>
1373 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId, vtkIdList* ids)
1374 {
1375 auto offsetsRange = GetRange(offsets);
1376 const auto& beginOffset = offsetsRange[cellId];
1377 const auto& endOffset = offsetsRange[cellId + 1];
1378 const vtkIdType cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1379 const auto cellConnectivity = GetRange(conn).begin() + beginOffset;
1380
1381 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1382 ids->SetNumberOfIds(cellSize);
1383 vtkIdType* idPtr = ids->GetPointer(0);
1384 for (vtkIdType i = 0; i < cellSize; ++i)
1385 {
1386 idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1387 }
1388 }
1389
1390 template <class OffsetsT, class ConnectivityT>
1391 void operator()(OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId,
1392 vtkIdType& cellSize, vtkIdType* cellPoints)
1393 {
1394 auto offsetsRange = GetRange(offsets);
1395 const auto& beginOffset = offsetsRange[cellId];
1396 const auto& endOffset = offsetsRange[cellId + 1];
1397 cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1398 const auto cellConnectivity = GetRange(conn).begin() + beginOffset;
1399
1400 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1401 for (vtkIdType i = 0; i < cellSize; ++i)
1402 {
1403 cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1404 }
1405 }
1406
1407 // SFINAE helper to check if a Functors's connectivity array's memory can be used as a vtkIdType*.
1408 template <typename ConnectivityT>
1410 {
1411 static constexpr bool value =
1412 std::is_base_of_v<vtkAOSDataArrayTemplate<vtkIdType>, ConnectivityT>;
1413 };
1414
1415 template <class OffsetsT, class ConnectivityT>
1416 typename std::enable_if_t<CanShareConnPtr<ConnectivityT>::value, void> operator()(
1417 OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId, vtkIdType& cellSize,
1418 vtkIdType const*& cellPoints, vtkIdList* vtkNotUsed(temp))
1419 {
1420 auto offsetsRange = GetRange(offsets);
1421 const auto& beginOffset = offsetsRange[cellId];
1422 const auto& endOffset = offsetsRange[cellId + 1];
1423 cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1424 // This is safe, see CanShareConnPtr helper above.
1425 cellPoints = conn->GetPointer(beginOffset);
1426 }
1427
1428 template <class OffsetsT, class ConnectivityT>
1429 typename std::enable_if_t<!CanShareConnPtr<ConnectivityT>::value, void> operator()(
1430 OffsetsT* offsets, ConnectivityT* conn, const vtkIdType cellId, vtkIdType& cellSize,
1431 vtkIdType const*& cellPoints, vtkIdList* temp)
1432 {
1433 auto offsetsRange = GetRange(offsets);
1434 const auto& beginOffset = offsetsRange[cellId];
1435 const auto& endOffset = offsetsRange[cellId + 1];
1436 cellSize = static_cast<vtkIdType>(endOffset - beginOffset);
1437 const auto cellConnectivity = GetRange(conn).begin() + beginOffset;
1438
1439 temp->SetNumberOfIds(cellSize);
1440 vtkIdType* tempPtr = temp->GetPointer(0);
1441 for (vtkIdType i = 0; i < cellSize; ++i)
1442 {
1443 tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1444 }
1445
1446 cellPoints = tempPtr;
1447 }
1448};
1449
1451{
1452 template <class OffsetsT, class ConnectivityT>
1453 void operator()(OffsetsT* offsets, ConnectivityT* conn, vtkIdType cellId,
1454 vtkIdType cellPointIndex, vtkIdType& pointId)
1455 {
1456 pointId =
1457 static_cast<vtkIdType>(GetRange(conn)[GetBeginOffset(offsets, cellId) + cellPointIndex]);
1458 }
1459};
1460
1462{
1463 template <class OffsetsT, class ConnectivityT>
1464 void operator()(OffsetsT* offsets, ConnectivityT* conn)
1465 {
1466 using ValueType = GetAPIType<OffsetsT>;
1467 using AccessorType = vtkDataArrayAccessor<OffsetsT>;
1468 offsets->Reset();
1469 conn->Reset();
1470 AccessorType accessor(offsets);
1471 ValueType firstOffset = 0;
1472 accessor.InsertNext(firstOffset);
1473 }
1474};
1475
1477{
1478 template <class OffsetsT, class ConnectivityT>
1479 void operator()(OffsetsT* vtkNotUsed(offsets), ConnectivityT* conn, vtkIdType id)
1480 {
1481 using ValueType = GetAPIType<ConnectivityT>;
1482 using AccessorType = vtkDataArrayAccessor<ConnectivityT>;
1483 AccessorType accessor(conn);
1484 accessor.InsertNext(static_cast<ValueType>(id));
1485 }
1486};
1487
1488VTK_ABI_NAMESPACE_END
1489} // end namespace vtkCellArray_detail
1490
1491VTK_ABI_NAMESPACE_BEGIN
1492//----------------------------------------------------------------------------
1494{
1495 this->TraversalCellId = 0;
1496}
1497
1498//----------------------------------------------------------------------------
1499inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1500{
1501 if (this->TraversalCellId < this->GetNumberOfCells())
1502 {
1503 this->GetCellAtId(this->TraversalCellId, npts, pts);
1504 ++this->TraversalCellId;
1505 return 1;
1506 }
1507
1508 npts = 0;
1509 pts = nullptr;
1510 return 0;
1511}
1512
1513//----------------------------------------------------------------------------
1515{
1517 {
1518 this->GetCellAtId(this->TraversalCellId, pts);
1519 ++this->TraversalCellId;
1520 return 1;
1521 }
1522
1523 pts->Reset();
1524 return 0;
1525}
1526//----------------------------------------------------------------------------
1528{
1529 vtkIdType cellSize;
1530 this->Dispatch(vtkCellArray_detail::GetCellSizeImpl{}, cellId, cellSize);
1531 return cellSize;
1532}
1533
1534//----------------------------------------------------------------------------
1535void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1536 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1537{
1538 this->Dispatch(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1539}
1540
1541//----------------------------------------------------------------------------
1543{
1544 this->Dispatch(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1545}
1546
1547//----------------------------------------------------------------------------
1548void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1549{
1550 this->Dispatch(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1551}
1552
1553//----------------------------------------------------------------------------
1555{
1556 vtkIdType pointId;
1557 this->Dispatch(vtkCellArray_detail::CellPointAtIdImpl{}, cellId, cellPointIndex, pointId);
1558 return pointId;
1559}
1560
1561//----------------------------------------------------------------------------
1563{
1564 switch (this->StorageType)
1565 {
1567 if (this->GetOffsetsAffineArray32()->GetBackend()->Slope != cellSize)
1568 {
1569 return this->ConvertTo32BitStorage();
1570 }
1571 return true;
1573 if (this->GetOffsetsAffineArray64()->GetBackend()->Slope != cellSize)
1574 {
1575 return this->ConvertTo64BitStorage();
1576 }
1577 return true;
1578 default:
1579 return true;
1580 }
1581}
1582
1583//----------------------------------------------------------------------------
1585 VTK_SIZEHINT(pts, npts)
1586{
1587 this->EnsureStorageForCellSize(npts);
1588 vtkIdType cellId;
1589 this->Dispatch(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts, cellId);
1590 return cellId;
1591}
1592
1593//----------------------------------------------------------------------------
1595{
1596 this->EnsureStorageForCellSize(npts);
1597 vtkIdType cellId;
1599 return cellId;
1600}
1601
1602//----------------------------------------------------------------------------
1607
1608//----------------------------------------------------------------------------
1610{
1611 this->EnsureStorageForCellSize(npts);
1613}
1614
1615//----------------------------------------------------------------------------
1617{
1618 return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
1619}
1620
1621//----------------------------------------------------------------------------
1623{
1624 vtkIdList* pts = cell->GetPointIds();
1625 return this->InsertNextCell(pts->GetNumberOfIds(), pts->GetPointer(0));
1626}
1627
1628//----------------------------------------------------------------------------
1630{
1632}
1633
1634VTK_ABI_NAMESPACE_END
1635#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.
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)
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.
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
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.
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
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.
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.
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
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...
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