26 std::string
const& geo_name,
52 for (
auto& child : *
this)
54 std::size_t
const n_pnts(child->polygon().getNumberOfPoints());
55 for (std::size_t k(1); k < n_pnts; k++)
62 .markSegment(k,
true);
70 if (
polygon().isPntInPolygon(*station))
73 for (
auto* child : *
this)
75 if (child->polygon().isPntInPolygon(*station))
80 if (rval && child->getNumberOfChildren() == 0)
97 if (!
polygon().isPartOfPolylineInPolygon(*ply))
104 for (
auto* child : *
this)
114 for (
auto segment_it(ply->
begin()); segment_it != ply->
end(); ++segment_it)
121 if (
polygon().containsSegment(*segment_it))
123 ply->
markSegment(segment_it.getSegmentNumber(),
true);
127 std::size_t seg_num(0);
129 while (
polygon().getNextIntersectionPointPolygonLine(
130 *segment_it, intersection_pnt, seg_num))
134 const std::size_t pnt_vec_size(pnt_vec.
size());
137 if (pnt_vec_size < pnt_vec.
size())
142 ply->
insertPoint(segment_it.getSegmentNumber(), pnt_id);
147 if (!
polygon().isPointIDInPolyline(pnt_id))
155 ply->
insertPoint(segment_it.getSegmentNumber() + 1, pnt_id);
159 std::size_t tmp_seg_num(seg_num + 1);
160 if (!
polygon().getNextIntersectionPointPolygonLine(
161 *segment_it, tmp_pnt, tmp_seg_num))
164 for (std::size_t i(0); i < 3; i++)
166 tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] +
167 (*segment_it).getEndPoint()[i]) /
170 if (
polygon().isPntInPolygon(tmp_pnt))
172 ply->
markSegment(segment_it.getSegmentNumber(),
true);
175 new GMSHLine((*segment_it).getBeginPoint().getID(),
176 (*segment_it).getEndPoint().getID()));
182 for (std::size_t i(0); i < 3; i++)
184 tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] +
185 (*segment_it).getEndPoint()[i]) /
191 if (
polygon().isPntInPolygon(tmp_pnt))
193 ply->
markSegment(segment_it.getSegmentNumber(),
true);
196 new GMSHLine((*segment_it).getBeginPoint().getID(),
197 (*segment_it).getEndPoint().getID()));
202 _plys.push_back(ply);
213 for (
auto seg_it_p(p->begin()); seg_it_p != p->end(); ++seg_it_p)
218 const std::size_t pnt_vec_size(pnt_vec.
size());
220 const std::size_t pnt_id(
222 if (pnt_vec_size < pnt_vec.
size())
225 p->insertPoint(seg_it_p.getSegmentNumber() + 1, pnt_id);
232 std::size_t
const k(seg_it_p.getSegmentNumber());
233 if (p->getPointID(k) != pnt_id &&
234 p->getPointID(k + 1) != pnt_id)
236 p->insertPoint(k + 1, pnt_id);
239 if (ply->
getPointID(ply_segment_number) != pnt_id &&
240 ply->
getPointID(ply_segment_number + 1) != pnt_id)
252 if (
auto* adaptive_mesh_density =
256 std::vector<GeoLib::Point const*> pnts;
257 const std::size_t n_pnts_polygon(
polygon().getNumberOfPoints());
258 for (std::size_t k(0); k < n_pnts_polygon; k++)
260 pnts.push_back(
polygon().getPoint(k));
264 const std::size_t n_plys(
_plys.size());
265 for (std::size_t k(0); k < n_plys; k++)
267 const std::size_t n_pnts_in_kth_ply(
_plys[k]->getNumberOfPoints());
268 for (std::size_t j(0); j < n_pnts_in_kth_ply; j++)
270 pnts.push_back(
_plys[k]->getPoint(j));
275 adaptive_mesh_density->initialize(pnts);
277 adaptive_mesh_density->addPoints(
_stations);
278 std::vector<GeoLib::Point const*> stations;
280 adaptive_mesh_density->addPoints(stations);
286 const std::size_t n_pnts_polygon(
polygon().getNumberOfPoints());
287 for (std::size_t k(0); k < n_pnts_polygon - 1; k++)
289 const std::size_t id(
polygon().getPointID(k));
292 if (gmsh_pnts[
id] !=
nullptr)
300 const std::size_t n_plys(
_plys.size());
301 std::stringstream error_messages;
302 error_messages.precision(std::numeric_limits<double>::max_digits10);
303 for (std::size_t k(0); k < n_plys; k++)
305 const std::size_t n_pnts_in_ply(
_plys[k]->getNumberOfPoints());
306 for (std::size_t j(0); j < n_pnts_in_ply; j++)
310 const std::size_t id(
_plys[k]->getPointID(j));
312 if (gmsh_pnts[
id] !=
nullptr)
323 auto const& p = *(
_plys[k]->getPoint(j));
324 error_messages <<
"\n\tpoint with id " << p.getID()
325 <<
" and coordinates (" << p[0] <<
", " << p[1]
327 <<
") is outside of the polygon.";
333 auto const error_message = error_messages.str();
334 if (!error_message.empty())
341 for (
auto* child : *
this)
348 std::size_t& sfc_offset, std::ostream& out,
349 bool const write_physical)
const
351 const std::size_t n_pnts(
polygon().getNumberOfPoints());
352 for (std::size_t k(1), first_pnt_id(
polygon().getPointID(0)); k < n_pnts;
356 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id <<
","
357 << second_pnt_id <<
"};\n";
358 first_pnt_id = second_pnt_id;
360 out <<
"Line Loop(" << line_offset + n_pnts - 1 <<
") = {";
361 for (std::size_t k(0); k < n_pnts - 2; k++)
363 out << line_offset + k <<
",";
365 out << line_offset + n_pnts - 2 <<
"};\n";
366 out <<
"Plane Surface(" << sfc_offset <<
") = {" << line_offset + n_pnts - 1
370 out <<
"Physical Curve(" << sfc_offset <<
") = {";
371 for (std::size_t k(0); k < n_pnts - 2; k++)
373 out << line_offset + k <<
",";
375 out << line_offset + n_pnts - 2 <<
"};\n";
376 out <<
"Physical Surface(" << sfc_offset <<
") = {" << sfc_offset
379 line_offset += n_pnts;
384 std::size_t sfc_number,
385 std::ostream& out)
const
387 for (
auto polyline :
_plys)
389 const std::size_t n_pnts(polyline->getNumberOfPoints());
390 std::size_t first_pnt_id(polyline->getPointID(0));
391 for (std::size_t k(1); k < n_pnts; k++)
393 auto const second_pnt_id = polyline->getPointID(k);
394 if (polyline->isSegmentMarked(k - 1) &&
395 polygon().isPntInPolygon(*(polyline->getPoint(k))) &&
398 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id
399 <<
"," << second_pnt_id <<
"};\n";
400 out <<
"Line { " << line_offset + k - 1 <<
" } In Surface { "
401 << sfc_number <<
" };\n";
403 first_pnt_id = second_pnt_id;
405 line_offset += n_pnts;
410 std::size_t& line_offset, std::size_t sfc_number, std::ostream& out)
const
412 for (
auto* child : *
this)
420 const std::size_t n_pnts(
polygon().getNumberOfPoints());
421 std::size_t first_pnt_id(
polygon().getPointID(0));
422 for (std::size_t k(1); k < n_pnts; k++)
425 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id
426 <<
"," << second_pnt_id <<
"};\n";
427 first_pnt_id = second_pnt_id;
428 out <<
"Line { " << line_offset + k - 1 <<
" } In Surface { "
429 << sfc_number <<
" };\n";
431 line_offset += n_pnts;
436 std::size_t sfc_number,
437 std::ostream& out)
const
441 out <<
"Point(" << pnt_id_offset <<
") = {" << (*station)[0] <<
", "
442 << (*station)[1] <<
", 0.0, "
446 out <<
"Point { " << pnt_id_offset <<
" } In Surface { " << sfc_number
453 std::size_t sfc_number,
454 std::ostream& out)
const
456 if (
auto const* adaptive_mesh_density =
459 std::vector<GeoLib::Point*> steiner_pnts;
460 adaptive_mesh_density->getSteinerPoints(steiner_pnts, 0);
461 const std::size_t n(steiner_pnts.size());
462 for (std::size_t k(0); k < n; k++)
464 if (
polygon().isPntInPolygon(*(steiner_pnts[k])))
466 out <<
"Point(" << pnt_id_offset + k <<
") = {"
467 << (*(steiner_pnts[k]))[0] <<
"," << (*(steiner_pnts[k]))[1]
472 out <<
"Point { " << pnt_id_offset + k <<
" } In Surface { "
473 << sfc_number <<
" };\n";
475 delete steiner_pnts[k];
481 if (
auto* adaptive_mesh_density =
484 auto const quad_tree_geo =
485 adaptive_mesh_density->getQuadTreeGeometry(
_geo_objs);
486 std::vector<std::size_t>
const& id_map(
487 (
_geo_objs.getPointVecObj(quad_tree_geo))->getIDMap());
488 auto& plys =
_geo_objs.getPolylineVecObj(quad_tree_geo)->getVector();
489 for (std::size_t k(0); k < plys.size(); k++)
498 std::vector<GeoLib::Point const*>& pnts)
const
500 for (
auto const* child : *
this)
508 std::vector<GeoLib::Point const*>& stations)
const
510 const std::size_t n_stations(
_stations.size());
511 for (std::size_t k(0); k < n_stations; k++)
516 for (
auto const* child : *
this)
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.
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
SimplePolygonTree(Polygon *polygon, SimplePolygonTree *parent)
const SimplePolygonTree * parent() const
Polygon const & polygon() const
A Station (observation site) is basically a Point with some additional information.
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)