Flow123d  release_2.2.0-914-gf1a3a4f
intersection_point_aux.hh
Go to the documentation of this file.
1 /*!
2  *
3 * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file intersection_point_aux.hh
15  * @brief Internal class representing intersection point.
16  * @author Viktor Fris, Pavel Exner
17  *
18  */
19 
20 #ifndef INTERSECTIONPOINT_H_
21 #define INTERSECTIONPOINT_H_
22 
23 #include <armadillo>
24 #include "mesh/mesh_types.hh"
25 
26 
27 //TODO: idea:replace with relative tolerance and use some user input tolerance (absolute) of the coordinates
28 static const double geometry_epsilon = 1e-9;//8*std::numeric_limits<double>::epsilon();//1e-9;
29 
30 //http://en.cppreference.com/w/cpp/types/numeric_limits/epsilon
31 static const double rounding_epsilon = geometry_epsilon;//8*std::numeric_limits<double>::epsilon();
33 
34 //forward declare
35 template<unsigned int N, unsigned int M> class IntersectionPointAux;
36 template<unsigned int N, unsigned int M> std::ostream& operator<<(std::ostream& os, const IntersectionPointAux<N,M>& IP);
37 
38 
39 enum class IntersectionResult {
40  positive = 1,
41  negative = 0,
42  degenerate = 2,
43  none = 3
44 };
45 
47  return int(a) < int(b);
48 }
49 
50 /** @brief Internal auxiliary class represents an intersection point of simplex<N> and simplex<M>.
51  *
52  * It contains barycentric coordinates of the point on both simplices.
53  * Further, it contains topology information of the intersection point.
54  * Namely its orientation (according to Plucker coordinates product),
55  * pathologic flag, local indices and dimension of element objects (node/line/triangle).
56  * Refered as 'IP' in further documentation.
57  */
58 template<unsigned int N, unsigned int M>
60 
61  arma::vec::fixed<N+1> local_bcoords_A_; ///< Barycentric coordinates of an IP on simplex<N>.
62  arma::vec::fixed<M+1> local_bcoords_B_; ///< Barycentric coordinates of an IP on simplex<M>.
63 
64  /** @brief Local indices of element objects that intersects.
65  *
66  * Can be indices of point (vertex), lines (edge), triangle (side) in intersectinh element,
67  * depending on the dimensions \p dim_A_, resp. \p dim_B_.
68  *
69  * Examples:
70  * dim_A=0, N=2 -> idx_A is local node index of triangle
71  * dim_B=2, N=3 -> idx_B is local side index of tetrahedron
72  * dim_B=1, N=3 -> idx_B is local line index of tetrahedron
73  */
74  //@{
75  unsigned int idx_A_;
76  unsigned int idx_B_;
77  //@}
78 
79  /** @brief Orientation according to Plucker products.
80  *
81  * All Plucker products > 0 then orientation is 1.
82  * All Plucker products < 0 then orientation is 0.
83  * (In case of line 1D and triangle 2D, the line is going in opposite direction to the normal of triangle.)
84  *
85  * In pathologic case, it is > 1.
86  */
88 
89  unsigned int dim_A_; ///< Dimension of the object A of intersection. Equal \p N, by default.
90  unsigned int dim_B_; ///< Dimension of the object B of intersection. Equal \p M, by default.
91 
92 public:
93 
94  IntersectionPointAux(); ///< Default constructor.
95  ~IntersectionPointAux(){}; ///< Destructor.
96 
97  /** @brief Constructor taking barycentric coordinates on simplices as input parameters.
98  * @param lcA barycentric coordinates of IP in Simplex<N>
99  * @param lcB barycentric coordinates of IP in Simplex<M>
100  * @param dim_A dimension of object A
101  * @param dim_B dimension of object B
102  */
103  IntersectionPointAux(const arma::vec::fixed<N+1> &lcA, const arma::vec::fixed<M+1> &lcB,
104  unsigned int dim_A = N, unsigned int dim_B = M);
105 
106 
107  /** Constructor - flipping dimension of an intersection point.
108  * @param IP is intersection point with flipped dimension (N->M, M->N)
109  */
110 // IntersectionPointAux(IntersectionPointAux<M, N> &IP);
111 
112  /** @brief Constructor interpolates the second bary coords
113  * of IntersectionPointAux<N,M-1> to IntersectionPointAux<N,M>
114  *
115  * Allowed only from dimension \p M 1 to 2 and from 2 to 3.
116  * @param IP intersection point of lower dimension of object B
117  * @param idx_B is the index of object B of IntersectionPointAux<N,M-1> in object B of IntersectionPointAux<N,M>
118  */
119  IntersectionPointAux(const IntersectionPointAux<N,M-1> &IP, unsigned int idx_B);
120 
121  /** @brief Constructor interpolates the second bary coords
122  * of IntersectionPointAux<N,M-2> to IntersectionPointAux<N,M>
123  *
124  * Allowed only from dimension \p M 1 to 3.
125  * @param IP intersection point of lower dimension of object B
126  * @param idx_B is the index of object B of IntersectionPointAux<N,M-2> in object B of IntersectionPointAux<N,M>
127  */
128  IntersectionPointAux(const IntersectionPointAux<N,M-2> &IP, unsigned int idx_B);
129 
130  /// Resets the object to default values.
131  void clear();
132 
133  /// Switches the object A and B.
134  IntersectionPointAux<M, N> switch_objects() const;
135 
136  ///@name Setters.
137  //@{
138  /** @brief Setter for coordinates.
139  * @param lcA braycentric coordinates of A
140  * @param lcB braycentric coordinates of B
141  */
142  void set_coordinates(const arma::vec::fixed<N+1> &lcA, const arma::vec::fixed<M+1> &lcB);
143 
144  /// Setter for topology data. See description of @p idx_A_ and @p dim_A_.
145  void set_topology(unsigned int idx_A, unsigned int dim_A,
146  unsigned int idx_B, unsigned int dim_B);
147 
148  void set_topology_A(unsigned int idx, unsigned int dim_A); ///< Sets the topology of object A in Simplex<N>.
149  void set_topology_B(unsigned int idx, unsigned int dim_B); ///< Sets the topology of object B in Simplex<M>.
150  void set_orientation(IntersectionResult orientation); ///< Setter orientation flag.
151 
152  //@}
153 
154 
155  ///@name Getters.
156  //@{
157  /// Returns barycentric coordinates in the Simplex<N>.
158  const arma::vec::fixed<N+1> &local_bcoords_A() const;
159 
160  /// Returns barycentric coordinates in the Simplex<M>.
161  const arma::vec::fixed<M+1> &local_bcoords_B() const;
162 
163  unsigned int dim_A() const; ///< Returns dimension of object A.
164  unsigned int dim_B() const; ///< Returns dimension of object B.
165  unsigned int idx_A() const; ///< Returns the index of Simplex<N>.
166  unsigned int idx_B() const; ///< Returns the index of Simplex<M>.
167  // orientation: 0 - negative sign, 1 - positive sign, 2 - degenerate (zero for all sides)
168  IntersectionResult orientation() const; ///< Returns the orientation.
169  //@}
170 
171  /// Computes real coordinates of IP, given the element @p ele in which IP lies.
172  arma::vec::fixed<3> coords(ElementFullIter ele) const;
173 
174  /// Returns true, if this is a pathologic case.
175  bool is_pathologic() const;
176 
177  /** @brief Comparison operator for sorting the IPs in convex hull tracing algorithm.
178  * Compares the points by x-coordinate (in case of a tie, compares by y-coordinate).
179  */
180  //bool operator<(const IntersectionPointAux<N,M> &ip) const;
181 
182  /// Friend output operator.
183  friend std::ostream& operator<< <>(std::ostream& os, const IntersectionPointAux<N,M>& IP);
184 };
185 
186 
187 /********************************************* IMPLEMENTATION ***********************************************/
188 
189 template<unsigned int N, unsigned int M>
190 void IntersectionPointAux<N,M>::set_coordinates(const arma::vec::fixed< N + 1 >& lcA, const arma::vec::fixed< M + 1 >& lcB)
191 { local_bcoords_A_ = lcA;
192  local_bcoords_B_ = lcB; }
193 
194 template<unsigned int N, unsigned int M>
195 void IntersectionPointAux<N,M>::set_topology(unsigned int idx_A,unsigned int dim_A, unsigned int idx_B, unsigned int dim_B)
196 { idx_A_ = idx_A;
197  idx_B_ = idx_B;
198  dim_A_ = dim_A;
199  dim_B_ = dim_B;
200 }
201 
202 template<unsigned int N, unsigned int M>
204 { orientation_ = orientation; }
205 
206 template<unsigned int N, unsigned int M>
208 { return dim_A_; }
209 
210 template<unsigned int N, unsigned int M>
212 { return dim_B_; }
213 
214 template<unsigned int N, unsigned int M>
215 const arma::vec::fixed< N + 1 >& IntersectionPointAux<N,M>::local_bcoords_A() const
216 { return local_bcoords_A_; }
217 
218 template<unsigned int N, unsigned int M>
219 const arma::vec::fixed< M + 1 >& IntersectionPointAux<N,M>::local_bcoords_B() const
220 { return local_bcoords_B_; }
221 
222 template<unsigned int N, unsigned int M>
223 void IntersectionPointAux<N,M>::set_topology_A(unsigned int idx_A, unsigned int dim_A)
224 { idx_A_ = idx_A;
225  dim_A_ = dim_A; }
226 
227 template<unsigned int N, unsigned int M>
228 void IntersectionPointAux<N,M>::set_topology_B(unsigned int idx_B, unsigned int dim_B)
229 { idx_B_ = idx_B;
230  dim_B_ = dim_B; }
231 
232 template<unsigned int N, unsigned int M>
234 { return idx_A_; }
235 
236 template<unsigned int N, unsigned int M>
238 { return idx_B_; }
239 
240 template<unsigned int N, unsigned int M>
242 { return orientation_; }
243 
244 template<unsigned int N, unsigned int M>
246 { return (unsigned int)(orientation_) > 1; }
247 
248 #endif /* INTERSECTIONPOINT_H_ */
unsigned int dim_A() const
Returns dimension of object A.
void set_topology_B(unsigned int idx, unsigned int dim_B)
Sets the topology of object B in Simplex<M>.
arma::vec::fixed< N+1 > local_bcoords_A_
Barycentric coordinates of an IP on simplex<N>.
void set_topology_A(unsigned int idx, unsigned int dim_A)
Sets the topology of object A in Simplex<N>.
arma::vec::fixed< M+1 > local_bcoords_B_
Barycentric coordinates of an IP on simplex<M>.
static const double rounding_epsilon
void set_orientation(IntersectionResult orientation)
Setter orientation flag.
static const double geometry_epsilon
const arma::vec::fixed< N+1 > & local_bcoords_A() const
Returns barycentric coordinates in the Simplex<N>.
const arma::vec::fixed< M+1 > & local_bcoords_B() const
Returns barycentric coordinates in the Simplex<M>.
unsigned int idx_A() const
Returns the index of Simplex<N>.
unsigned int dim_B() const
Returns dimension of object B.
void set_coordinates(const arma::vec::fixed< N+1 > &lcA, const arma::vec::fixed< M+1 > &lcB)
Setter for coordinates.
unsigned int idx_A_
Local indices of element objects that intersects.
unsigned int dim_A_
Dimension of the object A of intersection. Equal N, by default.
const double epsilon
Definition: mathfce.h:23
IntersectionResult orientation_
Orientation according to Plucker products.
unsigned int dim_B_
Dimension of the object B of intersection. Equal M, by default.
Internal auxiliary class represents an intersection point of simplex<N> and simplex<M>.
IntersectionResult orientation() const
Returns the orientation.
static const double rounding_epsilonX
unsigned int idx_B() const
Returns the index of Simplex<M>.
bool is_pathologic() const
Returns true, if this is a pathologic case.
bool operator<(IntersectionResult a, IntersectionResult b)
void set_topology(unsigned int idx_A, unsigned int dim_A, unsigned int idx_B, unsigned int dim_B)
Setter for topology data. See description of idx_A_ and dim_A_.