VTK  9.2.6
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=========================================================================*/
150#ifndef vtkCellArray_h
151#define vtkCellArray_h
152
153#include "vtkCommonDataModelModule.h" // For export macro
154#include "vtkObject.h"
155
156#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
157#include "vtkCell.h" // Needed for inline methods
158#include "vtkDataArrayRange.h" // Needed for inline methods
159#include "vtkFeatures.h" // for VTK_USE_MEMKIND
160#include "vtkSmartPointer.h" // For vtkSmartPointer
161#include "vtkTypeInt32Array.h" // Needed for inline methods
162#include "vtkTypeInt64Array.h" // Needed for inline methods
163#include "vtkTypeList.h" // Needed for ArrayList definition
164
165#include <cassert> // for assert
166#include <initializer_list> // for API
167#include <type_traits> // for std::is_same
168#include <utility> // for std::forward
169
190#define VTK_CELL_ARRAY_V2
191
193class vtkIdTypeArray;
194
195class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
196{
197public:
198 using ArrayType32 = vtkTypeInt32Array;
199 using ArrayType64 = vtkTypeInt64Array;
200
202
206 static vtkCellArray* New();
207 vtkTypeMacro(vtkCellArray, vtkObject);
208 void PrintSelf(ostream& os, vtkIndent indent) override;
209 void PrintDebug(ostream& os);
211
220 using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
221
233
242 vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
243 {
244 return this->AllocateExact(sz, sz) ? 1 : 0;
245 }
246
256 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
257 {
258 return this->AllocateExact(numCells, numCells * maxCellSize);
259 }
260
270 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
271
282 {
283 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
284 }
285
295 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
296
301
305 void Reset();
306
312 void Squeeze();
313
324 bool IsValid();
325
330 {
331 if (this->Storage.Is64Bit())
332 {
333 return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
334 }
335 else
336 {
337 return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
338 }
339 }
340
346 {
347 if (this->Storage.Is64Bit())
348 {
349 return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
350 }
351 else
352 {
353 return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
354 }
355 }
356
361 {
362 if (this->Storage.Is64Bit())
363 {
364 return this->Storage.GetArrays64().Offsets->GetValue(cellId);
365 }
366 else
367 {
368 return this->Storage.GetArrays32().Offsets->GetValue(cellId);
369 }
370 }
371
379 {
380 if (this->Storage.Is64Bit())
381 {
382 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
383 }
384 else
385 {
386 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
387 }
388 }
389
396
397#ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
408 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
409 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
410 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
416#endif // __VTK_WRAP__
417
430 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
431
445 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
446
451 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
452
460 {
461 if (this->Storage.Is64Bit())
462 {
464 }
465 else
466 {
468 }
469 }
470
525 {
526 if (this->Storage.Is64Bit())
527 {
528 return this->GetOffsetsArray64();
529 }
530 else
531 {
532 return this->GetOffsetsArray32();
533 }
534 }
546 {
547 if (this->Storage.Is64Bit())
548 {
549 return this->GetConnectivityArray64();
550 }
551 else
552 {
553 return this->GetConnectivityArray32();
554 }
555 }
569
579 void InitTraversal();
580
595 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
596
607 int GetNextCell(vtkIdList* pts);
608
619 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
620 VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
621
631 void GetCellAtId(
632 vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints, vtkIdList* ptIds)
633 VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
634
640 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
641 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
642
646 vtkIdType GetCellSize(const vtkIdType cellId) const;
647
651 vtkIdType InsertNextCell(vtkCell* cell);
652
657 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
658
663 vtkIdType InsertNextCell(vtkIdList* pts);
664
672 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
673 {
674 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
675 }
676
683 vtkIdType InsertNextCell(int npts);
684
689 void InsertCellPoint(vtkIdType id);
690
695 void UpdateCellCount(int npts);
696
711 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
712
722 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
723 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
733 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
734 {
735 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
736 }
737
743
748
753
757 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
758
770
783 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
797 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
798 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
799 VTK_SIZEHINT(data, len);
810 unsigned long GetActualMemorySize() const;
811
812 // The following code is used to support
813
814 // The wrappers get understandably confused by some of the template code below
815#ifndef __VTK_WRAP__
816
817 // Holds connectivity and offset arrays of the given ArrayType.
818 template <typename ArrayT>
820 {
821 using ArrayType = ArrayT;
822 using ValueType = typename ArrayType::ValueType;
823 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
824
825 // We can't just use is_same here, since binary compatible representations
826 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
827 // is a signed integer the same size as vtkIdType.
828 // If this value is true, ValueType pointers may be safely converted to
829 // vtkIdType pointers via reinterpret cast.
830 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
831 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
832
833 ArrayType* GetOffsets() { return this->Offsets; }
834 const ArrayType* GetOffsets() const { return this->Offsets; }
835
836 ArrayType* GetConnectivity() { return this->Connectivity; }
837 const ArrayType* GetConnectivity() const { return this->Connectivity; }
838
840
842
844
846
848
849 friend class vtkCellArray;
850
851 protected:
853 {
854 this->Connectivity = vtkSmartPointer<ArrayType>::New();
855 this->Offsets = vtkSmartPointer<ArrayType>::New();
856 this->Offsets->InsertNextValue(0);
858 {
859 this->IsInMemkind = true;
860 }
861 }
862 ~VisitState() = default;
863 void* operator new(size_t nSize)
864 {
865 void* r;
866#ifdef VTK_USE_MEMKIND
868#else
869 r = malloc(nSize);
870#endif
871 return r;
872 }
873 void operator delete(void* p)
874 {
875#ifdef VTK_USE_MEMKIND
876 VisitState* a = static_cast<VisitState*>(p);
877 if (a->IsInMemkind)
878 {
880 }
881 else
882 {
883 free(p);
884 }
885#else
886 free(p);
887#endif
888 }
889
892
893 private:
894 VisitState(const VisitState&) = delete;
895 VisitState& operator=(const VisitState&) = delete;
896 bool IsInMemkind = false;
897 };
898
899private: // Helpers that allow Visit to return a value:
900 template <typename Functor, typename... Args>
901 using GetReturnType = decltype(
902 std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
903
904 template <typename Functor, typename... Args>
905 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
906 {
907 };
908
909public:
979 template <typename Functor, typename... Args,
980 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
981 void Visit(Functor&& functor, Args&&... args)
982 {
983 if (this->Storage.Is64Bit())
984 {
985 // If you get an error on the next line, a call to Visit(functor, Args...)
986 // is being called with arguments that do not match the functor's call
987 // signature. See the Visit documentation for details.
988 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
989 }
990 else
991 {
992 // If you get an error on the next line, a call to Visit(functor, Args...)
993 // is being called with arguments that do not match the functor's call
994 // signature. See the Visit documentation for details.
995 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
996 }
997 }
998
999 template <typename Functor, typename... Args,
1000 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
1001 void Visit(Functor&& functor, Args&&... args) const
1002 {
1003 if (this->Storage.Is64Bit())
1004 {
1005 // If you get an error on the next line, a call to Visit(functor, Args...)
1006 // is being called with arguments that do not match the functor's call
1007 // signature. See the Visit documentation for details.
1008 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1009 }
1010 else
1011 {
1012 // If you get an error on the next line, a call to Visit(functor, Args...)
1013 // is being called with arguments that do not match the functor's call
1014 // signature. See the Visit documentation for details.
1015 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1016 }
1017 }
1018
1019 template <typename Functor, typename... Args,
1020 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1021 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1022 {
1023 if (this->Storage.Is64Bit())
1024 {
1025 // If you get an error on the next line, a call to Visit(functor, Args...)
1026 // is being called with arguments that do not match the functor's call
1027 // signature. See the Visit documentation for details.
1028 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1029 }
1030 else
1031 {
1032 // If you get an error on the next line, a call to Visit(functor, Args...)
1033 // is being called with arguments that do not match the functor's call
1034 // signature. See the Visit documentation for details.
1035 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1036 }
1037 }
1038 template <typename Functor, typename... Args,
1039 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1040 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1041 {
1042 if (this->Storage.Is64Bit())
1043 {
1044 // If you get an error on the next line, a call to Visit(functor, Args...)
1045 // is being called with arguments that do not match the functor's call
1046 // signature. See the Visit documentation for details.
1047 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1048 }
1049 else
1050 {
1051 // If you get an error on the next line, a call to Visit(functor, Args...)
1052 // is being called with arguments that do not match the functor's call
1053 // signature. See the Visit documentation for details.
1054 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1055 }
1056 }
1057
1060#endif // __VTK_WRAP__
1061
1062 //=================== Begin Legacy Methods ===================================
1063 // These should be deprecated at some point as they are confusing or very slow
1064
1072
1084 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1085
1095
1103
1113 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1114 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1115
1122 void GetCell(vtkIdType loc, vtkIdList* pts)
1123 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1124
1131 vtkIdType GetInsertLocation(int npts);
1132
1140 vtkIdType GetTraversalLocation();
1141 vtkIdType GetTraversalLocation(vtkIdType npts);
1142 void SetTraversalLocation(vtkIdType loc);
1152 void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1153
1165 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1166 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1167
1182 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1183
1194 vtkIdTypeArray* GetData();
1195
1196 //=================== End Legacy Methods =====================================
1197
1199
1200protected:
1202 ~vtkCellArray() override;
1203
1204 // Encapsulates storage of the internal arrays as a discriminated union
1205 // between 32-bit and 64-bit storage.
1206 struct Storage
1207 {
1208 // Union type that switches 32 and 64 bit array storage
1210 ArraySwitch() = default; // handled by Storage
1211 ~ArraySwitch() = default; // handle by Storage
1214 };
1215
1217 {
1218#ifdef VTK_USE_MEMKIND
1219 this->Arrays =
1221#else
1222 this->Arrays = new ArraySwitch;
1223#endif
1224
1225 // Default to the compile-time setting:
1226#ifdef VTK_USE_64BIT_IDS
1227
1228 this->Arrays->Int64 = new VisitState<ArrayType64>;
1229 this->StorageIs64Bit = true;
1230
1231#else // VTK_USE_64BIT_IDS
1232
1233 this->Arrays->Int32 = new VisitState<ArrayType32>;
1234 this->StorageIs64Bit = false;
1235
1236#endif // VTK_USE_64BIT_IDS
1237#ifdef VTK_USE_MEMKIND
1239 {
1240 this->IsInMemkind = true;
1241 }
1242#else
1243 (void)this->IsInMemkind; // comp warning workaround
1244#endif
1245 }
1246
1248 {
1249 if (this->StorageIs64Bit)
1250 {
1251 this->Arrays->Int64->~VisitState();
1252 delete this->Arrays->Int64;
1253 }
1254 else
1255 {
1256 this->Arrays->Int32->~VisitState();
1257 delete this->Arrays->Int32;
1258 }
1259#ifdef VTK_USE_MEMKIND
1260 if (this->IsInMemkind)
1261 {
1263 }
1264 else
1265 {
1266 free(this->Arrays);
1267 }
1268#else
1269 delete this->Arrays;
1270#endif
1271 }
1272
1273 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1274 // true if the storage changes.
1276 {
1277 if (!this->StorageIs64Bit)
1278 {
1279 return false;
1280 }
1281
1282 this->Arrays->Int64->~VisitState();
1283 delete this->Arrays->Int64;
1284 this->Arrays->Int32 = new VisitState<ArrayType32>;
1285 this->StorageIs64Bit = false;
1286
1287 return true;
1288 }
1289
1290 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1291 // true if the storage changes.
1293 {
1294 if (this->StorageIs64Bit)
1295 {
1296 return false;
1297 }
1298
1299 this->Arrays->Int32->~VisitState();
1300 delete this->Arrays->Int32;
1301 this->Arrays->Int64 = new VisitState<ArrayType64>;
1302 this->StorageIs64Bit = true;
1303
1304 return true;
1305 }
1306
1307 // Returns true if the storage is currently configured to be 64 bit.
1308 bool Is64Bit() const { return this->StorageIs64Bit; }
1309
1310 // Get the VisitState for 32-bit arrays
1312 {
1313 assert(!this->StorageIs64Bit);
1314 return *this->Arrays->Int32;
1315 }
1316
1318 {
1319 assert(!this->StorageIs64Bit);
1320 return *this->Arrays->Int32;
1321 }
1322
1323 // Get the VisitState for 64-bit arrays
1325 {
1326 assert(this->StorageIs64Bit);
1327 return *this->Arrays->Int64;
1328 }
1329
1331 {
1332 assert(this->StorageIs64Bit);
1333 return *this->Arrays->Int64;
1334 }
1335
1336 private:
1337 // Access restricted to ensure proper union construction/destruction thru
1338 // API.
1339 ArraySwitch* Arrays;
1340 bool StorageIs64Bit;
1341 bool IsInMemkind = false;
1342 };
1343
1346 vtkIdType TraversalCellId{ 0 };
1347
1349
1350private:
1351 vtkCellArray(const vtkCellArray&) = delete;
1352 void operator=(const vtkCellArray&) = delete;
1353};
1354
1355template <typename ArrayT>
1357{
1358 return this->Offsets->GetNumberOfValues() - 1;
1359}
1360
1361template <typename ArrayT>
1363{
1364 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1365}
1366
1367template <typename ArrayT>
1369{
1370 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1371}
1372
1373template <typename ArrayT>
1375{
1376 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1377}
1378
1379template <typename ArrayT>
1382{
1383 return vtk::DataArrayValueRange<1>(
1384 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1385}
1386
1388{
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, const 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 auto cellPts = state.GetCellRange(cellId);
1459
1460 ids->SetNumberOfIds(cellPts.size());
1461 vtkIdType* idPtr = ids->GetPointer(0);
1462
1463 for (ValueType ptId : cellPts)
1464 {
1465 *idPtr++ = static_cast<vtkIdType>(ptId);
1466 }
1467 }
1468
1469 // SFINAE helper to check if a VisitState's connectivity array's memory
1470 // can be used as a vtkIdType*.
1471 template <typename CellStateT>
1473 {
1474 private:
1475 using ValueType = typename CellStateT::ValueType;
1476 using ArrayType = typename CellStateT::ArrayType;
1478 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1479 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1480
1481 public:
1482 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1483 };
1484
1485 template <typename CellStateT>
1486 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
1487 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1488 vtkIdList* vtkNotUsed(temp))
1489 {
1490 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1491 const vtkIdType endOffset = state.GetEndOffset(cellId);
1492 cellSize = endOffset - beginOffset;
1493 // This is safe, see CanShareConnPtr helper above.
1494 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1495 }
1496
1497 template <typename CellStateT>
1498 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
1499 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1500 vtkIdList* temp)
1501 {
1502 using ValueType = typename CellStateT::ValueType;
1503
1504 const auto cellPts = state.GetCellRange(cellId);
1505 cellSize = cellPts.size();
1506
1507 // ValueType differs from vtkIdType, so we have to copy into a temporary
1508 // buffer:
1509 temp->SetNumberOfIds(cellSize);
1510 vtkIdType* tempPtr = temp->GetPointer(0);
1511 for (ValueType ptId : cellPts)
1512 {
1513 *tempPtr++ = static_cast<vtkIdType>(ptId);
1514 }
1515
1516 cellPoints = temp->GetPointer(0);
1517 }
1518};
1519
1521{
1522 template <typename CellStateT>
1523 void operator()(CellStateT& state)
1524 {
1525 state.GetOffsets()->Reset();
1526 state.GetConnectivity()->Reset();
1527 state.GetOffsets()->InsertNextValue(0);
1528 }
1529};
1530
1531} // end namespace vtkCellArray_detail
1532
1533//----------------------------------------------------------------------------
1535{
1536 this->TraversalCellId = 0;
1537}
1538
1539//----------------------------------------------------------------------------
1540inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1541{
1542 if (this->TraversalCellId < this->GetNumberOfCells())
1543 {
1544 this->GetCellAtId(this->TraversalCellId, npts, pts);
1545 ++this->TraversalCellId;
1546 return 1;
1547 }
1548
1549 npts = 0;
1550 pts = nullptr;
1551 return 0;
1552}
1553
1554//----------------------------------------------------------------------------
1556{
1557 if (this->TraversalCellId < this->GetNumberOfCells())
1558 {
1559 this->GetCellAtId(this->TraversalCellId, pts);
1560 ++this->TraversalCellId;
1561 return 1;
1562 }
1563
1564 pts->Reset();
1565 return 0;
1566}
1567//----------------------------------------------------------------------------
1569{
1570 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1571}
1572
1573//----------------------------------------------------------------------------
1574inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1575 vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1576{
1577 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1578}
1579
1580//----------------------------------------------------------------------------
1581inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1582 vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1583{
1584 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1585}
1586
1587//----------------------------------------------------------------------------
1589{
1590 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1591}
1592
1593//----------------------------------------------------------------------------
1595 VTK_SIZEHINT(pts, npts)
1596{
1597 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1598}
1599
1600//----------------------------------------------------------------------------
1602{
1603 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1604}
1605
1606//----------------------------------------------------------------------------
1608{
1609 if (this->Storage.Is64Bit())
1610 {
1611 using ValueType = typename ArrayType64::ValueType;
1612 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1613 }
1614 else
1615 {
1616 using ValueType = typename ArrayType32::ValueType;
1617 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1618 }
1619}
1620
1621//----------------------------------------------------------------------------
1623{
1625}
1626
1627//----------------------------------------------------------------------------
1629{
1630 return this->Visit(
1632}
1633
1634//----------------------------------------------------------------------------
1636{
1637 vtkIdList* pts = cell->GetPointIds();
1638 return this->Visit(
1640}
1641
1642//----------------------------------------------------------------------------
1644{
1646}
1647
1648#endif // vtkCellArray.h
Array-Of-Structs implementation of vtkGenericDataArray.
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
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.
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
vtkIdType GetOffset(vtkIdType cellId)
Get the offset (into the connectivity) for a specified cell id.
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.:
bool IsStorageShareable() const
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
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)
vtkTypeInt32Array ArrayType32
void Reset()
Reuse list.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
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.
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
vtkTypeInt64Array ArrayType64
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.
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
int GetMaxCellSize()
Returns the size of the largest cell.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
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.
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.
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.
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.
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)
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.
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.
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
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:70
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition vtkCell.h:165
abstract superclass for arrays of numeric data
list of point or cell ids
Definition vtkIdList.h:43
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:69
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:157
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:138
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:49
Allocate and hold a VTK object.
Definition vtkNew.h:71
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:72
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()
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)
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.
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