VTK  9.0.20201025
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 "vtkFeatures.h" // for VTK_USE_MEMKIND
145 #include "vtkSmartPointer.h" // For vtkSmartPointer
146 #include "vtkTypeInt32Array.h" // Needed for inline methods
147 #include "vtkTypeInt64Array.h" // Needed for inline methods
148 #include "vtkTypeList.h" // Needed for ArrayList definition
149 
150 #include <cassert> // for assert
151 #include <initializer_list> // for API
152 #include <type_traits> // for std::is_same
153 #include <utility> // for std::forward
154 
175 #define VTK_CELL_ARRAY_V2
176 
178 class vtkIdTypeArray;
179 
180 class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
181 {
182 public:
183  using ArrayType32 = vtkTypeInt32Array;
184  using ArrayType64 = vtkTypeInt64Array;
185 
187 
191  static vtkCellArray* New();
192  vtkTypeMacro(vtkCellArray, vtkObject);
193  void PrintSelf(ostream& os, vtkIndent indent) override;
194  void PrintDebug(ostream& os);
196 
205  using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
206 
215  using InputArrayList =
218 
227  vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
228  {
229  return this->AllocateExact(sz, sz) ? 1 : 0;
230  }
231 
241  bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
242  {
243  return this->AllocateExact(numCells, numCells * maxCellSize);
244  }
245 
255  bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
256 
267  {
268  return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
269  }
270 
280  bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
281 
285  void Initialize();
286 
290  void Reset();
291 
297  void Squeeze();
298 
309  bool IsValid();
310 
315  {
316  if (this->Storage.Is64Bit())
317  {
318  return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
319  }
320  else
321  {
322  return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
323  }
324  }
325 
331  {
332  if (this->Storage.Is64Bit())
333  {
334  return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
335  }
336  else
337  {
338  return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
339  }
340  }
341 
349  {
350  if (this->Storage.Is64Bit())
351  {
352  return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
353  }
354  else
355  {
356  return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
357  }
358  }
359 
365  VTK_NEWINSTANCE vtkCellArrayIterator* NewIterator();
366 
367 #ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
368 
378  void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
379  void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
380  void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
381  void SetData(vtkAOSDataArrayTemplate<int>* offsets, vtkAOSDataArrayTemplate<int>* connectivity);
382  void SetData(vtkAOSDataArrayTemplate<long>* offsets, vtkAOSDataArrayTemplate<long>* connectivity);
383  void SetData(
386 #endif // __VTK_WRAP__
387 
400  bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
401 
415  bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
416 
421  bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
422 
429  bool IsStorageShareable() const
430  {
431  if (this->Storage.Is64Bit())
432  {
434  }
435  else
436  {
438  }
439  }
440 
449  void Use32BitStorage();
450  void Use64BitStorage();
451  void UseDefaultStorage();
462  bool CanConvertTo32BitStorage() const;
463  bool CanConvertTo64BitStorage() const;
464  bool CanConvertToDefaultStorage() const;
483  bool ConvertTo32BitStorage();
484  bool ConvertTo64BitStorage();
485  bool ConvertToDefaultStorage();
486  bool ConvertToSmallestStorage();
495  {
496  if (this->Storage.Is64Bit())
497  {
498  return this->GetOffsetsArray64();
499  }
500  else
501  {
502  return this->GetOffsetsArray32();
503  }
504  }
516  {
517  if (this->Storage.Is64Bit())
518  {
519  return this->GetConnectivityArray64();
520  }
521  else
522  {
523  return this->GetConnectivityArray32();
524  }
525  }
538  vtkIdType IsHomogeneous();
539 
549  void InitTraversal();
550 
565  int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
566 
577  int GetNextCell(vtkIdList* pts);
578 
589  void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
590  VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
591 
597  void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
598  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
599 
603  vtkIdType GetCellSize(const vtkIdType cellId) const;
604 
608  vtkIdType InsertNextCell(vtkCell* cell);
609 
614  vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
615 
620  vtkIdType InsertNextCell(vtkIdList* pts);
621 
629  vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
630  {
631  return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
632  }
633 
640  vtkIdType InsertNextCell(int npts);
641 
646  void InsertCellPoint(vtkIdType id);
647 
652  void UpdateCellCount(int npts);
653 
661  vtkIdType GetTraversalCellId();
662  void SetTraversalCellId(vtkIdType cellId);
668  void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
669 
678  void ReplaceCellAtId(vtkIdType cellId, vtkIdList* list);
679  void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
680  VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
690  void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
691  {
692  return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
693  }
694 
699  int GetMaxCellSize();
700 
704  void DeepCopy(vtkCellArray* ca);
705 
709  void ShallowCopy(vtkCellArray* ca);
710 
714  void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
715 
726  void ExportLegacyFormat(vtkIdTypeArray* data);
727 
739  void ImportLegacyFormat(vtkIdTypeArray* data);
740  void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
754  void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
755  void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
756  VTK_SIZEHINT(data, len);
767  unsigned long GetActualMemorySize() const;
768 
769  // The following code is used to support
770 
771  // The wrappers get understandably confused by some of the template code below
772 #ifndef __VTK_WRAP__
773 
774  // Holds connectivity and offset arrays of the given ArrayType.
775  template <typename ArrayT>
776  struct VisitState
777  {
778  using ArrayType = ArrayT;
779  using ValueType = typename ArrayType::ValueType;
780  using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
781 
782  // We can't just use is_same here, since binary compatible representations
783  // (e.g. int and long) are distinct types. Instead, ensure that ValueType
784  // is a signed integer the same size as vtkIdType.
785  // If this value is true, ValueType pointers may be safely converted to
786  // vtkIdType pointers via reinterpret cast.
787  static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
788  std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
789 
790  ArrayType* GetOffsets() { return this->Offsets; }
791  const ArrayType* GetOffsets() const { return this->Offsets; }
792 
793  ArrayType* GetConnectivity() { return this->Connectivity; }
794  const ArrayType* GetConnectivity() const { return this->Connectivity; }
795 
796  vtkIdType GetNumberOfCells() const;
797 
798  vtkIdType GetBeginOffset(vtkIdType cellId) const;
799 
800  vtkIdType GetEndOffset(vtkIdType cellId) const;
801 
802  vtkIdType GetCellSize(vtkIdType cellId) const;
803 
804  CellRangeType GetCellRange(vtkIdType cellId);
805 
806  friend class vtkCellArray;
807 
808  protected:
810  {
811  this->Connectivity = vtkSmartPointer<ArrayType>::New();
812  this->Offsets = vtkSmartPointer<ArrayType>::New();
813  this->Offsets->InsertNextValue(0);
815  {
816  this->IsInMemkind = true;
817  }
818  }
819  ~VisitState() = default;
820  void* operator new(size_t nSize)
821  {
822  void* r;
823 #ifdef VTK_USE_MEMKIND
825 #else
826  r = malloc(nSize);
827 #endif
828  return r;
829  }
830  void operator delete(void* p)
831  {
832 #ifdef VTK_USE_MEMKIND
833  VisitState* a = static_cast<VisitState*>(p);
834  if (a->IsInMemkind)
835  {
837  }
838  else
839  {
840  free(p);
841  }
842 #else
843  free(p);
844 #endif
845  }
846 
849 
850  private:
851  VisitState(const VisitState&) = delete;
852  VisitState& operator=(const VisitState&) = delete;
853  bool IsInMemkind = false;
854  };
855 
856 private: // Helpers that allow Visit to return a value:
857  template <typename Functor, typename... Args>
858  using GetReturnType = decltype(
859  std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
860 
861  template <typename Functor, typename... Args>
862  struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
863  {
864  };
865 
866 public:
936  template <typename Functor, typename... Args,
937  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
938  void Visit(Functor&& functor, Args&&... args)
939  {
940  if (this->Storage.Is64Bit())
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  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
946  }
947  else
948  {
949  // If you get an error on the next line, a call to Visit(functor, Args...)
950  // is being called with arguments that do not match the functor's call
951  // signature. See the Visit documentation for details.
952  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
953  }
954  }
955 
956  template <typename Functor, typename... Args,
957  typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
958  void Visit(Functor&& functor, Args&&... args) const
959  {
960  if (this->Storage.Is64Bit())
961  {
962  // If you get an error on the next line, a call to Visit(functor, Args...)
963  // is being called with arguments that do not match the functor's call
964  // signature. See the Visit documentation for details.
965  functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
966  }
967  else
968  {
969  // If you get an error on the next line, a call to Visit(functor, Args...)
970  // is being called with arguments that do not match the functor's call
971  // signature. See the Visit documentation for details.
972  functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
973  }
974  }
975 
976  template <typename Functor, typename... Args,
977  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
978  GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
979  {
980  if (this->Storage.Is64Bit())
981  {
982  // If you get an error on the next line, a call to Visit(functor, Args...)
983  // is being called with arguments that do not match the functor's call
984  // signature. See the Visit documentation for details.
985  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
986  }
987  else
988  {
989  // If you get an error on the next line, a call to Visit(functor, Args...)
990  // is being called with arguments that do not match the functor's call
991  // signature. See the Visit documentation for details.
992  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
993  }
994  }
995  template <typename Functor, typename... Args,
996  typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
997  GetReturnType<Functor, Args...> 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  return 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  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1012  }
1013  }
1014 
1017 #endif // __VTK_WRAP__
1018 
1019  //=================== Begin Legacy Methods ===================================
1020  // These should be deprecated at some point as they are confusing or very slow
1021 
1028  virtual void SetNumberOfCells(vtkIdType);
1029 
1041  vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1042 
1051  vtkIdType GetSize();
1052 
1059  vtkIdType GetNumberOfConnectivityEntries();
1060 
1070  void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1071  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1072 
1079  void GetCell(vtkIdType loc, vtkIdList* pts)
1080  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1081 
1088  vtkIdType GetInsertLocation(int npts);
1089 
1097  vtkIdType GetTraversalLocation();
1098  vtkIdType GetTraversalLocation(vtkIdType npts);
1099  void SetTraversalLocation(vtkIdType loc);
1109  void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1110 
1122  void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1123  VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1124 
1139  void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1140 
1152 
1153  //=================== End Legacy Methods =====================================
1154 
1155  friend class vtkCellArrayIterator;
1156 
1157 protected:
1158  vtkCellArray();
1159  ~vtkCellArray() override;
1160 
1161  // Encapsulates storage of the internal arrays as a discriminated union
1162  // between 32-bit and 64-bit storage.
1163  struct Storage
1164  {
1165  // Union type that switches 32 and 64 bit array storage
1166  union ArraySwitch {
1167  ArraySwitch() = default; // handled by Storage
1168  ~ArraySwitch() = default; // handle by Storage
1171  };
1172 
1174  {
1175 #ifdef VTK_USE_MEMKIND
1176  this->Arrays =
1177  static_cast<ArraySwitch*>(vtkObjectBase::GetCurrentMallocFunction()(sizeof(ArraySwitch)));
1178 #else
1179  this->Arrays = new ArraySwitch;
1180 #endif
1181 
1182  // Default to the compile-time setting:
1183 #ifdef VTK_USE_64BIT_IDS
1184 
1185  this->Arrays->Int64 = new VisitState<ArrayType64>;
1186  this->StorageIs64Bit = true;
1187 
1188 #else // VTK_USE_64BIT_IDS
1189 
1190  this->Arrays->Int32 = new VisitState<ArrayType32>;
1191  this->StorageIs64Bit = false;
1192 
1193 #endif // VTK_USE_64BIT_IDS
1194 #ifdef VTK_USE_MEMKIND
1196  {
1197  this->IsInMemkind = true;
1198  }
1199 #else
1200  (void)this->IsInMemkind; // comp warning workaround
1201 #endif
1202  }
1203 
1205  {
1206  if (this->StorageIs64Bit)
1207  {
1208  this->Arrays->Int64->~VisitState();
1209  delete this->Arrays->Int64;
1210  }
1211  else
1212  {
1213  this->Arrays->Int32->~VisitState();
1214  delete this->Arrays->Int32;
1215  }
1216 #ifdef VTK_USE_MEMKIND
1217  if (this->IsInMemkind)
1218  {
1220  }
1221  else
1222  {
1223  free(this->Arrays);
1224  }
1225 #else
1226  delete this->Arrays;
1227 #endif
1228  }
1229 
1230  // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1231  // true if the storage changes.
1233  {
1234  if (!this->StorageIs64Bit)
1235  {
1236  return false;
1237  }
1238 
1239  this->Arrays->Int64->~VisitState();
1240  delete this->Arrays->Int64;
1241  this->Arrays->Int32 = new VisitState<ArrayType32>;
1242  this->StorageIs64Bit = false;
1243 
1244  return true;
1245  }
1246 
1247  // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1248  // true if the storage changes.
1250  {
1251  if (this->StorageIs64Bit)
1252  {
1253  return false;
1254  }
1255 
1256  this->Arrays->Int32->~VisitState();
1257  delete this->Arrays->Int32;
1258  this->Arrays->Int64 = new VisitState<ArrayType64>;
1259  this->StorageIs64Bit = true;
1260 
1261  return true;
1262  }
1263 
1264  // Returns true if the storage is currently configured to be 64 bit.
1265  bool Is64Bit() const { return this->StorageIs64Bit; }
1266 
1267  // Get the VisitState for 32-bit arrays
1269  {
1270  assert(!this->StorageIs64Bit);
1271  return *this->Arrays->Int32;
1272  }
1273 
1275  {
1276  assert(!this->StorageIs64Bit);
1277  return *this->Arrays->Int32;
1278  }
1279 
1280  // Get the VisitState for 64-bit arrays
1282  {
1283  assert(this->StorageIs64Bit);
1284  return *this->Arrays->Int64;
1285  }
1286 
1288  {
1289  assert(this->StorageIs64Bit);
1290  return *this->Arrays->Int64;
1291  }
1292 
1293  private:
1294  // Access restricted to ensure proper union construction/destruction thru
1295  // API.
1296  ArraySwitch* Arrays;
1297  bool StorageIs64Bit;
1298  bool IsInMemkind = false;
1299  };
1300 
1303  vtkIdType TraversalCellId{ 0 };
1304 
1306 
1307 private:
1308  vtkCellArray(const vtkCellArray&) = delete;
1309  void operator=(const vtkCellArray&) = delete;
1310 };
1311 
1312 template <typename ArrayT>
1314 {
1315  return this->Offsets->GetNumberOfValues() - 1;
1316 }
1317 
1318 template <typename ArrayT>
1320 {
1321  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1322 }
1323 
1324 template <typename ArrayT>
1326 {
1327  return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1328 }
1329 
1330 template <typename ArrayT>
1332 {
1333  return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1334 }
1335 
1336 template <typename ArrayT>
1339 {
1340  return vtk::DataArrayValueRange<1>(
1341  this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1342 }
1343 
1345 {
1346 
1348 {
1349  // Insert full cell
1350  template <typename CellStateT>
1351  vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1352  {
1353  using ValueType = typename CellStateT::ValueType;
1354  auto* conn = state.GetConnectivity();
1355  auto* offsets = state.GetOffsets();
1356 
1357  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1358 
1359  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1360 
1361  for (vtkIdType i = 0; i < npts; ++i)
1362  {
1363  conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1364  }
1365 
1366  return cellId;
1367  }
1368 
1369  // Just update offset table (for incremental API)
1370  template <typename CellStateT>
1371  vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1372  {
1373  using ValueType = typename CellStateT::ValueType;
1374  auto* conn = state.GetConnectivity();
1375  auto* offsets = state.GetOffsets();
1376 
1377  const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1378 
1379  offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1380 
1381  return cellId;
1382  }
1383 };
1384 
1385 // for incremental API:
1387 {
1388  template <typename CellStateT>
1389  void operator()(CellStateT& state, const vtkIdType npts)
1390  {
1391  using ValueType = typename CellStateT::ValueType;
1392 
1393  auto* offsets = state.GetOffsets();
1394  const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1395  offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1396  }
1397 };
1398 
1400 {
1401  template <typename CellStateT>
1402  vtkIdType operator()(CellStateT& state, const vtkIdType cellId)
1403  {
1404  return state.GetCellSize(cellId);
1405  }
1406 };
1407 
1409 {
1410  template <typename CellStateT>
1411  void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1412  {
1413  using ValueType = typename CellStateT::ValueType;
1414 
1415  const auto cellPts = state.GetCellRange(cellId);
1416 
1417  ids->SetNumberOfIds(cellPts.size());
1418  vtkIdType* idPtr = ids->GetPointer(0);
1419 
1420  for (ValueType ptId : cellPts)
1421  {
1422  *idPtr++ = static_cast<vtkIdType>(ptId);
1423  }
1424  }
1425 
1426  // SFINAE helper to check if a VisitState's connectivity array's memory
1427  // can be used as a vtkIdType*.
1428  template <typename CellStateT>
1430  {
1431  private:
1432  using ValueType = typename CellStateT::ValueType;
1433  using ArrayType = typename CellStateT::ArrayType;
1435  static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1436  static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1437 
1438  public:
1439  static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1440  };
1441 
1442  template <typename CellStateT>
1444  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1445  vtkIdList* vtkNotUsed(temp))
1446  {
1447  const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1448  const vtkIdType endOffset = state.GetEndOffset(cellId);
1449  cellSize = endOffset - beginOffset;
1450  // This is safe, see CanShareConnPtr helper above.
1451  cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1452  }
1453 
1454  template <typename CellStateT>
1456  CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1457  vtkIdList* temp)
1458  {
1459  using ValueType = typename CellStateT::ValueType;
1460 
1461  const auto cellPts = state.GetCellRange(cellId);
1462  cellSize = cellPts.size();
1463 
1464  // ValueType differs from vtkIdType, so we have to copy into a temporary
1465  // buffer:
1466  temp->SetNumberOfIds(cellSize);
1467  vtkIdType* tempPtr = temp->GetPointer(0);
1468  for (ValueType ptId : cellPts)
1469  {
1470  *tempPtr++ = static_cast<vtkIdType>(ptId);
1471  }
1472 
1473  cellPoints = temp->GetPointer(0);
1474  }
1475 };
1476 
1478 {
1479  template <typename CellStateT>
1480  void operator()(CellStateT& state)
1481  {
1482  state.GetOffsets()->Reset();
1483  state.GetConnectivity()->Reset();
1484  state.GetOffsets()->InsertNextValue(0);
1485  }
1486 };
1487 
1488 } // end namespace vtkCellArray_detail
1489 
1490 //----------------------------------------------------------------------------
1492 {
1493  this->TraversalCellId = 0;
1494 }
1495 
1496 //----------------------------------------------------------------------------
1497 inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1498 {
1499  if (this->TraversalCellId < this->GetNumberOfCells())
1500  {
1501  this->GetCellAtId(this->TraversalCellId, npts, pts);
1502  ++this->TraversalCellId;
1503  return 1;
1504  }
1505 
1506  npts = 0;
1507  pts = nullptr;
1508  return 0;
1509 }
1510 
1511 //----------------------------------------------------------------------------
1513 {
1514  if (this->TraversalCellId < this->GetNumberOfCells())
1515  {
1516  this->GetCellAtId(this->TraversalCellId, pts);
1517  ++this->TraversalCellId;
1518  return 1;
1519  }
1520 
1521  pts->Reset();
1522  return 0;
1523 }
1524 //----------------------------------------------------------------------------
1526 {
1527  return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1528 }
1529 
1530 //----------------------------------------------------------------------------
1531 inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1532  vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1533 {
1534  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1535 }
1536 
1537 //----------------------------------------------------------------------------
1539 {
1540  this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1541 }
1542 
1543 //----------------------------------------------------------------------------
1545  VTK_SIZEHINT(pts, npts)
1546 {
1547  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1548 }
1549 
1550 //----------------------------------------------------------------------------
1552 {
1553  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1554 }
1555 
1556 //----------------------------------------------------------------------------
1558 {
1559  if (this->Storage.Is64Bit())
1560  {
1561  using ValueType = typename ArrayType64::ValueType;
1562  this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1563  }
1564  else
1565  {
1566  using ValueType = typename ArrayType32::ValueType;
1567  this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1568  }
1569 }
1570 
1571 //----------------------------------------------------------------------------
1572 inline void vtkCellArray::UpdateCellCount(int npts)
1573 {
1575 }
1576 
1577 //----------------------------------------------------------------------------
1579 {
1580  return this->Visit(
1582 }
1583 
1584 //----------------------------------------------------------------------------
1586 {
1587  vtkIdList* pts = cell->GetPointIds();
1588  return this->Visit(
1590 }
1591 
1592 //----------------------------------------------------------------------------
1593 inline void vtkCellArray::Reset()
1594 {
1596 }
1597 
1598 #endif // vtkCellArray.h
vtkObjectBase::GetAlternateFreeFunction
static vtkFreeingFunction GetAlternateFreeFunction()
vtkCellArray::VisitState< ArrayType32 >::ArrayType
ArrayType32 ArrayType
Definition: vtkCellArray.h:778
vtkCellArray::Storage
Storage Storage
Definition: vtkCellArray.h:1301
vtkCellArray_detail::GetCellAtIdImpl::operator()
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
Definition: vtkCellArray.h:1411
vtkCellArray::GetConnectivityArray64
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:527
vtkCellArray::UpdateCellCount
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
Definition: vtkCellArray.h:1572
vtkIossUtilities::GetConnectivity
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
vtkCellArray::ArrayType64
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:184
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:44
vtkCellArray_detail::GetCellAtIdImpl::operator()
std::enable_if< CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *vtkNotUsed(temp))
Definition: vtkCellArray.h:1443
vtkX3D::value
Definition: vtkX3D.h:226
vtkCellArray::VisitState::GetBeginOffset
vtkIdType GetBeginOffset(vtkIdType cellId) const
Definition: vtkCellArray.h:1319
vtkIossUtilities::GetData
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.
vtkX3D::type
Definition: vtkX3D.h:522
vtkIdType
int vtkIdType
Definition: vtkType.h:330
vtkCellArray::Allocate
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
Definition: vtkCellArray.h:227
vtkDataArrayRange.h
vtkCellArray::VisitState::GetConnectivity
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:793
vtkX3D::data
Definition: vtkX3D.h:321
vtkCellArray::VisitState::Connectivity
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:847
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkCellArray_detail::GetCellAtIdImpl
Definition: vtkCellArray.h:1408
vtkCellArray::ArrayType32
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:183
vtkCellArray_detail::ResetImpl
Definition: vtkCellArray.h:1477
vtkCellArray_detail::GetCellAtIdImpl::CanShareConnPtr
Definition: vtkCellArray.h:1429
vtkCellArray::Visit
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
Definition: vtkCellArray.h:997
vtkAOSDataArrayTemplate.h
vtkCellArray::Storage::GetArrays64
VisitState< ArrayType64 > & GetArrays64()
Definition: vtkCellArray.h:1281
vtkCellArray::Storage::ArraySwitch
Definition: vtkCellArray.h:1166
vtkSmartPointer< ArrayType >
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkCellArray::InsertNextCell
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:629
vtkCellArray_detail::GetCellAtIdImpl::operator()
std::enable_if<!CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
Definition: vtkCellArray.h:1455
vtkCellArray::GetCellSize
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
Definition: vtkCellArray.h:1525
vtkCellArray::InputArrayList
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:217
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkCellArray::VisitState::ValueTypeIsSameAsIdType
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:787
vtkCellArray::GetOffsetsArray64
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:506
vtkCellArray::GetNumberOfCells
vtkIdType GetNumberOfCells() const
Get the number of cells in the array.
Definition: vtkCellArray.h:314
vtkCellArray::VisitState::GetCellSize
vtkIdType GetCellSize(vtkIdType cellId) const
Definition: vtkCellArray.h:1331
vtkCellArray_detail::GetCellSizeImpl
Definition: vtkCellArray.h:1399
vtkCellArray::GetOffsetsArray32
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:505
vtkCellArray_detail::InsertNextCellImpl::operator()
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
Definition: vtkCellArray.h:1351
vtkObjectBase::GetCurrentMallocFunction
static vtkMallocingFunction GetCurrentMallocFunction()
vtkCellArray::VisitState::GetCellRange
CellRangeType GetCellRange(vtkIdType cellId)
Definition: vtkCellArray.h:1338
vtkCellArray::Storage::GetArrays32
VisitState< ArrayType32 > & GetArrays32()
Definition: vtkCellArray.h:1268
vtkCellArray::GetNumberOfConnectivityIds
vtkIdType GetNumberOfConnectivityIds() const
Get the size of the connectivity array that stores the point ids.
Definition: vtkCellArray.h:348
vtkCell.h
vtkCellArray::GetCellAtId
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
Definition: vtkCellArray.h:1531
vtkCellArrayIterator
Encapsulate traversal logic for vtkCellArray.
Definition: vtkCellArrayIterator.h:78
vtkCellArray::VisitState::VisitState
VisitState()
Definition: vtkCellArray.h:809
vtkCellArray::Storage::~Storage
~Storage()
Definition: vtkCellArray.h:1204
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
vtkCellArray::GetNextCell
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)
Definition: vtkCellArray.h:1497
vtkCellArray_detail
Definition: vtkCellArray.h:1344
vtkCell::GetPointIds
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:153
vtkCellArray::AllocateEstimate
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
Definition: vtkCellArray.h:241
vtkCell
abstract class to specify cell behavior
Definition: vtkCell.h:57
vtkCellArray::IsStorageShareable
bool IsStorageShareable() const
Definition: vtkCellArray.h:429
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkCellArray::Storage::GetArrays64
const VisitState< ArrayType64 > & GetArrays64() const
Definition: vtkCellArray.h:1287
vtkCellArray
object to represent cell connectivity
Definition: vtkCellArray.h:180
vtkTypeList::Unique
Remove all duplicate types from TypeList TList, storing the new list in Result.
Definition: vtkTypeList.h:125
vtkCellArray::VisitState::GetEndOffset
vtkIdType GetEndOffset(vtkIdType cellId) const
Definition: vtkCellArray.h:1325
vtkCellArray_detail::InsertNextCellImpl::operator()
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
Definition: vtkCellArray.h:1371
vtkCellArray::VisitState::GetOffsets
ArrayType * GetOffsets()
Definition: vtkCellArray.h:790
vtkCellArray::InsertCellPoint
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
Definition: vtkCellArray.h:1557
vtkSmartPointer.h
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkSmartPointer::New
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
Definition: vtkSmartPointer.h:225
vtkCellArray::IsStorage64Bit
bool IsStorage64Bit() const
Definition: vtkCellArray.h:421
vtkNew< vtkIdList >
vtkCellArray_detail::GetCellSizeImpl::operator()
vtkIdType operator()(CellStateT &state, const vtkIdType cellId)
Definition: vtkCellArray.h:1402
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkCellArray_detail::UpdateCellCountImpl
Definition: vtkCellArray.h:1386
vtkTypeList.h
vtkCellArray::Storage::Use64BitStorage
bool Use64BitStorage()
Definition: vtkCellArray.h:1249
vtkCellArray_detail::ResetImpl::operator()
void operator()(CellStateT &state)
Definition: vtkCellArray.h:1480
vtkCellArray::LegacyData
vtkNew< vtkIdTypeArray > LegacyData
Definition: vtkCellArray.h:1305
vtkCellArray::Storage::Is64Bit
bool Is64Bit() const
Definition: vtkCellArray.h:1265
vtkCellArray_detail::InsertNextCellImpl
Definition: vtkCellArray.h:1347
vtkObject.h
vtkCellArray::Visit
void Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:938
vtkCellArray::Storage
Definition: vtkCellArray.h:1163
vtkCellArray::VisitState
Definition: vtkCellArray.h:776
vtkCellArray::GetNumberOfOffsets
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:330
vtkCellArray::VisitState::GetConnectivity
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:794
vtkCellArray_detail::UpdateCellCountImpl::operator()
void operator()(CellStateT &state, const vtkIdType npts)
Definition: vtkCellArray.h:1389
vtkIdTypeArray
dynamic, self-adjusting array of vtkIdType
Definition: vtkIdTypeArray.h:35
vtkCellArray::Visit
void Visit(Functor &&functor, Args &&... args) const
Definition: vtkCellArray.h:958
vtkCellArray::VisitState::GetOffsets
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:791
vtkCellArray::StorageArrayList
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:205
vtkCellArray::InitTraversal
void InitTraversal()
Definition: vtkCellArray.h:1491
vtkCellArray::InsertNextCell
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
Definition: vtkCellArray.h:1585
vtkCellArray::Storage::GetArrays32
const VisitState< ArrayType32 > & GetArrays32() const
Definition: vtkCellArray.h:1274
vtkCellArray::VisitState< ArrayType32 >::CellRangeType
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:780
vtkCellArray::GetOffsetsArray
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:494
vtkObjectBase::GetUsingMemkind
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
vtkIdList::GetPointer
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:120
vtkAOSDataArrayTemplate< long >
vtkIdList::SetNumberOfIds
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
vtkCellArray::Storage::Storage
Storage()
Definition: vtkCellArray.h:1173
VTK_NEWINSTANCE
#define VTK_NEWINSTANCE
Definition: vtkWrappingHints.h:42
vtkCellArray::AllocateCopy
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
Definition: vtkCellArray.h:266
vtkCellArray::TraversalCellId
vtkIdType TraversalCellId
Definition: vtkCellArray.h:1303
vtkCellArray::GetConnectivityArray32
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:526
vtkCellArray::VisitState< ArrayType32 >::ValueType
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:779
vtkCellArray::Storage::ArraySwitch::Int64
VisitState< ArrayType64 > * Int64
Definition: vtkCellArray.h:1170
vtkIdList::GetNumberOfIds
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:57
vtkCellArray::GetConnectivityArray
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:515
vtkCellArray::Visit
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:978
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkCellArray::VisitState::GetNumberOfCells
vtkIdType GetNumberOfCells() const
Definition: vtkCellArray.h:1313
vtkCellArray::Storage::ArraySwitch::Int32
VisitState< ArrayType32 > * Int32
Definition: vtkCellArray.h:1169
vtkCellArray::Storage::Use32BitStorage
bool Use32BitStorage()
Definition: vtkCellArray.h:1232
vtkIdList::Reset
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:139
vtkCellArray::Reset
void Reset()
Reuse list.
Definition: vtkCellArray.h:1593
vtkCellArray::VisitState::Offsets
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:848
vtkCellArray::TempCell
vtkNew< vtkIdList > TempCell
Definition: vtkCellArray.h:1302