VTK  9.1.0
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
178class vtkIdTypeArray;
179
180class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
181{
182public:
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
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
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
366
367#ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
378 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
379 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
380 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
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
430 {
431 if (this->Storage.Is64Bit())
432 {
434 }
435 else
436 {
438 }
439 }
440
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 }
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
668 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
669
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
700
705
710
714 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
715
727
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>
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
797
799
801
803
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
856private: // 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
866public:
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
1029
1041 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1042
1052
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
1151 vtkIdTypeArray* GetData();
1152
1153 //=================== End Legacy Methods =====================================
1154
1156
1157protected:
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
1167 ArraySwitch() = default; // handled by Storage
1168 ~ArraySwitch() = default; // handle by Storage
1171 };
1172
1174 {
1175#ifdef VTK_USE_MEMKIND
1176 this->Arrays =
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
1307private:
1308 vtkCellArray(const vtkCellArray&) = delete;
1309 void operator=(const vtkCellArray&) = delete;
1310};
1311
1312template <typename ArrayT>
1314{
1315 return this->Offsets->GetNumberOfValues() - 1;
1316}
1317
1318template <typename ArrayT>
1320{
1321 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1322}
1323
1324template <typename ArrayT>
1326{
1327 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1328}
1329
1330template <typename ArrayT>
1332{
1333 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1334}
1335
1336template <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>
1443 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
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>
1455 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
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//----------------------------------------------------------------------------
1497inline 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//----------------------------------------------------------------------------
1531inline 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//----------------------------------------------------------------------------
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//----------------------------------------------------------------------------
1594{
1596}
1597
1598#endif // vtkCellArray.h
Array-Of-Structs implementation of vtkGenericDataArray.
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
Definition: vtkCellArray.h:181
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:227
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:266
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:429
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.:
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
Definition: vtkCellArray.h:997
bool SetData(vtkIdType cellSize, vtkDataArray *connectivity)
Sets the internal arrays to the supported connectivity array with an offsets array automatically gene...
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:938
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:183
void Reset()
Reuse list.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:527
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:526
void SetData(vtkAOSDataArrayTemplate< long long > *offsets, vtkAOSDataArrayTemplate< long long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
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.
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:505
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
Definition: vtkCellArray.h:241
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:330
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:184
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.
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:515
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.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
void ReplaceCellAtId(vtkIdType cellId, vtkIdList *list)
Replaces the point ids for the specified cell with the supplied list.
void ReverseCellAtId(vtkIdType cellId)
Reverses the order of the point ids for the specified cell.
bool SetData(vtkDataArray *offsets, vtkDataArray *connectivity)
Sets the internal arrays to the supplied offsets and connectivity arrays.
void Squeeze()
Reclaim any extra memory while preserving data.
void SetData(vtkIdTypeArray *offsets, vtkIdTypeArray *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
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:958
int GetMaxCellSize()
Returns the size of the largest cell.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:506
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
void ShallowCopy(vtkCellArray *ca)
Shallow copy ca into this cell array.
void ExportLegacyFormat(vtkIdTypeArray *data)
Fill data with the old-style vtkCellArray data layout, e.g.
bool ConvertTo64BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
void SetData(vtkAOSDataArrayTemplate< long > *offsets, vtkAOSDataArrayTemplate< long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
void ImportLegacyFormat(const vtkIdType *data, vtkIdType len)
Import an array of data with the legacy vtkCellArray layout, e.g.:
void ImportLegacyFormat(vtkIdTypeArray *data)
Import an array of data with the legacy vtkCellArray layout, e.g.:
void Use32BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
void Initialize()
Free any memory and reset to an empty state.
void DeepCopy(vtkCellArray *ca)
Perform a deep copy (no reference counting) of the given cell array.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > > >::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
Definition: vtkCellArray.h:217
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:314
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:348
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:494
vtkNew< vtkIdTypeArray > LegacyData
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
void PrintDebug(ostream &os)
Standard methods for instantiation, type information, and printing.
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)
Definition: vtkCellArray.h:978
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
vtkNew< vtkIdList > TempCell
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:205
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:629
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:421
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:58
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:153
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
list of point or cell ids
Definition: vtkIdList.h:31
vtkIdType GetNumberOfIds() const noexcept
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:145
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:126
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
Allocate and hold a VTK object.
Definition: vtkNew.h:56
static vtkMallocingFunction GetCurrentMallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
abstract base class for most VTK objects
Definition: vtkObject.h:63
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
VisitState< ArrayType64 > & GetArrays64()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType32 > & GetArrays32()
ArrayType * GetOffsets()
Definition: vtkCellArray.h:790
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:848
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:847
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:787
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:791
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:780
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:794
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:779
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:793
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))
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
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:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE