1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkUnstructuredGridCellIterator.h"
#include "vtkCellArray.h"
#include "vtkCellArrayIterator.h"
#include "vtkIdList.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnstructuredGrid.h"
#include <cassert>
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkUnstructuredGridCellIterator);
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
if (this->Cells)
{
os << indent << "Cells:\n";
this->Cells->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << indent << "Cells: (none)" << endl;
}
if (this->Types)
{
os << indent << "Types:\n";
this->Types->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << indent << "Types: (none)" << endl;
}
if (this->PolyFaceConn)
{
os << indent << "FaceConn:\n";
this->PolyFaceConn->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << indent << "FaceConn: (none)" << endl;
}
if (this->PolyFaceLocs)
{
os << indent << "FaceLocs:\n";
this->PolyFaceLocs->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << indent << "FaceLocs: (none)" << endl;
}
if (this->Coords)
{
os << indent << "Coords:\n";
this->Coords->PrintSelf(os, indent.GetNextIndent());
}
else
{
os << indent << "Coords: (none)" << endl;
}
}
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::SetUnstructuredGrid(vtkUnstructuredGrid* ug)
{
// If the unstructured grid has not been initialized yet, these may not exist:
vtkUnsignedCharArray* cellTypeArray = ug ? ug->GetCellTypesArray() : nullptr;
vtkCellArray* cellArray = ug ? ug->GetCells() : nullptr;
vtkPoints* points = ug ? ug->GetPoints() : nullptr;
if (points)
{
this->Points->SetDataType(points->GetDataType());
}
if (ug && cellTypeArray && cellArray && points)
{
this->Cells = vtk::TakeSmartPointer(cellArray->NewIterator());
this->Cells->GoToFirstCell();
this->Types = cellTypeArray;
this->PolyFaceConn = ug->GetPolyhedronFaces();
this->PolyFaceLocs = ug->GetPolyhedronFaceLocations();
this->Coords = points;
}
}
//------------------------------------------------------------------------------
bool vtkUnstructuredGridCellIterator::IsDoneWithTraversal()
{
return this->Cells ? this->Cells->IsDoneWithTraversal() : true;
}
//------------------------------------------------------------------------------
vtkIdType vtkUnstructuredGridCellIterator::GetCellId()
{
return this->Cells->GetCurrentCellId();
}
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::IncrementToNextCell()
{
this->Cells->GoToNextCell();
}
//------------------------------------------------------------------------------
vtkUnstructuredGridCellIterator::vtkUnstructuredGridCellIterator() = default;
//------------------------------------------------------------------------------
vtkUnstructuredGridCellIterator::~vtkUnstructuredGridCellIterator() = default;
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::ResetToFirstCell()
{
if (this->Cells)
{
this->Cells->GoToFirstCell();
}
}
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchCellType()
{
const vtkIdType cellId = this->Cells->GetCurrentCellId();
this->CellType = this->Types->GetValue(cellId);
}
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchPointIds()
{
this->Cells->GetCurrentCell(this->PointIds);
}
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchPoints()
{
this->Coords->GetPoints(this->GetPointIds(), this->Points);
}
//----------------------------------------------------------------------------
// Supporting functions for FetchFaces()
namespace
{
struct GetPolyhedronNPts
{
// Insert full cell
template <typename CellStateT>
vtkIdType operator()(CellStateT& state, const vtkIdType cellId, const vtkCellArray* faces)
{
vtkIdType npts = 0;
const vtkIdType beginOffset = state.GetBeginOffset(cellId);
const vtkIdType endOffset = state.GetEndOffset(cellId);
const vtkIdType NumberOfFaces = endOffset - beginOffset;
const auto cellFaces = state.GetConnectivity()->GetPointer(beginOffset);
for (vtkIdType faceNum = 0; faceNum < NumberOfFaces; ++faceNum)
{
npts += faces->GetCellSize(static_cast<vtkIdType>(cellFaces[faceNum]));
}
return npts;
}
};
template <typename PointType>
struct InsertNextCellPoints
{
// Insert full cell
template <typename CellStateT>
vtkIdType operator()(CellStateT& state, const vtkIdType npts, const PointType pts[])
{
using ValueType = typename CellStateT::ValueType;
auto* conn = state.GetConnectivity();
auto* offsets = state.GetOffsets();
const vtkIdType cellId = offsets->GetNumberOfValues() - 1;
offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));
for (vtkIdType i = 0; i < npts; ++i)
{
conn->InsertNextValue(static_cast<ValueType>(pts[i]));
}
return cellId;
}
};
template <typename FaceIdType>
struct CopyPolyhedronFaces
{
template <typename CellStateT>
void operator()(CellStateT& state, const vtkIdType NumberOfFaces, const FaceIdType* cellFaces,
vtkCellArray* faces)
{
using ValueType = typename CellStateT::ValueType;
using TInsertNextCellPoints = InsertNextCellPoints<ValueType>;
for (vtkIdType faceNum = 0; faceNum < NumberOfFaces; ++faceNum)
{
const vtkIdType beginOffset = state.GetBeginOffset(cellFaces[faceNum]);
const vtkIdType endOffset = state.GetEndOffset(cellFaces[faceNum]);
const vtkIdType NumberOfPoints = endOffset - beginOffset;
const auto cellPoints = state.GetConnectivity()->GetPointer(beginOffset);
faces->Visit(TInsertNextCellPoints{}, NumberOfPoints, cellPoints);
}
}
};
struct CopyPolyhedronCell
{
// Insert full cell
template <typename CellStateT>
void operator()(CellStateT& state, const vtkIdType cellId, vtkCellArray* src, vtkCellArray* tgt)
{
using ValueType = typename CellStateT::ValueType;
using TCopyPolyhedronFaces = CopyPolyhedronFaces<ValueType>;
const vtkIdType beginOffset = state.GetBeginOffset(cellId);
const vtkIdType endOffset = state.GetEndOffset(cellId);
const vtkIdType NumberOfFaces = endOffset - beginOffset;
const auto cellFaces = state.GetConnectivity()->GetPointer(beginOffset);
src->Visit(TCopyPolyhedronFaces{}, NumberOfFaces, cellFaces, tgt);
}
};
} // end anon namespace
//------------------------------------------------------------------------------
void vtkUnstructuredGridCellIterator::FetchFaces()
{
if (this->PolyFaceLocs)
{
const vtkIdType cellId = this->Cells->GetCurrentCellId();
vtkIdType nfaces = 0;
vtkIdType npts = 0;
nfaces = this->PolyFaceLocs->GetCellSize(cellId);
npts = this->PolyFaceLocs->Visit(GetPolyhedronNPts{}, cellId, this->PolyFaceConn);
this->Faces->AllocateExact(nfaces, npts);
this->PolyFaceLocs->Visit(CopyPolyhedronCell{}, cellId, this->PolyFaceConn, this->Faces);
}
else
{
this->Faces->Reset();
}
}
VTK_ABI_NAMESPACE_END
|