SPHinXsys  alpha version
multi_polygon_shape.h
Go to the documentation of this file.
1 
13 #ifndef MULTI_POLYGON_SHAPE_H
14 #define MULTI_POLYGON_SHAPE_H
15 
16 #define _SILENCE_EXPERIMENTAL_FILESYSTEM_DEPRECATION_WARNING
17 
18 //boost library
19 #include <boost/geometry.hpp>
20 #include <boost/geometry/geometries/point_xy.hpp>
21 #include <boost/geometry/geometries/polygon.hpp>
22 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
23 #include <boost/geometry/strategies/transform.hpp>
24 #include <boost/geometry/strategies/transform/matrix_transformers.hpp>
25 
26 #include "base_data_package.h"
27 #include "base_geometry.h"
28 
29 #include <iostream>
30 #include <string>
31 #include <fstream>
32 
33 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
34 
35 using namespace boost::geometry;
36 
37 namespace SPH
38 {
39 
43  class Kernel;
44 
45  typedef model::polygon<model::d2::point_xy<Real>> boost_poly;
46  typedef model::multi_polygon<boost_poly> boost_multi_poly;
47 
53  {
54  public:
55  MultiPolygon(){};
56  explicit MultiPolygon(const std::vector<Vecd> &points);
57  explicit MultiPolygon(const Vec2d &center, Real radius, int resolution);
58  boost_multi_poly &getBoostMultiPoly() { return multi_poly_; };
59 
60  BoundingBox findBounds();
61  bool checkContain(const Vec2d &pnt, bool BOUNDARY_INCLUDED = true);
62  Vec2d findClosestPoint(const Vec2d &input_pnt);
63 
64  void addAMultiPolygon(MultiPolygon &multi_polygon, ShapeBooleanOps op);
65  void addABoostMultiPoly(boost_multi_poly &boost_multi_poly, ShapeBooleanOps op);
66  void addAPolygon(const std::vector<Vecd> &points, ShapeBooleanOps op);
67  void addABox(Transform2d transform2d, const Vec2d &halfsize, ShapeBooleanOps op);
68  void addACircle(const Vec2d &center, Real radius, int resolution, ShapeBooleanOps op);
69  void addAPolygonFromFile(std::string file_path_name, ShapeBooleanOps op, Vec2d translation = Vecd(0), Real scale_factor = 1.0);
70 
71  protected:
72  boost_multi_poly multi_poly_;
73  boost_multi_poly MultiPolygonByBooleanOps(boost_multi_poly multi_poly_in,
74  boost_multi_poly multi_poly_op,
75  ShapeBooleanOps boolean_op);
76  };
77 
82  class MultiPolygonShape : public Shape
83  {
84 
85  public:
87  explicit MultiPolygonShape(const std::string &shape_name) : Shape(shape_name){};
88  explicit MultiPolygonShape(const MultiPolygon &multi_polygon, const std::string &shape_name = "MultiPolygonShape")
89  : Shape(shape_name), multi_polygon_(multi_polygon){};
90  virtual ~MultiPolygonShape(){};
91 
92  virtual bool isValid() override;
93  virtual bool checkContain(const Vec2d &input_pnt, bool BOUNDARY_INCLUDED = true) override;
94  virtual Vec2d findClosestPoint(const Vec2d &input_pnt) override;
95 
96  protected:
97  MultiPolygon multi_polygon_;
98 
99  virtual BoundingBox findBounds() override;
100  };
101 }
102 
103 #endif //MULTI_POLYGON_SHAPE_H
MultiPolygonShape(const std::string &shape_name)
Definition: multi_polygon_shape.h:87
Base class for all volumetric geometries Note that checkContain and findClosest point are basic funct...
Definition: base_geometry.h:64
used to define a closed region
Definition: multi_polygon_shape.h:52
Coordinate transform in 2D Note that the rotation is around the frame (or local) origin.
Definition: base_data_type.h:453
Shape is the base class for all geometries.
A shape whose geometry is defined by a multi polygon.
Definition: multi_polygon_shape.h:82
Boolean operation for generate complex shapes.
Definition: solid_body_supplementary.cpp:9