VTK  9.4.20241121
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
469 {
470 if (this->Storage.Is64Bit())
471 {
472 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
473 }
474 else
475 {
476 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
477 }
478 }
479
486
497 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
502 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
503 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
518 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
519
533 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
534
539 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
540
547 bool IsStorageShareable() const override
548 {
549 if (this->Storage.Is64Bit())
550 {
552 }
553 else
554 {
556 }
557 }
558
613 {
614 if (this->Storage.Is64Bit())
615 {
616 return this->GetOffsetsArray64();
617 }
618 else
619 {
620 return this->GetOffsetsArray32();
621 }
622 }
634 {
635 if (this->Storage.Is64Bit())
636 {
637 return this->GetConnectivityArray64();
638 }
639 else
640 {
641 return this->GetConnectivityArray32();
642 }
643 }
657
667 void InitTraversal();
668
683 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
684
695 int GetNextCell(vtkIdList* pts);
696
707 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
708 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
709 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
710
716 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
717 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
718
726 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints) VTK_SIZEHINT(
727 cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
728
732 vtkIdType GetCellSize(vtkIdType cellId) const override;
733
737 vtkIdType InsertNextCell(vtkCell* cell);
738
743 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
744
749 vtkIdType InsertNextCell(vtkIdList* pts);
750
758 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
759 {
760 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
761 }
762
769 vtkIdType InsertNextCell(int npts);
770
775 void InsertCellPoint(vtkIdType id);
776
781 void UpdateCellCount(int npts);
782
797 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
798
808 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
809 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
819 void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
820
828 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
829 {
830 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
831 }
832
837 int GetMaxCellSize() override;
838
842 void DeepCopy(vtkAbstractCellArray* ca) override;
843
848
852 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
853
865
878 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
892 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
893 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
894 VTK_SIZEHINT(data, len);
905 unsigned long GetActualMemorySize() const;
906
907 // The following code is used to support
908
909 // The wrappers get understandably confused by some of the template code below
910#ifndef __VTK_WRAP__
911
912 // Holds connectivity and offset arrays of the given ArrayType.
913 template <typename ArrayT>
915 {
916 using ArrayType = ArrayT;
917 using ValueType = typename ArrayType::ValueType;
918 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
919
920 // We can't just use is_same here, since binary compatible representations
921 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
922 // is a signed integer the same size as vtkIdType.
923 // If this value is true, ValueType pointers may be safely converted to
924 // vtkIdType pointers via reinterpret cast.
925 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
926 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
927
928 ArrayType* GetOffsets() { return this->Offsets; }
929 const ArrayType* GetOffsets() const { return this->Offsets; }
930
931 ArrayType* GetConnectivity() { return this->Connectivity; }
932 const ArrayType* GetConnectivity() const { return this->Connectivity; }
933
935
937
939
941
943
944 friend class vtkCellArray;
945
946 protected:
948 {
949 this->Connectivity = vtkSmartPointer<ArrayType>::New();
950 this->Offsets = vtkSmartPointer<ArrayType>::New();
951 this->Offsets->InsertNextValue(0);
953 {
954 this->IsInMemkind = true;
955 }
956 }
957 ~VisitState() = default;
958 void* operator new(size_t nSize)
959 {
960 void* r;
961#ifdef VTK_USE_MEMKIND
963#else
964 r = malloc(nSize);
965#endif
966 return r;
967 }
968 void operator delete(void* p)
969 {
970#ifdef VTK_USE_MEMKIND
971 VisitState* a = static_cast<VisitState*>(p);
972 if (a->IsInMemkind)
973 {
975 }
976 else
977 {
978 free(p);
979 }
980#else
981 free(p);
982#endif
983 }
984
987
988 private:
989 VisitState(const VisitState&) = delete;
990 VisitState& operator=(const VisitState&) = delete;
991 bool IsInMemkind = false;
992 };
993
994private: // Helpers that allow Visit to return a value:
995 template <typename Functor, typename... Args>
996 using GetReturnType = decltype(std::declval<Functor>()(
997 std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
998
999 template <typename Functor, typename... Args>
1000 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1001 {
1002 };
1003
1004public:
1074 template <typename Functor, typename... Args,
1075 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1076 void Visit(Functor&& functor, Args&&... args)
1077 {
1078 if (this->Storage.Is64Bit())
1079 {
1080 // If you get an error on the next line, a call to Visit(functor, Args...)
1081 // is being called with arguments that do not match the functor's call
1082 // signature. See the Visit documentation for details.
1083 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1084 }
1085 else
1086 {
1087 // If you get an error on the next line, a call to Visit(functor, Args...)
1088 // is being called with arguments that do not match the functor's call
1089 // signature. See the Visit documentation for details.
1090 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1091 }
1092 }
1093
1094 template <typename Functor, typename... Args,
1095 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1096 void Visit(Functor&& functor, Args&&... args) const
1097 {
1098 if (this->Storage.Is64Bit())
1099 {
1100 // If you get an error on the next line, a call to Visit(functor, Args...)
1101 // is being called with arguments that do not match the functor's call
1102 // signature. See the Visit documentation for details.
1103 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1104 }
1105 else
1106 {
1107 // If you get an error on the next line, a call to Visit(functor, Args...)
1108 // is being called with arguments that do not match the functor's call
1109 // signature. See the Visit documentation for details.
1110 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1111 }
1112 }
1113
1114 template <typename Functor, typename... Args,
1115 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1116 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1117 {
1118 if (this->Storage.Is64Bit())
1119 {
1120 // If you get an error on the next line, a call to Visit(functor, Args...)
1121 // is being called with arguments that do not match the functor's call
1122 // signature. See the Visit documentation for details.
1123 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1124 }
1125 else
1126 {
1127 // If you get an error on the next line, a call to Visit(functor, Args...)
1128 // is being called with arguments that do not match the functor's call
1129 // signature. See the Visit documentation for details.
1130 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1131 }
1132 }
1133 template <typename Functor, typename... Args,
1134 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1135 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1136 {
1137 if (this->Storage.Is64Bit())
1138 {
1139 // If you get an error on the next line, a call to Visit(functor, Args...)
1140 // is being called with arguments that do not match the functor's call
1141 // signature. See the Visit documentation for details.
1142 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1143 }
1144 else
1145 {
1146 // If you get an error on the next line, a call to Visit(functor, Args...)
1147 // is being called with arguments that do not match the functor's call
1148 // signature. See the Visit documentation for details.
1149 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1150 }
1151 }
1152
1165#endif // __VTK_WRAP__
1166
1167 //=================== Begin Legacy Methods ===================================
1168 // These should be deprecated at some point as they are confusing or very slow
1169
1177
1189 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1190
1200
1208
1218 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1219 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1220
1227 void GetCell(vtkIdType loc, vtkIdList* pts)
1228 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1229
1236 vtkIdType GetInsertLocation(int npts);
1237
1245 vtkIdType GetTraversalLocation();
1246 vtkIdType GetTraversalLocation(vtkIdType npts);
1247 void SetTraversalLocation(vtkIdType loc);
1257 void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1258
1270 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1271 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1272
1287 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1288
1299 vtkIdTypeArray* GetData();
1300
1301 //=================== End Legacy Methods =====================================
1302
1304
1305protected:
1307 ~vtkCellArray() override;
1308
1309 // Encapsulates storage of the internal arrays as a discriminated union
1310 // between 32-bit and 64-bit storage.
1311 struct Storage
1312 {
1313 // Union type that switches 32 and 64 bit array storage
1315 {
1316 ArraySwitch() = default; // handled by Storage
1317 ~ArraySwitch() = default; // handle by Storage
1320 };
1321
1323 {
1324#ifdef VTK_USE_MEMKIND
1325 this->Arrays =
1327#else
1328 this->Arrays = new ArraySwitch;
1329#endif
1330
1331 // Default can be changed, to save memory
1333 {
1334 this->Arrays->Int64 = new VisitState<ArrayType64>;
1335 this->StorageIs64Bit = true;
1336 }
1337 else
1338 {
1339 this->Arrays->Int32 = new VisitState<ArrayType32>;
1340 this->StorageIs64Bit = false;
1341 }
1342
1343#ifdef VTK_USE_MEMKIND
1345 {
1346 this->IsInMemkind = true;
1347 }
1348#else
1349 (void)this->IsInMemkind; // comp warning workaround
1350#endif
1351 }
1352
1354 {
1355 if (this->StorageIs64Bit)
1356 {
1357 this->Arrays->Int64->~VisitState();
1358 delete this->Arrays->Int64;
1359 }
1360 else
1361 {
1362 this->Arrays->Int32->~VisitState();
1363 delete this->Arrays->Int32;
1364 }
1365#ifdef VTK_USE_MEMKIND
1366 if (this->IsInMemkind)
1367 {
1369 }
1370 else
1371 {
1372 free(this->Arrays);
1373 }
1374#else
1375 delete this->Arrays;
1376#endif
1377 }
1378
1379 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1380 // true if the storage changes.
1382 {
1383 if (!this->StorageIs64Bit)
1384 {
1385 return false;
1386 }
1387
1388 this->Arrays->Int64->~VisitState();
1389 delete this->Arrays->Int64;
1390 this->Arrays->Int32 = new VisitState<ArrayType32>;
1391 this->StorageIs64Bit = false;
1392
1393 return true;
1394 }
1395
1396 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1397 // true if the storage changes.
1399 {
1400 if (this->StorageIs64Bit)
1401 {
1402 return false;
1403 }
1404
1405 this->Arrays->Int32->~VisitState();
1406 delete this->Arrays->Int32;
1407 this->Arrays->Int64 = new VisitState<ArrayType64>;
1408 this->StorageIs64Bit = true;
1409
1410 return true;
1411 }
1412
1413 // Returns true if the storage is currently configured to be 64 bit.
1414 bool Is64Bit() const { return this->StorageIs64Bit; }
1415
1416 // Get the VisitState for 32-bit arrays
1418 {
1419 assert(!this->StorageIs64Bit);
1420 return *this->Arrays->Int32;
1421 }
1422
1424 {
1425 assert(!this->StorageIs64Bit);
1426 return *this->Arrays->Int32;
1427 }
1428
1429 // Get the VisitState for 64-bit arrays
1431 {
1432 assert(this->StorageIs64Bit);
1433 return *this->Arrays->Int64;
1434 }
1435
1437 {
1438 assert(this->StorageIs64Bit);
1439 return *this->Arrays->Int64;
1440 }
1441
1442 private:
1443 // Access restricted to ensure proper union construction/destruction thru
1444 // API.
1445 ArraySwitch* Arrays;
1446 bool StorageIs64Bit;
1447 bool IsInMemkind = false;
1448 };
1449
1451 vtkIdType TraversalCellId{ 0 };
1452
1454
1456
1457private:
1458 vtkCellArray(const vtkCellArray&) = delete;
1459 void operator=(const vtkCellArray&) = delete;
1460};
1461
1462template <typename ArrayT>
1464{
1465 return this->Offsets->GetNumberOfValues() - 1;
1466}
1467
1468template <typename ArrayT>
1470{
1471 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1472}
1473
1474template <typename ArrayT>
1476{
1477 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1478}
1479
1480template <typename ArrayT>
1482{
1483 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1484}
1485
1486template <typename ArrayT>
1489{
1490 return vtk::DataArrayValueRange<1>(
1491 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1492}
1493VTK_ABI_NAMESPACE_END
1494
1496{
1497VTK_ABI_NAMESPACE_BEGIN
1498
1500{
1501 // Insert full cell
1502 template <typename CellStateT>
1503 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1504 {
1505 using ValueType = typename CellStateT::ValueType;
1506 auto* conn = state.GetConnectivity();
1507 auto* offsets = state.GetOffsets();
1508
1509 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1510
1511 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1512
1513 for (vtkIdType i = 0; i < npts; ++i)
1514 {
1515 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1516 }
1517
1518 return cellId;
1519 }
1520
1521 // Just update offset table (for incremental API)
1522 template <typename CellStateT>
1523 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1524 {
1525 using ValueType = typename CellStateT::ValueType;
1526 auto* conn = state.GetConnectivity();
1527 auto* offsets = state.GetOffsets();
1528
1529 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1530
1531 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1532
1533 return cellId;
1534 }
1535};
1536
1537// for incremental API:
1539{
1540 template <typename CellStateT>
1541 void operator()(CellStateT& state, const vtkIdType npts)
1542 {
1543 using ValueType = typename CellStateT::ValueType;
1544
1545 auto* offsets = state.GetOffsets();
1546 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1547 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1548 }
1549};
1550
1552{
1553 template <typename CellStateT>
1554 vtkIdType operator()(CellStateT& state, vtkIdType cellId)
1555 {
1556 return state.GetCellSize(cellId);
1557 }
1558};
1559
1561{
1562 template <typename CellStateT>
1563 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1564 {
1565 using ValueType = typename CellStateT::ValueType;
1566
1567 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1568 const vtkIdType endOffset = state.GetEndOffset(cellId);
1569 const vtkIdType cellSize = endOffset - beginOffset;
1570 const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1571
1572 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1573 ids->SetNumberOfIds(cellSize);
1574 vtkIdType* idPtr = ids->GetPointer(0);
1575 for (ValueType i = 0; i < cellSize; ++i)
1576 {
1577 idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1578 }
1579 }
1580
1581 template <typename CellStateT>
1583 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1584 {
1585 using ValueType = typename CellStateT::ValueType;
1586
1587 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1588 const vtkIdType endOffset = state.GetEndOffset(cellId);
1589 cellSize = endOffset - beginOffset;
1590 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1591
1592 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1593 for (vtkIdType i = 0; i < cellSize; ++i)
1594 {
1595 cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1596 }
1597 }
1598
1599 // SFINAE helper to check if a VisitState's connectivity array's memory
1600 // can be used as a vtkIdType*.
1601 template <typename CellStateT>
1603 {
1604 private:
1605 using ValueType = typename CellStateT::ValueType;
1606 using ArrayType = typename CellStateT::ArrayType;
1608 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1609 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1610
1611 public:
1612 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1613 };
1614
1615 template <typename CellStateT>
1616 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
1617 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1618 vtkIdList* vtkNotUsed(temp))
1619 {
1620 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1621 const vtkIdType endOffset = state.GetEndOffset(cellId);
1622 cellSize = endOffset - beginOffset;
1623 // This is safe, see CanShareConnPtr helper above.
1624 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1625 }
1626
1627 template <typename CellStateT>
1628 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
1629 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1630 vtkIdList* temp)
1631 {
1632 using ValueType = typename CellStateT::ValueType;
1633
1634 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1635 const vtkIdType endOffset = state.GetEndOffset(cellId);
1636 cellSize = endOffset - beginOffset;
1637 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1638
1639 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1640 temp->SetNumberOfIds(cellSize);
1641 vtkIdType* tempPtr = temp->GetPointer(0);
1642 for (vtkIdType i = 0; i < cellSize; ++i)
1643 {
1644 tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1645 }
1646
1647 cellPoints = temp->GetPointer(0);
1648 }
1649};
1650
1652{
1653 template <typename CellStateT>
1654 void operator()(CellStateT& state)
1655 {
1656 state.GetOffsets()->Reset();
1657 state.GetConnectivity()->Reset();
1658 state.GetOffsets()->InsertNextValue(0);
1659 }
1660};
1661
1662VTK_ABI_NAMESPACE_END
1663} // end namespace vtkCellArray_detail
1664
1665VTK_ABI_NAMESPACE_BEGIN
1666//----------------------------------------------------------------------------
1668{
1669 this->TraversalCellId = 0;
1670}
1671
1672//----------------------------------------------------------------------------
1673inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1674{
1675 if (this->TraversalCellId < this->GetNumberOfCells())
1676 {
1677 this->GetCellAtId(this->TraversalCellId, npts, pts);
1678 ++this->TraversalCellId;
1679 return 1;
1680 }
1681
1682 npts = 0;
1683 pts = nullptr;
1684 return 0;
1685}
1686
1687//----------------------------------------------------------------------------
1689{
1690 if (this->TraversalCellId < this->GetNumberOfCells())
1691 {
1692 this->GetCellAtId(this->TraversalCellId, pts);
1693 ++this->TraversalCellId;
1694 return 1;
1695 }
1696
1697 pts->Reset();
1698 return 0;
1699}
1700//----------------------------------------------------------------------------
1702{
1703 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1704}
1705
1706//----------------------------------------------------------------------------
1707inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1708 vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1709{
1710 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1711}
1712
1713//----------------------------------------------------------------------------
1715{
1716 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1717}
1718
1719//----------------------------------------------------------------------------
1720inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1721{
1722 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1723}
1724
1725//----------------------------------------------------------------------------
1727 VTK_SIZEHINT(pts, npts)
1728{
1729 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1730}
1731
1732//----------------------------------------------------------------------------
1734{
1735 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1736}
1737
1738//----------------------------------------------------------------------------
1740{
1741 if (this->Storage.Is64Bit())
1742 {
1743 using ValueType = typename ArrayType64::ValueType;
1744 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1745 }
1746 else
1747 {
1748 using ValueType = typename ArrayType32::ValueType;
1749 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1750 }
1751}
1752
1753//----------------------------------------------------------------------------
1755{
1757}
1758
1759//----------------------------------------------------------------------------
1761{
1762 return this->Visit(
1764}
1765
1766//----------------------------------------------------------------------------
1768{
1769 vtkIdList* pts = cell->GetPointIds();
1770 return this->Visit(
1772}
1773
1774//----------------------------------------------------------------------------
1776{
1778}
1779
1780VTK_ABI_NAMESPACE_END
1781#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.
virtual vtkIdType GetCellSize(vtkIdType cellId) const =0
Return the size of 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.
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.
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.
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
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()
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:315
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE