VTK  9.1.0
vtkCellArray.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkCellArray.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
144#ifndef vtkCellArray_h
145#define vtkCellArray_h
146
147#include "vtkCommonDataModelModule.h" // For export macro
148#include "vtkObject.h"
149
150#include "vtkAOSDataArrayTemplate.h" // Needed for inline methods
151#include "vtkCell.h" // Needed for inline methods
152#include "vtkDataArrayRange.h" // Needed for inline methods
153#include "vtkFeatures.h" // for VTK_USE_MEMKIND
154#include "vtkSmartPointer.h" // For vtkSmartPointer
155#include "vtkTypeInt32Array.h" // Needed for inline methods
156#include "vtkTypeInt64Array.h" // Needed for inline methods
157#include "vtkTypeList.h" // Needed for ArrayList definition
158
159#include <cassert> // for assert
160#include <initializer_list> // for API
161#include <type_traits> // for std::is_same
162#include <utility> // for std::forward
163
184#define VTK_CELL_ARRAY_V2
185
187class vtkIdTypeArray;
188
189class VTKCOMMONDATAMODEL_EXPORT vtkCellArray : public vtkObject
190{
191public:
192 using ArrayType32 = vtkTypeInt32Array;
193 using ArrayType64 = vtkTypeInt64Array;
194
196
200 static vtkCellArray* New();
201 vtkTypeMacro(vtkCellArray, vtkObject);
202 void PrintSelf(ostream& os, vtkIndent indent) override;
203 void PrintDebug(ostream& os);
205
214 using StorageArrayList = vtkTypeList::Create<ArrayType32, ArrayType64>;
215
227
236 vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext) = 1000)
237 {
238 return this->AllocateExact(sz, sz) ? 1 : 0;
239 }
240
250 bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
251 {
252 return this->AllocateExact(numCells, numCells * maxCellSize);
253 }
254
264 bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize);
265
276 {
277 return this->AllocateExact(other->GetNumberOfCells(), other->GetNumberOfConnectivityIds());
278 }
279
289 bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize);
290
295
299 void Reset();
300
306 void Squeeze();
307
318 bool IsValid();
319
324 {
325 if (this->Storage.Is64Bit())
326 {
327 return this->Storage.GetArrays64().Offsets->GetNumberOfValues() - 1;
328 }
329 else
330 {
331 return this->Storage.GetArrays32().Offsets->GetNumberOfValues() - 1;
332 }
333 }
334
340 {
341 if (this->Storage.Is64Bit())
342 {
343 return this->Storage.GetArrays64().Offsets->GetNumberOfValues();
344 }
345 else
346 {
347 return this->Storage.GetArrays32().Offsets->GetNumberOfValues();
348 }
349 }
350
358 {
359 if (this->Storage.Is64Bit())
360 {
361 return this->Storage.GetArrays64().Connectivity->GetNumberOfValues();
362 }
363 else
364 {
365 return this->Storage.GetArrays32().Connectivity->GetNumberOfValues();
366 }
367 }
368
375
376#ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
387 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
388 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
389 void SetData(vtkIdTypeArray* offsets, vtkIdTypeArray* connectivity);
395#endif // __VTK_WRAP__
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
439 {
440 if (this->Storage.Is64Bit())
441 {
443 }
444 else
445 {
447 }
448 }
449
504 {
505 if (this->Storage.Is64Bit())
506 {
507 return this->GetOffsetsArray64();
508 }
509 else
510 {
511 return this->GetOffsetsArray32();
512 }
513 }
525 {
526 if (this->Storage.Is64Bit())
527 {
528 return this->GetConnectivityArray64();
529 }
530 else
531 {
532 return this->GetConnectivityArray32();
533 }
534 }
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 VTK_SIZEHINT(cellPoints, cellSize) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
600
606 void GetCellAtId(vtkIdType cellId, vtkIdList* pts)
607 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
608
612 vtkIdType GetCellSize(const vtkIdType cellId) const;
613
617 vtkIdType InsertNextCell(vtkCell* cell);
618
623 vtkIdType InsertNextCell(vtkIdType npts, const vtkIdType* pts) VTK_SIZEHINT(pts, npts);
624
629 vtkIdType InsertNextCell(vtkIdList* pts);
630
638 vtkIdType InsertNextCell(const std::initializer_list<vtkIdType>& cell)
639 {
640 return this->InsertNextCell(static_cast<vtkIdType>(cell.size()), cell.begin());
641 }
642
649 vtkIdType InsertNextCell(int npts);
650
655 void InsertCellPoint(vtkIdType id);
656
661 void UpdateCellCount(int npts);
662
677 void ReverseCellAtId(vtkIdType cellId) VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
678
688 void ReplaceCellAtId(vtkIdType cellId, vtkIdType cellSize, const vtkIdType* cellPoints)
689 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells()) VTK_SIZEHINT(cellPoints, cellSize);
699 void ReplaceCellAtId(vtkIdType cellId, const std::initializer_list<vtkIdType>& cell)
700 {
701 return this->ReplaceCellAtId(cellId, static_cast<vtkIdType>(cell.size()), cell.begin());
702 }
703
709
714
719
723 void Append(vtkCellArray* src, vtkIdType pointOffset = 0);
724
736
764 void AppendLegacyFormat(const vtkIdType* data, vtkIdType len, vtkIdType ptOffset = 0)
765 VTK_SIZEHINT(data, len);
776 unsigned long GetActualMemorySize() const;
777
778 // The following code is used to support
779
780 // The wrappers get understandably confused by some of the template code below
781#ifndef __VTK_WRAP__
782
783 // Holds connectivity and offset arrays of the given ArrayType.
784 template <typename ArrayT>
786 {
787 using ArrayType = ArrayT;
788 using ValueType = typename ArrayType::ValueType;
789 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
790
791 // We can't just use is_same here, since binary compatible representations
792 // (e.g. int and long) are distinct types. Instead, ensure that ValueType
793 // is a signed integer the same size as vtkIdType.
794 // If this value is true, ValueType pointers may be safely converted to
795 // vtkIdType pointers via reinterpret cast.
796 static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
798
799 ArrayType* GetOffsets() { return this->Offsets; }
800 const ArrayType* GetOffsets() const { return this->Offsets; }
801
802 ArrayType* GetConnectivity() { return this->Connectivity; }
803 const ArrayType* GetConnectivity() const { return this->Connectivity; }
804
806
808
810
812
814
815 friend class vtkCellArray;
816
817 protected:
819 {
820 this->Connectivity = vtkSmartPointer<ArrayType>::New();
821 this->Offsets = vtkSmartPointer<ArrayType>::New();
822 this->Offsets->InsertNextValue(0);
824 {
825 this->IsInMemkind = true;
826 }
827 }
828 ~VisitState() = default;
829 void* operator new(size_t nSize)
830 {
831 void* r;
832#ifdef VTK_USE_MEMKIND
834#else
835 r = malloc(nSize);
836#endif
837 return r;
838 }
839 void operator delete(void* p)
840 {
841#ifdef VTK_USE_MEMKIND
842 VisitState* a = static_cast<VisitState*>(p);
843 if (a->IsInMemkind)
844 {
846 }
847 else
848 {
849 free(p);
850 }
851#else
852 free(p);
853#endif
854 }
855
858
859 private:
860 VisitState(const VisitState&) = delete;
861 VisitState& operator=(const VisitState&) = delete;
862 bool IsInMemkind = false;
863 };
864
865private: // Helpers that allow Visit to return a value:
866 template <typename Functor, typename... Args>
867 using GetReturnType = decltype(
868 std::declval<Functor>()(std::declval<VisitState<ArrayType32>&>(), std::declval<Args>()...));
869
870 template <typename Functor, typename... Args>
871 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
872 {
873 };
874
875public:
945 template <typename Functor, typename... Args,
946 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
947 void Visit(Functor&& functor, Args&&... args)
948 {
949 if (this->Storage.Is64Bit())
950 {
951 // If you get an error on the next line, a call to Visit(functor, Args...)
952 // is being called with arguments that do not match the functor's call
953 // signature. See the Visit documentation for details.
954 functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
955 }
956 else
957 {
958 // If you get an error on the next line, a call to Visit(functor, Args...)
959 // is being called with arguments that do not match the functor's call
960 // signature. See the Visit documentation for details.
961 functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
962 }
963 }
964
965 template <typename Functor, typename... Args,
966 typename = typename std::enable_if<ReturnsVoid<Functor, Args...>::value>::type>
967 void Visit(Functor&& functor, Args&&... args) const
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 GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
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 return 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 return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
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) const
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
1026#endif // __VTK_WRAP__
1027
1028 //=================== Begin Legacy Methods ===================================
1029 // These should be deprecated at some point as they are confusing or very slow
1030
1038
1050 vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell);
1051
1061
1069
1079 void GetCell(vtkIdType loc, vtkIdType& npts, const vtkIdType*& pts)
1080 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1081
1088 void GetCell(vtkIdType loc, vtkIdList* pts)
1089 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1090
1097 vtkIdType GetInsertLocation(int npts);
1098
1106 vtkIdType GetTraversalLocation();
1107 vtkIdType GetTraversalLocation(vtkIdType npts);
1108 void SetTraversalLocation(vtkIdType loc);
1118 void ReverseCell(vtkIdType loc) VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1119
1131 void ReplaceCell(vtkIdType loc, int npts, const vtkIdType pts[])
1132 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries()) VTK_SIZEHINT(pts, npts);
1133
1148 void SetCells(vtkIdType ncells, vtkIdTypeArray* cells);
1149
1161
1162 //=================== End Legacy Methods =====================================
1163
1165
1166protected:
1168 ~vtkCellArray() override;
1169
1170 // Encapsulates storage of the internal arrays as a discriminated union
1171 // between 32-bit and 64-bit storage.
1172 struct Storage
1173 {
1174 // Union type that switches 32 and 64 bit array storage
1176 ArraySwitch() = default; // handled by Storage
1177 ~ArraySwitch() = default; // handle by Storage
1180 };
1181
1183 {
1184#ifdef VTK_USE_MEMKIND
1185 this->Arrays =
1187#else
1188 this->Arrays = new ArraySwitch;
1189#endif
1190
1191 // Default to the compile-time setting:
1192#ifdef VTK_USE_64BIT_IDS
1193
1194 this->Arrays->Int64 = new VisitState<ArrayType64>;
1195 this->StorageIs64Bit = true;
1196
1197#else // VTK_USE_64BIT_IDS
1198
1199 this->Arrays->Int32 = new VisitState<ArrayType32>;
1200 this->StorageIs64Bit = false;
1201
1202#endif // VTK_USE_64BIT_IDS
1203#ifdef VTK_USE_MEMKIND
1205 {
1206 this->IsInMemkind = true;
1207 }
1208#else
1209 (void)this->IsInMemkind; // comp warning workaround
1210#endif
1211 }
1212
1214 {
1215 if (this->StorageIs64Bit)
1216 {
1217 this->Arrays->Int64->~VisitState();
1218 delete this->Arrays->Int64;
1219 }
1220 else
1221 {
1222 this->Arrays->Int32->~VisitState();
1223 delete this->Arrays->Int32;
1224 }
1225#ifdef VTK_USE_MEMKIND
1226 if (this->IsInMemkind)
1227 {
1229 }
1230 else
1231 {
1232 free(this->Arrays);
1233 }
1234#else
1235 delete this->Arrays;
1236#endif
1237 }
1238
1239 // Switch the internal arrays to be 32-bit. Any old data is lost. Returns
1240 // true if the storage changes.
1242 {
1243 if (!this->StorageIs64Bit)
1244 {
1245 return false;
1246 }
1247
1248 this->Arrays->Int64->~VisitState();
1249 delete this->Arrays->Int64;
1250 this->Arrays->Int32 = new VisitState<ArrayType32>;
1251 this->StorageIs64Bit = false;
1252
1253 return true;
1254 }
1255
1256 // Switch the internal arrays to be 64-bit. Any old data is lost. Returns
1257 // true if the storage changes.
1259 {
1260 if (this->StorageIs64Bit)
1261 {
1262 return false;
1263 }
1264
1265 this->Arrays->Int32->~VisitState();
1266 delete this->Arrays->Int32;
1267 this->Arrays->Int64 = new VisitState<ArrayType64>;
1268 this->StorageIs64Bit = true;
1269
1270 return true;
1271 }
1272
1273 // Returns true if the storage is currently configured to be 64 bit.
1274 bool Is64Bit() const { return this->StorageIs64Bit; }
1275
1276 // Get the VisitState for 32-bit arrays
1278 {
1279 assert(!this->StorageIs64Bit);
1280 return *this->Arrays->Int32;
1281 }
1282
1284 {
1285 assert(!this->StorageIs64Bit);
1286 return *this->Arrays->Int32;
1287 }
1288
1289 // Get the VisitState for 64-bit arrays
1291 {
1292 assert(this->StorageIs64Bit);
1293 return *this->Arrays->Int64;
1294 }
1295
1297 {
1298 assert(this->StorageIs64Bit);
1299 return *this->Arrays->Int64;
1300 }
1301
1302 private:
1303 // Access restricted to ensure proper union construction/destruction thru
1304 // API.
1305 ArraySwitch* Arrays;
1306 bool StorageIs64Bit;
1307 bool IsInMemkind = false;
1308 };
1309
1312 vtkIdType TraversalCellId{ 0 };
1313
1315
1316private:
1317 vtkCellArray(const vtkCellArray&) = delete;
1318 void operator=(const vtkCellArray&) = delete;
1319};
1320
1321template <typename ArrayT>
1323{
1324 return this->Offsets->GetNumberOfValues() - 1;
1325}
1326
1327template <typename ArrayT>
1329{
1330 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1331}
1332
1333template <typename ArrayT>
1335{
1336 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1337}
1338
1339template <typename ArrayT>
1341{
1342 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1343}
1344
1345template <typename ArrayT>
1348{
1349 return vtk::DataArrayValueRange<1>(
1350 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1351}
1352
1354{
1355
1357{
1358 // Insert full cell
1359 template <typename CellStateT>
1360 vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
1361 {
1362 using ValueType = typename CellStateT::ValueType;
1363 auto* conn = state.GetConnectivity();
1364 auto* offsets = state.GetOffsets();
1365
1366 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1367
1368 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1369
1370 for (vtkIdType i = 0; i < npts; ++i)
1371 {
1372 conn->InsertNextValue(static_cast<ValueType>(pts[i]));
1373 }
1374
1375 return cellId;
1376 }
1377
1378 // Just update offset table (for incremental API)
1379 template <typename CellStateT>
1380 vtkIdType operator()(CellStateT& state, const vtkIdType npts)
1381 {
1382 using ValueType = typename CellStateT::ValueType;
1383 auto* conn = state.GetConnectivity();
1384 auto* offsets = state.GetOffsets();
1385
1386 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1387
1388 offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
1389
1390 return cellId;
1391 }
1392};
1393
1394// for incremental API:
1396{
1397 template <typename CellStateT>
1398 void operator()(CellStateT& state, const vtkIdType npts)
1399 {
1400 using ValueType = typename CellStateT::ValueType;
1401
1402 auto* offsets = state.GetOffsets();
1403 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1404 offsets->SetValue(offsets->GetMaxId(), static_cast<ValueType>(cellBegin + npts));
1405 }
1406};
1407
1409{
1410 template <typename CellStateT>
1411 vtkIdType operator()(CellStateT& state, const vtkIdType cellId)
1412 {
1413 return state.GetCellSize(cellId);
1414 }
1415};
1416
1418{
1419 template <typename CellStateT>
1420 void operator()(CellStateT& state, const vtkIdType cellId, vtkIdList* ids)
1421 {
1422 using ValueType = typename CellStateT::ValueType;
1423
1424 const auto cellPts = state.GetCellRange(cellId);
1425
1426 ids->SetNumberOfIds(cellPts.size());
1427 vtkIdType* idPtr = ids->GetPointer(0);
1428
1429 for (ValueType ptId : cellPts)
1430 {
1431 *idPtr++ = static_cast<vtkIdType>(ptId);
1432 }
1433 }
1434
1435 // SFINAE helper to check if a VisitState's connectivity array's memory
1436 // can be used as a vtkIdType*.
1437 template <typename CellStateT>
1439 {
1440 private:
1441 using ValueType = typename CellStateT::ValueType;
1442 using ArrayType = typename CellStateT::ArrayType;
1444 static constexpr bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1445 static constexpr bool ArrayTypeCompat = std::is_base_of<AOSArrayType, ArrayType>::value;
1446
1447 public:
1448 static constexpr bool value = ValueTypeCompat && ArrayTypeCompat;
1449 };
1450
1451 template <typename CellStateT>
1453 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1454 vtkIdList* vtkNotUsed(temp))
1455 {
1456 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1457 const vtkIdType endOffset = state.GetEndOffset(cellId);
1458 cellSize = endOffset - beginOffset;
1459 // This is safe, see CanShareConnPtr helper above.
1460 cellPoints = reinterpret_cast<vtkIdType*>(state.GetConnectivity()->GetPointer(beginOffset));
1461 }
1462
1463 template <typename CellStateT>
1465 CellStateT& state, const vtkIdType cellId, vtkIdType& cellSize, vtkIdType const*& cellPoints,
1466 vtkIdList* temp)
1467 {
1468 using ValueType = typename CellStateT::ValueType;
1469
1470 const auto cellPts = state.GetCellRange(cellId);
1471 cellSize = cellPts.size();
1472
1473 // ValueType differs from vtkIdType, so we have to copy into a temporary
1474 // buffer:
1475 temp->SetNumberOfIds(cellSize);
1476 vtkIdType* tempPtr = temp->GetPointer(0);
1477 for (ValueType ptId : cellPts)
1478 {
1479 *tempPtr++ = static_cast<vtkIdType>(ptId);
1480 }
1481
1482 cellPoints = temp->GetPointer(0);
1483 }
1484};
1485
1487{
1488 template <typename CellStateT>
1489 void operator()(CellStateT& state)
1490 {
1491 state.GetOffsets()->Reset();
1492 state.GetConnectivity()->Reset();
1493 state.GetOffsets()->InsertNextValue(0);
1494 }
1495};
1496
1497} // end namespace vtkCellArray_detail
1498
1499//----------------------------------------------------------------------------
1501{
1502 this->TraversalCellId = 0;
1503}
1504
1505//----------------------------------------------------------------------------
1506inline int vtkCellArray::GetNextCell(vtkIdType& npts, vtkIdType const*& pts) VTK_SIZEHINT(pts, npts)
1507{
1508 if (this->TraversalCellId < this->GetNumberOfCells())
1509 {
1510 this->GetCellAtId(this->TraversalCellId, npts, pts);
1511 ++this->TraversalCellId;
1512 return 1;
1513 }
1514
1515 npts = 0;
1516 pts = nullptr;
1517 return 0;
1518}
1519
1520//----------------------------------------------------------------------------
1522{
1523 if (this->TraversalCellId < this->GetNumberOfCells())
1524 {
1525 this->GetCellAtId(this->TraversalCellId, pts);
1526 ++this->TraversalCellId;
1527 return 1;
1528 }
1529
1530 pts->Reset();
1531 return 0;
1532}
1533//----------------------------------------------------------------------------
1535{
1536 return this->Visit(vtkCellArray_detail::GetCellSizeImpl{}, cellId);
1537}
1538
1539//----------------------------------------------------------------------------
1540inline void vtkCellArray::GetCellAtId(vtkIdType cellId, vtkIdType& cellSize,
1541 vtkIdType const*& cellPoints) VTK_SIZEHINT(cellPoints, cellSize)
1542{
1543 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, cellSize, cellPoints, this->TempCell);
1544}
1545
1546//----------------------------------------------------------------------------
1548{
1549 this->Visit(vtkCellArray_detail::GetCellAtIdImpl{}, cellId, pts);
1550}
1551
1552//----------------------------------------------------------------------------
1554 VTK_SIZEHINT(pts, npts)
1555{
1556 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
1557}
1558
1559//----------------------------------------------------------------------------
1561{
1562 return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts);
1563}
1564
1565//----------------------------------------------------------------------------
1567{
1568 if (this->Storage.Is64Bit())
1569 {
1570 using ValueType = typename ArrayType64::ValueType;
1571 this->Storage.GetArrays64().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1572 }
1573 else
1574 {
1575 using ValueType = typename ArrayType32::ValueType;
1576 this->Storage.GetArrays32().Connectivity->InsertNextValue(static_cast<ValueType>(id));
1577 }
1578}
1579
1580//----------------------------------------------------------------------------
1582{
1584}
1585
1586//----------------------------------------------------------------------------
1588{
1589 return this->Visit(
1591}
1592
1593//----------------------------------------------------------------------------
1595{
1596 vtkIdList* pts = cell->GetPointIds();
1597 return this->Visit(
1599}
1600
1601//----------------------------------------------------------------------------
1603{
1605}
1606
1607#endif // vtkCellArray.h
Encapsulate traversal logic for vtkCellArray.
object to represent cell connectivity
Definition: vtkCellArray.h:190
void SetData(vtkAOSDataArrayTemplate< int > *offsets, vtkAOSDataArrayTemplate< int > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
int GetNextCell(vtkIdType &npts, vtkIdType const *&pts)
vtkIdType GetNumberOfConnectivityEntries()
Return the size of the array that would be returned from ExportLegacyFormat().
vtkTypeBool Allocate(vtkIdType sz, vtkIdType vtkNotUsed(ext)=1000)
Allocate memory.
Definition: vtkCellArray.h:236
void UseDefaultStorage()
Initialize internal data structures to use 32- or 64-bit storage.
Storage Storage
bool AllocateCopy(vtkCellArray *other)
Pre-allocate memory in internal data structures to match the used size of the input vtkCellArray.
Definition: vtkCellArray.h:275
void AppendLegacyFormat(vtkIdTypeArray *data, vtkIdType ptOffset=0)
Append an array of data with the legacy vtkCellArray layout, e.g.
bool IsStorageShareable() const
Definition: vtkCellArray.h:438
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)
Definition: vtkCellArray.h:947
vtkTypeInt32Array ArrayType32
Definition: vtkCellArray.h:192
void Reset()
Reuse list.
ArrayType64 * GetConnectivityArray64()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:536
ArrayType32 * GetConnectivityArray32()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:535
void SetData(vtkAOSDataArrayTemplate< long long > *offsets, vtkAOSDataArrayTemplate< long long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool AllocateExact(vtkIdType numCells, vtkIdType connectivitySize)
Pre-allocate memory in internal data structures.
bool ResizeExact(vtkIdType numCells, vtkIdType connectivitySize)
ResizeExact() resizes the internal structures to hold numCells total cell offsets and connectivitySiz...
vtkIdType EstimateSize(vtkIdType numCells, int maxPtsPerCell)
Utility routines help manage memory of cell array.
ArrayType32 * GetOffsetsArray32()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:514
bool AllocateEstimate(vtkIdType numCells, vtkIdType maxCellSize)
Pre-allocate memory in internal data structures.
Definition: vtkCellArray.h:250
vtkIdType GetNumberOfOffsets() const
Get the number of elements in the offsets array.
Definition: vtkCellArray.h:339
vtkTypeInt64Array ArrayType64
Definition: vtkCellArray.h:193
vtkIdType TraversalCellId
void InitTraversal()
void Use64BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
bool ConvertToDefaultStorage()
Convert internal data structures to use 32- or 64-bit storage.
bool CanConvertToDefaultStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
void GetCell(vtkIdType loc, vtkIdType &npts, const vtkIdType *&pts)
Internal method used to retrieve a cell given a legacy offset location.
bool CanConvertTo32BitStorage() const
Check if the existing data can safely be converted to use 32- or 64- bit storage.
vtkDataArray * GetConnectivityArray()
Return the array used to store the point ids that define the cells' connectivity.
Definition: vtkCellArray.h:524
void InsertCellPoint(vtkIdType id)
Used in conjunction with InsertNextCell(npts) to add another point to the list of cells.
void GetCellAtId(vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints)
Return the point ids for the cell at cellId.
vtkCellArrayIterator * NewIterator()
NewIterator returns a new instance of vtkCellArrayIterator that is initialized to point at the first ...
void ReplaceCellAtId(vtkIdType cellId, vtkIdList *list)
Replaces the point ids for the specified cell with the supplied list.
void ReverseCellAtId(vtkIdType cellId)
Reverses the order of the point ids for the specified cell.
bool SetData(vtkDataArray *offsets, vtkDataArray *connectivity)
Sets the internal arrays to the supplied offsets and connectivity arrays.
void Squeeze()
Reclaim any extra memory while preserving data.
void SetData(vtkIdTypeArray *offsets, vtkIdTypeArray *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
bool ConvertTo32BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
vtkIdType IsHomogeneous()
Check if all cells have the same number of vertices.
void Visit(Functor &&functor, Args &&... args) const
Definition: vtkCellArray.h:967
int GetMaxCellSize()
Returns the size of the largest cell.
ArrayType64 * GetOffsetsArray64()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:515
bool ConvertToSmallestStorage()
Convert internal data structures to use 32- or 64-bit storage.
void ShallowCopy(vtkCellArray *ca)
Shallow copy ca into this cell array.
void ExportLegacyFormat(vtkIdTypeArray *data)
Fill data with the old-style vtkCellArray data layout, e.g.
bool ConvertTo64BitStorage()
Convert internal data structures to use 32- or 64-bit storage.
void SetData(vtkAOSDataArrayTemplate< long > *offsets, vtkAOSDataArrayTemplate< long > *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
void ImportLegacyFormat(const vtkIdType *data, vtkIdType len)
Import an array of data with the legacy vtkCellArray layout, e.g.
void ImportLegacyFormat(vtkIdTypeArray *data)
Import an array of data with the legacy vtkCellArray layout, e.g.
void Use32BitStorage()
Initialize internal data structures to use 32- or 64-bit storage.
void Initialize()
Free any memory and reset to an empty state.
void DeepCopy(vtkCellArray *ca)
Perform a deep copy (no reference counting) of the given cell array.
typename vtkTypeList::Unique< vtkTypeList::Create< vtkAOSDataArrayTemplate< int >, vtkAOSDataArrayTemplate< long >, vtkAOSDataArrayTemplate< long long > > >::Result InputArrayList
List of possible ArrayTypes that are compatible with internal storage.
Definition: vtkCellArray.h:226
void SetTraversalCellId(vtkIdType cellId)
Get/Set the current cellId for traversal.
void SetData(vtkTypeInt64Array *offsets, vtkTypeInt64Array *connectivity)
Set the internal data arrays to the supplied offsets and connectivity arrays.
vtkIdType GetNumberOfCells() const
Get the number of cells in the array.
Definition: vtkCellArray.h:323
vtkIdType InsertNextCell(vtkCell *cell)
Insert a cell object.
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
vtkIdType GetNumberOfConnectivityIds() const
Get the size of the connectivity array that stores the point ids.
Definition: vtkCellArray.h:357
vtkDataArray * GetOffsetsArray()
Return the array used to store cell offsets.
Definition: vtkCellArray.h:503
vtkNew< vtkIdTypeArray > LegacyData
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
void PrintDebug(ostream &os)
Standard methods for instantiation, type information, and printing.
void UpdateCellCount(int npts)
Used in conjunction with InsertNextCell(int npts) and InsertCellPoint() to update the number of point...
GetReturnType< Functor, Args... > Visit(Functor &&functor, Args &&... args)
Definition: vtkCellArray.h:987
static vtkCellArray * New()
Standard methods for instantiation, type information, and printing.
vtkNew< vtkIdList > TempCell
vtkIdType GetSize()
Get the size of the allocated connectivity array.
vtkTypeList::Create< ArrayType32, ArrayType64 > StorageArrayList
List of possible array types used for storage.
Definition: vtkCellArray.h:214
vtkIdType InsertNextCell(const std::initializer_list< vtkIdType > &cell)
Overload that allows InsertNextCell({0, 1, 2}) syntax.
Definition: vtkCellArray.h:638
void Append(vtkCellArray *src, vtkIdType pointOffset=0)
Append cells from src into this.
vtkIdType GetCellSize(const vtkIdType cellId) const
Return the size of the cell at cellId.
bool IsStorage64Bit() const
Definition: vtkCellArray.h:430
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:67
vtkIdList * GetPointIds()
Return the list of point ids defining the cell.
Definition: vtkCell.h:162
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:59
list of point or cell ids
Definition: vtkIdList.h:40
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:66
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:154
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:135
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:43
static vtkMallocingFunction GetCurrentMallocFunction()
static vtkFreeingFunction GetAlternateFreeFunction()
static bool GetUsingMemkind()
A global state flag that controls whether vtkObjects are constructed in the usual way (the default) o...
abstract base class for most VTK objects
Definition: vtkObject.h:63
static vtkSmartPointer< T > New()
Create an instance of a VTK object.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
@ value
Definition: vtkX3D.h:226
@ type
Definition: vtkX3D.h:522
@ data
Definition: vtkX3D.h:321
VisitState< ArrayType64 > & GetArrays64()
const VisitState< ArrayType64 > & GetArrays64() const
const VisitState< ArrayType32 > & GetArrays32() const
VisitState< ArrayType32 > & GetArrays32()
ArrayType * GetOffsets()
Definition: vtkCellArray.h:799
vtkIdType GetNumberOfCells() const
vtkIdType GetEndOffset(vtkIdType cellId) const
vtkSmartPointer< ArrayType > Offsets
Definition: vtkCellArray.h:857
vtkSmartPointer< ArrayType > Connectivity
Definition: vtkCellArray.h:856
static constexpr bool ValueTypeIsSameAsIdType
Definition: vtkCellArray.h:796
const ArrayType * GetOffsets() const
Definition: vtkCellArray.h:800
decltype(vtk::DataArrayValueRange< 1 >(std::declval< ArrayType >())) CellRangeType
Definition: vtkCellArray.h:789
CellRangeType GetCellRange(vtkIdType cellId)
vtkIdType GetBeginOffset(vtkIdType cellId) const
vtkIdType GetCellSize(vtkIdType cellId) const
const ArrayType * GetConnectivity() const
Definition: vtkCellArray.h:803
typename ArrayType::ValueType ValueType
Definition: vtkCellArray.h:788
ArrayType * GetConnectivity()
Definition: vtkCellArray.h:802
std::enable_if<!CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *temp)
std::enable_if< CanShareConnPtr< CellStateT >::value, void >::type operator()(CellStateT &state, const vtkIdType cellId, vtkIdType &cellSize, vtkIdType const *&cellPoints, vtkIdList *vtkNotUsed(temp))
void operator()(CellStateT &state, const vtkIdType cellId, vtkIdList *ids)
vtkIdType operator()(CellStateT &state, const vtkIdType cellId)
vtkIdType operator()(CellStateT &state, const vtkIdType npts, const vtkIdType pts[])
vtkIdType operator()(CellStateT &state, const vtkIdType npts)
void operator()(CellStateT &state)
void operator()(CellStateT &state, const vtkIdType npts)
Remove all duplicate types from TypeList TList, storing the new list in Result.
Definition: vtkTypeList.h:125
VisitState< ArrayType32 > * Int32
VisitState< ArrayType64 > * Int64
int vtkTypeBool
Definition: vtkABI.h:69
STL-compatible iterable ranges that provide access to vtkDataArray elements.
int vtkIdType
Definition: vtkType.h:332
#define VTK_SIZEHINT(...)
#define VTK_EXPECTS(x)
#define VTK_NEWINSTANCE