32 #include <vtkCellArray.h> 33 #include <vtkCellCenters.h> 34 #include <vtkPoints.h> 35 #include <vtkPolyData.h> 36 #include <vtkSelectEnclosedPoints.h> 37 #include <vtkSphereSource.h> 44 using nemAux::operator*;
45 using nemAux::operator+;
51 std::vector<double> result(coords, coords + 3);
58 std::vector<std::vector<double>> cell;
60 point_ids =
dataSet->GetCell(
id)->GetPointIds();
61 vtkIdType num_ids = point_ids->GetNumberOfIds();
63 for (vtkIdType i = 0; i < num_ids; ++i) {
64 nemId_t pntId = point_ids->GetId(i);
69 std::cerr <<
"Cell ID is out of range!" << std::endl;
76 std::vector<double> center(3);
77 std::vector<std::vector<double>> cell =
getCellVec(cellID);
79 for (
const auto &i : cell) center = center + i;
80 return (1.0 / static_cast<double>(cell.size())) * center;
94 std::vector<nemId_t> &ids,
bool fulImrsd) {
98 vcl->FindCellsWithinBounds(bb.data(), idl);
99 std::cout <<
"Found " << idl->GetNumberOfIds() <<
" cells." << std::endl;
100 std::vector<nemId_t> aids;
101 for (vtkIdType idx = 0; idx < idl->GetNumberOfIds(); idx++)
102 aids.push_back(idl->GetId(idx));
106 for (
const auto &aid : aids)
113 std::cout <<
"Remove " << nr <<
" cells from the list." << std::endl;
120 const std::vector<nemId_t> &conn,
121 std::set<nemId_t> &ids,
double tol)
const {
124 for (std::size_t iPnt = 0; iPnt < crds.size() / 3; iPnt++)
125 pnts->InsertNextPoint(crds[iPnt * 3], crds[iPnt * 3 + 1],
128 for (std::size_t iCel = 0; iCel < conn.size() / 3; iCel++) {
129 polys->InsertNextCell(3);
130 polys->InsertCellPoint(conn[iCel * 3]);
131 polys->InsertCellPoint(conn[iCel * 3 + 1]);
132 polys->InsertCellPoint(conn[iCel * 3 + 2]);
135 polyData->SetPoints(pnts);
136 polyData->SetPolys(polys);
150 vtkSmartPointer<vtkCellLocator> cellLocator =
152 cellLocator->SetDataSet(polyData);
153 cellLocator->BuildLocator();
155 double closestPoint[3];
156 double closestPointDist2;
160 std::vector<double> pnt =
getPoint(iPt);
161 cellLocator->FindClosestPoint(pnt.data(), closestPoint, cellId, subId,
163 if (closestPointDist2 < tol) ids.insert(iPt + 1);
171 for (std::size_t iPnt = 0; iPnt < crds.size() / 3; iPnt++)
172 pnts->InsertNextPoint(crds[iPnt * 3], crds[iPnt * 3 + 1],
175 polys->InsertNextCell(2);
176 polys->InsertCellPoint(0);
177 polys->InsertCellPoint(1);
179 polyData->SetPoints(pnts);
180 polyData->SetPolys(polys);
194 vtkSmartPointer<vtkCellLocator> cellLocator =
196 cellLocator->SetDataSet(polyData);
197 cellLocator->BuildLocator();
199 double closestPoint[3];
200 double closestPointDist2;
204 std::vector<double> pnt =
getPoint(iPt);
205 cellLocator->FindClosestPoint(pnt.data(), closestPoint, cellId, subId,
207 if (closestPointDist2 < tol) ids.insert(iPt + 1);
213 std::set<std::vector<nemId_t>> ids;
215 std::vector<nemId_t> cid;
217 idl =
dataSet->GetCell(ic)->GetPointIds();
218 for (vtkIdType
id = 0;
id < idl->GetNumberOfIds();
id++)
219 cid.push_back(idl->GetId(
id));
220 std::pair<std::set<std::vector<nemId_t>>::iterator,
bool> ret;
221 ret = ids.insert(cid);
222 if (!ret.second)
return true;
228 std::vector<nemId_t> &ids,
bool query3Donly,
236 vtkSmartPointer<vtkSelectEnclosedPoints> sep =
239 sep->SetInputConnection(cc->GetOutputPort());
241 sep->SetSurfaceData(polyData);
244 sep->SetTolerance(tol);
249 if (sep->IsInside(
id)) {
250 if (query3Donly &&
dataSet->GetCell(
id)->GetCellDimension() != 3)
252 ids.emplace_back(
id);
257 const std::vector<std::vector<double>> &crds,
258 const std::vector<std::vector<vtkIdType>> &conns, std::vector<nemId_t> &ids,
259 bool query3Donly,
double tol)
const {
265 for (
const auto &crd : crds) pnts->InsertNextPoint(crd.data());
266 for (
const auto &conn : conns)
267 polys->InsertNextCell(conn.size(), conn.data());
268 polyData->SetPoints(pnts);
269 polyData->SetPolys(polys);
281 double radius, std::vector<nemId_t> &ids,
282 bool query3Donly,
double tol)
const {
285 ss->SetRadius(radius);
286 ss->SetCenter(center[0], center[1], center[2]);
std::vector< std::vector< double > > getCellVec(nemId_t id) const override
get vector of coords of cell with id
vtkSmartPointer< vtkDataSet > dataSet
mesh points, topology and data
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
nemId_t numCells
number of cells in mesh
void FindCellsInTriSrf(const std::vector< std::vector< double >> &crds, const std::vector< std::vector< vtkIdType >> &conns, std::vector< nemId_t > &ids, bool query3Donly=true, double tol=0.1e-15) const
nemId_t getNumberOfPoints() const
return the number of points
vtkIdType id
id in .inp file
void FindPntsOnTriSrf(const std::vector< double > &crds, const std::vector< nemId_t > &conn, std::set< nemId_t > &ids, double tol=0.1e-15) const
void FindCellsInPolyData(vtkPolyData *polyData, std::vector< nemId_t > &ids, bool query3Donly=true, double tol=0.1e-15) const
void FindCellsWithinBounds(std::vector< double > &bb, std::vector< nemId_t > &ids, bool fulImrsd=true)
vtkSmartPointer< vtkCellLocator > vcl
std::vector< double > getCellCenter(nemId_t cellID) const override
get center of a cell
bool isInBBox(const std::vector< T > &crd, const std::vector< T > &bb)
void FindCellsInSphere(const std::vector< double > ¢er, double radius, std::vector< nemId_t > &ids, bool query3Donly=true, double tol=0.1e-15) const
void FindPntsOnEdge(std::vector< double > &crds, std::set< nemId_t > &ids, double tol=0.1e-15) const
nemId_t getNumberOfCells() const
return the number of cells
std::vector< double > getPoint(nemId_t id) const override
get point with id