135 #ifndef vtkCellArray_h
136 #define vtkCellArray_h
138 #include "vtkCommonDataModelModule.h"
145 #include "vtkTypeInt32Array.h"
146 #include "vtkTypeInt64Array.h"
150 #include <initializer_list>
151 #include <type_traits>
174 #define VTK_CELL_ARRAY_V2
193 void PrintDebug(ostream& os);
228 return this->AllocateExact(sz, sz) ? 1 : 0;
242 return this->AllocateExact(numCells, numCells * maxCellSize);
366 #ifndef __VTK_WRAP__ // The wrappers have issues with some of these templates
377 void SetData(vtkTypeInt32Array* offsets, vtkTypeInt32Array* connectivity);
378 void SetData(vtkTypeInt64Array* offsets, vtkTypeInt64Array* connectivity);
385 #endif // __VTK_WRAP__
433 void Use32BitStorage();
434 void Use64BitStorage();
435 void UseDefaultStorage();
446 bool CanConvertTo32BitStorage()
const;
447 bool CanConvertTo64BitStorage()
const;
448 bool CanConvertToDefaultStorage()
const;
467 bool ConvertTo32BitStorage();
468 bool ConvertTo64BitStorage();
469 bool ConvertToDefaultStorage();
470 bool ConvertToSmallestStorage();
482 return this->GetOffsetsArray64();
486 return this->GetOffsetsArray32();
503 return this->GetConnectivityArray64();
507 return this->GetConnectivityArray32();
533 void InitTraversal();
582 VTK_EXPECTS(0 <= cellId && cellId < GetNumberOfCells());
615 return this->InsertNextCell(
static_cast<vtkIdType>(cell.size()), cell.begin());
636 void UpdateCellCount(
int npts);
646 void SetTraversalCellId(
vtkIdType cellId);
676 return this->ReplaceCellAtId(cellId,
static_cast<vtkIdType>(cell.size()), cell.begin());
683 int GetMaxCellSize();
751 unsigned long GetActualMemorySize() const;
759 template <
typename ArrayT>
764 using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));
788 CellRangeType GetCellRange(
vtkIdType cellId);
797 this->Offsets->InsertNextValue(0);
810 template <
typename Functor,
typename... Args>
811 using GetReturnType = decltype(
814 template <
typename Functor,
typename... Args>
815 struct ReturnsVoid : std::is_same<GetReturnType<Functor, Args...>, void>
889 template <
typename Functor,
typename... Args,
890 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>
::value>
::type>
891 void Visit(Functor&& functor, Args&&... args)
909 template <
typename Functor,
typename... Args,
910 typename =
typename std::enable_if<ReturnsVoid<Functor, Args...>
::value>
::type>
911 void Visit(Functor&& functor, Args&&... args)
const
929 template <
typename Functor,
typename... Args,
930 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>
::value>
::type>
931 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
948 template <
typename Functor,
typename... Args,
949 typename =
typename std::enable_if<!ReturnsVoid<Functor, Args...>
::value>
::type>
950 GetReturnType<Functor, Args...>
Visit(Functor&& functor, Args&&... args)
const
970 #endif // __VTK_WRAP__
981 virtual void SetNumberOfCells(
vtkIdType);
1012 vtkIdType GetNumberOfConnectivityEntries();
1033 VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1052 void SetTraversalLocation(
vtkIdType loc);
1062 void ReverseCell(
vtkIdType loc)
VTK_EXPECTS(0 <= loc && loc < GetNumberOfConnectivityEntries());
1130 #ifdef VTK_USE_64BIT_IDS
1133 this->StorageIs64Bit =
true;
1135 #else // VTK_USE_64BIT_IDS
1138 this->StorageIs64Bit =
false;
1140 #endif // VTK_USE_64BIT_IDS
1145 if (this->StorageIs64Bit)
1147 this->Arrays.Int64.~VisitState();
1151 this->Arrays.Int32.~VisitState();
1159 if (!this->StorageIs64Bit)
1164 this->Arrays.Int64.~VisitState();
1166 this->StorageIs64Bit =
false;
1175 if (this->StorageIs64Bit)
1180 this->Arrays.Int32.~VisitState();
1182 this->StorageIs64Bit =
true;
1188 bool Is64Bit()
const {
return this->StorageIs64Bit; }
1193 assert(!this->StorageIs64Bit);
1194 return this->Arrays.Int32;
1199 assert(!this->StorageIs64Bit);
1200 return this->Arrays.Int32;
1206 assert(this->StorageIs64Bit);
1207 return this->Arrays.Int64;
1212 assert(this->StorageIs64Bit);
1213 return this->Arrays.Int64;
1220 bool StorageIs64Bit;
1234 template <
typename ArrayT>
1237 return this->Offsets->GetNumberOfValues() - 1;
1240 template <
typename ArrayT>
1243 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId));
1246 template <
typename ArrayT>
1249 return static_cast<vtkIdType>(this->Offsets->GetValue(cellId + 1));
1252 template <
typename ArrayT>
1255 return this->GetEndOffset(cellId) - this->GetBeginOffset(cellId);
1258 template <
typename ArrayT>
1262 return vtk::DataArrayValueRange<1>(
1263 this->GetConnectivity(), this->GetBeginOffset(cellId), this->GetEndOffset(cellId));
1272 template <
typename CellStateT>
1275 using ValueType =
typename CellStateT::ValueType;
1276 auto* conn = state.GetConnectivity();
1277 auto* offsets = state.GetOffsets();
1279 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1281 offsets->InsertNextValue(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1285 conn->InsertNextValue(
static_cast<ValueType
>(pts[i]));
1292 template <
typename CellStateT>
1295 using ValueType =
typename CellStateT::ValueType;
1296 auto* conn = state.GetConnectivity();
1297 auto* offsets = state.GetOffsets();
1299 const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
1301 offsets->InsertNextValue(
static_cast<ValueType
>(conn->GetNumberOfValues() + npts));
1310 template <
typename CellStateT>
1313 using ValueType =
typename CellStateT::ValueType;
1315 auto* offsets = state.GetOffsets();
1316 const ValueType cellBegin = offsets->GetValue(offsets->GetMaxId() - 1);
1317 offsets->SetValue(offsets->GetMaxId(),
static_cast<ValueType
>(cellBegin + npts));
1323 template <
typename CellStateT>
1326 return state.GetCellSize(cellId);
1332 template <
typename CellStateT>
1335 using ValueType =
typename CellStateT::ValueType;
1337 const auto cellPts = state.GetCellRange(cellId);
1342 for (ValueType ptId : cellPts)
1344 *idPtr++ =
static_cast<vtkIdType>(ptId);
1350 template <
typename CellStateT>
1354 using ValueType =
typename CellStateT::ValueType;
1355 using ArrayType =
typename CellStateT::ArrayType;
1357 static constexpr
bool ValueTypeCompat = CellStateT::ValueTypeIsSameAsIdType;
1361 static constexpr
bool value = ValueTypeCompat && ArrayTypeCompat;
1364 template <
typename CellStateT>
1369 const vtkIdType beginOffset = state.GetBeginOffset(cellId);
1370 const vtkIdType endOffset = state.GetEndOffset(cellId);
1371 cellSize = endOffset - beginOffset;
1373 cellPoints =
reinterpret_cast<vtkIdType*
>(state.GetConnectivity()->GetPointer(beginOffset));
1376 template <
typename CellStateT>
1381 using ValueType =
typename CellStateT::ValueType;
1383 const auto cellPts = state.GetCellRange(cellId);
1384 cellSize = cellPts.size();
1390 for (ValueType ptId : cellPts)
1392 *tempPtr++ =
static_cast<vtkIdType>(ptId);
1401 template <
typename CellStateT>
1404 state.GetOffsets()->Reset();
1405 state.GetConnectivity()->Reset();
1406 state.GetOffsets()->InsertNextValue(0);
1421 if (this->TraversalCellId < this->GetNumberOfCells())
1423 this->GetCellAtId(this->TraversalCellId, npts, pts);
1424 ++this->TraversalCellId;
1483 using ValueType =
typename ArrayType64::ValueType;
1488 using ValueType =
typename ArrayType32::ValueType;
1520 #endif // vtkCellArray.h