VTK  9.1.0
vtkCellArray.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkCellArray.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
244#ifndef vtkCellArray_h
245#define vtkCellArray_h
246
247#include "vtkCommonDataModelModule.h" // For export macro
248#include "vtkObject.h"
249
250#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
251#include "vtkCell.h" // Needed for inline methods
252#include "vtkDataArrayRange.h" // Needed for inline methods
253#include "vtkFeatures.h" // for VTK_USE_MEMKIND
254#include "vtkSmartPointer.h" // For vtkSmartPointer
255#include "vtkTypeInt32Array.h" // Needed for inline methods
256#include "vtkTypeInt64Array.h" // Needed for inline methods
257#include "vtkTypeList.h" // Needed for ArrayList definition
258
259#include <cassert> // for assert
260#include <initializer_list> // for API
261#include <type_traits> // for std::is_same
262#include <utility> // for std::forward
263
284#define VTK_CELL_ARRAY_V2
285
287class vtkIdTypeArray;
288
289class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
290{
291public:
292 using ArrayType32 = vtkTypeInt32Array;
293 using ArrayType64 = vtkTypeInt64Array;
294
296
300 static vtkCellArray* New();
301 vtkTypeMacro(vtkCellArray, vtkObject);
302 void PrintSelf(ostream& os, vtkIndent indent) override;
303 void PrintDebug(ostream& os);
305
314 using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
315
327
336 vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
337 {
338 return this->AllocateExact(sz, sz) ? 1 : 0;
339 }
340
350 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
351 {
352 return this->AllocateExact(numCells, numCells * maxCellSize);
353 }
354
364 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
365
376 {
377 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
378 }
379
389 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
390
395
399 void Reset();
400
406 void Squeeze();
407
418 bool IsValid();
419
424 {
425 if (this->Storage.Is64Bit())
426 {
427 return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
428 }
429 else
430 {
431 return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
432 }
433 }
434
440 {
441 if (this->Storage.Is64Bit())
442 {
443 return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
444 }
445 else
446 {
447 return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
448 }
449 }
450
458 {
459 if (this->Storage.Is64Bit())
460 {
461 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
462 }
463 else
464 {
465 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
466 }
467 }
468
475
476#ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
487 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
488 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
489 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
495#endif // __VTK_WRAP__
496
509 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
510
524 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
525
530 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
531
539 {
540 if (this->Storage.Is64Bit())
541 {
543 }
544 else
545 {
547 }
548 }
549
604 {
605 if (this->Storage.Is64Bit())
606 {
607 return this->GetOffsetsArray64();
608 }
609 else
610 {
611 return this->GetOffsetsArray32();
612 }
613 }
625 {
626 if (this->Storage.Is64Bit())
627 {
628 return this->GetConnectivityArray64();
629 }
630 else
631 {
632 return this->GetConnectivityArray32();
633 }
634 }
648
658 void InitTraversal();
659
674 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
675
686 int GetNextCell(vtkIdList* pts);
687
698 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
699 VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
700
706 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
707 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
708
712 vtkIdType GetCellSize(const vtkIdType cellId) const;
713
717 vtkIdType InsertNextCell(vtkCell* cell);
718
723 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
724
729 vtkIdType InsertNextCell(vtkIdList* pts);
730
738 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
739 {
740 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
741 }
742
749 vtkIdType InsertNextCell(int npts);
750
755 void InsertCellPoint(vtkIdType id);
756
761 void UpdateCellCount(int npts);
762
777 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
778
788 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
789 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
799 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
800 {
801 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
802 }
803
809
814
819
823 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
824
836
864 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
865 VTK_SIZEHINT(data, len);
876 unsigned long GetActualMemorySize() const;
877
878 // The following code is used to support
879
880 // The wrappers get understandably confused by some of the template code below
881#ifndef __VTK_WRAP__
882
883 // Holds connectivity and offset arrays of the given ArrayType.
884 template <typename ArrayT>
886 {
887 using ArrayType = ArrayT;
888 using ValueType = typename ArrayType::ValueType;
889 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
890
891 // We can't just use is_same here, since binary compatible representations
892 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
893 // is a signed integer the same size as vtkIdType.
894 // If this value is true, ValueType pointers may be safely converted to
895 // vtkIdType pointers via reinterpret cast.
896 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
898
899 ArrayType* GetOffsets() { return this->Offsets; }
900 const ArrayType* GetOffsets() const { return this->Offsets; }
901
902 ArrayType* GetConnectivity() { return this->Connectivity; }
903 const ArrayType* GetConnectivity() const { return this->Connectivity; }
904
906
908
910
912
914
915 friend class vtkCellArray;
916
917 protected:
919 {
920 this->Connectivity = vtkSmartPointer<ArrayType>::New();
921 this->Offsets = vtkSmartPointer<ArrayType>::New();
922 this->Offsets->InsertNextValue(0);
924 {
925 this->IsInMemkind = true;
926 }
927 }
928 ~VisitState() = default;
929 void* operator new(size_t nSize)
930 {
931 void* r;
932#ifdef VTK_USE_MEMKIND
934#else
935 r = malloc(nSize);
936#endif
937 return r;
938 }
939 void operator delete(void* p)
940 {
941#ifdef VTK_USE_MEMKIND
942 VisitState* a = static_cast<VisitState*>(p);
943 if (a->IsInMemkind)
944 {
946 }
947 else
948 {
949 free(p);
950 }
951#else
952 free(p);
953#endif
954 }
955
958
959 private:
960 VisitState(const VisitState&) = delete;
961 VisitState& operator=(const VisitState&) = delete;
962 bool IsInMemkind = false;
963 };
964
965private: // Helpers that allow Visit to return a value:
966 template <typename Functor, typename... Args>
967 using GetReturnType = decltype(
968 std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
969
970 template <typename Functor, typename... Args>
971 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
972 {
973 };
974
975public:
1045 template <typename Functor, typename... Args,
1046 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1047 void Visit(Functor&& functor, Args&&... args)
1048 {
1049 if (this->Storage.Is64Bit())
1050 {
1051 // If you get an error on the next line, a call to Visit(functor, Args...)
1052 // is being called with arguments that do not match the functor's call
1053 // signature. See the Visit documentation for details.
1054 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1055 }
1056 else
1057 {
1058 // If you get an error on the next line, a call to Visit(functor, Args...)
1059 // is being called with arguments that do not match the functor's call
1060 // signature. See the Visit documentation for details.
1061 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1062 }
1063 }
1064
1065 template <typename Functor, typename... Args,
1066 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1067 void Visit(Functor&& functor, Args&&... args) const
1068 {
1069 if (this->Storage.Is64Bit())
1070 {
1071 // If you get an error on the next line, a call to Visit(functor, Args...)
1072 // is being called with arguments that do not match the functor's call
1073 // signature. See the Visit documentation for details.
1074 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1075 }
1076 else
1077 {
1078 // If you get an error on the next line, a call to Visit(functor, Args...)
1079 // is being called with arguments that do not match the functor's call
1080 // signature. See the Visit documentation for details.
1081 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1082 }
1083 }
1084
1085 template <typename Functor, typename... Args,
1086 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1087 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1088 {
1089 if (this->Storage.Is64Bit())
1090 {
1091 // If you get an error on the next line, a call to Visit(functor, Args...)
1092 // is being called with arguments that do not match the functor's call
1093 // signature. See the Visit documentation for details.
1094 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1095 }
1096 else
1097 {
1098 // If you get an error on the next line, a call to Visit(functor, Args...)
1099 // is being called with arguments that do not match the functor's call
1100 // signature. See the Visit documentation for details.
1101 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1102 }
1103 }
1104 template <typename Functor, typename... Args,
1105 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1106 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1107 {
1108 if (this->Storage.Is64Bit())
1109 {
1110 // If you get an error on the next line, a call to Visit(functor, Args...)
1111 // is being called with arguments that do not match the functor's call
1112 // signature. See the Visit documentation for details.
1113 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1114 }
1115 else
1116 {
1117 // If you get an error on the next line, a call to Visit(functor, Args...)
1118 // is being called with arguments that do not match the functor's call
1119 // signature. See the Visit documentation for details.
1120 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1121 }
1122 }
1123
1126#endif // __VTK_WRAP__
1127
1128 //=================== Begin Legacy Methods ===================================
1129 // These should be deprecated at some point as they are confusing or very slow
1130
1138
1150 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1151
1161
1169
1179 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1180 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1181
1188 void GetCell(vtkIdType loc, vtkIdList* pts)
1189 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1190
1197 vtkIdType GetInsertLocation(int npts);
1198
1206 vtkIdType GetTraversalLocation();
1207 vtkIdType GetTraversalLocation(vtkIdType npts);
1208 void SetTraversalLocation(vtkIdType loc);
1218 void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1219
1231 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1232 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1233
1248 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1249
1261
1262 //=================== End Legacy Methods =====================================
1263
1265
1266protected:
1268 ~vtkCellArray() override;
1269
1270 // Encapsulates storage of the internal arrays as a discriminated union
1271 // between 32-bit and 64-bit storage.
1272 struct Storage
1273 {
1274 // Union type that switches 32 and 64 bit array storage
1276 ArraySwitch() = default; // handled by Storage
1277 ~ArraySwitch() = default; // handle by Storage
1280 };
1281
1283 {
1284#ifdef VTK_USE_MEMKIND
1285 this->Arrays =
1287#else
1288 this->Arrays = new ArraySwitch;
1289#endif
1290
1291 // Default to the compile-time setting:
1292#ifdef VTK_USE_64BIT_IDS
1293
1294 this->Arrays->Int64 = new VisitState<ArrayType64>;
1295 this->StorageIs64Bit = true;
1296
1297#else // VTK_USE_64BIT_IDS
1298
1299 this->Arrays->Int32 = new VisitState<ArrayType32>;
1300 this->StorageIs64Bit = false;
1301
1302#endif // VTK_USE_64BIT_IDS
1303#ifdef VTK_USE_MEMKIND
1305 {
1306 this->IsInMemkind = true;
1307 }
1308#else
1309 (void)this->IsInMemkind; // comp warning workaround
1310#endif
1311 }
1312
1314 {
1315 if (this->StorageIs64Bit)
1316 {
1317 this->Arrays->Int64->~VisitState();
1318 delete this->Arrays->Int64;
1319 }
1320 else
1321 {
1322 this->Arrays->Int32->~VisitState();
1323 delete this->Arrays->Int32;
1324 }
1325#ifdef VTK_USE_MEMKIND
1326 if (this->IsInMemkind)
1327 {
1329 }
1330 else
1331 {
1332 free(this->Arrays);
1333 }
1334#else
1335 delete this->Arrays;
1336#endif
1337 }
1338
1339 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1340 // true if the storage changes.
1342 {
1343 if (!this->StorageIs64Bit)
1344 {
1345 return false;
1346 }
1347
1348 this->Arrays->Int64->~VisitState();
1349 delete this->Arrays->Int64;
1350 this->Arrays->Int32 = new VisitState<ArrayType32>;
1351 this->StorageIs64Bit = false;
1352
1353 return true;
1354 }
1355
1356 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1357 // true if the storage changes.
1359 {
1360 if (this->StorageIs64Bit)
1361 {
1362 return false;
1363 }
1364
1365 this->Arrays->Int32->~VisitState();
1366 delete this->Arrays->Int32;
1367 this->Arrays->Int64 = new VisitState<ArrayType64>;
1368 this->StorageIs64Bit = true;
1369
1370 return true;
1371 }
1372
1373 // Returns true if the storage is currently configured to be 64 bit.
1374 bool Is64Bit() const { return this->StorageIs64Bit; }
1375
1376 // Get the VisitState for 32-bit arrays
1378 {
1379 assert(!this->StorageIs64Bit);
1380 return *this->Arrays->Int32;
1381 }
1382
1384 {
1385 assert(!this->StorageIs64Bit);
1386 return *this->Arrays->Int32;
1387 }
1388
1389 // Get the VisitState for 64-bit arrays
1391 {
1392 assert(this->StorageIs64Bit);
1393 return *this->Arrays->Int64;
1394 }
1395
1397 {
1398 assert(this->StorageIs64Bit);
1399 return *this->Arrays->Int64;
1400 }
1401
1402 private:
1403 // Access restricted to ensure proper union construction/destruction thru
1404 // API.
1405 ArraySwitch* Arrays;
1406 bool StorageIs64Bit;
1407 bool IsInMemkind = false;
1408 };
1409
1412 vtkIdType TraversalCellId{ 0 };
1413
1415
1416private:
1417 vtkCellArray(const vtkCellArray&) = delete;
1418 void operator=(const vtkCellArray&) = delete;
1419};
1420
1421template <typename ArrayT>
1423{
1424 return this->Offsets->GetNumberOfValues() - 1;
1425}
1426
1427template <typename ArrayT>
1429{
1430 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1431}
1432
1433template <typename ArrayT>
1435{
1436 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1437}
1438
1439template <typename ArrayT>
1441{
1442 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1443}
1444
1445template <typename ArrayT>
1448{
1449 return vtk::DataArrayValueRange<1>(
1450 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1451}
1452
1454{
1455
1457{
1458 // Insert full cell
1459 template <typename CellStateT>
1460 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1461 {
1462 using ValueType = typename CellStateT::ValueType;
1463 auto* conn = state.GetConnectivity();
1464 auto* offsets = state.GetOffsets();
1465
1466 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1467
1468 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1469
1470 for (vtkIdType i = 0; i < npts; ++i)
1471 {
1472 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1473 }
1474
1475 return cellId;
1476 }
1477
1478 // Just update offset table (for incremental API)
1479 template <typename CellStateT>
1480 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1481 {
1482 using ValueType = typename CellStateT::ValueType;
1483 auto* conn = state.GetConnectivity();
1484 auto* offsets = state.GetOffsets();
1485
1486 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1487
1488 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1489
1490 return cellId;
1491 }
1492};
1493
1494// for incremental API:
1496{
1497 template <typename CellStateT>
1498 void operator()(CellStateT& state, const vtkIdType npts)
1499 {
1500 using ValueType = typename CellStateT::ValueType;
1501
1502 auto* offsets = state.GetOffsets();
1503 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1504 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1505 }
1506};
1507
1509{
1510 template <typename CellStateT>
1511 vtkIdType operator()(CellStateT& state, const vtkIdType cellId)
1512 {
1513 return state.GetCellSize(cellId);
1514 }
1515};
1516
1518{
1519 template <typename CellStateT>
1520 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1521 {
1522 using ValueType = typename CellStateT::ValueType;
1523
1524 const auto cellPts = state.GetCellRange(cellId);
1525
1526 ids->SetNumberOfIds(cellPts.size());
1527 vtkIdType* idPtr = ids->GetPointer(0);
1528
1529 for (ValueType ptId : cellPts)
1530 {
1531 *idPtr++ = static_cast<vtkIdType>(ptId);
1532 }
1533 }
1534
1535 // SFINAE helper to check if a VisitState's connectivity array's memory
1536 // can be used as a vtkIdType*.
1537 template <typename CellStateT>
1539 {
1540 private:
1541 using ValueType = typename CellStateT::ValueType;
1542 using ArrayType = typename CellStateT::ArrayType;
1544 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1545 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1546
1547 public:
1548 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1549 };
1550
1551 template <typename CellStateT>
1553 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1554 vtkIdList* vtkNotUsed(temp))
1555 {
1556 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1557 const vtkIdType endOffset = state.GetEndOffset(cellId);
1558 cellSize = endOffset - beginOffset;
1559 // This is safe, see CanShareConnPtr helper above.
1560 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1561 }
1562
1563 template <typename CellStateT>
1565 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1566 vtkIdList* temp)
1567 {
1568 using ValueType = typename CellStateT::ValueType;
1569
1570 const auto cellPts = state.GetCellRange(cellId);
1571 cellSize = cellPts.size();
1572
1573 // ValueType differs from vtkIdType, so we have to copy into a temporary
1574 // buffer:
1575 temp->SetNumberOfIds(cellSize);
1576 vtkIdType* tempPtr = temp->GetPointer(0);
1577 for (ValueType ptId : cellPts)
1578 {
1579 *tempPtr++ = static_cast<vtkIdType>(ptId);
1580 }
1581
1582 cellPoints = temp->GetPointer(0);
1583 }
1584};
1585
1587{
1588 template <typename CellStateT>
1589 void operator()(CellStateT& state)
1590 {
1591 state.GetOffsets()->Reset();
1592 state.GetConnectivity()->Reset();
1593 state.GetOffsets()->InsertNextValue(0);
1594 }
1595};
1596
1597} // end namespace vtkCellArray_detail
1598
1599//----------------------------------------------------------------------------
1601{
1602 this->TraversalCellId = 0;
1603}
1604
1605//----------------------------------------------------------------------------
1606inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1607{
1608 if (this->TraversalCellId < this->GetNumberOfCells())
1609 {
1610 this->GetCellAtId(this->TraversalCellId, npts, pts);
1611 ++this->TraversalCellId;
1612 return 1;
1613 }
1614
1615 npts = 0;
1616 pts = nullptr;
1617 return 0;
1618}
1619
1620//----------------------------------------------------------------------------
1622{
1623 if (this->TraversalCellId < this->GetNumberOfCells())
1624 {
1625 this->GetCellAtId(this->TraversalCellId, pts);
1626 ++this->TraversalCellId;
1627 return 1;
1628 }
1629
1630 pts->Reset();
1631 return 0;
1632}
1633//----------------------------------------------------------------------------
1635{
1636 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1637}
1638
1639//----------------------------------------------------------------------------
1640inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1641 vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1642{
1643 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1644}
1645
1646//----------------------------------------------------------------------------
1648{
1649 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1650}
1651
1652//----------------------------------------------------------------------------
1654 VTK_SIZEHINT(pts, npts)
1655{
1656 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1657}
1658
1659//----------------------------------------------------------------------------
1661{
1662 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1663}
1664
1665//----------------------------------------------------------------------------
1667{
1668 if (this->Storage.Is64Bit())
1669 {
1670 using ValueType = typename ArrayType64::ValueType;
1671 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1672 }
1673 else
1674 {
1675 using ValueType = typename ArrayType32::ValueType;
1676 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1677 }
1678}
1679
1680//----------------------------------------------------------------------------
1682{
1684}
1685
1686//----------------------------------------------------------------------------
1688{
1689 return this->Visit(
1691}
1692
1693//----------------------------------------------------------------------------
1695{
1696 vtkIdList* pts = cell->GetPointIds();
1697 return this->Visit(
1699}
1700
1701//----------------------------------------------------------------------------
1703{
1705}
1706
1707#endif // vtkCellArray.h
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
Definition: vtkCellArray.h:290
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 GetNumberOfConnectivityEntries()
Return the size of the array that would be returned from ExportLegacyFormat().
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
Definition: vtkCellArray.h:336
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
Storage Storage
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
Definition: vtkCellArray.h:375
void AppendLegacyFormat(vtkIdTypeArray *data, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.
bool IsStorageShareable() const
Definition: vtkCellArray.h:538
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...
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:292
void Reset()
Reuse list.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:636
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:635
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.
Definition: vtkCellArray.h:614
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
Definition: vtkCellArray.h:350
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:439
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:293
vtkIdType TraversalCellId
void InitTraversal()
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.
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.
Definition: vtkCellArray.h:624
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
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 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.
vtkIdType IsHomogeneous()
Check if all cells have the same number of vertices.
void Visit(Functor &&functor, Args &&... args) const
int GetMaxCellSize()
Returns the size of the largest cell.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:615
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
void ShallowCopy(vtkCellArray *ca)
Shallow copy ca into this cell array.
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.
void Initialize()
Free any memory and reset to an empty state.
void DeepCopy(vtkCellArray *ca)
Perform a deep copy (no reference counting) of the given cell array.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > > >::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
Definition: vtkCellArray.h:326
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.
vtkIdType GetNumberOfCells() const
Get the number of cells in the array.
Definition: vtkCellArray.h:423
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
vtkIdType GetNumberOfConnectivityIds() const
Get the size of the connectivity array that stores the point ids.
Definition: vtkCellArray.h:457
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:603
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.
vtkNew< vtkIdList > TempCell
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:314
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:738
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
bool IsStorage64Bit() const
Definition: vtkCellArray.h:530
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:147
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:242
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
list of point or cell ids
Definition: vtkIdList.h:140
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:166
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:254
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:235
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:113
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...
abstract base class for most VTK objects
Definition: vtkObject.h:73
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321
VisitState< ArrayType64 > & GetArrays64()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType32 > & GetArrays32()
ArrayType * GetOffsets()
Definition: vtkCellArray.h:899
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:957
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:956
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:896
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:900
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:889
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:903
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:888
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:902
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)
vtkIdType operator()(CellStateT &state, const 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.
Definition: vtkTypeList.h:125
VisitState< ArrayType32 > * Int32
VisitState< ArrayType64 > * Int64
int vtkTypeBool
Definition: vtkABI.h:69
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_NEWINSTANCE