VTK  9.3.20240328
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 
244 #include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
245 #include "vtkCell.h" // Needed for inline methods
246 #include "vtkDataArrayRange.h" // Needed for inline methods
247 #include "vtkFeatures.h" // for VTK_USE_MEMKIND
248 #include "vtkSmartPointer.h" // For vtkSmartPointer
249 #include "vtkTypeInt32Array.h" // Needed for inline methods
250 #include "vtkTypeInt64Array.h" // Needed for inline methods
251 #include "vtkTypeList.h" // Needed for ArrayList definition
252 
253 #include <cassert> // for assert
254 #include <initializer_list> // for API
255 #include <type_traits> // for std::is_same
256 #include <utility> // for std::forward
257 
278 #define VTK_CELL_ARRAY_V2
279 
280 VTK_ABI_NAMESPACE_BEGIN
282 class vtkIdTypeArray;
283 
284 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkAbstractCellArray
285 {
286 public:
287  using ArrayType32 = vtkTypeInt32Array;
288  using ArrayType64 = vtkTypeInt64Array;
289 
291 
295  static vtkCellArray* New();
297  void PrintSelf(ostream& os, vtkIndent indent) override;
298  void PrintDebug(ostream& os);
300 
309  using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
310 
322 
331  vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
332  {
333  return this->AllocateExact(sz, sz) ? 1 : 0;
334  }
335 
345  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
346  {
347  return this->AllocateExact(numCells, numCells * maxCellSize);
348  }
349 
359  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
360 
371  {
372  return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
373  }
374 
384  bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
385 
389  void Initialize() override;
390 
394  void Reset();
395 
401  void Squeeze();
402 
413  bool IsValid();
414 
418  vtkIdType GetNumberOfCells() const override
419  {
420  if (this->Storage.Is64Bit())
421  {
422  return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
423  }
424  else
425  {
426  return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
427  }
428  }
429 
434  vtkIdType GetNumberOfOffsets() const override
435  {
436  if (this->Storage.Is64Bit())
437  {
438  return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
439  }
440  else
441  {
442  return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
443  }
444  }
445 
449  vtkIdType GetOffset(vtkIdType cellId) override
450  {
451  if (this->Storage.Is64Bit())
452  {
453  return this->Storage.GetArrays64().Offsets->GetValue(cellId);
454  }
455  else
456  {
457  return this->Storage.GetArrays32().Offsets->GetValue(cellId);
458  }
459  }
460 
468  {
469  if (this->Storage.Is64Bit())
470  {
471  return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
472  }
473  else
474  {
475  return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
476  }
477  }
478 
485 
496  void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
499  void SetData(
501  void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
502  void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
517  bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
518 
532  bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
533 
538  bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
539 
546  bool IsStorageShareable() const override
547  {
548  if (this->Storage.Is64Bit())
549  {
551  }
552  else
553  {
555  }
556  }
557 
612  {
613  if (this->Storage.Is64Bit())
614  {
615  return this->GetOffsetsArray64();
616  }
617  else
618  {
619  return this->GetOffsetsArray32();
620  }
621  }
633  {
634  if (this->Storage.Is64Bit())
635  {
636  return this->GetConnectivityArray64();
637  }
638  else
639  {
640  return this->GetConnectivityArray32();
641  }
642  }
656 
666  void InitTraversal();
667 
682  int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
683 
694  int GetNextCell(vtkIdList* pts);
695 
706  void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
707  vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
708  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
709 
715  void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
716  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
717 
725  void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints) VTK_SIZEHINT(
726  cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
727 
731  vtkIdType GetCellSize(vtkIdType cellId) const override;
732 
736  vtkIdType InsertNextCell(vtkCell* cell);
737 
742  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
743 
748  vtkIdType InsertNextCell(vtkIdList* pts);
749 
757  vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
758  {
759  return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
760  }
761 
768  vtkIdType InsertNextCell(int npts);
769 
774  void InsertCellPoint(vtkIdType id);
775 
780  void UpdateCellCount(int npts);
781 
796  void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
797 
806  void ReplaceCellAtId(vtkIdType cellId, vtkIdList* list);
807  void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
808  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
818  void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
819 
827  void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
828  {
829  return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
830  }
831 
836  int GetMaxCellSize() override;
837 
841  void DeepCopy(vtkAbstractCellArray* ca) override;
842 
846  void ShallowCopy(vtkAbstractCellArray* ca) override;
847 
851  void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
852 
864 
892  void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
893  VTK_SIZEHINT(data, len);
904  unsigned long GetActualMemorySize() const;
905 
906  // The following code is used to support
907 
908  // The wrappers get understandably confused by some of the template code below
909 #ifndef __VTK_WRAP__
910 
911  // Holds connectivity and offset arrays of the given ArrayType.
912  template <typename ArrayT>
913  struct VisitState
914  {
915  using ArrayType = ArrayT;
916  using ValueType = typename ArrayType::ValueType;
917  using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
918 
919  // We can't just use is_same here, since binary compatible representations
920  // (e.g. int and long) are distinct types. Instead, ensure that ValueType
921  // is a signed integer the same size as vtkIdType.
922  // If this value is true, ValueType pointers may be safely converted to
923  // vtkIdType pointers via reinterpret cast.
924  static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
925  std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
926 
927  ArrayType* GetOffsets() { return this->Offsets; }
928  const ArrayType* GetOffsets() const { return this->Offsets; }
929 
930  ArrayType* GetConnectivity() { return this->Connectivity; }
931  const ArrayType* GetConnectivity() const { return this->Connectivity; }
932 
934 
936 
938 
940 
942 
943  friend class vtkCellArray;
944 
945  protected:
947  {
948  this->Connectivity = vtkSmartPointer<ArrayType>::New();
949  this->Offsets = vtkSmartPointer<ArrayType>::New();
950  this->Offsets->InsertNextValue(0);
952  {
953  this->IsInMemkind = true;
954  }
955  }
956  ~VisitState() = default;
957  void* operator new(size_t nSize)
958  {
959  void* r;
960 #ifdef VTK_USE_MEMKIND
962 #else
963  r = malloc(nSize);
964 #endif
965  return r;
966  }
967  void operator delete(void* p)
968  {
969 #ifdef VTK_USE_MEMKIND
970  VisitState* a = static_cast<VisitState*>(p);
971  if (a->IsInMemkind)
972  {
974  }
975  else
976  {
977  free(p);
978  }
979 #else
980  free(p);
981 #endif
982  }
983 
986 
987  private:
988  VisitState(const VisitState&) = delete;
989  VisitState& operator=(const VisitState&) = delete;
990  bool IsInMemkind = false;
991  };
992 
993 private: // Helpers that allow Visit to return a value:
994  template <typename Functor, typename... Args>
995  using GetReturnType = decltype(
996  std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
997 
998  template <typename Functor, typename... Args>
999  struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
1000  {
1001  };
1002 
1003 public:
1073  template <typename Functor, typename... Args,
1074  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1075  void Visit(Functor&& functor, Args&&... args)
1076  {
1077  if (this->Storage.Is64Bit())
1078  {
1079  // If you get an error on the next line, a call to Visit(functor, Args...)
1080  // is being called with arguments that do not match the functor's call
1081  // signature. See the Visit documentation for details.
1082  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1083  }
1084  else
1085  {
1086  // If you get an error on the next line, a call to Visit(functor, Args...)
1087  // is being called with arguments that do not match the functor's call
1088  // signature. See the Visit documentation for details.
1089  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1090  }
1091  }
1092 
1093  template <typename Functor, typename... Args,
1094  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1095  void Visit(Functor&& functor, Args&&... args) const
1096  {
1097  if (this->Storage.Is64Bit())
1098  {
1099  // If you get an error on the next line, a call to Visit(functor, Args...)
1100  // is being called with arguments that do not match the functor's call
1101  // signature. See the Visit documentation for details.
1102  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1103  }
1104  else
1105  {
1106  // If you get an error on the next line, a call to Visit(functor, Args...)
1107  // is being called with arguments that do not match the functor's call
1108  // signature. See the Visit documentation for details.
1109  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1110  }
1111  }
1112 
1113  template <typename Functor, typename... Args,
1114  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1115  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1116  {
1117  if (this->Storage.Is64Bit())
1118  {
1119  // If you get an error on the next line, a call to Visit(functor, Args...)
1120  // is being called with arguments that do not match the functor's call
1121  // signature. See the Visit documentation for details.
1122  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1123  }
1124  else
1125  {
1126  // If you get an error on the next line, a call to Visit(functor, Args...)
1127  // is being called with arguments that do not match the functor's call
1128  // signature. See the Visit documentation for details.
1129  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1130  }
1131  }
1132  template <typename Functor, typename... Args,
1133  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1134  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1135  {
1136  if (this->Storage.Is64Bit())
1137  {
1138  // If you get an error on the next line, a call to Visit(functor, Args...)
1139  // is being called with arguments that do not match the functor's call
1140  // signature. See the Visit documentation for details.
1141  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1142  }
1143  else
1144  {
1145  // If you get an error on the next line, a call to Visit(functor, Args...)
1146  // is being called with arguments that do not match the functor's call
1147  // signature. See the Visit documentation for details.
1148  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1149  }
1150  }
1151 
1164 #endif // __VTK_WRAP__
1165 
1166  //=================== Begin Legacy Methods ===================================
1167  // These should be deprecated at some point as they are confusing or very slow
1168 
1176 
1188  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1189 
1199 
1207 
1217  void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1218  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1219 
1226  void GetCell(vtkIdType loc, vtkIdList* pts)
1227  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1228 
1235  vtkIdType GetInsertLocation(int npts);
1236 
1244  vtkIdType GetTraversalLocation();
1245  vtkIdType GetTraversalLocation(vtkIdType npts);
1246  void SetTraversalLocation(vtkIdType loc);
1256  void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1257 
1269  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1270  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1271 
1286  void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1287 
1299 
1300  //=================== End Legacy Methods =====================================
1301 
1302  friend class vtkCellArrayIterator;
1303 
1304 protected:
1306  ~vtkCellArray() override;
1307 
1308  // Encapsulates storage of the internal arrays as a discriminated union
1309  // between 32-bit and 64-bit storage.
1310  struct Storage
1311  {
1312  // Union type that switches 32 and 64 bit array storage
1313  union ArraySwitch {
1314  ArraySwitch() = default; // handled by Storage
1315  ~ArraySwitch() = default; // handle by Storage
1318  };
1319 
1321  {
1322 #ifdef VTK_USE_MEMKIND
1323  this->Arrays =
1325 #else
1326  this->Arrays = new ArraySwitch;
1327 #endif
1328 
1329  // Default can be changed, to save memory
1331  {
1332  this->Arrays->Int64 = new VisitState<ArrayType64>;
1333  this->StorageIs64Bit = true;
1334  }
1335  else
1336  {
1337  this->Arrays->Int32 = new VisitState<ArrayType32>;
1338  this->StorageIs64Bit = false;
1339  }
1340 
1341 #ifdef VTK_USE_MEMKIND
1343  {
1344  this->IsInMemkind = true;
1345  }
1346 #else
1347  (void)this->IsInMemkind; // comp warning workaround
1348 #endif
1349  }
1350 
1352  {
1353  if (this->StorageIs64Bit)
1354  {
1355  this->Arrays->Int64->~VisitState();
1356  delete this->Arrays->Int64;
1357  }
1358  else
1359  {
1360  this->Arrays->Int32->~VisitState();
1361  delete this->Arrays->Int32;
1362  }
1363 #ifdef VTK_USE_MEMKIND
1364  if (this->IsInMemkind)
1365  {
1367  }
1368  else
1369  {
1370  free(this->Arrays);
1371  }
1372 #else
1373  delete this->Arrays;
1374 #endif
1375  }
1376 
1377  // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1378  // true if the storage changes.
1380  {
1381  if (!this->StorageIs64Bit)
1382  {
1383  return false;
1384  }
1385 
1386  this->Arrays->Int64->~VisitState();
1387  delete this->Arrays->Int64;
1388  this->Arrays->Int32 = new VisitState<ArrayType32>;
1389  this->StorageIs64Bit = false;
1390 
1391  return true;
1392  }
1393 
1394  // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1395  // true if the storage changes.
1397  {
1398  if (this->StorageIs64Bit)
1399  {
1400  return false;
1401  }
1402 
1403  this->Arrays->Int32->~VisitState();
1404  delete this->Arrays->Int32;
1405  this->Arrays->Int64 = new VisitState<ArrayType64>;
1406  this->StorageIs64Bit = true;
1407 
1408  return true;
1409  }
1410 
1411  // Returns true if the storage is currently configured to be 64 bit.
1412  bool Is64Bit() const { return this->StorageIs64Bit; }
1413 
1414  // Get the VisitState for 32-bit arrays
1416  {
1417  assert(!this->StorageIs64Bit);
1418  return *this->Arrays->Int32;
1419  }
1420 
1422  {
1423  assert(!this->StorageIs64Bit);
1424  return *this->Arrays->Int32;
1425  }
1426 
1427  // Get the VisitState for 64-bit arrays
1429  {
1430  assert(this->StorageIs64Bit);
1431  return *this->Arrays->Int64;
1432  }
1433 
1435  {
1436  assert(this->StorageIs64Bit);
1437  return *this->Arrays->Int64;
1438  }
1439 
1440  private:
1441  // Access restricted to ensure proper union construction/destruction thru
1442  // API.
1443  ArraySwitch* Arrays;
1444  bool StorageIs64Bit;
1445  bool IsInMemkind = false;
1446  };
1447 
1449  vtkIdType TraversalCellId{ 0 };
1450 
1452 
1454 
1455 private:
1456  vtkCellArray(const vtkCellArray&) = delete;
1457  void operator=(const vtkCellArray&) = delete;
1458 };
1459 
1460 template <typename ArrayT>
1462 {
1463  return this->Offsets->GetNumberOfValues() - 1;
1464 }
1465 
1466 template <typename ArrayT>
1468 {
1469  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1470 }
1471 
1472 template <typename ArrayT>
1474 {
1475  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1476 }
1477 
1478 template <typename ArrayT>
1480 {
1481  return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1482 }
1483 
1484 template <typename ArrayT>
1487 {
1488  return vtk::DataArrayValueRange<1>(
1489  this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1490 }
1491 VTK_ABI_NAMESPACE_END
1492 
1494 {
1495 VTK_ABI_NAMESPACE_BEGIN
1496 
1498 {
1499  // Insert full cell
1500  template <typename CellStateT>
1501  vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1502  {
1503  using ValueType = typename CellStateT::ValueType;
1504  auto* conn = state.GetConnectivity();
1505  auto* offsets = state.GetOffsets();
1506 
1507  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1508 
1509  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1510 
1511  for (vtkIdType i = 0; i < npts; ++i)
1512  {
1513  conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1514  }
1515 
1516  return cellId;
1517  }
1518 
1519  // Just update offset table (for incremental API)
1520  template <typename CellStateT>
1521  vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1522  {
1523  using ValueType = typename CellStateT::ValueType;
1524  auto* conn = state.GetConnectivity();
1525  auto* offsets = state.GetOffsets();
1526 
1527  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1528 
1529  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1530 
1531  return cellId;
1532  }
1533 };
1534 
1535 // for incremental API:
1537 {
1538  template <typename CellStateT>
1539  void operator()(CellStateT& state, const vtkIdType npts)
1540  {
1541  using ValueType = typename CellStateT::ValueType;
1542 
1543  auto* offsets = state.GetOffsets();
1544  const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1545  offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1546  }
1547 };
1548 
1550 {
1551  template <typename CellStateT>
1552  vtkIdType operator()(CellStateT& state, vtkIdType cellId)
1553  {
1554  return state.GetCellSize(cellId);
1555  }
1556 };
1557 
1559 {
1560  template <typename CellStateT>
1561  void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1562  {
1563  using ValueType = typename CellStateT::ValueType;
1564 
1565  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1566  const vtkIdType endOffset = state.GetEndOffset(cellId);
1567  const vtkIdType cellSize = endOffset - beginOffset;
1568  const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1569 
1570  // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1571  ids->SetNumberOfIds(cellSize);
1572  vtkIdType* idPtr = ids->GetPointer(0);
1573  for (ValueType i = 0; i < cellSize; ++i)
1574  {
1575  idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1576  }
1577  }
1578 
1579  template <typename CellStateT>
1581  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1582  {
1583  using ValueType = typename CellStateT::ValueType;
1584 
1585  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1586  const vtkIdType endOffset = state.GetEndOffset(cellId);
1587  cellSize = endOffset - beginOffset;
1588  const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1589 
1590  // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1591  for (vtkIdType i = 0; i < cellSize; ++i)
1592  {
1593  cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1594  }
1595  }
1596 
1597  // SFINAE helper to check if a VisitState's connectivity array's memory
1598  // can be used as a vtkIdType*.
1599  template <typename CellStateT>
1601  {
1602  private:
1603  using ValueType = typename CellStateT::ValueType;
1604  using ArrayType = typename CellStateT::ArrayType;
1606  static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1607  static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1608 
1609  public:
1610  static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1611  };
1612 
1613  template <typename CellStateT>
1615  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1616  vtkIdList* vtkNotUsed(temp))
1617  {
1618  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1619  const vtkIdType endOffset = state.GetEndOffset(cellId);
1620  cellSize = endOffset - beginOffset;
1621  // This is safe, see CanShareConnPtr helper above.
1622  cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1623  }
1624 
1625  template <typename CellStateT>
1627  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1628  vtkIdList* temp)
1629  {
1630  using ValueType = typename CellStateT::ValueType;
1631 
1632  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1633  const vtkIdType endOffset = state.GetEndOffset(cellId);
1634  cellSize = endOffset - beginOffset;
1635  const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1636 
1637  // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1638  temp->SetNumberOfIds(cellSize);
1639  vtkIdType* tempPtr = temp->GetPointer(0);
1640  for (vtkIdType i = 0; i < cellSize; ++i)
1641  {
1642  tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1643  }
1644 
1645  cellPoints = temp->GetPointer(0);
1646  }
1647 };
1648 
1650 {
1651  template <typename CellStateT>
1652  void operator()(CellStateT& state)
1653  {
1654  state.GetOffsets()->Reset();
1655  state.GetConnectivity()->Reset();
1656  state.GetOffsets()->InsertNextValue(0);
1657  }
1658 };
1659 
1660 VTK_ABI_NAMESPACE_END
1661 } // end namespace vtkCellArray_detail
1662 
1663 VTK_ABI_NAMESPACE_BEGIN
1664 //----------------------------------------------------------------------------
1666 {
1667  this->TraversalCellId = 0;
1668 }
1669 
1670 //----------------------------------------------------------------------------
1671 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1672 {
1673  if (this->TraversalCellId < this->GetNumberOfCells())
1674  {
1675  this->GetCellAtId(this->TraversalCellId, npts, pts);
1676  ++this->TraversalCellId;
1677  return 1;
1678  }
1679 
1680  npts = 0;
1681  pts = nullptr;
1682  return 0;
1683 }
1684 
1685 //----------------------------------------------------------------------------
1687 {
1688  if (this->TraversalCellId < this->GetNumberOfCells())
1689  {
1690  this->GetCellAtId(this->TraversalCellId, pts);
1691  ++this->TraversalCellId;
1692  return 1;
1693  }
1694 
1695  pts->Reset();
1696  return 0;
1697 }
1698 //----------------------------------------------------------------------------
1700 {
1701  return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1702 }
1703 
1704 //----------------------------------------------------------------------------
1705 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1706  vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1707 {
1708  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1709 }
1710 
1711 //----------------------------------------------------------------------------
1713 {
1714  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1715 }
1716 
1717 //----------------------------------------------------------------------------
1718 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1719 {
1720  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1721 }
1722 
1723 //----------------------------------------------------------------------------
1725  VTK_SIZEHINT(pts, npts)
1726 {
1727  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1728 }
1729 
1730 //----------------------------------------------------------------------------
1732 {
1733  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1734 }
1735 
1736 //----------------------------------------------------------------------------
1738 {
1739  if (this->Storage.Is64Bit())
1740  {
1741  using ValueType = typename ArrayType64::ValueType;
1742  this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1743  }
1744  else
1745  {
1746  using ValueType = typename ArrayType32::ValueType;
1747  this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1748  }
1749 }
1750 
1751 //----------------------------------------------------------------------------
1752 inline void vtkCellArray::UpdateCellCount(int npts)
1753 {
1755 }
1756 
1757 //----------------------------------------------------------------------------
1759 {
1760  return this->Visit(
1762 }
1763 
1764 //----------------------------------------------------------------------------
1766 {
1767  vtkIdList* pts = cell->GetPointIds();
1768  return this->Visit(
1770 }
1771 
1772 //----------------------------------------------------------------------------
1773 inline void vtkCellArray::Reset()
1774 {
1776 }
1777 
1778 VTK_ABI_NAMESPACE_END
1779 #endif // vtkCellArray.h
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
Definition: vtkCellArray.h:285
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.
Definition: vtkCellArray.h:449
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.
Definition: vtkCellArray.h:331
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:370
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.
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:622
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.
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.
Definition: vtkCellArray.h:434
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:287
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
Definition: vtkCellArray.h:418
void Reset()
Reuse list.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:623
vtkIdType GetNumberOfConnectivityIds() const override
Get the size of the connectivity array that stores the point ids.
Definition: vtkCellArray.h:467
void SetData(vtkAOSDataArrayTemplate< long long > *offsets, vtkAOSDataArrayTemplate< long long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
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.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
Definition: vtkCellArray.h:345
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:288
vtkIdType TraversalCellId
void InitTraversal()
bool IsStorageShareable() const override
Definition: vtkCellArray.h:546
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.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
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.
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:643
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:644
bool ConvertTo32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
void Visit(Functor &&functor, Args &&... args) const
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.
Definition: vtkCellArray.h:321
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:632
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.
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.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:611
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:309
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:757
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
bool IsStorage64Bit() const
Definition: vtkCellArray.h:538
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
Definition: vtkDataArray.h:154
list of point or cell ids
Definition: vtkIdList.h:132
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:158
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:243
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:224
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:108
static vtkMallocingFunction GetCurrentMallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
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.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
@ value
Definition: vtkX3D.h:220
@ type
Definition: vtkX3D.h:516
@ data
Definition: vtkX3D.h:315
VisitState< ArrayType32 > & GetArrays32()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType64 > & GetArrays64()
ArrayType * GetOffsets()
Definition: vtkCellArray.h:927
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:985
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:984
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:930
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:917
CellRangeType GetCellRange(vtkIdType cellId)
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:928
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:931
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:916
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType *cellPoints)
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))
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.
Definition: vtkTypeList.h:110
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_NEWINSTANCE