VTK  9.0.3
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 =========================================================================*/
135 #ifndef vtkCellArray_h
136 #define vtkCellArray_h
137 
138 #include "vtkCommonDataModelModule.h" // For export macro
139 #include "vtkObject.h"
140 
141 #include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
142 #include "vtkCell.h" // Needed for inline methods
143 #include "vtkDataArrayRange.h" // Needed for inline methods
144 #include "vtkSmartPointer.h" // For vtkSmartPointer
145 #include "vtkTypeInt32Array.h" // Needed for inline methods
146 #include "vtkTypeInt64Array.h" // Needed for inline methods
147 #include "vtkTypeList.h" // Needed for ArrayList definition
148 
149 #include <cassert> // for assert
150 #include <initializer_list> // for API
151 #include <type_traits> // for std::is_same
152 #include <utility> // for std::forward
153 
174 #define VTK_CELL_ARRAY_V2
175 
177 class vtkIdTypeArray;
178 
179 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
180 {
181 public:
182  using ArrayType32 = vtkTypeInt32Array;
183  using ArrayType64 = vtkTypeInt64Array;
184 
186 
190  static vtkCellArray* New();
191  vtkTypeMacro(vtkCellArray, vtkObject);
192  void PrintSelf(ostream& os, vtkIndent indent) override;
193  void PrintDebug(ostream& os);
195 
204  using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
205 
217 
226  vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
227  {
228  return this->AllocateExact(sz, sz) ? 1 : 0;
229  }
230 
240  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
241  {
242  return this->AllocateExact(numCells, numCells * maxCellSize);
243  }
244 
254  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
255 
266  {
267  return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
268  }
269 
279  bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
280 
284  void Initialize();
285 
289  void Reset();
290 
296  void Squeeze();
297 
308  bool IsValid();
309 
314  {
315  if (this->Storage.Is64Bit())
316  {
317  return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
318  }
319  else
320  {
321  return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
322  }
323  }
324 
330  {
331  if (this->Storage.Is64Bit())
332  {
333  return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
334  }
335  else
336  {
337  return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
338  }
339  }
340 
348  {
349  if (this->Storage.Is64Bit())
350  {
351  return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
352  }
353  else
354  {
355  return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
356  }
357  }
358 
365 
366 #ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
377  void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
378  void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
379  void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
382  void SetData(
385 #endif // __VTK_WRAP__
386 
399  bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
400 
405  bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
406 
413  bool IsStorageShareable() const
414  {
415  if (this->Storage.Is64Bit())
416  {
418  }
419  else
420  {
422  }
423  }
424 
479  {
480  if (this->Storage.Is64Bit())
481  {
482  return this->GetOffsetsArray64();
483  }
484  else
485  {
486  return this->GetOffsetsArray32();
487  }
488  }
500  {
501  if (this->Storage.Is64Bit())
502  {
503  return this->GetConnectivityArray64();
504  }
505  else
506  {
507  return this->GetConnectivityArray32();
508  }
509  }
523 
533  void InitTraversal();
534 
549  int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
550 
561  int GetNextCell(vtkIdList* pts);
562 
573  void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
574  VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
575 
581  void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
582  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
583 
587  vtkIdType GetCellSize(const vtkIdType cellId) const;
588 
592  vtkIdType InsertNextCell(vtkCell* cell);
593 
599 
604  vtkIdType InsertNextCell(vtkIdList* pts);
605 
613  vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
614  {
615  return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
616  }
617 
624  vtkIdType InsertNextCell(int npts);
625 
630  void InsertCellPoint(vtkIdType id);
631 
636  void UpdateCellCount(int npts);
637 
652  void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
653 
662  void ReplaceCellAtId(vtkIdType cellId, vtkIdList* list);
663  void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
664  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
674  void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
675  {
676  return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
677  }
678 
684 
689 
694 
698  void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
699 
711 
739  void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
740  VTK_SIZEHINT(data, len);
751  unsigned long GetActualMemorySize() const;
752 
753  // The following code is used to support
754 
755  // The wrappers get understandably confused by some of the template code below
756 #ifndef __VTK_WRAP__
757 
758  // Holds connectivity and offset arrays of the given ArrayType.
759  template <typename ArrayT>
760  struct VisitState
761  {
762  using ArrayType = ArrayT;
763  using ValueType = typename ArrayType::ValueType;
764  using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
765 
766  // We can't just use is_same here, since binary compatible representations
767  // (e.g. int and long) are distinct types. Instead, ensure that ValueType
768  // is a signed integer the same size as vtkIdType.
769  // If this value is true, ValueType pointers may be safely converted to
770  // vtkIdType pointers via reinterpret cast.
771  static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
772  std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
773 
774  ArrayType* GetOffsets() { return this->Offsets; }
775  const ArrayType* GetOffsets() const { return this->Offsets; }
776 
777  ArrayType* GetConnectivity() { return this->Connectivity; }
778  const ArrayType* GetConnectivity() const { return this->Connectivity; }
779 
781 
783 
785 
787 
789 
790  friend class vtkCellArray;
791 
792  protected:
794  : Connectivity(vtkSmartPointer<ArrayType>::New())
795  , Offsets(vtkSmartPointer<ArrayType>::New())
796  {
797  this->Offsets->InsertNextValue(0);
798  }
799  ~VisitState() = default;
800 
803 
804  private:
805  VisitState(const VisitState&) = delete;
806  VisitState& operator=(const VisitState&) = delete;
807  };
808 
809 private: // Helpers that allow Visit to return a value:
810  template <typename Functor, typename... Args>
811  using GetReturnType = decltype(
812  std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
813 
814  template <typename Functor, typename... Args>
815  struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
816  {
817  };
818 
819 public:
889  template <typename Functor, typename... Args,
890  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
891  void Visit(Functor&& functor, Args&&... args)
892  {
893  if (this->Storage.Is64Bit())
894  {
895  // If you get an error on the next line, a call to Visit(functor, Args...)
896  // is being called with arguments that do not match the functor's call
897  // signature. See the Visit documentation for details.
898  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
899  }
900  else
901  {
902  // If you get an error on the next line, a call to Visit(functor, Args...)
903  // is being called with arguments that do not match the functor's call
904  // signature. See the Visit documentation for details.
905  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
906  }
907  }
908 
909  template <typename Functor, typename... Args,
910  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
911  void Visit(Functor&& functor, Args&&... args) const
912  {
913  if (this->Storage.Is64Bit())
914  {
915  // If you get an error on the next line, a call to Visit(functor, Args...)
916  // is being called with arguments that do not match the functor's call
917  // signature. See the Visit documentation for details.
918  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
919  }
920  else
921  {
922  // If you get an error on the next line, a call to Visit(functor, Args...)
923  // is being called with arguments that do not match the functor's call
924  // signature. See the Visit documentation for details.
925  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
926  }
927  }
928 
929  template <typename Functor, typename... Args,
930  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
931  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
932  {
933  if (this->Storage.Is64Bit())
934  {
935  // If you get an error on the next line, a call to Visit(functor, Args...)
936  // is being called with arguments that do not match the functor's call
937  // signature. See the Visit documentation for details.
938  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
939  }
940  else
941  {
942  // If you get an error on the next line, a call to Visit(functor, Args...)
943  // is being called with arguments that do not match the functor's call
944  // signature. See the Visit documentation for details.
945  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
946  }
947  }
948  template <typename Functor, typename... Args,
949  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
950  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
951  {
952  if (this->Storage.Is64Bit())
953  {
954  // If you get an error on the next line, a call to Visit(functor, Args...)
955  // is being called with arguments that do not match the functor's call
956  // signature. See the Visit documentation for details.
957  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
958  }
959  else
960  {
961  // If you get an error on the next line, a call to Visit(functor, Args...)
962  // is being called with arguments that do not match the functor's call
963  // signature. See the Visit documentation for details.
964  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
965  }
966  }
967 
970 #endif // __VTK_WRAP__
971 
972  //=================== Begin Legacy Methods ===================================
973  // These should be deprecated at some point as they are confusing or very slow
974 
982 
994  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
995 
1005 
1013 
1023  void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1024  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1025 
1032  void GetCell(vtkIdType loc, vtkIdList* pts)
1033  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1034 
1041  vtkIdType GetInsertLocation(int npts);
1042 
1050  vtkIdType GetTraversalLocation();
1051  vtkIdType GetTraversalLocation(vtkIdType npts);
1052  void SetTraversalLocation(vtkIdType loc);
1062  void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1063 
1075  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1076  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1077 
1092  void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1093 
1104  vtkIdTypeArray* GetData();
1105 
1106  //=================== End Legacy Methods =====================================
1107 
1108  friend class vtkCellArrayIterator;
1109 
1110 protected:
1112  ~vtkCellArray() override;
1113 
1114  // Encapsulates storage of the internal arrays as a discriminated union
1115  // between 32-bit and 64-bit storage.
1116  struct Storage
1117  {
1118  // Union type that switches 32 and 64 bit array storage
1119  union ArraySwitch {
1120  ArraySwitch() {} // handled by Storage
1121  ~ArraySwitch() {} // handle by Storage
1122 
1125  };
1126 
1128  {
1129  // Default to the compile-time setting:
1130 #ifdef VTK_USE_64BIT_IDS
1131 
1132  new (&this->Arrays.Int64) VisitState<ArrayType64>;
1133  this->StorageIs64Bit = true;
1134 
1135 #else // VTK_USE_64BIT_IDS
1136 
1137  new (&this->Arrays.Int32) VisitState<ArrayType32>;
1138  this->StorageIs64Bit = false;
1139 
1140 #endif // VTK_USE_64BIT_IDS
1141  }
1142 
1144  {
1145  if (this->StorageIs64Bit)
1146  {
1147  this->Arrays.Int64.~VisitState();
1148  }
1149  else
1150  {
1151  this->Arrays.Int32.~VisitState();
1152  }
1153  }
1154 
1155  // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1156  // true if the storage changes.
1158  {
1159  if (!this->StorageIs64Bit)
1160  {
1161  return false;
1162  }
1163 
1164  this->Arrays.Int64.~VisitState();
1165  new (&this->Arrays.Int32) VisitState<ArrayType32>;
1166  this->StorageIs64Bit = false;
1167 
1168  return true;
1169  }
1170 
1171  // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1172  // true if the storage changes.
1174  {
1175  if (this->StorageIs64Bit)
1176  {
1177  return false;
1178  }
1179 
1180  this->Arrays.Int32.~VisitState();
1181  new (&this->Arrays.Int64) VisitState<ArrayType64>;
1182  this->StorageIs64Bit = true;
1183 
1184  return true;
1185  }
1186 
1187  // Returns true if the storage is currently configured to be 64 bit.
1188  bool Is64Bit() const { return this->StorageIs64Bit; }
1189 
1190  // Get the VisitState for 32-bit arrays
1192  {
1193  assert(!this->StorageIs64Bit);
1194  return this->Arrays.Int32;
1195  }
1196 
1198  {
1199  assert(!this->StorageIs64Bit);
1200  return this->Arrays.Int32;
1201  }
1202 
1203  // Get the VisitState for 64-bit arrays
1205  {
1206  assert(this->StorageIs64Bit);
1207  return this->Arrays.Int64;
1208  }
1209 
1211  {
1212  assert(this->StorageIs64Bit);
1213  return this->Arrays.Int64;
1214  }
1215 
1216  private:
1217  // Access restricted to ensure proper union construction/destruction thru
1218  // API.
1219  ArraySwitch Arrays;
1220  bool StorageIs64Bit;
1221  };
1222 
1225  vtkIdType TraversalCellId{ 0 };
1226 
1228 
1229 private:
1230  vtkCellArray(const vtkCellArray&) = delete;
1231  void operator=(const vtkCellArray&) = delete;
1232 };
1233 
1234 template <typename ArrayT>
1236 {
1237  return this->Offsets->GetNumberOfValues() - 1;
1238 }
1239 
1240 template <typename ArrayT>
1242 {
1243  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1244 }
1245 
1246 template <typename ArrayT>
1248 {
1249  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1250 }
1251 
1252 template <typename ArrayT>
1254 {
1255  return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1256 }
1257 
1258 template <typename ArrayT>
1261 {
1262  return vtk::DataArrayValueRange<1>(
1263  this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1264 }
1265 
1267 {
1268 
1270 {
1271  // Insert full cell
1272  template <typename CellStateT>
1273  vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1274  {
1275  using ValueType = typename CellStateT::ValueType;
1276  auto* conn = state.GetConnectivity();
1277  auto* offsets = state.GetOffsets();
1278 
1279  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1280 
1281  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1282 
1283  for (vtkIdType i = 0; i < npts; ++i)
1284  {
1285  conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1286  }
1287 
1288  return cellId;
1289  }
1290 
1291  // Just update offset table (for incremental API)
1292  template <typename CellStateT>
1293  vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1294  {
1295  using ValueType = typename CellStateT::ValueType;
1296  auto* conn = state.GetConnectivity();
1297  auto* offsets = state.GetOffsets();
1298 
1299  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1300 
1301  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1302 
1303  return cellId;
1304  }
1305 };
1306 
1307 // for incremental API:
1309 {
1310  template <typename CellStateT>
1311  void operator()(CellStateT& state, const vtkIdType npts)
1312  {
1313  using ValueType = typename CellStateT::ValueType;
1314 
1315  auto* offsets = state.GetOffsets();
1316  const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1317  offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1318  }
1319 };
1320 
1322 {
1323  template <typename CellStateT>
1324  vtkIdType operator()(CellStateT& state, const vtkIdType cellId)
1325  {
1326  return state.GetCellSize(cellId);
1327  }
1328 };
1329 
1331 {
1332  template <typename CellStateT>
1333  void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1334  {
1335  using ValueType = typename CellStateT::ValueType;
1336 
1337  const auto cellPts = state.GetCellRange(cellId);
1338 
1339  ids->SetNumberOfIds(cellPts.size());
1340  vtkIdType* idPtr = ids->GetPointer(0);
1341 
1342  for (ValueType ptId : cellPts)
1343  {
1344  *idPtr++ = static_cast<vtkIdType>(ptId);
1345  }
1346  }
1347 
1348  // SFINAE helper to check if a VisitState's connectivity array's memory
1349  // can be used as a vtkIdType*.
1350  template <typename CellStateT>
1352  {
1353  private:
1354  using ValueType = typename CellStateT::ValueType;
1355  using ArrayType = typename CellStateT::ArrayType;
1357  static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1358  static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1359 
1360  public:
1361  static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1362  };
1363 
1364  template <typename CellStateT>
1366  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1367  vtkIdList* vtkNotUsed(temp))
1368  {
1369  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1370  const vtkIdType endOffset = state.GetEndOffset(cellId);
1371  cellSize = endOffset - beginOffset;
1372  // This is safe, see CanShareConnPtr helper above.
1373  cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1374  }
1375 
1376  template <typename CellStateT>
1378  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1379  vtkIdList* temp)
1380  {
1381  using ValueType = typename CellStateT::ValueType;
1382 
1383  const auto cellPts = state.GetCellRange(cellId);
1384  cellSize = cellPts.size();
1385 
1386  // ValueType differs from vtkIdType, so we have to copy into a temporary
1387  // buffer:
1388  temp->SetNumberOfIds(cellSize);
1389  vtkIdType* tempPtr = temp->GetPointer(0);
1390  for (ValueType ptId : cellPts)
1391  {
1392  *tempPtr++ = static_cast<vtkIdType>(ptId);
1393  }
1394 
1395  cellPoints = temp->GetPointer(0);
1396  }
1397 };
1398 
1400 {
1401  template <typename CellStateT>
1402  void operator()(CellStateT& state)
1403  {
1404  state.GetOffsets()->Reset();
1405  state.GetConnectivity()->Reset();
1406  state.GetOffsets()->InsertNextValue(0);
1407  }
1408 };
1409 
1410 } // end namespace vtkCellArray_detail
1411 
1412 //----------------------------------------------------------------------------
1414 {
1415  this->TraversalCellId = 0;
1416 }
1417 
1418 //----------------------------------------------------------------------------
1419 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1420 {
1421  if (this->TraversalCellId < this->GetNumberOfCells())
1422  {
1423  this->GetCellAtId(this->TraversalCellId, npts, pts);
1424  ++this->TraversalCellId;
1425  return 1;
1426  }
1427 
1428  npts = 0;
1429  pts = nullptr;
1430  return 0;
1431 }
1432 
1433 //----------------------------------------------------------------------------
1435 {
1436  if (this->TraversalCellId < this->GetNumberOfCells())
1437  {
1438  this->GetCellAtId(this->TraversalCellId, pts);
1439  ++this->TraversalCellId;
1440  return 1;
1441  }
1442 
1443  pts->Reset();
1444  return 0;
1445 }
1446 //----------------------------------------------------------------------------
1448 {
1449  return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1450 }
1451 
1452 //----------------------------------------------------------------------------
1453 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1454  vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1455 {
1456  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1457 }
1458 
1459 //----------------------------------------------------------------------------
1461 {
1462  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1463 }
1464 
1465 //----------------------------------------------------------------------------
1467  VTK_SIZEHINT(pts, npts)
1468 {
1469  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1470 }
1471 
1472 //----------------------------------------------------------------------------
1474 {
1475  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1476 }
1477 
1478 //----------------------------------------------------------------------------
1480 {
1481  if (this->Storage.Is64Bit())
1482  {
1483  using ValueType = typename ArrayType64::ValueType;
1484  this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1485  }
1486  else
1487  {
1488  using ValueType = typename ArrayType32::ValueType;
1489  this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1490  }
1491 }
1492 
1493 //----------------------------------------------------------------------------
1494 inline void vtkCellArray::UpdateCellCount(int npts)
1495 {
1497 }
1498 
1499 //----------------------------------------------------------------------------
1501 {
1502  return this->Visit(
1504 }
1505 
1506 //----------------------------------------------------------------------------
1508 {
1509  vtkIdList* pts = cell->GetPointIds();
1510  return this->Visit(
1512 }
1513 
1514 //----------------------------------------------------------------------------
1515 inline void vtkCellArray::Reset()
1516 {
1518 }
1519 
1520 #endif // vtkCellArray.h
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
Definition: vtkCellArray.h:180
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:226
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:265
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:413
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:489
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.
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:891
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:182
void Reset()
Reuse list.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:490
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)
Definition: vtkCellArray.h:931
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:240
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:329
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:183
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.
vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType *pts)
Create a cell by specifying the number of points and an array of point id's.
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:510
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:216
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:511
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:911
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.
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:499
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:313
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:347
vtkNew< vtkIdTypeArray > LegacyData
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void PrintDebug(ostream &os)
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
Definition: vtkCellArray.h:950
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:478
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:204
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:613
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:405
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:57
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:152
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
list of point or cell ids
Definition: vtkIdList.h:31
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:120
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:57
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:139
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:34
abstract base class for most VTK objects
Definition: vtkObject.h:63
Hold a reference to a vtkObjectBase instance.
@ 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:774
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:802
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:801
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:771
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:777
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:764
CellRangeType GetCellRange(vtkIdType cellId)
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:775
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:778
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:763
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:125
VisitState< ArrayType32 > Int32
VisitState< ArrayType64 > Int64
int vtkTypeBool
Definition: vtkABI.h:69
STL-compatible iterable ranges that provide access to vtkDataArray elements.
int vtkIdType
Definition: vtkType.h:338
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE