VTK  9.4.20251007
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
360 {
361 if (this->Storage.Is64Bit())
362 {
363 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
364 }
365 else
366 {
367 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
368 }
369 }
370
377
388 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
393 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
394 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
396
409 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
410
424 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
425
430 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
431
438 bool IsStorageShareable() const override
439 {
440 if (this->Storage.Is64Bit())
441 {
443 }
444 else
445 {
447 }
448 }
449
462
475
497
504 {
505 if (this->Storage.Is64Bit())
506 {
507 return this->GetOffsetsArray64();
508 }
509 else
510 {
511 return this->GetOffsetsArray32();
512 }
513 }
517
525 {
526 if (this->Storage.Is64Bit())
527 {
528 return this->GetConnectivityArray64();
529 }
530 else
531 {
532 return this->GetConnectivityArray32();
533 }
534 }
538
548
558 void InitTraversal();
559
574 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
575
586 int GetNextCell(vtkIdList* pts);
587
598 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
599 vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
600 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
601
607 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
608 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
609
617 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints) VTK_SIZEHINT(
618 cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) override;
619
623 vtkIdType GetCellSize(vtkIdType cellId) const override;
624
629
634 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
635
641
649 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
650 {
651 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
652 }
653
660 vtkIdType InsertNextCell(int npts);
661
666 void InsertCellPoint(vtkIdType id);
667
672 void UpdateCellCount(int npts);
673
684
688 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
689
699 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
700 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
702
710 void ReplaceCellPointAtId(vtkIdType cellId, vtkIdType cellPointIndex, vtkIdType newPointId);
711
719 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
720 {
721 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
722 }
723
728 int GetMaxCellSize() override;
729
733 void DeepCopy(vtkAbstractCellArray* ca) override;
734
739
743 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
744
756
769 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
771
783 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
784 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
785 VTK_SIZEHINT(data, len);
787
796 unsigned long GetActualMemorySize() const;
797
798 // The following code is used to support
799
800 // The wrappers get understandably confused by some of the template code below
801#ifndef __VTK_WRAP__
802
803 // Holds connectivity and offset arrays of the given ArrayType.
804 template <typename ArrayT>
806 {
807 using ArrayType = ArrayT;
808 using ValueType = typename ArrayType::ValueType;
809 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
810
811 // We can't just use is_same here, since binary compatible representations
812 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
813 // is a signed integer the same size as vtkIdType.
814 // If this value is true, ValueType pointers may be safely converted to
815 // vtkIdType pointers via reinterpret cast.
816 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
817 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
818
819 ArrayType* GetOffsets() { return this->Offsets; }
820 const ArrayType* GetOffsets() const { return this->Offsets; }
821
823 const ArrayType* GetConnectivity() const { return this->Connectivity; }
824
826
828
830
832
834
835 friend class vtkCellArray;
836
837 protected:
839 {
842 this->Offsets->InsertNextValue(0);
844 {
845 this->IsInMemkind = true;
846 }
847 }
848 ~VisitState() = default;
849 void* operator new(size_t nSize)
850 {
851 void* r;
852#ifdef VTK_USE_MEMKIND
854#else
855 r = malloc(nSize);
856#endif
857 return r;
858 }
859 void operator delete(void* p)
860 {
861#ifdef VTK_USE_MEMKIND
862 VisitState* a = static_cast<VisitState*>(p);
863 if (a->IsInMemkind)
864 {
866 }
867 else
868 {
869 free(p);
870 }
871#else
872 free(p);
873#endif
874 }
875
878
879 private:
880 VisitState(const VisitState&) = delete;
881 VisitState& operator=(const VisitState&) = delete;
882 bool IsInMemkind = false;
883 };
884
885private: // Helpers that allow Visit to return a value:
886 template <typename Functor, typename... Args>
887 using GetReturnType = decltype(std::declval<Functor>()(
888 std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
889
890 template <typename Functor, typename... Args>
891 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
892 {
893 };
894
895public:
965 template <typename Functor, typename... Args,
966 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
967 void Visit(Functor&& functor, Args&&... args)
968 {
969 if (this->Storage.Is64Bit())
970 {
971 // If you get an error on the next line, a call to Visit(functor, Args...)
972 // is being called with arguments that do not match the functor's call
973 // signature. See the Visit documentation for details.
974 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
975 }
976 else
977 {
978 // If you get an error on the next line, a call to Visit(functor, Args...)
979 // is being called with arguments that do not match the functor's call
980 // signature. See the Visit documentation for details.
981 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
982 }
983 }
984
985 template <typename Functor, typename... Args,
986 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
987 void Visit(Functor&& functor, Args&&... args) const
988 {
989 if (this->Storage.Is64Bit())
990 {
991 // If you get an error on the next line, a call to Visit(functor, Args...)
992 // is being called with arguments that do not match the functor's call
993 // signature. See the Visit documentation for details.
994 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
995 }
996 else
997 {
998 // If you get an error on the next line, a call to Visit(functor, Args...)
999 // is being called with arguments that do not match the functor's call
1000 // signature. See the Visit documentation for details.
1001 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1002 }
1003 }
1004
1005 template <typename Functor, typename... Args,
1006 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1007 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1008 {
1009 if (this->Storage.Is64Bit())
1010 {
1011 // If you get an error on the next line, a call to Visit(functor, Args...)
1012 // is being called with arguments that do not match the functor's call
1013 // signature. See the Visit documentation for details.
1014 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1015 }
1016 else
1017 {
1018 // If you get an error on the next line, a call to Visit(functor, Args...)
1019 // is being called with arguments that do not match the functor's call
1020 // signature. See the Visit documentation for details.
1021 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1022 }
1023 }
1024 template <typename Functor, typename... Args,
1025 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1026 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1027 {
1028 if (this->Storage.Is64Bit())
1029 {
1030 // If you get an error on the next line, a call to Visit(functor, Args...)
1031 // is being called with arguments that do not match the functor's call
1032 // signature. See the Visit documentation for details.
1033 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1034 }
1035 else
1036 {
1037 // If you get an error on the next line, a call to Visit(functor, Args...)
1038 // is being called with arguments that do not match the functor's call
1039 // signature. See the Visit documentation for details.
1040 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1041 }
1042 }
1043
1045
1055
1056#endif // __VTK_WRAP__
1057
1058 //=================== Begin Legacy Methods ===================================
1059 // These should be deprecated at some point as they are confusing or very slow
1060
1068
1080 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1081
1091
1099
1109 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1110 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1111
1119 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1120
1128
1140
1149
1161 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1162 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1163
1178 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1179
1191
1192 //=================== End Legacy Methods =====================================
1193
1195
1196protected:
1198 ~vtkCellArray() override;
1199
1200 // Encapsulates storage of the internal arrays as a discriminated union
1201 // between 32-bit and 64-bit storage.
1202 struct Storage
1203 {
1204 // Union type that switches 32 and 64 bit array storage
1206 {
1207 ArraySwitch() = default; // handled by Storage
1208 ~ArraySwitch() = default; // handle by Storage
1211 };
1212
1214 {
1215#ifdef VTK_USE_MEMKIND
1216 this->Arrays =
1218#else
1219 this->Arrays = new ArraySwitch;
1220#endif
1221
1222 // Default can be changed, to save memory
1224 {
1225 this->Arrays->Int64 = new VisitState<ArrayType64>;
1226 this->StorageIs64Bit = true;
1227 }
1228 else
1229 {
1230 this->Arrays->Int32 = new VisitState<ArrayType32>;
1231 this->StorageIs64Bit = false;
1232 }
1233
1234#ifdef VTK_USE_MEMKIND
1236 {
1237 this->IsInMemkind = true;
1238 }
1239#else
1240 (void)this->IsInMemkind; // comp warning workaround
1241#endif
1242 }
1243
1245 {
1246 if (this->StorageIs64Bit)
1247 {
1248 this->Arrays->Int64->~VisitState();
1249 delete this->Arrays->Int64;
1250 }
1251 else
1252 {
1253 this->Arrays->Int32->~VisitState();
1254 delete this->Arrays->Int32;
1255 }
1256#ifdef VTK_USE_MEMKIND
1257 if (this->IsInMemkind)
1258 {
1260 }
1261 else
1262 {
1263 free(this->Arrays);
1264 }
1265#else
1266 delete this->Arrays;
1267#endif
1268 }
1269
1270 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1271 // true if the storage changes.
1273 {
1274 if (!this->StorageIs64Bit)
1275 {
1276 return false;
1277 }
1278
1279 this->Arrays->Int64->~VisitState();
1280 delete this->Arrays->Int64;
1281 this->Arrays->Int32 = new VisitState<ArrayType32>;
1282 this->StorageIs64Bit = false;
1283
1284 return true;
1285 }
1286
1287 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1288 // true if the storage changes.
1290 {
1291 if (this->StorageIs64Bit)
1292 {
1293 return false;
1294 }
1295
1296 this->Arrays->Int32->~VisitState();
1297 delete this->Arrays->Int32;
1298 this->Arrays->Int64 = new VisitState<ArrayType64>;
1299 this->StorageIs64Bit = true;
1300
1301 return true;
1302 }
1303
1304 // Returns true if the storage is currently configured to be 64 bit.
1305 bool Is64Bit() const { return this->StorageIs64Bit; }
1306
1307 // Get the VisitState for 32-bit arrays
1309 {
1310 assert(!this->StorageIs64Bit);
1311 return *this->Arrays->Int32;
1312 }
1313
1315 {
1316 assert(!this->StorageIs64Bit);
1317 return *this->Arrays->Int32;
1318 }
1319
1320 // Get the VisitState for 64-bit arrays
1322 {
1323 assert(this->StorageIs64Bit);
1324 return *this->Arrays->Int64;
1325 }
1326
1328 {
1329 assert(this->StorageIs64Bit);
1330 return *this->Arrays->Int64;
1331 }
1332
1333 private:
1334 // Access restricted to ensure proper union construction/destruction thru
1335 // API.
1336 ArraySwitch* Arrays;
1337 bool StorageIs64Bit;
1338 bool IsInMemkind = false;
1339 };
1340
1343
1345
1347
1348private:
1349 vtkCellArray(const vtkCellArray&) = delete;
1350 void operator=(const vtkCellArray&) = delete;
1351};
1352
1353template <typename ArrayT>
1355{
1356 return this->Offsets->GetNumberOfValues() - 1;
1357}
1358
1359template <typename ArrayT>
1361{
1362 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1363}
1364
1365template <typename ArrayT>
1367{
1368 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1369}
1370
1371template <typename ArrayT>
1373{
1374 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1375}
1376
1377template <typename ArrayT>
1384VTK_ABI_NAMESPACE_END
1385
1387{
1388VTK_ABI_NAMESPACE_BEGIN
1389
1391{
1392 // Insert full cell
1393 template <typename CellStateT>
1394 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1395 {
1396 using ValueType = typename CellStateT::ValueType;
1397 auto* conn = state.GetConnectivity();
1398 auto* offsets = state.GetOffsets();
1399
1400 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1401
1402 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1403
1404 for (vtkIdType i = 0; i < npts; ++i)
1405 {
1406 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1407 }
1408
1409 return cellId;
1410 }
1411
1412 // Just update offset table (for incremental API)
1413 template <typename CellStateT>
1414 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1415 {
1416 using ValueType = typename CellStateT::ValueType;
1417 auto* conn = state.GetConnectivity();
1418 auto* offsets = state.GetOffsets();
1419
1420 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1421
1422 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1423
1424 return cellId;
1425 }
1426};
1427
1428// for incremental API:
1430{
1431 template <typename CellStateT>
1432 void operator()(CellStateT& state, const vtkIdType npts)
1433 {
1434 using ValueType = typename CellStateT::ValueType;
1435
1436 auto* offsets = state.GetOffsets();
1437 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1438 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1439 }
1440};
1441
1443{
1444 template <typename CellStateT>
1445 vtkIdType operator()(CellStateT& state, vtkIdType cellId)
1446 {
1447 return state.GetCellSize(cellId);
1448 }
1449};
1450
1452{
1453 template <typename CellStateT>
1454 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1455 {
1456 using ValueType = typename CellStateT::ValueType;
1457
1458 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1459 const vtkIdType endOffset = state.GetEndOffset(cellId);
1460 const vtkIdType cellSize = endOffset - beginOffset;
1461 const auto cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1462
1463 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1464 ids->SetNumberOfIds(cellSize);
1465 vtkIdType* idPtr = ids->GetPointer(0);
1466 for (ValueType i = 0; i < cellSize; ++i)
1467 {
1468 idPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1469 }
1470 }
1471
1472 template <typename CellStateT>
1474 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1475 {
1476 using ValueType = typename CellStateT::ValueType;
1477
1478 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1479 const vtkIdType endOffset = state.GetEndOffset(cellId);
1480 cellSize = endOffset - beginOffset;
1481 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1482
1483 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1484 for (vtkIdType i = 0; i < cellSize; ++i)
1485 {
1486 cellPoints[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1487 }
1488 }
1489
1490 // SFINAE helper to check if a VisitState's connectivity array's memory
1491 // can be used as a vtkIdType*.
1492 template <typename CellStateT>
1494 {
1495 private:
1496 using ValueType = typename CellStateT::ValueType;
1497 using ArrayType = typename CellStateT::ArrayType;
1498 using AOSArrayType = vtkAOSDataArrayTemplate<ValueType>;
1499 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1500 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1501
1502 public:
1503 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1504 };
1505
1506 template <typename CellStateT>
1507 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
1508 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1509 vtkIdList* vtkNotUsed(temp))
1510 {
1511 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1512 const vtkIdType endOffset = state.GetEndOffset(cellId);
1513 cellSize = endOffset - beginOffset;
1514 // This is safe, see CanShareConnPtr helper above.
1515 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1516 }
1517
1518 template <typename CellStateT>
1519 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
1520 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1521 vtkIdList* temp)
1522 {
1523 using ValueType = typename CellStateT::ValueType;
1524
1525 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1526 const vtkIdType endOffset = state.GetEndOffset(cellId);
1527 cellSize = endOffset - beginOffset;
1528 const ValueType* cellConnectivity = state.GetConnectivity()->GetPointer(beginOffset);
1529
1530 // ValueType differs from vtkIdType, so we have to copy into a temporary buffer:
1531 temp->SetNumberOfIds(cellSize);
1532 vtkIdType* tempPtr = temp->GetPointer(0);
1533 for (vtkIdType i = 0; i < cellSize; ++i)
1534 {
1535 tempPtr[i] = static_cast<vtkIdType>(cellConnectivity[i]);
1536 }
1537
1538 cellPoints = temp->GetPointer(0);
1539 }
1540};
1541
1543{
1544 template <typename CellStateT>
1545 void operator()(CellStateT& state)
1546 {
1547 state.GetOffsets()->Reset();
1548 state.GetConnectivity()->Reset();
1549 state.GetOffsets()->InsertNextValue(0);
1550 }
1551};
1552
1553VTK_ABI_NAMESPACE_END
1554} // end namespace vtkCellArray_detail
1555
1556VTK_ABI_NAMESPACE_BEGIN
1557//----------------------------------------------------------------------------
1559{
1560 this->TraversalCellId = 0;
1561}
1562
1563//----------------------------------------------------------------------------
1564inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1565{
1566 if (this->TraversalCellId < this->GetNumberOfCells())
1567 {
1568 this->GetCellAtId(this->TraversalCellId, npts, pts);
1569 ++this->TraversalCellId;
1570 return 1;
1571 }
1572
1573 npts = 0;
1574 pts = nullptr;
1575 return 0;
1576}
1577
1578//----------------------------------------------------------------------------
1580{
1582 {
1583 this->GetCellAtId(this->TraversalCellId, pts);
1584 ++this->TraversalCellId;
1585 return 1;
1586 }
1587
1588 pts->Reset();
1589 return 0;
1590}
1591//----------------------------------------------------------------------------
1593{
1594 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1595}
1596
1597//----------------------------------------------------------------------------
1598inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1599 vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1600{
1601 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1602}
1603
1604//----------------------------------------------------------------------------
1606{
1607 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1608}
1609
1610//----------------------------------------------------------------------------
1611inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType* cellPoints)
1612{
1613 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints);
1614}
1615
1616//----------------------------------------------------------------------------
1618 VTK_SIZEHINT(pts, npts)
1619{
1620 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1621}
1622
1623//----------------------------------------------------------------------------
1625{
1626 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1627}
1628
1629//----------------------------------------------------------------------------
1631{
1632 if (this->Storage.Is64Bit())
1633 {
1634 using ValueType = typename ArrayType64::ValueType;
1635 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1636 }
1637 else
1638 {
1639 using ValueType = typename ArrayType32::ValueType;
1640 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1641 }
1642}
1643
1644//----------------------------------------------------------------------------
1646{
1648}
1649
1650//----------------------------------------------------------------------------
1656
1657//----------------------------------------------------------------------------
1659{
1660 vtkIdList* pts = cell->GetPointIds();
1661 return this->Visit(
1663}
1664
1665//----------------------------------------------------------------------------
1667{
1669}
1670
1671VTK_ABI_NAMESPACE_END
1672#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.
virtual vtkIdType GetCellSize(vtkIdType cellId) const =0
Return the size of 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.
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.
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.
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
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()
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.
int vtkIdType
Definition vtkType.h:315
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_MARSHALMANUAL
#define VTK_NEWINSTANCE