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=========================================================================*/
135#ifndef vtkCellArray_h
136#define vtkCellArray_h
137
138#include "vtkCommonDataModelModule.h" // For export macro
139#include "vtkObject.h"
140
141#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
142#include "vtkCell.h" // Needed for inline methods
143#include "vtkDataArrayRange.h" // Needed for inline methods
144#include "vtkFeatures.h" // for VTK_USE_MEMKIND
145#include "vtkSmartPointer.h" // For vtkSmartPointer
146#include "vtkTypeInt32Array.h" // Needed for inline methods
147#include "vtkTypeInt64Array.h" // Needed for inline methods
148#include "vtkTypeList.h" // Needed for ArrayList definition
149
150#include <cassert> // for assert
151#include <initializer_list> // for API
152#include <type_traits> // for std::is_same
153#include <utility> // for std::forward
154
175#define VTK_CELL_ARRAY_V2
176
178class vtkIdTypeArray;
179
180class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
181{
182public:
183 using ArrayType32 = vtkTypeInt32Array;
184 using ArrayType64 = vtkTypeInt64Array;
185
187
191 static vtkCellArray* New();
192 vtkTypeMacro(vtkCellArray, vtkObject);
193 void PrintSelf(ostream& os, vtkIndent indent) override;
194 void PrintDebug(ostream& os);
196
205 using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
206
218
227 vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
228 {
229 return this->AllocateExact(sz, sz) ? 1 : 0;
230 }
231
241 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
242 {
243 return this->AllocateExact(numCells, numCells * maxCellSize);
244 }
245
255 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
256
267 {
268 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
269 }
270
280 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
281
286
290 void Reset();
291
297 void Squeeze();
298
309 bool IsValid();
310
315 {
316 if (this->Storage.Is64Bit())
317 {
318 return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
319 }
320 else
321 {
322 return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
323 }
324 }
325
331 {
332 if (this->Storage.Is64Bit())
333 {
334 return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
335 }
336 else
337 {
338 return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
339 }
340 }
341
346 {
347 if (this->Storage.Is64Bit())
348 {
349 return this->Storage.GetArrays64().Offsets->GetValue(cellId);
350 }
351 else
352 {
353 return this->Storage.GetArrays32().Offsets->GetValue(cellId);
354 }
355 }
356
364 {
365 if (this->Storage.Is64Bit())
366 {
367 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
368 }
369 else
370 {
371 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
372 }
373 }
374
381
382#ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
393 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
394 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
395 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
401#endif // __VTK_WRAP__
402
415 bool SetData(vtkDataArray* offsets, vtkDataArray* connectivity);
416
430 bool SetData(vtkIdType cellSize, vtkDataArray* connectivity);
431
436 bool IsStorage64Bit() const { return this->Storage.Is64Bit(); }
437
445 {
446 if (this->Storage.Is64Bit())
447 {
449 }
450 else
451 {
453 }
454 }
455
510 {
511 if (this->Storage.Is64Bit())
512 {
513 return this->GetOffsetsArray64();
514 }
515 else
516 {
517 return this->GetOffsetsArray32();
518 }
519 }
531 {
532 if (this->Storage.Is64Bit())
533 {
534 return this->GetConnectivityArray64();
535 }
536 else
537 {
538 return this->GetConnectivityArray32();
539 }
540 }
554
564 void InitTraversal();
565
580 int GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts);
581
592 int GetNextCell(vtkIdList* pts);
593
604 void GetCellAtId(vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints)
605 VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
606
616 void GetCellAtId(
617 vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints, vtkIdList* ptIds)
618 VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
619
625 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
626 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
627
631 vtkIdType GetCellSize(const vtkIdType cellId) const;
632
636 vtkIdType InsertNextCell(vtkCell* cell);
637
642 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
643
648 vtkIdType InsertNextCell(vtkIdList* pts);
649
657 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
658 {
659 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
660 }
661
668 vtkIdType InsertNextCell(int npts);
669
674 void InsertCellPoint(vtkIdType id);
675
680 void UpdateCellCount(int npts);
681
696 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
697
707 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
708 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
718 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
719 {
720 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
721 }
722
728
733
738
742 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
743
755
768 void ImportLegacyFormat(const vtkIdType* data, vtkIdType len) VTK_SIZEHINT(data, len);
782 void AppendLegacyFormat(vtkIdTypeArray* data, vtkIdType ptOffset = 0);
783 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
784 VTK_SIZEHINT(data, len);
795 unsigned long GetActualMemorySize() const;
796
797 // The following code is used to support
798
799 // The wrappers get understandably confused by some of the template code below
800#ifndef __VTK_WRAP__
801
802 // Holds connectivity and offset arrays of the given ArrayType.
803 template <typename ArrayT>
805 {
806 using ArrayType = ArrayT;
807 using ValueType = typename ArrayType::ValueType;
808 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
809
810 // We can't just use is_same here, since binary compatible representations
811 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
812 // is a signed integer the same size as vtkIdType.
813 // If this value is true, ValueType pointers may be safely converted to
814 // vtkIdType pointers via reinterpret cast.
815 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
816 std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));
817
818 ArrayType* GetOffsets() { return this->Offsets; }
819 const ArrayType* GetOffsets() const { return this->Offsets; }
820
821 ArrayType* GetConnectivity() { return this->Connectivity; }
822 const ArrayType* GetConnectivity() const { return this->Connectivity; }
823
825
827
829
831
833
834 friend class vtkCellArray;
835
836 protected:
838 {
839 this->Connectivity = vtkSmartPointer<ArrayType>::New();
840 this->Offsets = vtkSmartPointer<ArrayType>::New();
841 this->Offsets->InsertNextValue(0);
843 {
844 this->IsInMemkind = true;
845 }
846 }
847 ~VisitState() = default;
848 void* operator new(size_t nSize)
849 {
850 void* r;
851#ifdef VTK_USE_MEMKIND
853#else
854 r = malloc(nSize);
855#endif
856 return r;
857 }
858 void operator delete(void* p)
859 {
860#ifdef VTK_USE_MEMKIND
861 VisitState* a = static_cast<VisitState*>(p);
862 if (a->IsInMemkind)
863 {
865 }
866 else
867 {
868 free(p);
869 }
870#else
871 free(p);
872#endif
873 }
874
877
878 private:
879 VisitState(const VisitState&) = delete;
880 VisitState& operator=(const VisitState&) = delete;
881 bool IsInMemkind = false;
882 };
883
884private: // Helpers that allow Visit to return a value:
885 template <typename Functor, typename... Args>
886 using GetReturnType = decltype(
887 std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
888
889 template <typename Functor, typename... Args>
890 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
891 {
892 };
893
894public:
964 template <typename Functor, typename... Args,
965 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
966 void Visit(Functor&& functor, Args&&... args)
967 {
968 if (this->Storage.Is64Bit())
969 {
970 // If you get an error on the next line, a call to Visit(functor, Args...)
971 // is being called with arguments that do not match the functor's call
972 // signature. See the Visit documentation for details.
973 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
974 }
975 else
976 {
977 // If you get an error on the next line, a call to Visit(functor, Args...)
978 // is being called with arguments that do not match the functor's call
979 // signature. See the Visit documentation for details.
980 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
981 }
982 }
983
984 template <typename Functor, typename... Args,
985 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
986 void Visit(Functor&& functor, Args&&... args) const
987 {
988 if (this->Storage.Is64Bit())
989 {
990 // If you get an error on the next line, a call to Visit(functor, Args...)
991 // is being called with arguments that do not match the functor's call
992 // signature. See the Visit documentation for details.
993 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
994 }
995 else
996 {
997 // If you get an error on the next line, a call to Visit(functor, Args...)
998 // is being called with arguments that do not match the functor's call
999 // signature. See the Visit documentation for details.
1000 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1001 }
1002 }
1003
1004 template <typename Functor, typename... Args,
1005 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1006 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
1007 {
1008 if (this->Storage.Is64Bit())
1009 {
1010 // If you get an error on the next line, a call to Visit(functor, Args...)
1011 // is being called with arguments that do not match the functor's call
1012 // signature. See the Visit documentation for details.
1013 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1014 }
1015 else
1016 {
1017 // If you get an error on the next line, a call to Visit(functor, Args...)
1018 // is being called with arguments that do not match the functor's call
1019 // signature. See the Visit documentation for details.
1020 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1021 }
1022 }
1023 template <typename Functor, typename... Args,
1024 typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
1025 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args) const
1026 {
1027 if (this->Storage.Is64Bit())
1028 {
1029 // If you get an error on the next line, a call to Visit(functor, Args...)
1030 // is being called with arguments that do not match the functor's call
1031 // signature. See the Visit documentation for details.
1032 return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
1033 }
1034 else
1035 {
1036 // If you get an error on the next line, a call to Visit(functor, Args...)
1037 // is being called with arguments that do not match the functor's call
1038 // signature. See the Visit documentation for details.
1039 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
1040 }
1041 }
1042
1045#endif // __VTK_WRAP__
1046
1047 //=================== Begin Legacy Methods ===================================
1048 // These should be deprecated at some point as they are confusing or very slow
1049
1057
1069 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1070
1080
1088
1098 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1099 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1100
1107 void GetCell(vtkIdType loc, vtkIdList* pts)
1108 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1109
1116 vtkIdType GetInsertLocation(int npts);
1117
1125 vtkIdType GetTraversalLocation();
1126 vtkIdType GetTraversalLocation(vtkIdType npts);
1127 void SetTraversalLocation(vtkIdType loc);
1137 void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1138
1150 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1151 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1152
1167 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1168
1179 vtkIdTypeArray* GetData();
1180
1181 //=================== End Legacy Methods =====================================
1182
1184
1185protected:
1187 ~vtkCellArray() override;
1188
1189 // Encapsulates storage of the internal arrays as a discriminated union
1190 // between 32-bit and 64-bit storage.
1191 struct Storage
1192 {
1193 // Union type that switches 32 and 64 bit array storage
1195 ArraySwitch() = default; // handled by Storage
1196 ~ArraySwitch() = default; // handle by Storage
1199 };
1200
1202 {
1203#ifdef VTK_USE_MEMKIND
1204 this->Arrays =
1206#else
1207 this->Arrays = new ArraySwitch;
1208#endif
1209
1210 // Default to the compile-time setting:
1211#ifdef VTK_USE_64BIT_IDS
1212
1213 this->Arrays->Int64 = new VisitState<ArrayType64>;
1214 this->StorageIs64Bit = true;
1215
1216#else // VTK_USE_64BIT_IDS
1217
1218 this->Arrays->Int32 = new VisitState<ArrayType32>;
1219 this->StorageIs64Bit = false;
1220
1221#endif // VTK_USE_64BIT_IDS
1222#ifdef VTK_USE_MEMKIND
1224 {
1225 this->IsInMemkind = true;
1226 }
1227#else
1228 (void)this->IsInMemkind; // comp warning workaround
1229#endif
1230 }
1231
1233 {
1234 if (this->StorageIs64Bit)
1235 {
1236 this->Arrays->Int64->~VisitState();
1237 delete this->Arrays->Int64;
1238 }
1239 else
1240 {
1241 this->Arrays->Int32->~VisitState();
1242 delete this->Arrays->Int32;
1243 }
1244#ifdef VTK_USE_MEMKIND
1245 if (this->IsInMemkind)
1246 {
1248 }
1249 else
1250 {
1251 free(this->Arrays);
1252 }
1253#else
1254 delete this->Arrays;
1255#endif
1256 }
1257
1258 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1259 // true if the storage changes.
1261 {
1262 if (!this->StorageIs64Bit)
1263 {
1264 return false;
1265 }
1266
1267 this->Arrays->Int64->~VisitState();
1268 delete this->Arrays->Int64;
1269 this->Arrays->Int32 = new VisitState<ArrayType32>;
1270 this->StorageIs64Bit = false;
1271
1272 return true;
1273 }
1274
1275 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1276 // true if the storage changes.
1278 {
1279 if (this->StorageIs64Bit)
1280 {
1281 return false;
1282 }
1283
1284 this->Arrays->Int32->~VisitState();
1285 delete this->Arrays->Int32;
1286 this->Arrays->Int64 = new VisitState<ArrayType64>;
1287 this->StorageIs64Bit = true;
1288
1289 return true;
1290 }
1291
1292 // Returns true if the storage is currently configured to be 64 bit.
1293 bool Is64Bit() const { return this->StorageIs64Bit; }
1294
1295 // Get the VisitState for 32-bit arrays
1297 {
1298 assert(!this->StorageIs64Bit);
1299 return *this->Arrays->Int32;
1300 }
1301
1303 {
1304 assert(!this->StorageIs64Bit);
1305 return *this->Arrays->Int32;
1306 }
1307
1308 // Get the VisitState for 64-bit arrays
1310 {
1311 assert(this->StorageIs64Bit);
1312 return *this->Arrays->Int64;
1313 }
1314
1316 {
1317 assert(this->StorageIs64Bit);
1318 return *this->Arrays->Int64;
1319 }
1320
1321 private:
1322 // Access restricted to ensure proper union construction/destruction thru
1323 // API.
1324 ArraySwitch* Arrays;
1325 bool StorageIs64Bit;
1326 bool IsInMemkind = false;
1327 };
1328
1331 vtkIdType TraversalCellId{ 0 };
1332
1334
1335private:
1336 vtkCellArray(const vtkCellArray&) = delete;
1337 void operator=(const vtkCellArray&) = delete;
1338};
1339
1340template <typename ArrayT>
1342{
1343 return this->Offsets->GetNumberOfValues() - 1;
1344}
1345
1346template <typename ArrayT>
1348{
1349 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1350}
1351
1352template <typename ArrayT>
1354{
1355 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1356}
1357
1358template <typename ArrayT>
1360{
1361 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1362}
1363
1364template <typename ArrayT>
1367{
1368 return vtk::DataArrayValueRange<1>(
1369 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1370}
1371
1373{
1374
1376{
1377 // Insert full cell
1378 template <typename CellStateT>
1379 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1380 {
1381 using ValueType = typename CellStateT::ValueType;
1382 auto* conn = state.GetConnectivity();
1383 auto* offsets = state.GetOffsets();
1384
1385 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1386
1387 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1388
1389 for (vtkIdType i = 0; i < npts; ++i)
1390 {
1391 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1392 }
1393
1394 return cellId;
1395 }
1396
1397 // Just update offset table (for incremental API)
1398 template <typename CellStateT>
1399 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1400 {
1401 using ValueType = typename CellStateT::ValueType;
1402 auto* conn = state.GetConnectivity();
1403 auto* offsets = state.GetOffsets();
1404
1405 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1406
1407 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1408
1409 return cellId;
1410 }
1411};
1412
1413// for incremental API:
1415{
1416 template <typename CellStateT>
1417 void operator()(CellStateT& state, const vtkIdType npts)
1418 {
1419 using ValueType = typename CellStateT::ValueType;
1420
1421 auto* offsets = state.GetOffsets();
1422 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1423 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1424 }
1425};
1426
1428{
1429 template <typename CellStateT>
1430 vtkIdType operator()(CellStateT& state, const vtkIdType cellId)
1431 {
1432 return state.GetCellSize(cellId);
1433 }
1434};
1435
1437{
1438 template <typename CellStateT>
1439 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1440 {
1441 using ValueType = typename CellStateT::ValueType;
1442
1443 const auto cellPts = state.GetCellRange(cellId);
1444
1445 ids->SetNumberOfIds(cellPts.size());
1446 vtkIdType* idPtr = ids->GetPointer(0);
1447
1448 for (ValueType ptId : cellPts)
1449 {
1450 *idPtr++ = static_cast<vtkIdType>(ptId);
1451 }
1452 }
1453
1454 // SFINAE helper to check if a VisitState's connectivity array's memory
1455 // can be used as a vtkIdType*.
1456 template <typename CellStateT>
1458 {
1459 private:
1460 using ValueType = typename CellStateT::ValueType;
1461 using ArrayType = typename CellStateT::ArrayType;
1463 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1464 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1465
1466 public:
1467 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1468 };
1469
1470 template <typename CellStateT>
1471 typename std::enable_if<CanShareConnPtr<CellStateT>::value, void>::type operator()(
1472 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1473 vtkIdList* vtkNotUsed(temp))
1474 {
1475 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1476 const vtkIdType endOffset = state.GetEndOffset(cellId);
1477 cellSize = endOffset - beginOffset;
1478 // This is safe, see CanShareConnPtr helper above.
1479 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1480 }
1481
1482 template <typename CellStateT>
1483 typename std::enable_if<!CanShareConnPtr<CellStateT>::value, void>::type operator()(
1484 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1485 vtkIdList* temp)
1486 {
1487 using ValueType = typename CellStateT::ValueType;
1488
1489 const auto cellPts = state.GetCellRange(cellId);
1490 cellSize = cellPts.size();
1491
1492 // ValueType differs from vtkIdType, so we have to copy into a temporary
1493 // buffer:
1494 temp->SetNumberOfIds(cellSize);
1495 vtkIdType* tempPtr = temp->GetPointer(0);
1496 for (ValueType ptId : cellPts)
1497 {
1498 *tempPtr++ = static_cast<vtkIdType>(ptId);
1499 }
1500
1501 cellPoints = temp->GetPointer(0);
1502 }
1503};
1504
1506{
1507 template <typename CellStateT>
1508 void operator()(CellStateT& state)
1509 {
1510 state.GetOffsets()->Reset();
1511 state.GetConnectivity()->Reset();
1512 state.GetOffsets()->InsertNextValue(0);
1513 }
1514};
1515
1516} // end namespace vtkCellArray_detail
1517
1518//----------------------------------------------------------------------------
1520{
1521 this->TraversalCellId = 0;
1522}
1523
1524//----------------------------------------------------------------------------
1525inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1526{
1527 if (this->TraversalCellId < this->GetNumberOfCells())
1528 {
1529 this->GetCellAtId(this->TraversalCellId, npts, pts);
1530 ++this->TraversalCellId;
1531 return 1;
1532 }
1533
1534 npts = 0;
1535 pts = nullptr;
1536 return 0;
1537}
1538
1539//----------------------------------------------------------------------------
1541{
1542 if (this->TraversalCellId < this->GetNumberOfCells())
1543 {
1544 this->GetCellAtId(this->TraversalCellId, pts);
1545 ++this->TraversalCellId;
1546 return 1;
1547 }
1548
1549 pts->Reset();
1550 return 0;
1551}
1552//----------------------------------------------------------------------------
1554{
1555 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1556}
1557
1558//----------------------------------------------------------------------------
1559inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1560 vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1561{
1562 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1563}
1564
1565//----------------------------------------------------------------------------
1566inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1567 vtkIdType const*& cellPoints, vtkIdList* ptIds) VTK_SIZEHINT(cellPoints, cellSize)
1568{
1569 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, ptIds);
1570}
1571
1572//----------------------------------------------------------------------------
1574{
1575 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1576}
1577
1578//----------------------------------------------------------------------------
1580 VTK_SIZEHINT(pts, npts)
1581{
1582 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1583}
1584
1585//----------------------------------------------------------------------------
1587{
1588 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1589}
1590
1591//----------------------------------------------------------------------------
1593{
1594 if (this->Storage.Is64Bit())
1595 {
1596 using ValueType = typename ArrayType64::ValueType;
1597 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1598 }
1599 else
1600 {
1601 using ValueType = typename ArrayType32::ValueType;
1602 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1603 }
1604}
1605
1606//----------------------------------------------------------------------------
1608{
1610}
1611
1612//----------------------------------------------------------------------------
1614{
1615 return this->Visit(
1617}
1618
1619//----------------------------------------------------------------------------
1621{
1622 vtkIdList* pts = cell->GetPointIds();
1623 return this->Visit(
1625}
1626
1627//----------------------------------------------------------------------------
1629{
1631}
1632
1633#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:58
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition vtkCell.h:153
abstract superclass for arrays of numeric data
list of point or cell ids
Definition vtkIdList.h:31
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:57
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:145
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:126
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
dynamic, self-adjusting array of vtkIdType
a simple class to control print indentation
Definition vtkIndent.h:34
Allocate and hold a VTK object.
Definition vtkNew.h:56
static vtkMallocingFunction GetCurrentMallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
abstract base class for most VTK objects
Definition vtkObject.h:57
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