msbGrid  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
point.hh
Go to the documentation of this file.
1 /*****************************************************************************
2 * This program is part of the msbGrid software *
3 * *
4 * msbGrid stands for multi-structured block Grid generator *
5 * *
6 * msbGrid is a free software: you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation, either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * msbGrid is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * See the file COPYING for full copying permissions. *
17 *****************************************************************************/
23 #ifndef _POINT_HH_
24 #define _POINT_HH_
25 
26 #include <cassert>
27 #include <geometricentity.hh>
28 
29 class msbGrid :: Point : public msbGrid :: GeometricEntity
30 {
31 public:
33 
37 
39 
40  enum { dim = msbGrid :: dim };
41 
42 private:
43  std :: vector< Scalar > x_; /* Coordinates container */
44 
45  std :: vector< Point * > vpNeighbor0_; /*vector of neighbor points in a circle of radius diag*/
46  std :: vector< Point * > vpNeighbor1_; /*vector of neighbor points in a circle of radius diag*/
47 
48  /* data for *.m output files */
50 
51  /* data for *.geo output files */
52  Scalar cl_; /* Characteristic length */
53 
54 public:
55  Point() : ParentT()
56  {
57  assert(dim == 2);
58 
59  x_.resize(dim);
60 
61  this->vPt_.push_back(this);
62 
63  marker_.symbol = "'o'";
64  marker_.size = 4;
65  marker_.edgeColor = Black;
66  marker_.faceColor = White;
67 
68  cl_ = 1.0;
69  }
70 
71  Point(const std :: vector< Scalar > & x0) : Point()
72  {
73  assert(x0.size() >= dim);
74 
75  for ( unsigned int iDim = 0; iDim < dim; ++iDim ) {
76  x_ [ iDim ] = x0 [ iDim ];
77  }
78  }
79 
80  Point(const Scalar & x, const Scalar & y) : Point()
81  {
82  x_ [ 0 ] = x;
83  x_ [ 1 ] = y;
84  }
85 
86  ~Point() {}
87 
88  const std :: vector< Scalar > &pos() const
89  { return x_; }
90 
91  const std :: vector< Scalar > &x() const
92  { return x_; }
93 
94  std :: vector< Scalar > &x()
95  { return x_; }
96 
97  const std :: vector< Point * > &vpNeighbor0() const
98  { return vpNeighbor0_; }
99 
100  std :: vector< Point * > &vpNeighbor0()
101  { return vpNeighbor0_; }
102 
103  const std :: vector< Point * > &vpNeighbor1() const
104  { return vpNeighbor1_; }
105 
106  std :: vector< Point * > &vpNeighbor1()
107  { return vpNeighbor1_; }
108 
109  const std :: vector< Point * > onBlockBoundvpNeighbor1() const /* needed by gridfactory */
110  {
111  std :: vector< Point * > onBlockBoundNeighbors;
112  for ( unsigned int iPt1 = 0; iPt1 < 4; ++iPt1 ) {
113  if ( vpNeighbor1_ [ iPt1 ]->onBlockBoundary() ) {
114  onBlockBoundNeighbors.push_back(vpNeighbor1_ [ iPt1 ]);
115  }
116  }
117 
118  return onBlockBoundNeighbors;
119  }
120 
121  const msbGrid :: Marker &marker() const
122  { return marker_; }
123 
125  { return marker_; }
126 
127  const Scalar &cl() const
128  { return cl_; }
129 
131  { return cl_; }
132 
133  void translate(const std :: vector< Scalar > &dx)
134  {
135  for ( int i = 0; i < dim; ++i ) {
136  x_ [ i ] += dx [ i ];
137  }
138  }
139 
140  void rotate(const Scalar &_angle, const Point &mc)
141  {
142  assert(mc.dim == 2); /* TODO : rotate() must be modified to handle 3D space */
143 
144  Scalar angle = deg2Rad(_angle);
145 
146  std :: vector< Scalar > dx( dim, Scalar( 0.0 ) );
147  for ( int i = 0; i < dim; ++i ) {
148  dx [ i ] = x_ [ i ] - mc.x_ [ i ];
149  }
150 
151  x_ [ 0 ] = std :: cos(angle) * dx [ 0 ] - std :: sin(angle) * dx [ 1 ] + mc.x_ [ 0 ];
152  x_ [ 1 ] = std :: sin(angle) * dx [ 0 ] + std :: cos(angle) * dx [ 1 ] + mc.x_ [ 1 ];
153  }
154 
155  friend const Scalar eucDistance(const Point &pt0, const Point &pt1) /* Euclidean distance */
156  {
157  Scalar s = 0;
158  for ( int iDim = 0; iDim < dim; ++iDim ) {
159  const Scalar dxi = ( pt0.x_ [ iDim ] - pt1.x_ [ iDim ] );
160  s += ( dxi * dxi );
161  }
162 
163  return std :: sqrt(s);
164  }
165 
167  friend const Scalar angle(const Point &a, const Point &b, const Point &c)
168  {
169  assert(dim == 2);
170 
171  Point ab(b.x() [ 0 ] - a.x() [ 0 ], b.x() [ 1 ] - a.x() [ 1 ]);
172  Point cb(b.x() [ 0 ] - c.x() [ 0 ], b.x() [ 1 ] - c.x() [ 1 ]);
173  Scalar dot = ( ab.x() [ 0 ] * cb.x() [ 0 ] + ab.x() [ 1 ] * cb.x() [ 1 ] ); /* dot product */
174  Scalar cross = ( ab.x() [ 0 ] * cb.x() [ 1 ] - ab.x() [ 1 ] * cb.x() [ 0 ] ); /* cross product */
175 
176  return ( atan2(cross, dot) * ( Constants :: _PI / Constants :: PI ) );
177  }
178 
179  /* return True if the three points a, b and c are colinear */
180  friend const bool colinear(const Point &a, const Point &b, const Point &c)
181  {
182  return ( std :: abs(angle(a, b, c) - 180.0) <= Constants :: TOLERANCE );
183  }
184 
185  friend const std :: vector< Point * > notMarked(const std :: vector< Point * > &vPt0)
186  {
187  std :: vector< Point * > vPt1;
188  vPt1.clear();
189  for ( int iPt = 0; iPt < vPt0.size(); ++iPt ) {
190  if ( !vPt0 [ iPt ]->mark() ) {
191  vPt1.push_back(vPt0 [ iPt ]);
192  }
193  }
194 
195  return vPt1;
196  }
197 
198  friend const bool superposed(const Point &pt0, const Point &pt1)
199  {
200  for ( int iDim = 0; iDim < dim; ++iDim ) {
201  if ( !( std :: abs(pt1.x() [ iDim ] - pt0.x() [ iDim ]) <= Constants :: TOLERANCE ) ) {
202  return false;
203  }
204  }
205 
206  return true;
207  }
208 
209  template< typename VEdgePtrT >
210  friend const bool pointWith3BoundaryEdges(const VEdgePtrT &vEd0)
211  {
212  int res = 0;
213  for ( int ie = 0; ie < vEd0.size(); ++ie ) {
214  if ( vEd0 [ ie ]->onBlockBoundary() ) {
215  ++res;
216  }
217  }
218 
219  return ( res == 3 );
220  }
221 
222  void infos(const std :: string &name0 = "") const
223  {
224  std :: cout << "# point " << name0 << " ";
225 
226  std :: cout << ": (";
227  for ( int i = 0; i < dim - 1; ++i ) {
228  std :: cout << x_ [ i ] << ", ";
229  }
230 
231  std :: cout << x_ [ dim - 1 ] << ")";
232 
233  std :: cout << " , color = " << colorName( this->color() )
234  << " , Id = " << this->Id()
235  << " , mark = " << this->mark()
236  << " , onBlockBoundary = " << this->onBlockBoundary();
237 
238  std :: cout << " , markersize = " << marker_.size
239  << " , markerSymbol = " << marker_.symbol
240  << " , markerEdgeColor = " << colorName(marker_.edgeColor)
241  << " , markerFaceColor = " << colorName(marker_.faceColor) << "\n";
242  }
243 };
244 
245 #endif /* #ifndef _POINT_HH_ */