Medusa  1.1
Coordinate Free Mehless Method implementation
DomainShape_fwd.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_DOMAINS_DOMAINSHAPE_FWD_HPP_
2 #define MEDUSA_BITS_DOMAINS_DOMAINSHAPE_FWD_HPP_
3 
11 #include <medusa/Config.hpp>
14 #include <iosfwd>
15 #include <utility>
16 #include <ostream>
17 #include <functional>
18 
19 namespace mm {
20 
21 template <class vec_t>
23 
24 template <class vec_t>
26 
27 // These must be hidden during a doxygen run due to a bug in processing forward declarations.
28 // See https://github.com/doxygen/doxygen/issues/8177
29 #ifndef DOXYGEN_RUN
30 template <typename vec_t>
31 class ShapeUnion;
32 
33 template <typename vec_t>
34 class ShapeDifference;
35 
36 template <typename vec_t>
37 class TranslatedShape;
38 
39 template <typename vec_t>
40 class RotatedShape;
41 #endif
42 
51 template <typename vec_t>
52 class DomainShape {
53  public:
54  typedef vec_t vector_t;
55  typedef typename vec_t::Scalar scalar_t;
56  enum { dim = vec_t::dim };
58 
59  protected:
65  public:
67  DomainShape() : margin_(1e-10) {}
69  virtual ~DomainShape() = default;
70 
72  scalar_t margin() const { return margin_; }
73 
75  virtual void setMargin(scalar_t margin) { margin_ = margin; }
77  void toggleMargin() { setMargin(-margin()); }
79  ShapeUnion<vec_t> add(const DomainShape& other) const;
81  ShapeUnion<vec_t> operator+(const DomainShape& other) const { return add(other); }
82 
84  ShapeDifference<vec_t> subtract(const DomainShape& other) const;
86  ShapeDifference<vec_t> operator-(const DomainShape& other) const { return subtract(other); }
87 
89  virtual std::pair<bool, vec_t> projectPointToBoundary(const vec_t& point,
90  const vec_t& unit_normal) const;
91 
93  virtual bool contains(const vec_t& point) const = 0;
94 
96  virtual bool hasContains() const { return true; }
97 
103  virtual std::pair<vec_t, vec_t> bbox() const = 0;
105  virtual DomainShape* clone() const = 0;
107  virtual std::ostream& print(std::ostream& os) const = 0;
108 
109  // Two types of discretizations: uniform step and density (will possibly add random later).
110 
111  // STEP -- calls density by default
119  return discretizeBoundaryWithDensity([=](const vec_t&) { return step; }, type);
120  }
121 
127  return this->discretizeBoundaryWithStep(step, 0);
128  }
138  scalar_t step, int internal_type, int boundary_type) const {
139  return discretizeWithDensity([=](const vec_t&) { return step; }, internal_type,
140  boundary_type);
141  }
142 
145  return this->discretizeWithStep(step, 0, 0);
146  }
147 
148  // DENSITY -- calls fill engine in interior
158  const std::function<scalar_t(vec_t)>& dr, int internal_type, int boundary_type) const;
159 
161  template <typename func_t, typename fill_t>
162  DomainDiscretization<vec_t> discretizeWithDensity(const func_t& dr, const fill_t& fill,
163  int internal_type, int boundary_type) const {
165  fill(domain, dr, internal_type);
166  return domain;
167  }
168 
171  const std::function<scalar_t(vec_t)>& dr) const {
172  return discretizeWithDensity(dr, 0, 0);
173  }
174 
176  template <typename func_t, typename fill_t>
177  DomainDiscretization<vec_t> discretizeWithDensity(const func_t& dr, const fill_t& fill) const {
178  return discretizeWithDensity(dr, fill, 0, 0);
179  }
180 
186  const std::function<scalar_t(vec_t)>& dr, int type) const = 0;
187 
190  const std::function<scalar_t(vec_t)>& dr) const {
191  return this->discretizeBoundaryWithDensity(dr, 0);
192  }
193 
199  TranslatedShape<vec_t> translate(const vec_t& a);
200 
206  RotatedShape<vec_t> rotate(const Eigen::Matrix<scalar_t, dim, dim>& Q);
207 
210 
211  template <typename V>
212  friend std::ostream& operator<<(std::ostream& os, const DomainShape<V>& shape);
213 };
214 
219 template <typename V>
220 std::ostream& operator<<(std::ostream& os, const DomainShape<V>& shape) {
221  return shape.print(os);
222 }
223 
224 } // namespace mm
225 
226 #endif // MEDUSA_BITS_DOMAINS_DOMAINSHAPE_FWD_HPP_
mm::DomainShape::margin_
scalar_t margin_
Tolerance for the geometric operation of the domain.
Definition: DomainShape_fwd.hpp:64
mm::DomainShape::add
ShapeUnion< vec_t > add(const DomainShape &other) const
Returns a shape representing a union of *this and other.
Definition: DomainShape.hpp:66
mm::DomainShape::DomainShape
DomainShape()
Construct domain with default margin.
Definition: DomainShape_fwd.hpp:67
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::DomainShape::discretizeWithDensity
DomainDiscretization< vec_t > discretizeWithDensity(const func_t &dr, const fill_t &fill) const
Overload for fill engine with default types.
Definition: DomainShape_fwd.hpp:177
mm::DomainShape::contains
virtual bool contains(const vec_t &point) const =0
Return true if point is not more than margin() outside the domain.
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::DomainShape::discretizeBoundaryWithStep
DomainDiscretization< vec_t > discretizeBoundaryWithStep(scalar_t step) const
Returns a discretization of the boundary of this shape with approximately uniform distance step betwe...
Definition: DomainShape_fwd.hpp:126
mm::DomainDiscretization
Class representing domain discretization along with an associated shape.
Definition: DomainDiscretization_fwd.hpp:46
mm::ShapeUnion
Class representing a union of two shapes.
Definition: ShapeUnion_fwd.hpp:28
mm::DomainShape::rotate
RotatedShape< vec_t > rotate(const Eigen::Matrix< scalar_t, dim, dim > &Q)
Transform the shape by given orthogonal matrix Q.
Definition: DomainShape.hpp:98
mm::DomainShape::operator-
ShapeDifference< vec_t > operator-(const DomainShape &other) const
Operator form of DomainShape::subtract.
Definition: DomainShape_fwd.hpp:86
mm::TranslatedShape
Class for working with translated domain shapes.
Definition: TranslatedShape_fwd.hpp:27
dim
@ dim
Number of elements of this matrix.
Definition: MatrixBaseAddons.hpp:14
mm::RotatedShape
Class for working with rotated (or mirrored) domain shapes.
Definition: RotatedShape_fwd.hpp:27
mm::DomainShape::discretizeWithDensity
DomainDiscretization< vec_t > discretizeWithDensity(const std::function< scalar_t(vec_t)> &dr) const
Overload with default types.
Definition: DomainShape_fwd.hpp:170
mm::DomainShape::dim
@ dim
Dimensionality of the domain.
Definition: DomainShape_fwd.hpp:57
mm::operator<<
std::ostream & operator<<(std::ostream &os, const Gaussian< S > &b)
Output basic information about given Gaussian RBF.
Definition: Gaussian.hpp:37
mm::DomainShape::discretizeWithDensity
DomainDiscretization< vec_t > discretizeWithDensity(const func_t &dr, const fill_t &fill, int internal_type, int boundary_type) const
Overload for fill engine.
Definition: DomainShape_fwd.hpp:162
mm::DomainShape::toggleMargin
void toggleMargin()
Toggles the margin from positive to negative.
Definition: DomainShape_fwd.hpp:77
mm::DomainShape::setMargin
virtual void setMargin(scalar_t margin)
Sets domain margin to margin.
Definition: DomainShape_fwd.hpp:75
mm::DomainShape::clone
virtual DomainShape * clone() const =0
Polymorphic clone pattern.
mm::DomainShape::discretizeWithStep
virtual DomainDiscretization< vec_t > discretizeWithStep(scalar_t step, int internal_type, int boundary_type) const
Returns a discretization of this shape with approximately uniform distance step between nodes.
Definition: DomainShape_fwd.hpp:137
mm::DomainShape
Base class for geometric shapes of domains.
Definition: DomainShape_fwd.hpp:52
Config.hpp
mm::DomainShape::translate
TranslatedShape< vec_t > translate(const vec_t &a)
Translate the shape by given vector a.
Definition: DomainShape.hpp:84
mm::DomainShape::vector_t
vec_t vector_t
Vector data type used in computations.
Definition: DomainShape_fwd.hpp:54
mm::DomainShape::print
virtual std::ostream & print(std::ostream &os) const =0
Output information about this shape to given output stream os.
mm::DomainShape::discretizeBoundaryWithDensity
virtual DomainDiscretization< vec_t > discretizeBoundaryWithDensity(const std::function< scalar_t(vec_t)> &dr, int type) const =0
Discretizes boundary with given density and fill engine.
Vec_fwd.hpp
mm::DomainShape::discretizeWithDensity
virtual DomainDiscretization< vec_t > discretizeWithDensity(const std::function< scalar_t(vec_t)> &dr, int internal_type, int boundary_type) const
Returns a discretization of the domain with spatially variable step.
Definition: DomainShape.hpp:77
mm::DomainShape::subtract
ShapeDifference< vec_t > subtract(const DomainShape &other) const
Returns a shape representing a difference of *this and other.
Definition: DomainShape.hpp:71
mm::DomainShape::bbox
virtual std::pair< vec_t, vec_t > bbox() const =0
Return the bounding box of the domain.
mm::DomainShape::~DomainShape
virtual ~DomainShape()=default
Virtual destructor to properly destruct base class when invoked polymorphically.
mm::DomainShape::discretizeBoundaryWithStep
virtual DomainDiscretization< vec_t > discretizeBoundaryWithStep(scalar_t step, int type) const
Returns a discretization of the boundary of this shape with approximately uniform distance step betwe...
Definition: DomainShape_fwd.hpp:118
mm::DomainShape::projectPointToBoundary
virtual std::pair< bool, vec_t > projectPointToBoundary(const vec_t &point, const vec_t &unit_normal) const
Project point to boundary using bisection along the line define by unit_normal.
Definition: DomainShape.hpp:21
mm::DomainShape::margin
scalar_t margin() const
Returns current margin.
Definition: DomainShape_fwd.hpp:72
mm::DomainShape::operator+
ShapeUnion< vec_t > operator+(const DomainShape &other) const
Operator form of DomainShape::add.
Definition: DomainShape_fwd.hpp:81
mm::ShapeDifference
A class representing a set-difference of two shapes.
Definition: ShapeDifference_fwd.hpp:26
mm::DomainShape::discretizeWithStep
DomainDiscretization< vec_t > discretizeWithStep(scalar_t step) const
discretizeWithStep but with default types as assigned by the shape.
Definition: DomainShape_fwd.hpp:144
memutils.hpp
mm::DomainShape::discretizeBoundaryWithDensity
DomainDiscretization< vec_t > discretizeBoundaryWithDensity(const std::function< scalar_t(vec_t)> &dr) const
Overload with default type.
Definition: DomainShape_fwd.hpp:189
mm::deep_copy_unique_ptr
Unique pointer with polymorphic deep copy semantics.
Definition: DomainShape_fwd.hpp:22
mm::DomainShape::scalar_t
vec_t::Scalar scalar_t
Scalar data type used in computation.
Definition: DomainShape_fwd.hpp:55
mm::DomainShape::operator<<
friend std::ostream & operator<<(std::ostream &os, const DomainShape< V > &shape)
Output info about given shape to ostream.
Definition: DomainShape_fwd.hpp:220
mm::DomainShape::hasContains
virtual bool hasContains() const
Return true if shape has contains() method implemented.
Definition: DomainShape_fwd.hpp:96