34 std::string
const& geo_name,
36 :
GeoLib::SimplePolygonTree(polygon, parent),
39 _mesh_density_strategy(mesh_density_strategy)
60 for (
auto& child : *
this)
62 std::size_t
const n_pnts(child->polygon().getNumberOfPoints());
63 for (std::size_t k(1); k < n_pnts; k++)
70 .markSegment(k,
true);
78 if (
polygon().isPntInPolygon(*station))
81 for (
auto* child : *
this)
83 if (child->polygon().isPntInPolygon(*station))
88 if (rval && child->getNumberOfChildren() == 0)
105 if (!
polygon().isPartOfPolylineInPolygon(*ply))
112 for (
auto* child : *
this)
122 for (
auto segment_it(ply->
begin()); segment_it != ply->
end(); ++segment_it)
129 if (
polygon().containsSegment(*segment_it))
131 ply->
markSegment(segment_it.getSegmentNumber(),
true);
135 std::size_t seg_num(0);
137 while (
polygon().getNextIntersectionPointPolygonLine(
138 *segment_it, intersection_pnt, seg_num))
142 const std::size_t pnt_vec_size(pnt_vec.
size());
145 if (pnt_vec_size < pnt_vec.
size())
150 ply->
insertPoint(segment_it.getSegmentNumber(), pnt_id);
155 if (!
polygon().isPointIDInPolyline(pnt_id))
163 ply->
insertPoint(segment_it.getSegmentNumber() + 1, pnt_id);
167 std::size_t tmp_seg_num(seg_num + 1);
168 if (!
polygon().getNextIntersectionPointPolygonLine(
169 *segment_it, tmp_pnt, tmp_seg_num))
172 for (std::size_t i(0); i < 3; i++)
174 tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] +
175 (*segment_it).getEndPoint()[i]) /
178 if (
polygon().isPntInPolygon(tmp_pnt))
180 ply->
markSegment(segment_it.getSegmentNumber(),
true);
183 new GMSHLine((*segment_it).getBeginPoint().getID(),
184 (*segment_it).getEndPoint().getID()));
190 for (std::size_t i(0); i < 3; i++)
192 tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] +
193 (*segment_it).getEndPoint()[i]) /
199 if (
polygon().isPntInPolygon(tmp_pnt))
201 ply->
markSegment(segment_it.getSegmentNumber(),
true);
204 new GMSHLine((*segment_it).getBeginPoint().getID(),
205 (*segment_it).getEndPoint().getID()));
210 _plys.push_back(ply);
221 for (
auto seg_it_p(p->begin()); seg_it_p != p->end(); ++seg_it_p)
226 const std::size_t pnt_vec_size(pnt_vec.
size());
228 const std::size_t pnt_id(
230 if (pnt_vec_size < pnt_vec.
size())
233 p->insertPoint(seg_it_p.getSegmentNumber() + 1, pnt_id);
240 std::size_t
const k(seg_it_p.getSegmentNumber());
241 if (p->getPointID(k) != pnt_id &&
242 p->getPointID(k + 1) != pnt_id)
244 p->insertPoint(k + 1, pnt_id);
247 if (ply->
getPointID(ply_segment_number) != pnt_id &&
248 ply->
getPointID(ply_segment_number + 1) != pnt_id)
260 if (
auto* adaptive_mesh_density =
264 std::vector<GeoLib::Point const*> pnts;
265 const std::size_t n_pnts_polygon(
polygon().getNumberOfPoints());
266 for (std::size_t k(0); k < n_pnts_polygon; k++)
268 pnts.push_back(
polygon().getPoint(k));
272 const std::size_t n_plys(
_plys.size());
273 for (std::size_t k(0); k < n_plys; k++)
275 const std::size_t n_pnts_in_kth_ply(
_plys[k]->getNumberOfPoints());
276 for (std::size_t j(0); j < n_pnts_in_kth_ply; j++)
278 pnts.push_back(
_plys[k]->getPoint(j));
283 adaptive_mesh_density->initialize(pnts);
285 adaptive_mesh_density->addPoints(
_stations);
286 std::vector<GeoLib::Point const*> stations;
288 adaptive_mesh_density->addPoints(stations);
294 const std::size_t n_pnts_polygon(
polygon().getNumberOfPoints());
295 for (std::size_t k(0); k < n_pnts_polygon - 1; k++)
297 const std::size_t id(
polygon().getPointID(k));
300 if (gmsh_pnts[
id] !=
nullptr)
308 const std::size_t n_plys(
_plys.size());
309 std::stringstream error_messages;
310 error_messages.precision(std::numeric_limits<double>::max_digits10);
311 for (std::size_t k(0); k < n_plys; k++)
313 const std::size_t n_pnts_in_ply(
_plys[k]->getNumberOfPoints());
314 for (std::size_t j(0); j < n_pnts_in_ply; j++)
318 const std::size_t id(
_plys[k]->getPointID(j));
320 if (gmsh_pnts[
id] !=
nullptr)
331 auto const& p = *(
_plys[k]->getPoint(j));
332 error_messages <<
"\n\tpoint with id " << p.getID()
333 <<
" and coordinates (" << p[0] <<
", " << p[1]
335 <<
") is outside of the polygon.";
341 auto const error_message = error_messages.str();
342 if (!error_message.empty())
349 for (
auto* child : *
this)
356 std::size_t& sfc_offset, std::ostream& out,
357 bool const write_physical)
const
359 const std::size_t n_pnts(
polygon().getNumberOfPoints());
360 for (std::size_t k(1), first_pnt_id(
polygon().getPointID(0)); k < n_pnts;
364 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id <<
","
365 << second_pnt_id <<
"};\n";
366 first_pnt_id = second_pnt_id;
368 out <<
"Line Loop(" << line_offset + n_pnts - 1 <<
") = {";
369 for (std::size_t k(0); k < n_pnts - 2; k++)
371 out << line_offset + k <<
",";
373 out << line_offset + n_pnts - 2 <<
"};\n";
374 out <<
"Plane Surface(" << sfc_offset <<
") = {" << line_offset + n_pnts - 1
378 out <<
"Physical Curve(" << sfc_offset <<
") = {";
379 for (std::size_t k(0); k < n_pnts - 2; k++)
381 out << line_offset + k <<
",";
383 out << line_offset + n_pnts - 2 <<
"};\n";
384 out <<
"Physical Surface(" << sfc_offset <<
") = {" << sfc_offset
387 line_offset += n_pnts;
392 std::size_t sfc_number,
393 std::ostream& out)
const
395 for (
auto polyline :
_plys)
397 const std::size_t n_pnts(polyline->getNumberOfPoints());
398 std::size_t first_pnt_id(polyline->getPointID(0));
399 for (std::size_t k(1); k < n_pnts; k++)
401 auto const second_pnt_id = polyline->getPointID(k);
402 if (polyline->isSegmentMarked(k - 1) &&
403 polygon().isPntInPolygon(*(polyline->getPoint(k))) &&
406 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id
407 <<
"," << second_pnt_id <<
"};\n";
408 out <<
"Line { " << line_offset + k - 1 <<
" } In Surface { "
409 << sfc_number <<
" };\n";
411 first_pnt_id = second_pnt_id;
413 line_offset += n_pnts;
418 std::size_t& line_offset, std::size_t sfc_number, std::ostream& out)
const
420 for (
auto* child : *
this)
428 const std::size_t n_pnts(
polygon().getNumberOfPoints());
429 std::size_t first_pnt_id(
polygon().getPointID(0));
430 for (std::size_t k(1); k < n_pnts; k++)
433 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id
434 <<
"," << second_pnt_id <<
"};\n";
435 first_pnt_id = second_pnt_id;
436 out <<
"Line { " << line_offset + k - 1 <<
" } In Surface { "
437 << sfc_number <<
" };\n";
439 line_offset += n_pnts;
444 std::size_t sfc_number,
445 std::ostream& out)
const
449 out <<
"Point(" << pnt_id_offset <<
") = {" << (*station)[0] <<
", "
450 << (*station)[1] <<
", 0.0, "
454 out <<
"Point { " << pnt_id_offset <<
" } In Surface { " << sfc_number
461 std::size_t sfc_number,
462 std::ostream& out)
const
464 if (
auto const* adaptive_mesh_density =
467 std::vector<GeoLib::Point*> steiner_pnts;
468 adaptive_mesh_density->getSteinerPoints(steiner_pnts, 0);
469 const std::size_t n(steiner_pnts.size());
470 for (std::size_t k(0); k < n; k++)
472 if (
polygon().isPntInPolygon(*(steiner_pnts[k])))
474 out <<
"Point(" << pnt_id_offset + k <<
") = {"
475 << (*(steiner_pnts[k]))[0] <<
"," << (*(steiner_pnts[k]))[1]
480 out <<
"Point { " << pnt_id_offset + k <<
" } In Surface { "
481 << sfc_number <<
" };\n";
483 delete steiner_pnts[k];
489 if (
auto* adaptive_mesh_density =
492 auto const quad_tree_geo =
493 adaptive_mesh_density->getQuadTreeGeometry(
_geo_objs);
494 std::vector<std::size_t>
const& id_map(
497 for (std::size_t k(0); k < plys.size(); k++)
506 std::vector<GeoLib::Point const*>& pnts)
const
508 for (
auto const* child : *
this)
516 std::vector<GeoLib::Point const*>& stations)
const
518 const std::size_t n_stations(
_stations.size());
519 for (std::size_t k(0); k < n_stations; k++)
524 for (
auto const* child : *
this)
Definition of analytical geometry functions.
Definition of the GEOObjects class.
Definition of the Point class.
Definition of the Polygon class.
Definition of the PolylineWithSegmentMarker class.
Definition of the Station class.
virtual double getMeshDensityAtStation(GeoLib::Point const *const) const =0
virtual double getMeshDensityAtPoint(GeoLib::Point const *const) const =0
void writeSubPolygonsAsLineConstraints(std::size_t &line_offset, std::size_t sfc_number, std::ostream &out) const
std::vector< GeoLib::PolylineWithSegmentMarker * > _plys
GMSHMeshDensityStrategy & _mesh_density_strategy
void insertPolyline(GeoLib::PolylineWithSegmentMarker *ply)
virtual void writeLineConstraints(std::size_t &line_offset, std::size_t sfc_number, std::ostream &out) const
std::string const & _geo_name
~GMSHPolygonTree() override
void writeAdditionalPointData(std::size_t &pnt_id_offset, std::size_t sfc_number, std::ostream &out) const
std::vector< GeoLib::Point const * > _stations
GMSHPolygonTree(GeoLib::PolygonWithSegmentMarker *polygon, GMSHPolygonTree *parent, GeoLib::GEOObjects &geo_objs, std::string const &geo_name, GMSHMeshDensityStrategy &mesh_density_strategy)
void getStationsInsideSubPolygons(std::vector< GeoLib::Point const * > &stations) const
void markSharedSegments()
void writeStations(std::size_t &pnt_id_offset, std::size_t sfc_number, std::ostream &out) const
void createGMSHPoints(std::vector< GMSHPoint * > &gmsh_pnts) const
void getPointsFromSubPolygons(std::vector< GeoLib::Point const * > &pnts) const
void checkIntersectionsSegmentExistingPolylines(GeoLib::PolylineWithSegmentMarker *ply, GeoLib::Polyline::SegmentIterator const &seg_it)
void initMeshDensityStrategy()
GeoLib::GEOObjects & _geo_objs
bool insertStation(GeoLib::Point const *station)
std::vector< GMSHLine * > _gmsh_lines_for_constraints
virtual void writeLineLoop(std::size_t &line_offset, std::size_t &sfc_offset, std::ostream &out, bool const write_physical) const
Container class for geometric objects.
const PointVec * getPointVecObj(const std::string &name) const
const PolylineVec * getPolylineVecObj(const std::string &name) const
This class manages pointers to Points in a std::vector along with a name. It also handles the deletio...
std::size_t push_back(Point *pnt)
bool isSegmentMarked(std::size_t seg_num) const
void markSegment(std::size_t seg_num, bool mark_val=true)
bool insertPoint(std::size_t pos, std::size_t pnt_id) override
std::size_t getSegmentNumber() const
std::size_t getPointID(std::size_t const i) const
virtual bool insertPoint(std::size_t pos, std::size_t pnt_id)
SegmentIterator begin() const
bool isPointIDInPolyline(std::size_t pnt_id) const
SegmentIterator end() const
const SimplePolygonTree * parent() const
Polygon const & polygon() const
A Station (observation site) is basically a Point with some additional information.
std::vector< T * > const & getVector() const
void cleanupVectorElements(std::vector< T * > &items)
bool containsEdge(const Polyline &ply, std::size_t id0, std::size_t id1)
void resetPointIDs(Polyline &polyline, std::vector< std::size_t > const &mapping)
Resets the point IDs of the polyline corresponding to the mapping.
bool lineSegmentIntersect(GeoLib::LineSegment const &s0, GeoLib::LineSegment const &s1, GeoLib::Point &s)