msbGrid  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edge.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 _EDGE_HH_
24 #define _EDGE_HH_
25 
26 #include <geometricentity.hh>
27 
28 class msbGrid :: Edge : public msbGrid :: GeometricEntity
29 {
30 public:
32 
36 
37  enum { dim = msbGrid :: dim };
38  static const int verticesNumber_ = 2;
39 
40 private:
42 
43 public:
44 
45  Edge(Point * p0, Point * p1) : ParentT()
46  {
47  this->vPt_.clear();
48  this->vPt_.push_back(p0);
49  this->vPt_.push_back(p1);
50 
51  this->vEd_.push_back(this);
52  this->vCel_.clear();
53 
54  eucSize_ = eucDistance(* p0, * p1);
55  }
56 
57  ~Edge() {}
58 
59  const Scalar &eucSize() const
60  { return eucSize_; }
61 
63  { return eucSize_; }
64 
65  const std :: vector< Scalar > pos() const /* TODO add primary variable pos_ */
66  {
67  std :: vector< Scalar > pos0;
68  pos0.resize(dim);
69  pos0.assign( dim, Scalar(0.0) );
70 
71  for ( int iDim = 0; iDim < dim; ++iDim ) {
72  for ( int iPt = 0; iPt < this->vPt_.size(); ++iPt ) {
73  pos0 [ iDim ] += this->vPt_ [ iPt ]->pos() [ iDim ];
74  }
75  }
76 
77  for ( int iDim = 0; iDim < dim; ++iDim ) {
78  pos0 [ iDim ] /= verticesNumber_;
79  }
80 
81  return pos0;
82  }
83 
84  const bool has(const Point &p0) const
85  {
86  return ( superposed(p0, * this->vPt() [ 0 ]) || superposed(p0, * this->vPt() [ 1 ]) );
87  }
88 
89  const int indexOf(const Point &p0) const
90  {
91  return superposed(p0, * this->vPt() [ 0 ]) ? 0 :
92  superposed(p0, * this->vPt() [ 1 ]) ? 1 : ( -1 );
93  }
94 
95  friend const bool superposed0(const Edge &e0, const Edge &e1)
96  {
97  return ( superposed(* e0.vPt() [ 0 ], * e1.vPt() [ 0 ]) && superposed(* e0.vPt() [ 1 ], * e1.vPt() [ 1 ]) );
98  }
99 
100  friend const bool superposed1(const Edge &e0, const Edge &e1)
101  {
102  return ( superposed(* e0.vPt() [ 0 ], * e1.vPt() [ 1 ]) && superposed(* e0.vPt() [ 1 ], * e1.vPt() [ 0 ]) );
103  }
104 
105  friend const bool superposed(const Edge &e0, const Edge &e1)
106  {
107  return ( superposed0(e0, e1) || superposed1(e0, e1) );
108  }
109 
110  friend const bool oneSharedPoint(const Edge &e0, const Edge &e1)
111  {
112  int sharedPointsNumber = 0;
113  if ( superposed(* e0.vPt() [ 0 ], * e1.vPt() [ 0 ]) ) {
114  ++sharedPointsNumber;
115  }
116 
117  if ( superposed(* e0.vPt() [ 0 ], * e1.vPt() [ 1 ]) ) {
118  ++sharedPointsNumber;
119  }
120 
121  if ( superposed(* e0.vPt() [ 1 ], * e1.vPt() [ 0 ]) ) {
122  ++sharedPointsNumber;
123  }
124 
125  if ( superposed(* e0.vPt() [ 1 ], * e1.vPt() [ 1 ]) ) {
126  ++sharedPointsNumber;
127  }
128 
129  return ( sharedPointsNumber == 1 );
130  }
131 
132  /*
133  * add the right side neighbor edge of ve1 that exist in ve0
134  * Notes :
135  * leftSideNeighbor = edge from ve0 sharing with ve1 its first point of its first edge : ve1.front()->vPt()[0]
136  * rightSideNeighbor = edge from ve0 sharing with ve1 its last second point of its last edge : ve1.back()->vPt()[1]
137  */
138  friend bool addLeftSideNeighbor(const std :: vector< Edge * > &ve0, std :: vector< Edge * > &ve1, int &headPointIndex)
139  {
140  std :: vector< Edge * > neighbors;
141  neighbors.clear();
142  int newHeadPointIndex = -1;
143  for ( int ie0 = 0; ie0 < ve0.size(); ++ie0 ) {
144  if ( ve0 [ ie0 ]->has(* ve1.front()->vPt() [ headPointIndex ]) && !superposed( * ve0 [ ie0 ], * ve1.front() ) ) {
145  neighbors.push_back(ve0 [ ie0 ]);
146  newHeadPointIndex = 1 - ( ve0 [ ie0 ]->indexOf(* ve1.front()->vPt() [ headPointIndex ]) );
147  }
148  }
149 
150  if ( neighbors.size() > 1 ) {
151  std :: cerr << "error : neighbors.size() must be 0 or 1 in Edge::addLeftSideNeighbor()\n";
152  std :: cerr << "exiting the program by calling : std::exit(1);\n";
153  std :: exit(1);
154  }
155 
156  ve1.insert(ve1.begin(), neighbors [ 0 ]);
157  headPointIndex = newHeadPointIndex;
158  return ( neighbors.size() == 1 );
159  }
160 
161  void translate(const std :: vector< Scalar > &dx)
162  {
163  for ( int iPt = 0; iPt < verticesNumber_; ++iPt ) {
164  this->vPt_ [ iPt ]->translate(dx);
165  }
166  }
167 
168  void infos(const std :: string &name0 = "") const
169  {
170  std :: cout << "# edge " << name0 << " ";
171 
172  std :: cout << ": color = " << colorName( this->color() )
173  << " , Id = " << this->Id()
174  << " , mark = " << this->mark()
175  << " , onBlockBoundary = " << this->onBlockBoundary() << "\n";
176 
177  this->vPt() [ 0 ]->infos();
178  this->vPt() [ 1 ]->infos();
179  }
180 };
181 
182 #endif /* _EDGE_HH_ */