VTK  9.3.0
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
138 #ifndef vtkCellArray_h
139 #define vtkCellArray_h
140 
141 #include "vtkCommonDataModelModule.h" // For export macro
142 #include "vtkObject.h"
143 
144 #include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
145 #include "vtkCell.h" // Needed for inline methods
146 #include "vtkDataArrayRange.h" // Needed for inline methods
147 #include "vtkFeatures.h" // for VTK_USE_MEMKIND
148 #include "vtkSmartPointer.h" // For vtkSmartPointer
149 #include "vtkTypeInt32Array.h" // Needed for inline methods
150 #include "vtkTypeInt64Array.h" // Needed for inline methods
151 #include "vtkTypeList.h" // Needed for ArrayList definition
152 
153 #include <cassert> // for assert
154 #include <initializer_list> // for API
155 #include <type_traits> // for std::is_same
156 #include <utility> // for std::forward
157 
178 #define VTK_CELL_ARRAY_V2
179 
180 VTK_ABI_NAMESPACE_BEGIN
182 class vtkIdTypeArray;
183 
184 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
185 {
186 public:
187  using ArrayType32 = vtkTypeInt32Array;
188  using ArrayType64 = vtkTypeInt64Array;
189 
191 
195  static vtkCellArray* New();
196  vtkTypeMacro(vtkCellArray, vtkObject);
197  void PrintSelf(ostream& os, vtkIndent indent) override;
198  void PrintDebug(ostream& os);
200 
209  using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
210 
222 
231  vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
232  {
233  return this->AllocateExact(sz, sz) ? 1 : 0;
234  }
235 
245  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
246  {
247  return this->AllocateExact(numCells, numCells * maxCellSize);
248  }
249 
259  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
260 
271  {
272  return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
273  }
274 
284  bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
285 
289  void Initialize();
290 
294  void Reset();
295 
301  void Squeeze();
302 
313  bool IsValid();
314 
319  {
320  if (this->Storage.Is64Bit())
321  {
322  return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
323  }
324  else
325  {
326  return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
327  }
328  }
329 
335  {
336  if (this->Storage.Is64Bit())
337  {
338  return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
339  }
340  else
341  {
342  return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
343  }
344  }
345 
350  {
351  if (this->Storage.Is64Bit())
352  {
353  return this->Storage.GetArrays64().Offsets->GetValue(cellId);
354  }
355  else
356  {
357  return this->Storage.GetArrays32().Offsets->GetValue(cellId);
358  }
359  }
360 
368  {
369  if (this->Storage.Is64Bit())
370  {
371  return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
372  }
373  else
374  {
375  return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
376  }
377  }
378 
385 
396  void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
399  void SetData(
401  void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
402  void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
417  bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
418 
432  bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
433 
438  bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
439 
446  bool IsStorageShareable() const
447  {
448  if (this->Storage.Is64Bit())
449  {
451  }
452  else
453  {
455  }
456  }
457 
512  {
513  if (this->Storage.Is64Bit())
514  {
515  return this->GetOffsetsArray64();
516  }
517  else
518  {
519  return this->GetOffsetsArray32();
520  }
521  }
533  {
534  if (this->Storage.Is64Bit())
535  {
536  return this->GetConnectivityArray64();
537  }
538  else
539  {
540  return this->GetConnectivityArray32();
541  }
542  }
556 
566  void InitTraversal();
567 
582  int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
583 
594  int GetNextCell(vtkIdList* pts);
595 
606  void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
607  VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
608 
618  void GetCellAtId(
619  vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints, vtkIdList* ptIds)
620  VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
621 
627  void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
628  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
629 
633  vtkIdType GetCellSize(vtkIdType cellId) const;
634 
638  vtkIdType InsertNextCell(vtkCell* cell);
639 
644  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
645 
650  vtkIdType InsertNextCell(vtkIdList* pts);
651 
659  vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
660  {
661  return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
662  }
663 
670  vtkIdType InsertNextCell(int npts);
671 
676  void InsertCellPoint(vtkIdType id);
677 
682  void UpdateCellCount(int npts);
683 
698  void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
699 
708  void ReplaceCellAtId(vtkIdType cellId, vtkIdList* list);
709  void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
710  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
720  void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
721 
729  void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
730  {
731  return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
732  }
733 
739 
744 
749 
753  void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
754 
766 
794  void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
795  VTK_SIZEHINT(data, len);
806  unsigned long GetActualMemorySize() const;
807 
808  // The following code is used to support
809 
810  // The wrappers get understandably confused by some of the template code below
811 #ifndef __VTK_WRAP__
812 
813  // Holds connectivity and offset arrays of the given ArrayType.
814  template <typename ArrayT>
815  struct VisitState
816  {
817  using ArrayType = ArrayT;
818  using ValueType = typename ArrayType::ValueType;
819  using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
820 
821  // We can't just use is_same here, since binary compatible representations
822  // (e.g. int and long) are distinct types. Instead, ensure that ValueType
823  // is a signed integer the same size as vtkIdType.
824  // If this value is true, ValueType pointers may be safely converted to
825  // vtkIdType pointers via reinterpret cast.
826  static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
827  std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
828 
829  ArrayType* GetOffsets() { return this->Offsets; }
830  const ArrayType* GetOffsets() const { return this->Offsets; }
831 
832  ArrayType* GetConnectivity() { return this->Connectivity; }
833  const ArrayType* GetConnectivity() const { return this->Connectivity; }
834 
836 
838 
840 
842 
844 
845  friend class vtkCellArray;
846 
847  protected:
849  {
850  this->Connectivity = vtkSmartPointer<ArrayType>::New();
851  this->Offsets = vtkSmartPointer<ArrayType>::New();
852  this->Offsets->InsertNextValue(0);
854  {
855  this->IsInMemkind = true;
856  }
857  }
858  ~VisitState() = default;
859  void* operator new(size_t nSize)
860  {
861  void* r;
862 #ifdef VTK_USE_MEMKIND
864 #else
865  r = malloc(nSize);
866 #endif
867  return r;
868  }
869  void operator delete(void* p)
870  {
871 #ifdef VTK_USE_MEMKIND
872  VisitState* a = static_cast<VisitState*>(p);
873  if (a->IsInMemkind)
874  {
876  }
877  else
878  {
879  free(p);
880  }
881 #else
882  free(p);
883 #endif
884  }
885 
888 
889  private:
890  VisitState(const VisitState&) = delete;
891  VisitState& operator=(const VisitState&) = delete;
892  bool IsInMemkind = false;
893  };
894 
895 private: // Helpers that allow Visit to return a value:
896  template <typename Functor, typename... Args>
897  using GetReturnType = decltype(
898  std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
899 
900  template <typename Functor, typename... Args>
901  struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
902  {
903  };
904 
905 public:
975  template <typename Functor, typename... Args,
976  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
977  void Visit(Functor&& functor, Args&&... args)
978  {
979  if (this->Storage.Is64Bit())
980  {
981  // If you get an error on the next line, a call to Visit(functor, Args...)
982  // is being called with arguments that do not match the functor's call
983  // signature. See the Visit documentation for details.
984  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
985  }
986  else
987  {
988  // If you get an error on the next line, a call to Visit(functor, Args...)
989  // is being called with arguments that do not match the functor's call
990  // signature. See the Visit documentation for details.
991  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
992  }
993  }
994 
995  template <typename Functor, typename... Args,
996  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
997  void Visit(Functor&& functor, Args&&... args) const
998  {
999  if (this->Storage.Is64Bit())
1000  {
1001  // If you get an error on the next line, a call to Visit(functor, Args...)
1002  // is being called with arguments that do not match the functor's call
1003  // signature. See the Visit documentation for details.
1004  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1005  }
1006  else
1007  {
1008  // If you get an error on the next line, a call to Visit(functor, Args...)
1009  // is being called with arguments that do not match the functor's call
1010  // signature. See the Visit documentation for details.
1011  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1012  }
1013  }
1014 
1015  template <typename Functor, typename... Args,
1016  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1017  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1018  {
1019  if (this->Storage.Is64Bit())
1020  {
1021  // If you get an error on the next line, a call to Visit(functor, Args...)
1022  // is being called with arguments that do not match the functor's call
1023  // signature. See the Visit documentation for details.
1024  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1025  }
1026  else
1027  {
1028  // If you get an error on the next line, a call to Visit(functor, Args...)
1029  // is being called with arguments that do not match the functor's call
1030  // signature. See the Visit documentation for details.
1031  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1032  }
1033  }
1034  template <typename Functor, typename... Args,
1035  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1036  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1037  {
1038  if (this->Storage.Is64Bit())
1039  {
1040  // If you get an error on the next line, a call to Visit(functor, Args...)
1041  // is being called with arguments that do not match the functor's call
1042  // signature. See the Visit documentation for details.
1043  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1044  }
1045  else
1046  {
1047  // If you get an error on the next line, a call to Visit(functor, Args...)
1048  // is being called with arguments that do not match the functor's call
1049  // signature. See the Visit documentation for details.
1050  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1051  }
1052  }
1053 
1056 #endif // __VTK_WRAP__
1057 
1058  //=================== Begin Legacy Methods ===================================
1059  // These should be deprecated at some point as they are confusing or very slow
1060 
1068 
1080  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1081 
1091 
1099 
1109  void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1110  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1111 
1118  void GetCell(vtkIdType loc, vtkIdList* pts)
1119  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1120 
1127  vtkIdType GetInsertLocation(int npts);
1128 
1136  vtkIdType GetTraversalLocation();
1137  vtkIdType GetTraversalLocation(vtkIdType npts);
1138  void SetTraversalLocation(vtkIdType loc);
1148  void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1149 
1161  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1162  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1163 
1178  void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1179 
1191 
1192  //=================== End Legacy Methods =====================================
1193 
1194  friend class vtkCellArrayIterator;
1195 
1196 protected:
1198  ~vtkCellArray() override;
1199 
1200  // Encapsulates storage of the internal arrays as a discriminated union
1201  // between 32-bit and 64-bit storage.
1202  struct Storage
1203  {
1204  // Union type that switches 32 and 64 bit array storage
1205  union ArraySwitch {
1206  ArraySwitch() = default; // handled by Storage
1207  ~ArraySwitch() = default; // handle by Storage
1210  };
1211 
1213  {
1214 #ifdef VTK_USE_MEMKIND
1215  this->Arrays =
1217 #else
1218  this->Arrays = new ArraySwitch;
1219 #endif
1220 
1221  // Default to the compile-time setting:
1222 #ifdef VTK_USE_64BIT_IDS
1223 
1224  this->Arrays->Int64 = new VisitState<ArrayType64>;
1225  this->StorageIs64Bit = true;
1226 
1227 #else // VTK_USE_64BIT_IDS
1228 
1229  this->Arrays->Int32 = new VisitState<ArrayType32>;
1230  this->StorageIs64Bit = false;
1231 
1232 #endif // VTK_USE_64BIT_IDS
1233 #ifdef VTK_USE_MEMKIND
1235  {
1236  this->IsInMemkind = true;
1237  }
1238 #else
1239  (void)this->IsInMemkind; // comp warning workaround
1240 #endif
1241  }
1242 
1244  {
1245  if (this->StorageIs64Bit)
1246  {
1247  this->Arrays->Int64->~VisitState();
1248  delete this->Arrays->Int64;
1249  }
1250  else
1251  {
1252  this->Arrays->Int32->~VisitState();
1253  delete this->Arrays->Int32;
1254  }
1255 #ifdef VTK_USE_MEMKIND
1256  if (this->IsInMemkind)
1257  {
1259  }
1260  else
1261  {
1262  free(this->Arrays);
1263  }
1264 #else
1265  delete this->Arrays;
1266 #endif
1267  }
1268 
1269  // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1270  // true if the storage changes.
1272  {
1273  if (!this->StorageIs64Bit)
1274  {
1275  return false;
1276  }
1277 
1278  this->Arrays->Int64->~VisitState();
1279  delete this->Arrays->Int64;
1280  this->Arrays->Int32 = new VisitState<ArrayType32>;
1281  this->StorageIs64Bit = false;
1282 
1283  return true;
1284  }
1285 
1286  // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1287  // true if the storage changes.
1289  {
1290  if (this->StorageIs64Bit)
1291  {
1292  return false;
1293  }
1294 
1295  this->Arrays->Int32->~VisitState();
1296  delete this->Arrays->Int32;
1297  this->Arrays->Int64 = new VisitState<ArrayType64>;
1298  this->StorageIs64Bit = true;
1299 
1300  return true;
1301  }
1302 
1303  // Returns true if the storage is currently configured to be 64 bit.
1304  bool Is64Bit() const { return this->StorageIs64Bit; }
1305 
1306  // Get the VisitState for 32-bit arrays
1308  {
1309  assert(!this->StorageIs64Bit);
1310  return *this->Arrays->Int32;
1311  }
1312 
1314  {
1315  assert(!this->StorageIs64Bit);
1316  return *this->Arrays->Int32;
1317  }
1318 
1319  // Get the VisitState for 64-bit arrays
1321  {
1322  assert(this->StorageIs64Bit);
1323  return *this->Arrays->Int64;
1324  }
1325 
1327  {
1328  assert(this->StorageIs64Bit);
1329  return *this->Arrays->Int64;
1330  }
1331 
1332  private:
1333  // Access restricted to ensure proper union construction/destruction thru
1334  // API.
1335  ArraySwitch* Arrays;
1336  bool StorageIs64Bit;
1337  bool IsInMemkind = false;
1338  };
1339 
1342  vtkIdType TraversalCellId{ 0 };
1343 
1345 
1346 private:
1347  vtkCellArray(const vtkCellArray&) = delete;
1348  void operator=(const vtkCellArray&) = delete;
1349 };
1350 
1351 template <typename ArrayT>
1353 {
1354  return this->Offsets->GetNumberOfValues() - 1;
1355 }
1356 
1357 template <typename ArrayT>
1359 {
1360  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1361 }
1362 
1363 template <typename ArrayT>
1365 {
1366  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1367 }
1368 
1369 template <typename ArrayT>
1371 {
1372  return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1373 }
1374 
1375 template <typename ArrayT>
1378 {
1379  return vtk::DataArrayValueRange<1>(
1380  this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1381 }
1382 VTK_ABI_NAMESPACE_END
1383 
1385 {
1386 VTK_ABI_NAMESPACE_BEGIN
1387 
1389 {
1390  // Insert full cell
1391  template <typename CellStateT>
1392  vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1393  {
1394  using ValueType = typename CellStateT::ValueType;
1395  auto* conn = state.GetConnectivity();
1396  auto* offsets = state.GetOffsets();
1397 
1398  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1399 
1400  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1401 
1402  for (vtkIdType i = 0; i < npts; ++i)
1403  {
1404  conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1405  }
1406 
1407  return cellId;
1408  }
1409 
1410  // Just update offset table (for incremental API)
1411  template <typename CellStateT>
1412  vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1413  {
1414  using ValueType = typename CellStateT::ValueType;
1415  auto* conn = state.GetConnectivity();
1416  auto* offsets = state.GetOffsets();
1417 
1418  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1419 
1420  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1421 
1422  return cellId;
1423  }
1424 };
1425 
1426 // for incremental API:
1428 {
1429  template <typename CellStateT>
1430  void operator()(CellStateT& state, const vtkIdType npts)
1431  {
1432  using ValueType = typename CellStateT::ValueType;
1433 
1434  auto* offsets = state.GetOffsets();
1435  const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1436  offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1437  }
1438 };
1439 
1441 {
1442  template <typename CellStateT>
1443  vtkIdType operator()(CellStateT& state, vtkIdType cellId)
1444  {
1445  return state.GetCellSize(cellId);
1446  }
1447 };
1448 
1450 {
1451  template <typename CellStateT>
1452  void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1453  {
1454  using ValueType = typename CellStateT::ValueType;
1455 
1456  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1457  const vtkIdType endOffset = state.GetEndOffset(cellId);
1458  const vtkIdType cellSize = endOffset - beginOffset;
1459  const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1460 
1461  // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1462  ids->SetNumberOfIds(cellSize);
1463  vtkIdType* idPtr = ids->GetPointer(0);
1464  for (ValueType i = 0; i < cellSize; ++i)
1465  {
1466  idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1467  }
1468  }
1469 
1470  // SFINAE helper to check if a VisitState's connectivity array's memory
1471  // can be used as a vtkIdType*.
1472  template <typename CellStateT>
1474  {
1475  private:
1476  using ValueType = typename CellStateT::ValueType;
1477  using ArrayType = typename CellStateT::ArrayType;
1479  static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1480  static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1481 
1482  public:
1483  static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1484  };
1485 
1486  template <typename CellStateT>
1488  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1489  vtkIdList* vtkNotUsed(temp))
1490  {
1491  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1492  const vtkIdType endOffset = state.GetEndOffset(cellId);
1493  cellSize = endOffset - beginOffset;
1494  // This is safe, see CanShareConnPtr helper above.
1495  cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1496  }
1497 
1498  template <typename CellStateT>
1500  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1501  vtkIdList* temp)
1502  {
1503  using ValueType = typename CellStateT::ValueType;
1504 
1505  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1506  const vtkIdType endOffset = state.GetEndOffset(cellId);
1507  cellSize = endOffset - beginOffset;
1508  const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1509 
1510  // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1511  temp->SetNumberOfIds(cellSize);
1512  vtkIdType* tempPtr = temp->GetPointer(0);
1513  for (vtkIdType i = 0; i < cellSize; ++i)
1514  {
1515  tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1516  }
1517 
1518  cellPoints = temp->GetPointer(0);
1519  }
1520 };
1521 
1523 {
1524  template <typename CellStateT>
1525  void operator()(CellStateT& state)
1526  {
1527  state.GetOffsets()->Reset();
1528  state.GetConnectivity()->Reset();
1529  state.GetOffsets()->InsertNextValue(0);
1530  }
1531 };
1532 
1533 VTK_ABI_NAMESPACE_END
1534 } // end namespace vtkCellArray_detail
1535 
1536 VTK_ABI_NAMESPACE_BEGIN
1537 //----------------------------------------------------------------------------
1539 {
1540  this->TraversalCellId = 0;
1541 }
1542 
1543 //----------------------------------------------------------------------------
1544 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1545 {
1546  if (this->TraversalCellId < this->GetNumberOfCells())
1547  {
1548  this->GetCellAtId(this->TraversalCellId, npts, pts);
1549  ++this->TraversalCellId;
1550  return 1;
1551  }
1552 
1553  npts = 0;
1554  pts = nullptr;
1555  return 0;
1556 }
1557 
1558 //----------------------------------------------------------------------------
1560 {
1561  if (this->TraversalCellId < this->GetNumberOfCells())
1562  {
1563  this->GetCellAtId(this->TraversalCellId, pts);
1564  ++this->TraversalCellId;
1565  return 1;
1566  }
1567 
1568  pts->Reset();
1569  return 0;
1570 }
1571 //----------------------------------------------------------------------------
1573 {
1574  return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1575 }
1576 
1577 //----------------------------------------------------------------------------
1578 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1579  vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1580 {
1581  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1582 }
1583 
1584 //----------------------------------------------------------------------------
1585 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1586  vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1587 {
1588  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1589 }
1590 
1591 //----------------------------------------------------------------------------
1593 {
1594  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1595 }
1596 
1597 //----------------------------------------------------------------------------
1599  VTK_SIZEHINT(pts, npts)
1600 {
1601  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1602 }
1603 
1604 //----------------------------------------------------------------------------
1606 {
1607  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1608 }
1609 
1610 //----------------------------------------------------------------------------
1612 {
1613  if (this->Storage.Is64Bit())
1614  {
1615  using ValueType = typename ArrayType64::ValueType;
1616  this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1617  }
1618  else
1619  {
1620  using ValueType = typename ArrayType32::ValueType;
1621  this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1622  }
1623 }
1624 
1625 //----------------------------------------------------------------------------
1626 inline void vtkCellArray::UpdateCellCount(int npts)
1627 {
1629 }
1630 
1631 //----------------------------------------------------------------------------
1633 {
1634  return this->Visit(
1636 }
1637 
1638 //----------------------------------------------------------------------------
1640 {
1641  vtkIdList* pts = cell->GetPointIds();
1642  return this->Visit(
1644 }
1645 
1646 //----------------------------------------------------------------------------
1647 inline void vtkCellArray::Reset()
1648 {
1650 }
1651 
1652 VTK_ABI_NAMESPACE_END
1653 #endif // vtkCellArray.h
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
Definition: vtkCellArray.h:185
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().
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:231
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
Storage Storage
vtkIdType GetOffset(vtkIdType cellId)
Get the offset (into the connectivity) for a specified cell id.
Definition: vtkCellArray.h:349
vtkIdType GetCellSize(vtkIdType cellId) const
Return the size of the cell at cellId.
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
Definition: vtkCellArray.h:270
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:446
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:522
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)
Definition: vtkCellArray.h:977
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:187
void Reset()
Reuse list.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:523
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:245
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:334
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:188
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:543
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:544
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
Definition: vtkCellArray.h:997
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:221
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:532
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:318
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:367
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:511
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:209
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:659
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
bool IsStorage64Bit() const
Definition: vtkCellArray.h:438
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:59
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:154
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
list of point or cell ids
Definition: vtkIdList.h:32
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:58
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:143
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:124
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition: vtkIndent.h:38
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:61
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:829
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:887
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:886
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:832
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:819
CellRangeType GetCellRange(vtkIdType cellId)
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:830
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:833
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:818
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, 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