VTK  9.5.20250530
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
238#ifndef vtkCellArray_h
239#define vtkCellArray_h
240
241#include "vtkAbstractCellArray.h"
242#include "vtkCommonDataModelModule.h" // For export macro
243#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
244
245#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
246#include "vtkCell.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> // for assert
255#include <initializer_list> // for API
256#include <type_traits> // for std::is_same
257#include <utility> // 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:
288 using ArrayType32 = vtkTypeInt32Array;
289 using ArrayType64 = vtkTypeInt64Array;
290
292
296 static vtkCellArray* New();
298 void PrintSelf(ostream& os, vtkIndent indent) override;
299 void PrintDebug(ostream& os);
301
310 using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
311
323
332 vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
333 {
334 return this->AllocateExact(sz, sz) ? 1 : 0;
335 }
336
346 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
347 {
348 return this->AllocateExact(numCells, numCells * maxCellSize);
349 }
350
360 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
361
372 {
373 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
374 }
375
385 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
386
390 void Initialize() override;
391
395 void Reset();
396
402 void Squeeze();
403
414 bool IsValid();
415
420 {
421 if (this->Storage.Is64Bit())
422 {
423 return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
424 }
425 else
426 {
427 return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
428 }
429 }
430
436 {
437 if (this->Storage.Is64Bit())
438 {
439 return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
440 }
441 else
442 {
443 return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
444 }
445 }
446
451 {
452 if (this->Storage.Is64Bit())
453 {
454 return this->Storage.GetArrays64().Offsets->GetValue(cellId);
455 }
456 else
457 {
458 return this->Storage.GetArrays32().Offsets->GetValue(cellId);
459 }
460 }
461
465 void SetOffset(vtkIdType cellId, vtkIdType offset)
466 {
467 if (this->Storage.Is64Bit())
468 {
469 this->Storage.GetArrays64().Offsets->SetValue(cellId, offset);
470 }
471 else
472 {
473 this->Storage.GetArrays32().Offsets->SetValue(cellId, offset);
474 }
475 }
476
484 {
485 if (this->Storage.Is64Bit())
486 {
487 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
488 }
489 else
490 {
491 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
492 }
493 }
494
501
512 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
517 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
518 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
533 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
534
548 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
549
554 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
555
562 bool IsStorageShareable() const override
563 {
564 if (this->Storage.Is64Bit())
565 {
567 }
568 else
569 {
571 }
572 }
573
628 {
629 if (this->Storage.Is64Bit())
630 {
631 return this->GetOffsetsArray64();
632 }
633 else
634 {
635 return this->GetOffsetsArray32();
636 }
637 }
649 {
650 if (this->Storage.Is64Bit())
651 {
652 return this->GetConnectivityArray64();
653 }
654 else
655 {
656 return this->GetConnectivityArray32();
657 }
658 }
672
682 void InitTraversal();
683
698 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
699
710 int GetNextCell(vtkIdList* pts);
711
722 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
723 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
724 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
725
731 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
732 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
733
741 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints) VTK_SIZEHINT(
742 cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
743
747 vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
748 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells())
749 VTK_EXPECTS(0 <= cellPointIndex && cellPointIndex < this->GetCellSize(cellId));
750
754 vtkIdType GetCellSize(vtkIdType cellId) const override;
755
759 vtkIdType InsertNextCell(vtkCell* cell);
760
765 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
766
771 vtkIdType InsertNextCell(vtkIdList* pts);
772
780 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
781 {
782 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
783 }
784
791 vtkIdType InsertNextCell(int npts);
792
797 void InsertCellPoint(vtkIdType id);
798
803 void UpdateCellCount(int npts);
804
819 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
820
830 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
831 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
841 void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
842
850 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
851 {
852 this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
853 }
854
859 int GetMaxCellSize() override;
860
864 void DeepCopy(vtkAbstractCellArray* ca) override;
865
870
874 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
875
887
900 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
914 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
915 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
916 VTK_SIZEHINT(data, len);
927 unsigned long GetActualMemorySize() const;
928
929 // The following code is used to support
930
931 // The wrappers get understandably confused by some of the template code below
932#ifndef __VTK_WRAP__
933
934 // Holds connectivity and offset arrays of the given ArrayType.
935 template <typename ArrayT>
937 {
938 using ArrayType = ArrayT;
939 using ValueType = typename ArrayType::ValueType;
940 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
941
942 // We can't just use is_same here, since binary compatible representations
943 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
944 // is a signed integer the same size as vtkIdType.
945 // If this value is true, ValueType pointers may be safely converted to
946 // vtkIdType pointers via reinterpret cast.
947 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
948 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
949
950 ArrayType* GetOffsets() { return this->Offsets; }
951 const ArrayType* GetOffsets() const { return this->Offsets; }
952
953 ArrayType* GetConnectivity() { return this->Connectivity; }
954 const ArrayType* GetConnectivity() const { return this->Connectivity; }
955
957
959
961
963
965
966 friend class vtkCellArray;
967
968 protected:
970 {
971 this->Connectivity = vtkSmartPointer<ArrayType>::New();
972 this->Offsets = vtkSmartPointer<ArrayType>::New();
973 this->Offsets->InsertNextValue(0);
975 {
976 this->IsInMemkind = true;
977 }
978 }
979 ~VisitState() = default;
980 void* operator new(size_t nSize)
981 {
982 void* r;
983#ifdef VTK_USE_MEMKIND
985#else
986 r = malloc(nSize);
987#endif
988 return r;
989 }
990 void operator delete(void* p)
991 {
992#ifdef VTK_USE_MEMKIND
993 VisitState* a = static_cast<VisitState*>(p);
994 if (a->IsInMemkind)
995 {
997 }
998 else
999 {
1000 free(p);
1001 }
1002#else
1003 free(p);
1004#endif
1005 }
1006
1009
1010 private:
1011 VisitState(const VisitState&) = delete;
1012 VisitState& operator=(const VisitState&) = delete;
1013 bool IsInMemkind = false;
1014 };
1015
1016private: // Helpers that allow Visit to return a value:
1017 template <typename Functor, typename... Args>
1018 using GetReturnType = decltype(std::declval<Functor>()(
1019 std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
1020
1021 template <typename Functor, typename... Args>
1022 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1023 {
1024 };
1025
1026public:
1096 template <typename Functor, typename... Args,
1097 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1098 void Visit(Functor&& functor, Args&&... args)
1099 {
1100 if (this->Storage.Is64Bit())
1101 {
1102 // If you get an error on the next line, a call to Visit(functor, Args...)
1103 // is being called with arguments that do not match the functor's call
1104 // signature. See the Visit documentation for details.
1105 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1106 }
1107 else
1108 {
1109 // If you get an error on the next line, a call to Visit(functor, Args...)
1110 // is being called with arguments that do not match the functor's call
1111 // signature. See the Visit documentation for details.
1112 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1113 }
1114 }
1115
1116 template <typename Functor, typename... Args,
1117 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1118 void Visit(Functor&& functor, Args&&... args) const
1119 {
1120 if (this->Storage.Is64Bit())
1121 {
1122 // If you get an error on the next line, a call to Visit(functor, Args...)
1123 // is being called with arguments that do not match the functor's call
1124 // signature. See the Visit documentation for details.
1125 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1126 }
1127 else
1128 {
1129 // If you get an error on the next line, a call to Visit(functor, Args...)
1130 // is being called with arguments that do not match the functor's call
1131 // signature. See the Visit documentation for details.
1132 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1133 }
1134 }
1135
1136 template <typename Functor, typename... Args,
1137 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1138 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1139 {
1140 if (this->Storage.Is64Bit())
1141 {
1142 // If you get an error on the next line, a call to Visit(functor, Args...)
1143 // is being called with arguments that do not match the functor's call
1144 // signature. See the Visit documentation for details.
1145 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1146 }
1147 else
1148 {
1149 // If you get an error on the next line, a call to Visit(functor, Args...)
1150 // is being called with arguments that do not match the functor's call
1151 // signature. See the Visit documentation for details.
1152 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1153 }
1154 }
1155 template <typename Functor, typename... Args,
1156 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1157 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1158 {
1159 if (this->Storage.Is64Bit())
1160 {
1161 // If you get an error on the next line, a call to Visit(functor, Args...)
1162 // is being called with arguments that do not match the functor's call
1163 // signature. See the Visit documentation for details.
1164 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1165 }
1166 else
1167 {
1168 // If you get an error on the next line, a call to Visit(functor, Args...)
1169 // is being called with arguments that do not match the functor's call
1170 // signature. See the Visit documentation for details.
1171 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1172 }
1173 }
1174
1175#endif // __VTK_WRAP__
1176
1189 //=================== Begin Legacy Methods ===================================
1190 // These should be deprecated at some point as they are confusing or very slow
1191
1199
1211 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1212
1222
1230
1240 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1241 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1242
1249 void GetCell(vtkIdType loc, vtkIdList* pts)
1250 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1251
1258 vtkIdType GetInsertLocation(int npts);
1259
1267 vtkIdType GetTraversalLocation();
1268 vtkIdType GetTraversalLocation(vtkIdType npts);
1269 void SetTraversalLocation(vtkIdType loc);
1279 void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1280
1292 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1293 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1294
1309 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1310
1321 vtkIdTypeArray* GetData();
1322
1323 //=================== End Legacy Methods =====================================
1324
1326
1327protected:
1329 ~vtkCellArray() override;
1330
1331 // Encapsulates storage of the internal arrays as a discriminated union
1332 // between 32-bit and 64-bit storage.
1333 struct Storage
1334 {
1335 // Union type that switches 32 and 64 bit array storage
1337 {
1338 ArraySwitch() = default; // handled by Storage
1339 ~ArraySwitch() = default; // handle by Storage
1342 };
1343
1345 {
1346#ifdef VTK_USE_MEMKIND
1347 this->Arrays =
1349#else
1350 this->Arrays = new ArraySwitch;
1351#endif
1352
1353 // Default can be changed, to save memory
1355 {
1356 this->Arrays->Int64 = new VisitState<ArrayType64>;
1357 this->StorageIs64Bit = true;
1358 }
1359 else
1360 {
1361 this->Arrays->Int32 = new VisitState<ArrayType32>;
1362 this->StorageIs64Bit = false;
1363 }
1364
1365#ifdef VTK_USE_MEMKIND
1367 {
1368 this->IsInMemkind = true;
1369 }
1370#else
1371 (void)this->IsInMemkind; // comp warning workaround
1372#endif
1373 }
1374
1376 {
1377 if (this->StorageIs64Bit)
1378 {
1379 this->Arrays->Int64->~VisitState();
1380 delete this->Arrays->Int64;
1381 }
1382 else
1383 {
1384 this->Arrays->Int32->~VisitState();
1385 delete this->Arrays->Int32;
1386 }
1387#ifdef VTK_USE_MEMKIND
1388 if (this->IsInMemkind)
1389 {
1391 }
1392 else
1393 {
1394 free(this->Arrays);
1395 }
1396#else
1397 delete this->Arrays;
1398#endif
1399 }
1400
1401 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1402 // true if the storage changes.
1404 {
1405 if (!this->StorageIs64Bit)
1406 {
1407 return false;
1408 }
1409
1410 this->Arrays->Int64->~VisitState();
1411 delete this->Arrays->Int64;
1412 this->Arrays->Int32 = new VisitState<ArrayType32>;
1413 this->StorageIs64Bit = false;
1414
1415 return true;
1416 }
1417
1418 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1419 // true if the storage changes.
1421 {
1422 if (this->StorageIs64Bit)
1423 {
1424 return false;
1425 }
1426
1427 this->Arrays->Int32->~VisitState();
1428 delete this->Arrays->Int32;
1429 this->Arrays->Int64 = new VisitState<ArrayType64>;
1430 this->StorageIs64Bit = true;
1431
1432 return true;
1433 }
1434
1435 // Returns true if the storage is currently configured to be 64 bit.
1436 bool Is64Bit() const { return this->StorageIs64Bit; }
1437
1438 // Get the VisitState for 32-bit arrays
1440 {
1441 assert(!this->StorageIs64Bit);
1442 return *this->Arrays->Int32;
1443 }
1444
1446 {
1447 assert(!this->StorageIs64Bit);
1448 return *this->Arrays->Int32;
1449 }
1450
1451 // Get the VisitState for 64-bit arrays
1453 {
1454 assert(this->StorageIs64Bit);
1455 return *this->Arrays->Int64;
1456 }
1457
1459 {
1460 assert(this->StorageIs64Bit);
1461 return *this->Arrays->Int64;
1462 }
1463
1464 private:
1465 // Access restricted to ensure proper union construction/destruction thru
1466 // API.
1467 ArraySwitch* Arrays;
1468 bool StorageIs64Bit;
1469 bool IsInMemkind = false;
1470 };
1471
1473 vtkIdType TraversalCellId{ 0 };
1474
1476
1478
1479private:
1480 vtkCellArray(const vtkCellArray&) = delete;
1481 void operator=(const vtkCellArray&) = delete;
1482};
1483
1484template <typename ArrayT>
1486{
1487 return this->Offsets->GetNumberOfValues() - 1;
1488}
1489
1490template <typename ArrayT>
1492{
1493 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1494}
1495
1496template <typename ArrayT>
1498{
1499 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1500}
1501
1502template <typename ArrayT>
1504{
1505 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1506}
1507
1508template <typename ArrayT>
1511{
1512 return vtk::DataArrayValueRange<1>(
1513 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1514}
1515VTK_ABI_NAMESPACE_END
1516
1518{
1519VTK_ABI_NAMESPACE_BEGIN
1520
1522{
1523 // Insert full cell
1524 template <typename CellStateT>
1525 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1526 {
1527 using ValueType = typename CellStateT::ValueType;
1528 auto* conn = state.GetConnectivity();
1529 auto* offsets = state.GetOffsets();
1530
1531 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1532
1533 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1534
1535 for (vtkIdType i = 0; i < npts; ++i)
1536 {
1537 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1538 }
1539
1540 return cellId;
1541 }
1542
1543 // Just update offset table (for incremental API)
1544 template <typename CellStateT>
1545 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1546 {
1547 using ValueType = typename CellStateT::ValueType;
1548 auto* conn = state.GetConnectivity();
1549 auto* offsets = state.GetOffsets();
1550
1551 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1552
1553 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1554
1555 return cellId;
1556 }
1557};
1558
1559// for incremental API:
1561{
1562 template <typename CellStateT>
1563 void operator()(CellStateT& state, const vtkIdType npts)
1564 {
1565 using ValueType = typename CellStateT::ValueType;
1566
1567 auto* offsets = state.GetOffsets();
1568 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1569 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1570 }
1571};
1572
1574{
1575 template <typename CellStateT>
1576 vtkIdType operator()(CellStateT& state, vtkIdType cellId)
1577 {
1578 return state.GetCellSize(cellId);
1579 }
1580};
1581
1583{
1584 template <typename CellStateT>
1585 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1586 {
1587 using ValueType = typename CellStateT::ValueType;
1588
1589 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1590 const vtkIdType endOffset = state.GetEndOffset(cellId);
1591 const vtkIdType cellSize = endOffset - beginOffset;
1592 const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1593
1594 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1595 ids->SetNumberOfIds(cellSize);
1596 vtkIdType* idPtr = ids->GetPointer(0);
1597 for (ValueType i = 0; i < cellSize; ++i)
1598 {
1599 idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1600 }
1601 }
1602
1603 template <typename CellStateT>
1605 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1606 {
1607 using ValueType = typename CellStateT::ValueType;
1608
1609 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1610 const vtkIdType endOffset = state.GetEndOffset(cellId);
1611 cellSize = endOffset - beginOffset;
1612 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1613
1614 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1615 for (vtkIdType i = 0; i < cellSize; ++i)
1616 {
1617 cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1618 }
1619 }
1620
1621 // SFINAE helper to check if a VisitState's connectivity array's memory
1622 // can be used as a vtkIdType*.
1623 template <typename CellStateT>
1625 {
1626 private:
1627 using ValueType = typename CellStateT::ValueType;
1628 using ArrayType = typename CellStateT::ArrayType;
1630 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1631 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1632
1633 public:
1634 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1635 };
1636
1637 template <typename CellStateT>
1638 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
1639 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1640 vtkIdList* vtkNotUsed(temp))
1641 {
1642 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1643 const vtkIdType endOffset = state.GetEndOffset(cellId);
1644 cellSize = endOffset - beginOffset;
1645 // This is safe, see CanShareConnPtr helper above.
1646 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1647 }
1648
1649 template <typename CellStateT>
1650 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
1651 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1652 vtkIdList* temp)
1653 {
1654 using ValueType = typename CellStateT::ValueType;
1655
1656 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1657 const vtkIdType endOffset = state.GetEndOffset(cellId);
1658 cellSize = endOffset - beginOffset;
1659 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1660
1661 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1662 temp->SetNumberOfIds(cellSize);
1663 vtkIdType* tempPtr = temp->GetPointer(0);
1664 for (vtkIdType i = 0; i < cellSize; ++i)
1665 {
1666 tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1667 }
1668
1669 cellPoints = temp->GetPointer(0);
1670 }
1671};
1672
1674{
1675 template <typename CellStateT>
1676 vtkIdType operator()(CellStateT& cells, vtkIdType cellId, vtkIdType cellPointIndex) const
1677 {
1678 return static_cast<vtkIdType>(
1679 cells.GetConnectivity()->GetValue(cells.GetBeginOffset(cellId) + cellPointIndex));
1680 }
1681};
1682
1684{
1685 template <typename CellStateT>
1686 void operator()(CellStateT& state)
1687 {
1688 state.GetOffsets()->Reset();
1689 state.GetConnectivity()->Reset();
1690 state.GetOffsets()->InsertNextValue(0);
1691 }
1692};
1693
1694VTK_ABI_NAMESPACE_END
1695} // end namespace vtkCellArray_detail
1696
1697VTK_ABI_NAMESPACE_BEGIN
1698//----------------------------------------------------------------------------
1700{
1701 this->TraversalCellId = 0;
1702}
1703
1704//----------------------------------------------------------------------------
1705inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1706{
1707 if (this->TraversalCellId < this->GetNumberOfCells())
1708 {
1709 this->GetCellAtId(this->TraversalCellId, npts, pts);
1710 ++this->TraversalCellId;
1711 return 1;
1712 }
1713
1714 npts = 0;
1715 pts = nullptr;
1716 return 0;
1717}
1718
1719//----------------------------------------------------------------------------
1721{
1722 if (this->TraversalCellId < this->GetNumberOfCells())
1723 {
1724 this->GetCellAtId(this->TraversalCellId, pts);
1725 ++this->TraversalCellId;
1726 return 1;
1727 }
1728
1729 pts->Reset();
1730 return 0;
1731}
1732//----------------------------------------------------------------------------
1734{
1735 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1736}
1737
1738//----------------------------------------------------------------------------
1739inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1740 vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1741{
1742 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1743}
1744
1745//----------------------------------------------------------------------------
1747{
1748 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1749}
1750
1751//----------------------------------------------------------------------------
1752inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1753{
1754 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1755}
1756
1757//----------------------------------------------------------------------------
1759{
1760 return this->Visit(vtkCellArray_detail::CellPointAtIdImpl{}, cellId, cellPointIndex);
1761}
1762
1763//----------------------------------------------------------------------------
1765 VTK_SIZEHINT(pts, npts)
1766{
1767 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1768}
1769
1770//----------------------------------------------------------------------------
1772{
1773 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1774}
1775
1776//----------------------------------------------------------------------------
1778{
1779 if (this->Storage.Is64Bit())
1780 {
1781 using ValueType = typename ArrayType64::ValueType;
1782 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1783 }
1784 else
1785 {
1786 using ValueType = typename ArrayType32::ValueType;
1787 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1788 }
1789}
1790
1791//----------------------------------------------------------------------------
1793{
1795}
1796
1797//----------------------------------------------------------------------------
1799{
1800 return this->Visit(
1802}
1803
1804//----------------------------------------------------------------------------
1806{
1807 vtkIdList* pts = cell->GetPointIds();
1808 return this->Visit(
1810}
1811
1812//----------------------------------------------------------------------------
1814{
1816}
1817
1818VTK_ABI_NAMESPACE_END
1819#endif // vtkCellArray.h
Array-Of-Structs implementation of vtkGenericDataArray.
abstract object to represent cell connectivity
virtual vtkIdType GetNumberOfCells() const =0
Get the number of cells in the array.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
vtkIdType GetCellSize(vtkIdType cellId) const override
Return the size of the cell at cellId.
void SetData(vtkAOSDataArrayTemplate< int > *offsets, vtkAOSDataArrayTemplate< int > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)
vtkIdType IsHomogeneous() override
Check if all cells have the same number of vertices.
vtkIdType GetOffset(vtkIdType cellId) override
Get the offset (into the connectivity) for a specified cell id.
vtkIdType GetNumberOfConnectivityEntries()
Return the size of the array that would be returned from ExportLegacyFormat().
void SetData(vtkTypeInt32Array *offsets, vtkTypeInt32Array *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
void AppendLegacyFormat(vtkIdTypeArray *data, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
static void SetDefaultStorageIs64Bit(bool val)
Control the default internal storage size.
void DeepCopy(vtkAbstractCellArray *ca) override
Perform a deep copy (no reference counting) of the given cell array.
bool IsValid()
Check that internal storage is consistent and in a valid state.
void AppendLegacyFormat(const vtkIdType *data, vtkIdType len, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
bool SetData(vtkIdType cellSize, vtkDataArray *connectivity)
Sets the internal arrays to the supported connectivity array with an offsets array automatically gene...
void ShallowCopy(vtkAbstractCellArray *ca) override
Shallow copy ca into this cell array.
vtkIdType GetNumberOfOffsets() const override
Get the number of elements in the offsets array.
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
void Reset()
Reuse list.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
vtkIdType GetNumberOfConnectivityIds() const override
Get the size of the connectivity array that stores the point ids.
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
void SetData(vtkAOSDataArrayTemplate< long long > *offsets, vtkAOSDataArrayTemplate< long long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize)
Pre-allocate memory in internal data structures.
bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize)
ResizeExact() resizes the internal structures to hold numCells total cell offsets and connectivitySiz...
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
vtkTypeInt64Array ArrayType64
vtkIdType TraversalCellId
void InitTraversal()
bool IsStorageShareable() const override
void Use64BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
bool ConvertToDefaultStorage()
Convert internal data structures to use 32- or 64-bit storage.
bool CanConvertToDefaultStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
static bool DefaultStorageIs64Bit
void GetCell(vtkIdType loc, vtkIdType &npts, const vtkIdType *&pts)
Internal method used to retrieve a cell given a legacy offset location.
bool CanConvertTo32BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *ptIds) override
Return the point ids for the cell at cellId.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
void ReplaceCellAtId(vtkIdType cellId, vtkIdList *list)
Replaces the point ids for the specified cell with the supplied list.
void ReverseCellAtId(vtkIdType cellId)
Reverses the order of the point ids for the specified cell.
bool SetData(vtkDataArray *offsets, vtkDataArray *connectivity)
Sets the internal arrays to the supplied offsets and connectivity arrays.
void Initialize() override
Free any memory and reset to an empty state.
void Squeeze()
Reclaim any extra memory while preserving data.
void SetData(vtkIdTypeArray *offsets, vtkIdTypeArray *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool ConvertTo32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
void Visit(Functor &&functor, Args &&... args) const
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
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.
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.
vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
Return the point id at cellPointIndex for the cell at cellId.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > > >::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
void SetTraversalCellId(vtkIdType cellId)
Get/Set the current cellId for traversal.
void SetData(vtkTypeInt64Array *offsets, vtkTypeInt64Array *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
static bool GetDefaultStorageIs64Bit()
Control the default internal storage size.
int GetMaxCellSize() override
Returns the size of the largest cell.
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
vtkNew< vtkIdTypeArray > LegacyData
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
void PrintDebug(ostream &os)
Standard methods for instantiation, type information, and printing.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
bool IsStorage64Bit() const
void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType *cellPoints)
Replaces the point ids for the specified cell with the supplied list.
bool CanConvertTo64BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
abstract class to specify cell behavior
Definition vtkCell.h:130
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition vtkCell.h:228
abstract superclass for arrays of numeric data
list of point or cell ids
Definition vtkIdList.h:133
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:159
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:244
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:225
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:108
Allocate and hold a VTK object.
Definition vtkNew.h:167
static vtkMallocingFunction GetCurrentMallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
VisitState< ArrayType64 > & GetArrays64()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType32 > & GetArrays32()
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
vtkSmartPointer< ArrayType > Connectivity
const ArrayType * GetOffsets() const
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
typename ArrayType::ValueType ValueType
ArrayType * GetConnectivity()
vtkIdType operator()(CellStateT &cells, vtkIdType cellId, vtkIdType cellPointIndex) const
std::enable_if<!CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
std::enable_if< CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *vtkNotUsed(temp))
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType *cellPoints)
vtkIdType operator()(CellStateT &state, vtkIdType cellId)
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
void operator()(CellStateT &state)
void operator()(CellStateT &state, const vtkIdType npts)
Remove all duplicate types from TypeList TList, storing the new list in Result.
VisitState< ArrayType32 > * Int32
VisitState< ArrayType64 > * Int64
int vtkTypeBool
Definition vtkABI.h:64
STL-compatible iterable ranges that provide access to vtkDataArray elements.
int vtkIdType
Definition vtkType.h:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE