VTK  9.1.20220525
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 =========================================================================*/
250 #ifndef vtkCellArray_h
251 #define vtkCellArray_h
252 
253 #include "vtkCommonDataModelModule.h" // For export macro
254 #include "vtkObject.h"
255 
256 #include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
257 #include "vtkCell.h" // Needed for inline methods
258 #include "vtkDataArrayRange.h" // Needed for inline methods
259 #include "vtkFeatures.h" // for VTK_USE_MEMKIND
260 #include "vtkSmartPointer.h" // For vtkSmartPointer
261 #include "vtkTypeInt32Array.h" // Needed for inline methods
262 #include "vtkTypeInt64Array.h" // Needed for inline methods
263 #include "vtkTypeList.h" // Needed for ArrayList definition
264 
265 #include <cassert> // for assert
266 #include <initializer_list> // for API
267 #include <type_traits> // for std::is_same
268 #include <utility> // for std::forward
269 
290 #define VTK_CELL_ARRAY_V2
291 
293 class vtkIdTypeArray;
294 
295 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
296 {
297 public:
298  using ArrayType32 = vtkTypeInt32Array;
299  using ArrayType64 = vtkTypeInt64Array;
300 
302 
306  static vtkCellArray* New();
307  vtkTypeMacro(vtkCellArray, vtkObject);
308  void PrintSelf(ostream& os, vtkIndent indent) override;
309  void PrintDebug(ostream& os);
311 
320  using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
321 
333 
342  vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
343  {
344  return this->AllocateExact(sz, sz) ? 1 : 0;
345  }
346 
356  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
357  {
358  return this->AllocateExact(numCells, numCells * maxCellSize);
359  }
360 
370  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
371 
382  {
383  return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
384  }
385 
395  bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
396 
400  void Initialize();
401 
405  void Reset();
406 
412  void Squeeze();
413 
424  bool IsValid();
425 
430  {
431  if (this->Storage.Is64Bit())
432  {
433  return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
434  }
435  else
436  {
437  return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
438  }
439  }
440 
446  {
447  if (this->Storage.Is64Bit())
448  {
449  return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
450  }
451  else
452  {
453  return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
454  }
455  }
456 
464  {
465  if (this->Storage.Is64Bit())
466  {
467  return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
468  }
469  else
470  {
471  return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
472  }
473  }
474 
481 
482 #ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
493  void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
494  void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
495  void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
498  void SetData(
501 #endif // __VTK_WRAP__
502 
515  bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
516 
530  bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
531 
536  bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
537 
544  bool IsStorageShareable() const
545  {
546  if (this->Storage.Is64Bit())
547  {
549  }
550  else
551  {
553  }
554  }
555 
610  {
611  if (this->Storage.Is64Bit())
612  {
613  return this->GetOffsetsArray64();
614  }
615  else
616  {
617  return this->GetOffsetsArray32();
618  }
619  }
631  {
632  if (this->Storage.Is64Bit())
633  {
634  return this->GetConnectivityArray64();
635  }
636  else
637  {
638  return this->GetConnectivityArray32();
639  }
640  }
654 
664  void InitTraversal();
665 
680  int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
681 
692  int GetNextCell(vtkIdList* pts);
693 
704  void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
705  VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
706 
712  void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
713  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
714 
718  vtkIdType GetCellSize(const vtkIdType cellId) const;
719 
723  vtkIdType InsertNextCell(vtkCell* cell);
724 
729  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
730 
735  vtkIdType InsertNextCell(vtkIdList* pts);
736 
744  vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
745  {
746  return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
747  }
748 
755  vtkIdType InsertNextCell(int npts);
756 
761  void InsertCellPoint(vtkIdType id);
762 
767  void UpdateCellCount(int npts);
768 
783  void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
784 
793  void ReplaceCellAtId(vtkIdType cellId, vtkIdList* list);
794  void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
795  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
805  void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
806  {
807  return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
808  }
809 
815 
820 
825 
829  void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
830 
842 
870  void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
871  VTK_SIZEHINT(data, len);
882  unsigned long GetActualMemorySize() const;
883 
884  // The following code is used to support
885 
886  // The wrappers get understandably confused by some of the template code below
887 #ifndef __VTK_WRAP__
888 
889  // Holds connectivity and offset arrays of the given ArrayType.
890  template <typename ArrayT>
891  struct VisitState
892  {
893  using ArrayType = ArrayT;
894  using ValueType = typename ArrayType::ValueType;
895  using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
896 
897  // We can't just use is_same here, since binary compatible representations
898  // (e.g. int and long) are distinct types. Instead, ensure that ValueType
899  // is a signed integer the same size as vtkIdType.
900  // If this value is true, ValueType pointers may be safely converted to
901  // vtkIdType pointers via reinterpret cast.
902  static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
903  std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
904 
905  ArrayType* GetOffsets() { return this->Offsets; }
906  const ArrayType* GetOffsets() const { return this->Offsets; }
907 
908  ArrayType* GetConnectivity() { return this->Connectivity; }
909  const ArrayType* GetConnectivity() const { return this->Connectivity; }
910 
912 
914 
916 
918 
920 
921  friend class vtkCellArray;
922 
923  protected:
925  {
926  this->Connectivity = vtkSmartPointer<ArrayType>::New();
927  this->Offsets = vtkSmartPointer<ArrayType>::New();
928  this->Offsets->InsertNextValue(0);
930  {
931  this->IsInMemkind = true;
932  }
933  }
934  ~VisitState() = default;
935  void* operator new(size_t nSize)
936  {
937  void* r;
938 #ifdef VTK_USE_MEMKIND
940 #else
941  r = malloc(nSize);
942 #endif
943  return r;
944  }
945  void operator delete(void* p)
946  {
947 #ifdef VTK_USE_MEMKIND
948  VisitState* a = static_cast<VisitState*>(p);
949  if (a->IsInMemkind)
950  {
952  }
953  else
954  {
955  free(p);
956  }
957 #else
958  free(p);
959 #endif
960  }
961 
964 
965  private:
966  VisitState(const VisitState&) = delete;
967  VisitState& operator=(const VisitState&) = delete;
968  bool IsInMemkind = false;
969  };
970 
971 private: // Helpers that allow Visit to return a value:
972  template <typename Functor, typename... Args>
973  using GetReturnType = decltype(
974  std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
975 
976  template <typename Functor, typename... Args>
977  struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
978  {
979  };
980 
981 public:
1051  template <typename Functor, typename... Args,
1052  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1053  void Visit(Functor&& functor, Args&&... args)
1054  {
1055  if (this->Storage.Is64Bit())
1056  {
1057  // If you get an error on the next line, a call to Visit(functor, Args...)
1058  // is being called with arguments that do not match the functor's call
1059  // signature. See the Visit documentation for details.
1060  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1061  }
1062  else
1063  {
1064  // If you get an error on the next line, a call to Visit(functor, Args...)
1065  // is being called with arguments that do not match the functor's call
1066  // signature. See the Visit documentation for details.
1067  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1068  }
1069  }
1070 
1071  template <typename Functor, typename... Args,
1072  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1073  void Visit(Functor&& functor, Args&&... args) const
1074  {
1075  if (this->Storage.Is64Bit())
1076  {
1077  // If you get an error on the next line, a call to Visit(functor, Args...)
1078  // is being called with arguments that do not match the functor's call
1079  // signature. See the Visit documentation for details.
1080  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1081  }
1082  else
1083  {
1084  // If you get an error on the next line, a call to Visit(functor, Args...)
1085  // is being called with arguments that do not match the functor's call
1086  // signature. See the Visit documentation for details.
1087  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1088  }
1089  }
1090 
1091  template <typename Functor, typename... Args,
1092  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1093  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1094  {
1095  if (this->Storage.Is64Bit())
1096  {
1097  // If you get an error on the next line, a call to Visit(functor, Args...)
1098  // is being called with arguments that do not match the functor's call
1099  // signature. See the Visit documentation for details.
1100  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1101  }
1102  else
1103  {
1104  // If you get an error on the next line, a call to Visit(functor, Args...)
1105  // is being called with arguments that do not match the functor's call
1106  // signature. See the Visit documentation for details.
1107  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1108  }
1109  }
1110  template <typename Functor, typename... Args,
1111  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1112  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1113  {
1114  if (this->Storage.Is64Bit())
1115  {
1116  // If you get an error on the next line, a call to Visit(functor, Args...)
1117  // is being called with arguments that do not match the functor's call
1118  // signature. See the Visit documentation for details.
1119  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1120  }
1121  else
1122  {
1123  // If you get an error on the next line, a call to Visit(functor, Args...)
1124  // is being called with arguments that do not match the functor's call
1125  // signature. See the Visit documentation for details.
1126  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1127  }
1128  }
1129 
1132 #endif // __VTK_WRAP__
1133 
1134  //=================== Begin Legacy Methods ===================================
1135  // These should be deprecated at some point as they are confusing or very slow
1136 
1144 
1156  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1157 
1167 
1175 
1185  void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1186  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1187 
1194  void GetCell(vtkIdType loc, vtkIdList* pts)
1195  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1196 
1203  vtkIdType GetInsertLocation(int npts);
1204 
1212  vtkIdType GetTraversalLocation();
1213  vtkIdType GetTraversalLocation(vtkIdType npts);
1214  void SetTraversalLocation(vtkIdType loc);
1224  void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1225 
1237  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1238  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1239 
1254  void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1255 
1267 
1268  //=================== End Legacy Methods =====================================
1269 
1270  friend class vtkCellArrayIterator;
1271 
1272 protected:
1274  ~vtkCellArray() override;
1275 
1276  // Encapsulates storage of the internal arrays as a discriminated union
1277  // between 32-bit and 64-bit storage.
1278  struct Storage
1279  {
1280  // Union type that switches 32 and 64 bit array storage
1281  union ArraySwitch {
1282  ArraySwitch() = default; // handled by Storage
1283  ~ArraySwitch() = default; // handle by Storage
1286  };
1287 
1289  {
1290 #ifdef VTK_USE_MEMKIND
1291  this->Arrays =
1293 #else
1294  this->Arrays = new ArraySwitch;
1295 #endif
1296 
1297  // Default to the compile-time setting:
1298 #ifdef VTK_USE_64BIT_IDS
1299 
1300  this->Arrays->Int64 = new VisitState<ArrayType64>;
1301  this->StorageIs64Bit = true;
1302 
1303 #else // VTK_USE_64BIT_IDS
1304 
1305  this->Arrays->Int32 = new VisitState<ArrayType32>;
1306  this->StorageIs64Bit = false;
1307 
1308 #endif // VTK_USE_64BIT_IDS
1309 #ifdef VTK_USE_MEMKIND
1311  {
1312  this->IsInMemkind = true;
1313  }
1314 #else
1315  (void)this->IsInMemkind; // comp warning workaround
1316 #endif
1317  }
1318 
1320  {
1321  if (this->StorageIs64Bit)
1322  {
1323  this->Arrays->Int64->~VisitState();
1324  delete this->Arrays->Int64;
1325  }
1326  else
1327  {
1328  this->Arrays->Int32->~VisitState();
1329  delete this->Arrays->Int32;
1330  }
1331 #ifdef VTK_USE_MEMKIND
1332  if (this->IsInMemkind)
1333  {
1335  }
1336  else
1337  {
1338  free(this->Arrays);
1339  }
1340 #else
1341  delete this->Arrays;
1342 #endif
1343  }
1344 
1345  // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1346  // true if the storage changes.
1348  {
1349  if (!this->StorageIs64Bit)
1350  {
1351  return false;
1352  }
1353 
1354  this->Arrays->Int64->~VisitState();
1355  delete this->Arrays->Int64;
1356  this->Arrays->Int32 = new VisitState<ArrayType32>;
1357  this->StorageIs64Bit = false;
1358 
1359  return true;
1360  }
1361 
1362  // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1363  // true if the storage changes.
1365  {
1366  if (this->StorageIs64Bit)
1367  {
1368  return false;
1369  }
1370 
1371  this->Arrays->Int32->~VisitState();
1372  delete this->Arrays->Int32;
1373  this->Arrays->Int64 = new VisitState<ArrayType64>;
1374  this->StorageIs64Bit = true;
1375 
1376  return true;
1377  }
1378 
1379  // Returns true if the storage is currently configured to be 64 bit.
1380  bool Is64Bit() const { return this->StorageIs64Bit; }
1381 
1382  // Get the VisitState for 32-bit arrays
1384  {
1385  assert(!this->StorageIs64Bit);
1386  return *this->Arrays->Int32;
1387  }
1388 
1390  {
1391  assert(!this->StorageIs64Bit);
1392  return *this->Arrays->Int32;
1393  }
1394 
1395  // Get the VisitState for 64-bit arrays
1397  {
1398  assert(this->StorageIs64Bit);
1399  return *this->Arrays->Int64;
1400  }
1401 
1403  {
1404  assert(this->StorageIs64Bit);
1405  return *this->Arrays->Int64;
1406  }
1407 
1408  private:
1409  // Access restricted to ensure proper union construction/destruction thru
1410  // API.
1411  ArraySwitch* Arrays;
1412  bool StorageIs64Bit;
1413  bool IsInMemkind = false;
1414  };
1415 
1418  vtkIdType TraversalCellId{ 0 };
1419 
1421 
1422 private:
1423  vtkCellArray(const vtkCellArray&) = delete;
1424  void operator=(const vtkCellArray&) = delete;
1425 };
1426 
1427 template <typename ArrayT>
1429 {
1430  return this->Offsets->GetNumberOfValues() - 1;
1431 }
1432 
1433 template <typename ArrayT>
1435 {
1436  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1437 }
1438 
1439 template <typename ArrayT>
1441 {
1442  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1443 }
1444 
1445 template <typename ArrayT>
1447 {
1448  return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1449 }
1450 
1451 template <typename ArrayT>
1454 {
1455  return vtk::DataArrayValueRange<1>(
1456  this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1457 }
1458 
1460 {
1461 
1463 {
1464  // Insert full cell
1465  template <typename CellStateT>
1466  vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1467  {
1468  using ValueType = typename CellStateT::ValueType;
1469  auto* conn = state.GetConnectivity();
1470  auto* offsets = state.GetOffsets();
1471 
1472  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1473 
1474  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1475 
1476  for (vtkIdType i = 0; i < npts; ++i)
1477  {
1478  conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1479  }
1480 
1481  return cellId;
1482  }
1483 
1484  // Just update offset table (for incremental API)
1485  template <typename CellStateT>
1486  vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1487  {
1488  using ValueType = typename CellStateT::ValueType;
1489  auto* conn = state.GetConnectivity();
1490  auto* offsets = state.GetOffsets();
1491 
1492  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1493 
1494  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1495 
1496  return cellId;
1497  }
1498 };
1499 
1500 // for incremental API:
1502 {
1503  template <typename CellStateT>
1504  void operator()(CellStateT& state, const vtkIdType npts)
1505  {
1506  using ValueType = typename CellStateT::ValueType;
1507 
1508  auto* offsets = state.GetOffsets();
1509  const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1510  offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1511  }
1512 };
1513 
1515 {
1516  template <typename CellStateT>
1517  vtkIdType operator()(CellStateT& state, const vtkIdType cellId)
1518  {
1519  return state.GetCellSize(cellId);
1520  }
1521 };
1522 
1524 {
1525  template <typename CellStateT>
1526  void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1527  {
1528  using ValueType = typename CellStateT::ValueType;
1529 
1530  const auto cellPts = state.GetCellRange(cellId);
1531 
1532  ids->SetNumberOfIds(cellPts.size());
1533  vtkIdType* idPtr = ids->GetPointer(0);
1534 
1535  for (ValueType ptId : cellPts)
1536  {
1537  *idPtr++ = static_cast<vtkIdType>(ptId);
1538  }
1539  }
1540 
1541  // SFINAE helper to check if a VisitState's connectivity array's memory
1542  // can be used as a vtkIdType*.
1543  template <typename CellStateT>
1545  {
1546  private:
1547  using ValueType = typename CellStateT::ValueType;
1548  using ArrayType = typename CellStateT::ArrayType;
1550  static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1551  static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1552 
1553  public:
1554  static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1555  };
1556 
1557  template <typename CellStateT>
1559  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1560  vtkIdList* vtkNotUsed(temp))
1561  {
1562  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1563  const vtkIdType endOffset = state.GetEndOffset(cellId);
1564  cellSize = endOffset - beginOffset;
1565  // This is safe, see CanShareConnPtr helper above.
1566  cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1567  }
1568 
1569  template <typename CellStateT>
1571  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1572  vtkIdList* temp)
1573  {
1574  using ValueType = typename CellStateT::ValueType;
1575 
1576  const auto cellPts = state.GetCellRange(cellId);
1577  cellSize = cellPts.size();
1578 
1579  // ValueType differs from vtkIdType, so we have to copy into a temporary
1580  // buffer:
1581  temp->SetNumberOfIds(cellSize);
1582  vtkIdType* tempPtr = temp->GetPointer(0);
1583  for (ValueType ptId : cellPts)
1584  {
1585  *tempPtr++ = static_cast<vtkIdType>(ptId);
1586  }
1587 
1588  cellPoints = temp->GetPointer(0);
1589  }
1590 };
1591 
1593 {
1594  template <typename CellStateT>
1595  void operator()(CellStateT& state)
1596  {
1597  state.GetOffsets()->Reset();
1598  state.GetConnectivity()->Reset();
1599  state.GetOffsets()->InsertNextValue(0);
1600  }
1601 };
1602 
1603 } // end namespace vtkCellArray_detail
1604 
1605 //----------------------------------------------------------------------------
1607 {
1608  this->TraversalCellId = 0;
1609 }
1610 
1611 //----------------------------------------------------------------------------
1612 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1613 {
1614  if (this->TraversalCellId < this->GetNumberOfCells())
1615  {
1616  this->GetCellAtId(this->TraversalCellId, npts, pts);
1617  ++this->TraversalCellId;
1618  return 1;
1619  }
1620 
1621  npts = 0;
1622  pts = nullptr;
1623  return 0;
1624 }
1625 
1626 //----------------------------------------------------------------------------
1628 {
1629  if (this->TraversalCellId < this->GetNumberOfCells())
1630  {
1631  this->GetCellAtId(this->TraversalCellId, pts);
1632  ++this->TraversalCellId;
1633  return 1;
1634  }
1635 
1636  pts->Reset();
1637  return 0;
1638 }
1639 //----------------------------------------------------------------------------
1641 {
1642  return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1643 }
1644 
1645 //----------------------------------------------------------------------------
1646 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1647  vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1648 {
1649  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1650 }
1651 
1652 //----------------------------------------------------------------------------
1654 {
1655  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1656 }
1657 
1658 //----------------------------------------------------------------------------
1660  VTK_SIZEHINT(pts, npts)
1661 {
1662  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1663 }
1664 
1665 //----------------------------------------------------------------------------
1667 {
1668  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1669 }
1670 
1671 //----------------------------------------------------------------------------
1673 {
1674  if (this->Storage.Is64Bit())
1675  {
1676  using ValueType = typename ArrayType64::ValueType;
1677  this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1678  }
1679  else
1680  {
1681  using ValueType = typename ArrayType32::ValueType;
1682  this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1683  }
1684 }
1685 
1686 //----------------------------------------------------------------------------
1687 inline void vtkCellArray::UpdateCellCount(int npts)
1688 {
1690 }
1691 
1692 //----------------------------------------------------------------------------
1694 {
1695  return this->Visit(
1697 }
1698 
1699 //----------------------------------------------------------------------------
1701 {
1702  vtkIdList* pts = cell->GetPointIds();
1703  return this->Visit(
1705 }
1706 
1707 //----------------------------------------------------------------------------
1708 inline void vtkCellArray::Reset()
1709 {
1711 }
1712 
1713 #endif // vtkCellArray.h
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
Definition: vtkCellArray.h:296
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:342
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:381
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:544
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:620
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...
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:298
void Reset()
Reuse list.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:621
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:356
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:445
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:299
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.
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.
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.
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:641
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:642
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.
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:332
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:630
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:429
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:463
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...
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
vtkNew< vtkIdList > TempCell
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:609
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:320
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:744
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:536
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:150
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:245
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:165
list of point or cell ids
Definition: vtkIdList.h:143
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:238
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:169
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:257
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:119
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:82
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:226
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321
VisitState< ArrayType32 > & GetArrays32()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType64 > & GetArrays64()
ArrayType * GetOffsets()
Definition: vtkCellArray.h:905
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:963
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:962
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:902
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:908
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:895
CellRangeType GetCellRange(vtkIdType cellId)
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:906
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:909
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:894
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
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, 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:126
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