VTK  9.5.2
vtkCellArray.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
128
129#ifndef vtkCellArray_h
130#define vtkCellArray_h
131
132#include "vtkAbstractCellArray.h"
133#include "vtkCommonDataModelModule.h" // For export macro
134#include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
135
136#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
137#include "vtkCell.h" // Needed for inline methods
138#include "vtkDataArrayRange.h" // Needed for inline methods
139#include "vtkFeatures.h" // for VTK_USE_MEMKIND
140#include "vtkSmartPointer.h" // For vtkSmartPointer
141#include "vtkTypeInt32Array.h" // Needed for inline methods
142#include "vtkTypeInt64Array.h" // Needed for inline methods
143#include "vtkTypeList.h" // Needed for ArrayList definition
144
145#include <cassert> // for assert
146#include <initializer_list> // for API
147#include <type_traits> // for std::is_same
148#include <utility> // for std::forward
149
170#define VTK_CELL_ARRAY_V2
171
172VTK_ABI_NAMESPACE_BEGIN
174class vtkIdTypeArray;
175
176class VTKCOMMONDATAMODEL_EXPORT VTK_MARSHALMANUAL vtkCellArray : public vtkAbstractCellArray
177{
178public:
179 using ArrayType32 = vtkTypeInt32Array;
180 using ArrayType64 = vtkTypeInt64Array;
181
183
187 static vtkCellArray* New();
189 void PrintSelf(ostream& os, vtkIndent indent) override;
190 void PrintDebug(ostream& os);
192
201 using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
202
214
223 vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
224 {
225 return this->AllocateExact(sz, sz) ? 1 : 0;
226 }
227
237 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
238 {
239 return this->AllocateExact(numCells, numCells * maxCellSize);
240 }
241
251 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
252
263 {
264 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
265 }
266
276 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
277
281 void Initialize() override;
282
286 void Reset();
287
293 void Squeeze();
294
305 bool IsValid();
306
311 {
312 if (this->Storage.Is64Bit())
313 {
314 return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
315 }
316 else
317 {
318 return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
319 }
320 }
321
327 {
328 if (this->Storage.Is64Bit())
329 {
330 return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
331 }
332 else
333 {
334 return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
335 }
336 }
337
342 {
343 if (this->Storage.Is64Bit())
344 {
345 return this->Storage.GetArrays64().Offsets->GetValue(cellId);
346 }
347 else
348 {
349 return this->Storage.GetArrays32().Offsets->GetValue(cellId);
350 }
351 }
352
356 void SetOffset(vtkIdType cellId, vtkIdType offset)
357 {
358 if (this->Storage.Is64Bit())
359 {
360 this->Storage.GetArrays64().Offsets->SetValue(cellId, offset);
361 }
362 else
363 {
364 this->Storage.GetArrays32().Offsets->SetValue(cellId, offset);
365 }
366 }
367
375 {
376 if (this->Storage.Is64Bit())
377 {
378 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
379 }
380 else
381 {
382 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
383 }
384 }
385
392
403 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
408 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
409 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
411
424 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
425
439 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
440
445 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
446
453 bool IsStorageShareable() const override
454 {
455 if (this->Storage.Is64Bit())
456 {
458 }
459 else
460 {
462 }
463 }
464
477
490
512
519 {
520 if (this->Storage.Is64Bit())
521 {
522 return this->GetOffsetsArray64();
523 }
524 else
525 {
526 return this->GetOffsetsArray32();
527 }
528 }
532
540 {
541 if (this->Storage.Is64Bit())
542 {
543 return this->GetConnectivityArray64();
544 }
545 else
546 {
547 return this->GetConnectivityArray32();
548 }
549 }
553
563
573 void InitTraversal();
574
589 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
590
601 int GetNextCell(vtkIdList* pts);
602
613 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
614 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
615 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
616
622 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
623 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
624
632 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints) VTK_SIZEHINT(
633 cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
634
638 vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
639 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells())
640 VTK_EXPECTS(0 <= cellPointIndex && cellPointIndex < this->GetCellSize(cellId));
641
645 vtkIdType GetCellSize(vtkIdType cellId) const override;
646
651
656 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
657
663
671 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
672 {
673 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
674 }
675
682 vtkIdType InsertNextCell(int npts);
683
688 void InsertCellPoint(vtkIdType id);
689
694 void UpdateCellCount(int npts);
695
706
710 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
711
721 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
722 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
724
732 void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
733
741 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
742 {
743 this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
744 }
745
750 int GetMaxCellSize() override;
751
755 void DeepCopy(vtkAbstractCellArray* ca) override;
756
761
765 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
766
778
791 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
793
805 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
806 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
807 VTK_SIZEHINT(data, len);
809
818 unsigned long GetActualMemorySize() const;
819
820 // The following code is used to support
821
822 // The wrappers get understandably confused by some of the template code below
823#ifndef __VTK_WRAP__
824
825 // Holds connectivity and offset arrays of the given ArrayType.
826 template <typename ArrayT>
828 {
829 using ArrayType = ArrayT;
830 using ValueType = typename ArrayType::ValueType;
831 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
832
833 // We can't just use is_same here, since binary compatible representations
834 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
835 // is a signed integer the same size as vtkIdType.
836 // If this value is true, ValueType pointers may be safely converted to
837 // vtkIdType pointers via reinterpret cast.
838 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
839 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
840
841 ArrayType* GetOffsets() { return this->Offsets; }
842 const ArrayType* GetOffsets() const { return this->Offsets; }
843
845 const ArrayType* GetConnectivity() const { return this->Connectivity; }
846
848
850
852
854
856
857 friend class vtkCellArray;
858
859 protected:
861 {
864 this->Offsets->InsertNextValue(0);
866 {
867 this->IsInMemkind = true;
868 }
869 }
870 ~VisitState() = default;
871 void* operator new(size_t nSize)
872 {
873 void* r;
874#ifdef VTK_USE_MEMKIND
876#else
877 r = malloc(nSize);
878#endif
879 return r;
880 }
881 void operator delete(void* p)
882 {
883#ifdef VTK_USE_MEMKIND
884 VisitState* a = static_cast<VisitState*>(p);
885 if (a->IsInMemkind)
886 {
888 }
889 else
890 {
891 free(p);
892 }
893#else
894 free(p);
895#endif
896 }
897
900
901 private:
902 VisitState(const VisitState&) = delete;
903 VisitState& operator=(const VisitState&) = delete;
904 bool IsInMemkind = false;
905 };
906
907private: // Helpers that allow Visit to return a value:
908 template <typename Functor, typename... Args>
909 using GetReturnType = decltype(std::declval<Functor>()(
910 std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
911
912 template <typename Functor, typename... Args>
913 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
914 {
915 };
916
917public:
987 template <typename Functor, typename... Args,
988 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
989 void Visit(Functor&& functor, Args&&... args)
990 {
991 if (this->Storage.Is64Bit())
992 {
993 // If you get an error on the next line, a call to Visit(functor, Args...)
994 // is being called with arguments that do not match the functor's call
995 // signature. See the Visit documentation for details.
996 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
997 }
998 else
999 {
1000 // If you get an error on the next line, a call to Visit(functor, Args...)
1001 // is being called with arguments that do not match the functor's call
1002 // signature. See the Visit documentation for details.
1003 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1004 }
1005 }
1006
1007 template <typename Functor, typename... Args,
1008 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1009 void Visit(Functor&& functor, Args&&... args) const
1010 {
1011 if (this->Storage.Is64Bit())
1012 {
1013 // If you get an error on the next line, a call to Visit(functor, Args...)
1014 // is being called with arguments that do not match the functor's call
1015 // signature. See the Visit documentation for details.
1016 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1017 }
1018 else
1019 {
1020 // If you get an error on the next line, a call to Visit(functor, Args...)
1021 // is being called with arguments that do not match the functor's call
1022 // signature. See the Visit documentation for details.
1023 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1024 }
1025 }
1026
1027 template <typename Functor, typename... Args,
1028 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1029 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1030 {
1031 if (this->Storage.Is64Bit())
1032 {
1033 // If you get an error on the next line, a call to Visit(functor, Args...)
1034 // is being called with arguments that do not match the functor's call
1035 // signature. See the Visit documentation for details.
1036 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1037 }
1038 else
1039 {
1040 // If you get an error on the next line, a call to Visit(functor, Args...)
1041 // is being called with arguments that do not match the functor's call
1042 // signature. See the Visit documentation for details.
1043 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1044 }
1045 }
1046 template <typename Functor, typename... Args,
1047 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1048 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1049 {
1050 if (this->Storage.Is64Bit())
1051 {
1052 // If you get an error on the next line, a call to Visit(functor, Args...)
1053 // is being called with arguments that do not match the functor's call
1054 // signature. See the Visit documentation for details.
1055 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1056 }
1057 else
1058 {
1059 // If you get an error on the next line, a call to Visit(functor, Args...)
1060 // is being called with arguments that do not match the functor's call
1061 // signature. See the Visit documentation for details.
1062 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1063 }
1064 }
1065
1066#endif // __VTK_WRAP__
1067
1069
1079
1080 //=================== Begin Legacy Methods ===================================
1081 // These should be deprecated at some point as they are confusing or very slow
1082
1090
1102 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1103
1113
1121
1131 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1132 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1133
1141 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1142
1150
1162
1171
1183 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1184 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1185
1200 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1201
1213
1214 //=================== End Legacy Methods =====================================
1215
1217
1218protected:
1220 ~vtkCellArray() override;
1221
1222 // Encapsulates storage of the internal arrays as a discriminated union
1223 // between 32-bit and 64-bit storage.
1224 struct Storage
1225 {
1226 // Union type that switches 32 and 64 bit array storage
1228 {
1229 ArraySwitch() = default; // handled by Storage
1230 ~ArraySwitch() = default; // handle by Storage
1233 };
1234
1236 {
1237#ifdef VTK_USE_MEMKIND
1238 this->Arrays =
1240#else
1241 this->Arrays = new ArraySwitch;
1242#endif
1243
1244 // Default can be changed, to save memory
1246 {
1247 this->Arrays->Int64 = new VisitState<ArrayType64>;
1248 this->StorageIs64Bit = true;
1249 }
1250 else
1251 {
1252 this->Arrays->Int32 = new VisitState<ArrayType32>;
1253 this->StorageIs64Bit = false;
1254 }
1255
1256#ifdef VTK_USE_MEMKIND
1258 {
1259 this->IsInMemkind = true;
1260 }
1261#else
1262 (void)this->IsInMemkind; // comp warning workaround
1263#endif
1264 }
1265
1267 {
1268 if (this->StorageIs64Bit)
1269 {
1270 this->Arrays->Int64->~VisitState();
1271 delete this->Arrays->Int64;
1272 }
1273 else
1274 {
1275 this->Arrays->Int32->~VisitState();
1276 delete this->Arrays->Int32;
1277 }
1278#ifdef VTK_USE_MEMKIND
1279 if (this->IsInMemkind)
1280 {
1282 }
1283 else
1284 {
1285 free(this->Arrays);
1286 }
1287#else
1288 delete this->Arrays;
1289#endif
1290 }
1291
1292 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1293 // true if the storage changes.
1295 {
1296 if (!this->StorageIs64Bit)
1297 {
1298 return false;
1299 }
1300
1301 this->Arrays->Int64->~VisitState();
1302 delete this->Arrays->Int64;
1303 this->Arrays->Int32 = new VisitState<ArrayType32>;
1304 this->StorageIs64Bit = false;
1305
1306 return true;
1307 }
1308
1309 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1310 // true if the storage changes.
1312 {
1313 if (this->StorageIs64Bit)
1314 {
1315 return false;
1316 }
1317
1318 this->Arrays->Int32->~VisitState();
1319 delete this->Arrays->Int32;
1320 this->Arrays->Int64 = new VisitState<ArrayType64>;
1321 this->StorageIs64Bit = true;
1322
1323 return true;
1324 }
1325
1326 // Returns true if the storage is currently configured to be 64 bit.
1327 bool Is64Bit() const { return this->StorageIs64Bit; }
1328
1329 // Get the VisitState for 32-bit arrays
1331 {
1332 assert(!this->StorageIs64Bit);
1333 return *this->Arrays->Int32;
1334 }
1335
1337 {
1338 assert(!this->StorageIs64Bit);
1339 return *this->Arrays->Int32;
1340 }
1341
1342 // Get the VisitState for 64-bit arrays
1344 {
1345 assert(this->StorageIs64Bit);
1346 return *this->Arrays->Int64;
1347 }
1348
1350 {
1351 assert(this->StorageIs64Bit);
1352 return *this->Arrays->Int64;
1353 }
1354
1355 private:
1356 // Access restricted to ensure proper union construction/destruction thru
1357 // API.
1358 ArraySwitch* Arrays;
1359 bool StorageIs64Bit;
1360 bool IsInMemkind = false;
1361 };
1362
1365
1367
1369
1370private:
1371 vtkCellArray(const vtkCellArray&) = delete;
1372 void operator=(const vtkCellArray&) = delete;
1373};
1374
1375template <typename ArrayT>
1377{
1378 return this->Offsets->GetNumberOfValues() - 1;
1379}
1380
1381template <typename ArrayT>
1383{
1384 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1385}
1386
1387template <typename ArrayT>
1389{
1390 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1391}
1392
1393template <typename ArrayT>
1395{
1396 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1397}
1398
1399template <typename ArrayT>
1406VTK_ABI_NAMESPACE_END
1407
1409{
1410VTK_ABI_NAMESPACE_BEGIN
1411
1413{
1414 // Insert full cell
1415 template <typename CellStateT>
1416 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1417 {
1418 using ValueType = typename CellStateT::ValueType;
1419 auto* conn = state.GetConnectivity();
1420 auto* offsets = state.GetOffsets();
1421
1422 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1423
1424 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1425
1426 for (vtkIdType i = 0; i < npts; ++i)
1427 {
1428 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1429 }
1430
1431 return cellId;
1432 }
1433
1434 // Just update offset table (for incremental API)
1435 template <typename CellStateT>
1436 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1437 {
1438 using ValueType = typename CellStateT::ValueType;
1439 auto* conn = state.GetConnectivity();
1440 auto* offsets = state.GetOffsets();
1441
1442 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1443
1444 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1445
1446 return cellId;
1447 }
1448};
1449
1450// for incremental API:
1452{
1453 template <typename CellStateT>
1454 void operator()(CellStateT& state, const vtkIdType npts)
1455 {
1456 using ValueType = typename CellStateT::ValueType;
1457
1458 auto* offsets = state.GetOffsets();
1459 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1460 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1461 }
1462};
1463
1465{
1466 template <typename CellStateT>
1467 vtkIdType operator()(CellStateT& state, vtkIdType cellId)
1468 {
1469 return state.GetCellSize(cellId);
1470 }
1471};
1472
1474{
1475 template <typename CellStateT>
1476 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1477 {
1478 using ValueType = typename CellStateT::ValueType;
1479
1480 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1481 const vtkIdType endOffset = state.GetEndOffset(cellId);
1482 const vtkIdType cellSize = endOffset - beginOffset;
1483 const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1484
1485 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1486 ids->SetNumberOfIds(cellSize);
1487 vtkIdType* idPtr = ids->GetPointer(0);
1488 for (ValueType i = 0; i < cellSize; ++i)
1489 {
1490 idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1491 }
1492 }
1493
1494 template <typename CellStateT>
1496 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1497 {
1498 using ValueType = typename CellStateT::ValueType;
1499
1500 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1501 const vtkIdType endOffset = state.GetEndOffset(cellId);
1502 cellSize = endOffset - beginOffset;
1503 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1504
1505 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1506 for (vtkIdType i = 0; i < cellSize; ++i)
1507 {
1508 cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1509 }
1510 }
1511
1512 // SFINAE helper to check if a VisitState's connectivity array's memory
1513 // can be used as a vtkIdType*.
1514 template <typename CellStateT>
1516 {
1517 private:
1518 using ValueType = typename CellStateT::ValueType;
1519 using ArrayType = typename CellStateT::ArrayType;
1520 using AOSArrayType = vtkAOSDataArrayTemplate<ValueType>;
1521 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1522 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1523
1524 public:
1525 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1526 };
1527
1528 template <typename CellStateT>
1529 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
1530 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1531 vtkIdList* vtkNotUsed(temp))
1532 {
1533 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1534 const vtkIdType endOffset = state.GetEndOffset(cellId);
1535 cellSize = endOffset - beginOffset;
1536 // This is safe, see CanShareConnPtr helper above.
1537 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1538 }
1539
1540 template <typename CellStateT>
1541 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
1542 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1543 vtkIdList* temp)
1544 {
1545 using ValueType = typename CellStateT::ValueType;
1546
1547 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1548 const vtkIdType endOffset = state.GetEndOffset(cellId);
1549 cellSize = endOffset - beginOffset;
1550 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1551
1552 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1553 temp->SetNumberOfIds(cellSize);
1554 vtkIdType* tempPtr = temp->GetPointer(0);
1555 for (vtkIdType i = 0; i < cellSize; ++i)
1556 {
1557 tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1558 }
1559
1560 cellPoints = temp->GetPointer(0);
1561 }
1562};
1563
1565{
1566 template <typename CellStateT>
1567 vtkIdType operator()(CellStateT& cells, vtkIdType cellId, vtkIdType cellPointIndex) const
1568 {
1569 return static_cast<vtkIdType>(
1570 cells.GetConnectivity()->GetValue(cells.GetBeginOffset(cellId) + cellPointIndex));
1571 }
1572};
1573
1575{
1576 template <typename CellStateT>
1577 void operator()(CellStateT& state)
1578 {
1579 state.GetOffsets()->Reset();
1580 state.GetConnectivity()->Reset();
1581 state.GetOffsets()->InsertNextValue(0);
1582 }
1583};
1584
1585VTK_ABI_NAMESPACE_END
1586} // end namespace vtkCellArray_detail
1587
1588VTK_ABI_NAMESPACE_BEGIN
1589//----------------------------------------------------------------------------
1591{
1592 this->TraversalCellId = 0;
1593}
1594
1595//----------------------------------------------------------------------------
1596inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1597{
1598 if (this->TraversalCellId < this->GetNumberOfCells())
1599 {
1600 this->GetCellAtId(this->TraversalCellId, npts, pts);
1601 ++this->TraversalCellId;
1602 return 1;
1603 }
1604
1605 npts = 0;
1606 pts = nullptr;
1607 return 0;
1608}
1609
1610//----------------------------------------------------------------------------
1612{
1614 {
1615 this->GetCellAtId(this->TraversalCellId, pts);
1616 ++this->TraversalCellId;
1617 return 1;
1618 }
1619
1620 pts->Reset();
1621 return 0;
1622}
1623//----------------------------------------------------------------------------
1625{
1626 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1627}
1628
1629//----------------------------------------------------------------------------
1630inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1631 vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1632{
1633 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1634}
1635
1636//----------------------------------------------------------------------------
1638{
1639 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1640}
1641
1642//----------------------------------------------------------------------------
1643inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1644{
1645 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1646}
1647
1648//----------------------------------------------------------------------------
1650{
1651 return this->Visit(vtkCellArray_detail::CellPointAtIdImpl{}, cellId, cellPointIndex);
1652}
1653
1654//----------------------------------------------------------------------------
1656 VTK_SIZEHINT(pts, npts)
1657{
1658 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1659}
1660
1661//----------------------------------------------------------------------------
1663{
1664 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1665}
1666
1667//----------------------------------------------------------------------------
1669{
1670 if (this->Storage.Is64Bit())
1671 {
1672 using ValueType = typename ArrayType64::ValueType;
1673 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1674 }
1675 else
1676 {
1677 using ValueType = typename ArrayType32::ValueType;
1678 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1679 }
1680}
1681
1682//----------------------------------------------------------------------------
1684{
1686}
1687
1688//----------------------------------------------------------------------------
1694
1695//----------------------------------------------------------------------------
1697{
1698 vtkIdList* pts = cell->GetPointIds();
1699 return this->Visit(
1701}
1702
1703//----------------------------------------------------------------------------
1705{
1707}
1708
1709VTK_ABI_NAMESPACE_END
1710#endif // vtkCellArray.h
Array-Of-Structs implementation of vtkGenericDataArray.
virtual vtkIdType GetNumberOfCells() const =0
Get the number of cells in the array.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
Encapsulate traversal logic for vtkCellArray.
vtkIdType GetCellSize(vtkIdType cellId) const override
Return the size of the cell at cellId.
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)
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
vtkIdType IsHomogeneous() override
Check if all cells have the same number of vertices.
vtkIdType GetOffset(vtkIdType cellId) override
Get the offset (into the connectivity) for a specified cell id.
vtkIdType GetNumberOfConnectivityEntries()
Return the size of the array that would be returned from ExportLegacyFormat().
void SetData(vtkTypeInt32Array *offsets, vtkTypeInt32Array *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
void AppendLegacyFormat(vtkIdTypeArray *data, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.:
static void SetDefaultStorageIs64Bit(bool val)
Control the default internal storage size.
void DeepCopy(vtkAbstractCellArray *ca) override
Perform a deep copy (no reference counting) of the given cell array.
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.:
friend class vtkCellArrayIterator
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args) const
bool SetData(vtkIdType cellSize, vtkDataArray *connectivity)
Sets the internal arrays to the supported connectivity array with an offsets array automatically gene...
void ShallowCopy(vtkAbstractCellArray *ca) override
Shallow copy ca into this cell array.
vtkIdType GetNumberOfOffsets() const override
Get the number of elements in the offsets array.
void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
Replace the point ids of the cell at the legacy location with a different list of point ids.
vtkIdType GetTraversalCellId()
Get/Set the current cellId for traversal.
void Visit(Functor &&functor, Args &&... args)
vtkTypeInt32Array ArrayType32
vtkIdType GetNumberOfCells() const override
Get the number of cells in the array.
void Reset()
Reuse list.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
vtkIdType GetNumberOfConnectivityIds() const override
Get the size of the connectivity array that stores the point ids.
vtkIdType GetTraversalLocation()
Get/Set the current traversal legacy location.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > > >::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
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.
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
void ReverseCell(vtkIdType loc)
Special method inverts ordering of cell at the specified legacy location.
vtkTypeInt64Array ArrayType64
vtkIdType TraversalCellId
void InitTraversal()
bool IsStorageShareable() const override
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.
static bool DefaultStorageIs64Bit
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.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *ptIds) override
Return the point ids for the cell at cellId.
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
unsigned long GetActualMemorySize() const
Return the memory in kibibytes (1024 bytes) consumed by this cell array.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
void SetTraversalLocation(vtkIdType loc)
Get/Set the current traversal legacy location.
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 Initialize() override
Free any memory and reset to an empty state.
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.
void Visit(Functor &&functor, Args &&... args) const
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
void SetOffset(vtkIdType cellId, vtkIdType offset)
Set the offset (into the connectivity) for a specified cell id.
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
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.
vtkIdType GetCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex) const
Return the point id at cellPointIndex for the cell at cellId.
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.
static bool GetDefaultStorageIs64Bit()
Control the default internal storage size.
int GetMaxCellSize() override
Returns the size of the largest cell.
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
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.
vtkIdType GetInsertLocation(int npts)
Computes the current legacy insertion location within the internal array.
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)
void SetCells(vtkIdType ncells, vtkIdTypeArray *cells)
Define multiple cells by providing a connectivity list.
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId)
Replaces the pointId at cellPointIndex of a cell with newPointId.
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
bool IsStorage64Bit() const
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:51
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition vtkCell.h:149
list of point or cell ids
Definition vtkIdList.h:24
void SetNumberOfIds(vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:50
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:135
vtkIdType * GetPointer(vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:116
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:29
Allocate and hold a VTK object.
Definition vtkNew.h:58
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...
Hold a reference to a vtkObjectBase instance.
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
VTK_ITER_INLINE auto DataArrayValueRange(const ArrayTypePtr &array, ValueIdType start=-1, ValueIdType end=-1) -> typename detail::SelectValueRange< ArrayTypePtr, TupleSize, ForceValueTypeForVtkDataArray >::type
Generate an stl and for-range compatible range of flat AOS iterators from a vtkDataArray.
VisitState< ArrayType64 > & GetArrays64()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType32 > & GetArrays32()
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
vtkSmartPointer< ArrayType > Connectivity
static constexpr bool ValueTypeIsSameAsIdType
const ArrayType * GetOffsets() const
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
typename ArrayType::ValueType ValueType
ArrayType * GetConnectivity()
vtkIdType operator()(CellStateT &cells, vtkIdType cellId, vtkIdType cellPointIndex) const
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)
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType *cellPoints)
vtkIdType operator()(CellStateT &state, vtkIdType cellId)
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
void operator()(CellStateT &state)
void operator()(CellStateT &state, const vtkIdType npts)
Remove all duplicate types from TypeList TList, storing the new list in Result.
VisitState< ArrayType32 > * Int32
VisitState< ArrayType64 > * Int64
int vtkTypeBool
Definition vtkABI.h:64
#define vtkDataArray
STL-compatible iterable ranges that provide access to vtkDataArray elements.
void Reset()
Initializes the field list to empty.
int vtkIdType
Definition vtkType.h:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE