Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DElementaryEdge.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "InterpKernelGeo2DElementaryEdge.hxx"
21 #include "InterpKernelException.hxx"
22 #include "InterpKernelGeo2DEdge.hxx"
23
24 using namespace INTERP_KERNEL;
25
26 ElementaryEdge::ElementaryEdge(const ElementaryEdge& other):_direction(other._direction),_ptr(other._ptr)
27 {
28   _ptr->incrRef(); 
29 }
30
31 ElementaryEdge::~ElementaryEdge()
32 {
33   if(_ptr)
34     _ptr->decrRef();
35 }
36
37 bool ElementaryEdge::isNodeIn(Node *n) const
38 {
39   return _ptr->getStartNode()==n || _ptr->getEndNode()==n;
40 }
41
42 /*!
43  * \b WARNING contrary to INTERP_KERNEL::Edge::getBarycenterOfZone method called,
44  * this one is cumulative.
45  */
46 void ElementaryEdge::getBarycenterOfZone(double *bary) const
47 {
48   double tmp[2];
49   _ptr->getBarycenterOfZone(tmp);
50   if(_direction)
51     {
52       bary[0]+=tmp[0];
53       bary[1]+=tmp[1];
54     }
55   else
56     {
57       bary[0]-=tmp[0];
58       bary[1]-=tmp[1];
59     }
60 }
61
62 void ElementaryEdge::fillBounds(Bounds& output) const
63 {
64   output.aggregate(_ptr->getBounds());
65 }
66
67 void ElementaryEdge::getAllNodes(std::set<Node *>& output) const
68 {
69   output.insert(_ptr->getStartNode());
70   output.insert(_ptr->getEndNode());
71 }
72
73 void ElementaryEdge::getBarycenter(double *bary, double& weigh) const
74 {
75   _ptr->getBarycenter(bary);
76   weigh=_ptr->getCurveLength();
77 }
78
79 ElementaryEdge *ElementaryEdge::clone() const
80 {
81   return new ElementaryEdge(*this);
82 }
83
84 void ElementaryEdge::initLocations() const
85 {
86   _ptr->initLocs();
87 }
88
89 /*!
90  * WARNING use this method if and only if this is so that it is completely in/out/on of @param pol.
91  */
92 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelf(const ComposedEdge& pol, TypeOfEdgeLocInPolygon precEdgeLoc) const
93 {
94   if(getLoc()!=FULL_UNKNOWN)
95     return getLoc();
96   //obvious cases
97   if(precEdgeLoc==FULL_IN_1)
98     {
99       if(getStartNode()->getLoc()==ON_1)
100         {
101           declareOut();
102           return getLoc();
103         }
104       else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
105         {
106           declareIn();
107           return getLoc();
108         }
109     }
110   if(precEdgeLoc==FULL_OUT_1)
111     {
112       if(getStartNode()->getLoc()==ON_1)
113         {
114           declareIn();
115           return getLoc();
116         }
117       else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
118         {
119           declareOut();
120           return getLoc();
121         }
122     }
123   if(getStartNode()->getLoc()==IN_1 || getEndNode()->getLoc()==IN_1)
124     {
125       declareIn();
126       return getLoc();
127     }
128   if(getStartNode()->getLoc()==OUT_1 || getEndNode()->getLoc()==OUT_1)
129     {
130       declareOut();
131       return getLoc();
132     }
133   //a seek is requested
134   return locateFullyMySelfAbsolute(pol);
135 }
136
137 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelfAbsolute(const ComposedEdge& pol) const
138 {
139   Node *node=_ptr->buildRepresentantOfMySelf();
140   if(pol.isInOrOut(node))
141     declareIn(); 
142   else
143     declareOut();
144   node->decrRef();
145   return getLoc();
146 }
147
148 Node *ElementaryEdge::getEndNode() const
149
150   if(_direction)
151     return _ptr->getEndNode();
152   else return _ptr->getStartNode();
153 }
154
155 Node *ElementaryEdge::getStartNode() const
156 {
157   if(_direction)
158     return _ptr->getStartNode();
159   else 
160     return _ptr->getEndNode();
161 }
162
163 bool ElementaryEdge::changeEndNodeWith(Node *node) const
164 {
165   if(_direction)
166     return _ptr->changeEndNodeWith(node);
167   else 
168     return _ptr->changeStartNodeWith(node);
169 }
170
171 bool ElementaryEdge::changeStartNodeWith(Node *node) const
172 {
173   if(_direction)
174     return _ptr->changeStartNodeWith(node);
175   else 
176     return _ptr->changeEndNodeWith(node);
177 }
178
179 void ElementaryEdge::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
180 {
181   _ptr->dumpInXfigFile(stream,_direction,resolution,box);
182 }
183
184 bool ElementaryEdge::intresicEqual(const ElementaryEdge *other) const
185 {
186   return _ptr==other->_ptr;
187 }
188
189 bool ElementaryEdge::intresicEqualDirSensitive(const ElementaryEdge *other) const
190 {
191   return ( _direction==other->_direction ) && (_ptr==other->_ptr);
192 }
193
194 bool ElementaryEdge::intresincEqCoarse(const Edge *other) const
195 {
196   return _ptr==other;
197 }
198
199 bool ElementaryEdge::isEqual(const ElementaryEdge& other) const
200 {
201   return _ptr->isEqual(*other._ptr);
202 }
203
204 /*!
205  * Called by QuadraticPolygon::splitAbs method.
206  */
207 void ElementaryEdge::fillGlobalInfoAbs(const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, double fact, double baryX, double baryY,
208                                        std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const
209 {
210   _ptr->fillGlobalInfoAbs(_direction,mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesThis,addCoo,mapAddCoo);
211 }
212
213 /*!
214  * Called by QuadraticPolygon::splitAbs method. Close to ElementaryEdge::fillGlobalInfoAbs method expect that here edgesOther (that replace edgesThis) is here an in/out parameter that only contains nodes
215  * unsorted because the "other" mesh is not subdivided yet.
216  */
217 void ElementaryEdge::fillGlobalInfoAbs2(const std::map<INTERP_KERNEL::Node *,int>& mapThis, const std::map<INTERP_KERNEL::Node *,int>& mapOther, int offset1, int offset2, double fact, double baryX, double baryY,
218                                         std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const
219 {
220   _ptr->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesOther,addCoo,mapAddCoo);
221 }
222
223 /*!
224  * This method builds from descending conn of a quadratic polygon stored in crude mode (MEDCoupling). Descending conn is in FORTRAN relative mode in order to give the
225  * orientation of edge. Called by QuadraticPolygon::buildFromCrudeDataArray.
226  */
227 ElementaryEdge *ElementaryEdge::BuildEdgeFromCrudeDataArray(bool direction, INTERP_KERNEL::Node *start, INTERP_KERNEL::Node *end)
228 {
229   Edge *ptr=Edge::BuildEdgeFrom(start,end);
230   return new ElementaryEdge(ptr,direction);
231 }