VTK  9.0.1
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 
205 
214  using InputArrayList =
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 
364  VTK_NEWINSTANCE vtkCellArrayIterator* NewIterator();
365 
366 #ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
367 
377  void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
378  void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
379  void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
380  void SetData(vtkAOSDataArrayTemplate<int>* offsets, vtkAOSDataArrayTemplate<int>* connectivity);
381  void SetData(vtkAOSDataArrayTemplate<long>* offsets, vtkAOSDataArrayTemplate<long>* 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 
433  void Use32BitStorage();
434  void Use64BitStorage();
435  void UseDefaultStorage();
446  bool CanConvertTo32BitStorage() const;
447  bool CanConvertTo64BitStorage() const;
448  bool CanConvertToDefaultStorage() const;
467  bool ConvertTo32BitStorage();
468  bool ConvertTo64BitStorage();
469  bool ConvertToDefaultStorage();
470  bool ConvertToSmallestStorage();
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  }
522  vtkIdType IsHomogeneous();
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 
598  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
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 
645  vtkIdType GetTraversalCellId();
646  void SetTraversalCellId(vtkIdType cellId);
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 
683  int GetMaxCellSize();
684 
688  void DeepCopy(vtkCellArray* ca);
689 
693  void ShallowCopy(vtkCellArray* ca);
694 
698  void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
699 
710  void ExportLegacyFormat(vtkIdTypeArray* data);
711 
723  void ImportLegacyFormat(vtkIdTypeArray* data);
724  void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
738  void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
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 
780  vtkIdType GetNumberOfCells() const;
781 
782  vtkIdType GetBeginOffset(vtkIdType cellId) const;
783 
784  vtkIdType GetEndOffset(vtkIdType cellId) const;
785 
786  vtkIdType GetCellSize(vtkIdType cellId) const;
787 
788  CellRangeType GetCellRange(vtkIdType cellId);
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 
981  virtual void SetNumberOfCells(vtkIdType);
982 
994  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
995 
1004  vtkIdType GetSize();
1005 
1012  vtkIdType GetNumberOfConnectivityEntries();
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:
1111  vtkCellArray();
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
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells&#39; connectivity. ...
Definition: vtkCellArray.h:511
vtkIdType GetCellSize(vtkIdType cellId) const
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
Definition: vtkCellArray.h:226
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells&#39; connectivity. ...
Definition: vtkCellArray.h:510
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells&#39; connectivity. ...
Definition: vtkCellArray.h:499
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:777
abstract base class for most VTK objects
Definition: vtkObject.h:62
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
Definition: vtkCellArray.h:950
Remove all duplicate types from TypeList TList, storing the new list in Result.
Definition: vtkTypeList.h:125
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:764
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells...
vtkIdType operator()(CellStateT &state, const vtkIdType cellId)
void operator()(CellStateT &state)
vtkNew< vtkIdTypeArray > LegacyData
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:139
vtkIdType GetNumberOfIds()
Return the number of id&#39;s in the list.
Definition: vtkIdList.h:57
vtkIdType GetNumberOfConnectivityIds() const
Get the size of the connectivity array that stores the point ids.
Definition: vtkCellArray.h:347
void InitTraversal()
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:801
void Visit(Functor &&functor, Args &&... args) const
Definition: vtkCellArray.h:911
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:204
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:489
dynamic, self-adjusting array of vtkIdType
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:32
const VisitState< ArrayType32 > & GetArrays32() const
int vtkIdType
Definition: vtkType.h:338
vtkIdType TraversalCellId
typename vtkTypeList::detail::CreateImpl< Ts... >::type Create
Definition: vtkTypeList.h:176
bool IsStorageShareable() const
Definition: vtkCellArray.h:413
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray...
Definition: vtkCellArray.h:265
int vtkTypeBool
Definition: vtkABI.h:69
vtkNew< vtkIdList > TempCell
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:931
abstract class to specify cell behavior
Definition: vtkCell.h:56
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:771
void Reset()
Reuse list.
void operator()(CellStateT &state, const vtkIdType npts)
a simple class to control print indentation
Definition: vtkIndent.h:33
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
bool IsStorage64Bit() const
Definition: vtkCellArray.h:405
list of point or cell ids
Definition: vtkIdList.h:30
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:183
#define VTK_SIZEHINT(...)
VisitState< ArrayType64 > Int64
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
#define VTK_NEWINSTANCE
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:775
std::enable_if< CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *vtkNotUsed(temp))
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:802
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
VisitState< ArrayType64 > & GetArrays64()
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:478
object to represent cell connectivity
Definition: vtkCellArray.h:179
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:182
ArrayType * GetOffsets()
Definition: vtkCellArray.h:774
VisitState< ArrayType32 > Int32
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:763
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:613
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:329
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:778
void Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:891
vtkIdType GetBeginOffset(vtkIdType cellId) const
std::enable_if<!CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:490
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:152
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
VisitState< ArrayType32 > & GetArrays32()
vtkIdType GetNumberOfCells() const
Get the number of cells in the array.
Definition: vtkCellArray.h:313
#define VTK_EXPECTS(x)
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:120
Encapsulate traversal logic for vtkCellArray.
Storage Storage
vtkIdType GetNumberOfCells() const
const VisitState< ArrayType64 > & GetArrays64() const
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
STL-compatible iterable ranges that provide access to vtkDataArray elements.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
Definition: vtkCellArray.h:240
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)