30 std::string
const& geo_name,
32 :
GeoLib::SimplePolygonTree(polygon, parent),
35 _mesh_density_strategy(mesh_density_strategy)
45 for (
auto* polyline :
_plys)
59 for (
auto& child : *
this)
61 std::size_t
const n_pnts(child->polygon().getNumberOfPoints());
62 for (std::size_t k(1); k < n_pnts; k++)
69 .markSegment(k,
true);
77 if (
polygon().isPntInPolygon(*station))
80 for (
auto* child : *
this)
82 if (child->polygon().isPntInPolygon(*station))
87 if (rval && child->getNumberOfChildren() == 0)
104 if (!
polygon().isPartOfPolylineInPolygon(*ply))
111 for (
auto* child : *
this)
121 for (
auto segment_it(ply->
begin()); segment_it != ply->
end(); ++segment_it)
128 if (
polygon().containsSegment(*segment_it))
130 ply->
markSegment(segment_it.getSegmentNumber(),
true);
134 std::size_t seg_num(0);
136 while (
polygon().getNextIntersectionPointPolygonLine(
137 *segment_it, intersection_pnt, seg_num))
141 const std::size_t pnt_vec_size(pnt_vec.
size());
144 if (pnt_vec_size < pnt_vec.
size())
149 ply->
insertPoint(segment_it.getSegmentNumber(), pnt_id);
154 if (!
polygon().isPointIDInPolyline(pnt_id))
162 ply->
insertPoint(segment_it.getSegmentNumber() + 1, pnt_id);
166 std::size_t tmp_seg_num(seg_num + 1);
167 if (!
polygon().getNextIntersectionPointPolygonLine(
168 *segment_it, tmp_pnt, tmp_seg_num))
171 for (std::size_t i(0); i < 3; i++)
173 tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] +
174 (*segment_it).getEndPoint()[i]) /
179 ply->
markSegment(segment_it.getSegmentNumber(),
true);
182 new GMSHLine((*segment_it).getBeginPoint().getID(),
183 (*segment_it).getEndPoint().getID()));
189 for (std::size_t i(0); i < 3; i++)
191 tmp_pnt[i] = ((*segment_it).getBeginPoint()[i] +
192 (*segment_it).getEndPoint()[i]) /
198 if (
polygon().isPntInPolygon(tmp_pnt))
200 ply->
markSegment(segment_it.getSegmentNumber(),
true);
203 new GMSHLine((*segment_it).getBeginPoint().getID(),
204 (*segment_it).getEndPoint().getID()));
209 _plys.push_back(ply);
220 for (
auto seg_it_p(p->begin()); seg_it_p != p->end(); ++seg_it_p)
225 const std::size_t pnt_vec_size(pnt_vec.
size());
227 const std::size_t pnt_id(
229 if (pnt_vec_size < pnt_vec.
size())
232 p->insertPoint(seg_it_p.getSegmentNumber() + 1, pnt_id);
239 std::size_t
const k(seg_it_p.getSegmentNumber());
240 if (p->getPointID(k) != pnt_id &&
241 p->getPointID(k + 1) != pnt_id)
243 p->insertPoint(k + 1, pnt_id);
246 if (ply->
getPointID(ply_segment_number) != pnt_id &&
247 ply->
getPointID(ply_segment_number + 1) != pnt_id)
259 if (
auto* adaptive_mesh_density =
263 std::vector<GeoLib::Point const*> pnts;
264 const std::size_t n_pnts_polygon(
polygon().getNumberOfPoints());
265 for (std::size_t k(0); k < n_pnts_polygon; k++)
267 pnts.push_back(
polygon().getPoint(k));
271 const std::size_t n_plys(
_plys.size());
272 for (std::size_t k(0); k < n_plys; k++)
274 const std::size_t n_pnts_in_kth_ply(
_plys[k]->getNumberOfPoints());
275 for (std::size_t j(0); j < n_pnts_in_kth_ply; j++)
277 pnts.push_back(
_plys[k]->getPoint(j));
282 adaptive_mesh_density->initialize(pnts);
284 adaptive_mesh_density->addPoints(
_stations);
285 std::vector<GeoLib::Point const*> stations;
287 adaptive_mesh_density->addPoints(stations);
293 const std::size_t n_pnts_polygon(
polygon().getNumberOfPoints());
294 for (std::size_t k(0); k < n_pnts_polygon - 1; k++)
296 const std::size_t id(
polygon().getPointID(k));
299 if (gmsh_pnts[
id] !=
nullptr)
307 const std::size_t n_plys(
_plys.size());
308 for (std::size_t k(0); k < n_plys; k++)
310 const std::size_t n_pnts_in_ply(
_plys[k]->getNumberOfPoints());
311 for (std::size_t j(0); j < n_pnts_in_ply; j++)
315 const std::size_t id(
_plys[k]->getPointID(j));
317 if (gmsh_pnts[
id] !=
nullptr)
330 for (
auto* child : *
this)
337 std::size_t& sfc_offset, std::ostream& out,
338 bool const write_physical)
const
340 const std::size_t n_pnts(
polygon().getNumberOfPoints());
341 for (std::size_t k(1), first_pnt_id(
polygon().getPointID(0)); k < n_pnts;
345 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id <<
","
346 << second_pnt_id <<
"};\n";
347 first_pnt_id = second_pnt_id;
349 out <<
"Line Loop(" << line_offset + n_pnts - 1 <<
") = {";
350 for (std::size_t k(0); k < n_pnts - 2; k++)
352 out << line_offset + k <<
",";
354 out << line_offset + n_pnts - 2 <<
"};\n";
355 out <<
"Plane Surface(" << sfc_offset <<
") = {" << line_offset + n_pnts - 1
359 out <<
"Physical Curve(" << sfc_offset <<
") = {";
360 for (std::size_t k(0); k < n_pnts - 2; k++)
362 out << line_offset + k <<
",";
364 out << line_offset + n_pnts - 2 <<
"};\n";
365 out <<
"Physical Surface(" << sfc_offset <<
") = {" << sfc_offset
368 line_offset += n_pnts;
373 std::size_t sfc_number,
374 std::ostream& out)
const
376 for (
auto polyline :
_plys)
378 const std::size_t n_pnts(polyline->getNumberOfPoints());
379 std::size_t first_pnt_id(polyline->getPointID(0));
380 for (std::size_t k(1); k < n_pnts; k++)
382 auto const second_pnt_id = polyline->getPointID(k);
383 if (polyline->isSegmentMarked(k - 1) &&
384 polygon().isPntInPolygon(*(polyline->getPoint(k))) &&
387 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id
388 <<
"," << second_pnt_id <<
"};\n";
389 out <<
"Line { " << line_offset + k - 1 <<
" } In Surface { "
390 << sfc_number <<
" };\n";
392 first_pnt_id = second_pnt_id;
394 line_offset += n_pnts;
399 std::size_t& line_offset, std::size_t sfc_number, std::ostream& out)
const
401 for (
auto* child : *
this)
409 const std::size_t n_pnts(
polygon().getNumberOfPoints());
410 std::size_t first_pnt_id(
polygon().getPointID(0));
411 for (std::size_t k(1); k < n_pnts; k++)
414 out <<
"Line(" << line_offset + k - 1 <<
") = {" << first_pnt_id
415 <<
"," << second_pnt_id <<
"};\n";
416 first_pnt_id = second_pnt_id;
417 out <<
"Line { " << line_offset + k - 1 <<
" } In Surface { "
418 << sfc_number <<
" };\n";
420 line_offset += n_pnts;
425 std::size_t sfc_number,
426 std::ostream& out)
const
430 out <<
"Point(" << pnt_id_offset <<
") = {" << (*station)[0] <<
", "
431 << (*station)[1] <<
", 0.0, "
435 out <<
"Point { " << pnt_id_offset <<
" } In Surface { " << sfc_number
442 std::size_t sfc_number,
443 std::ostream& out)
const
445 if (
auto* adaptive_mesh_density =
448 std::vector<GeoLib::Point*> steiner_pnts;
449 adaptive_mesh_density->getSteinerPoints(steiner_pnts, 0);
450 const std::size_t n(steiner_pnts.size());
451 for (std::size_t k(0); k < n; k++)
453 if (
polygon().isPntInPolygon(*(steiner_pnts[k])))
455 out <<
"Point(" << pnt_id_offset + k <<
") = {"
456 << (*(steiner_pnts[k]))[0] <<
"," << (*(steiner_pnts[k]))[1]
461 out <<
"Point { " << pnt_id_offset + k <<
" } In Surface { "
462 << sfc_number <<
" };\n";
464 delete steiner_pnts[k];
470 if (
auto* adaptive_mesh_density =
473 auto pnts = std::make_unique<std::vector<GeoLib::Point*>>();
474 auto plys = std::make_unique<std::vector<GeoLib::Polyline*>>();
475 adaptive_mesh_density->getQuadTreeGeometry(*pnts, *plys);
476 std::string quad_tree_geo(
"QuadTree");
478 std::vector<std::size_t>
const& id_map(
480 for (std::size_t k(0); k < plys->size(); k++)
482 for (std::size_t j(0); j < (*plys)[k]->getNumberOfPoints(); j++)
485 ->setPointID(j, id_map[((*plys)[k])->getPointID(j)]);
494 std::vector<GeoLib::Point const*>& pnts)
const
496 for (
auto const* child : *
this)
504 std::vector<GeoLib::Point const*>& stations)
const
506 const std::size_t n_stations(
_stations.size());
507 for (std::size_t k(0); k < n_stations; k++)
512 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
void addPointVec(std::unique_ptr< std::vector< Point * >> points, std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> pnt_id_name_map=nullptr, double eps=std::sqrt(std::numeric_limits< double >::epsilon()))
void addPolylineVec(std::unique_ptr< std::vector< Polyline * >> lines, const std::string &name, std::unique_ptr< std::map< std::string, std::size_t >> ply_names=nullptr)
This class manages pointers to Points in a std::vector along with a name. It also handles the deletin...
std::size_t push_back(Point *pnt)
bool isPntInPolygon(const MathLib::Point3d &pnt) const
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 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.
bool containsEdge(const Polyline &ply, std::size_t id0, std::size_t id1)
bool lineSegmentIntersect(GeoLib::LineSegment const &s0, GeoLib::LineSegment const &s1, GeoLib::Point &s)