Salome HOME
Unwarningization under Win.
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DElementaryEdge.cxx
1 // Copyright (C) 2007-2013  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 // Author : Anthony Geay (CEA/DEN)
20
21 #include "InterpKernelGeo2DElementaryEdge.hxx"
22 #include "InterpKernelException.hxx"
23 #include "InterpKernelGeo2DEdge.hxx"
24
25 using namespace INTERP_KERNEL;
26
27 ElementaryEdge::ElementaryEdge(const ElementaryEdge& other):_direction(other._direction),_ptr(other._ptr)
28 {
29   _ptr->incrRef(); 
30 }
31
32 ElementaryEdge::~ElementaryEdge()
33 {
34   if(_ptr)
35     _ptr->decrRef();
36 }
37
38 bool ElementaryEdge::isNodeIn(Node *n) const
39 {
40   return _ptr->getStartNode()==n || _ptr->getEndNode()==n;
41 }
42
43 /*!
44  * \b WARNING contrary to INTERP_KERNEL::Edge::getBarycenterOfZone method called,
45  * this one is cumulative.
46  */
47 void ElementaryEdge::getBarycenterOfZone(double *bary) const
48 {
49   double tmp[2];
50   _ptr->getBarycenterOfZone(tmp);
51   if(_direction)
52     {
53       bary[0]+=tmp[0];
54       bary[1]+=tmp[1];
55     }
56   else
57     {
58       bary[0]-=tmp[0];
59       bary[1]-=tmp[1];
60     }
61 }
62
63 void ElementaryEdge::fillBounds(Bounds& output) const
64 {
65   output.aggregate(_ptr->getBounds());
66 }
67
68 void ElementaryEdge::getAllNodes(std::set<Node *>& output) const
69 {
70   output.insert(_ptr->getStartNode());
71   output.insert(_ptr->getEndNode());
72 }
73
74 void ElementaryEdge::getBarycenter(double *bary, double& weigh) const
75 {
76   _ptr->getBarycenter(bary);
77   weigh=_ptr->getCurveLength();
78 }
79
80 ElementaryEdge *ElementaryEdge::clone() const
81 {
82   return new ElementaryEdge(*this);
83 }
84
85 void ElementaryEdge::initLocations() const
86 {
87   _ptr->initLocs();
88 }
89
90 /*!
91  * WARNING use this method if and only if this is so that it is completely in/out/on of @param pol.
92  */
93 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelf(const ComposedEdge& pol, TypeOfEdgeLocInPolygon precEdgeLoc) const
94 {
95   if(getLoc()!=FULL_UNKNOWN)
96     return getLoc();
97   //obvious cases
98   if(precEdgeLoc==FULL_IN_1)
99     {
100       if(getStartNode()->getLoc()==ON_1)
101         {
102           declareOut();
103           return getLoc();
104         }
105       else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
106         {
107           declareIn();
108           return getLoc();
109         }
110     }
111   if(precEdgeLoc==FULL_OUT_1)
112     {
113       if(getStartNode()->getLoc()==ON_1)
114         {
115           declareIn();
116           return getLoc();
117         }
118       else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
119         {
120           declareOut();
121           return getLoc();
122         }
123     }
124   if(getStartNode()->getLoc()==IN_1 || getEndNode()->getLoc()==IN_1)
125     {
126       declareIn();
127       return getLoc();
128     }
129   if(getStartNode()->getLoc()==OUT_1 || getEndNode()->getLoc()==OUT_1)
130     {
131       declareOut();
132       return getLoc();
133     }
134   //a seek is requested
135   return locateFullyMySelfAbsolute(pol);
136 }
137
138 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelfAbsolute(const ComposedEdge& pol) const
139 {
140   Node *node=_ptr->buildRepresentantOfMySelf();
141   if(pol.isInOrOut(node))
142     declareIn(); 
143   else
144     declareOut();
145   node->decrRef();
146   return getLoc();
147 }
148
149 Node *ElementaryEdge::getEndNode() const
150
151   if(_direction)
152     return _ptr->getEndNode();
153   else return _ptr->getStartNode();
154 }
155
156 Node *ElementaryEdge::getStartNode() const
157 {
158   if(_direction)
159     return _ptr->getStartNode();
160   else 
161     return _ptr->getEndNode();
162 }
163
164 bool ElementaryEdge::changeEndNodeWith(Node *node) const
165 {
166   if(_direction)
167     return _ptr->changeEndNodeWith(node);
168   else 
169     return _ptr->changeStartNodeWith(node);
170 }
171
172 bool ElementaryEdge::changeStartNodeWith(Node *node) const
173 {
174   if(_direction)
175     return _ptr->changeStartNodeWith(node);
176   else 
177     return _ptr->changeEndNodeWith(node);
178 }
179
180 void ElementaryEdge::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
181 {
182   _ptr->dumpInXfigFile(stream,_direction,resolution,box);
183 }
184
185 bool ElementaryEdge::intresicEqual(const ElementaryEdge *other) const
186 {
187   return _ptr==other->_ptr;
188 }
189
190 bool ElementaryEdge::intresicEqualDirSensitive(const ElementaryEdge *other) const
191 {
192   return ( _direction==other->_direction ) && (_ptr==other->_ptr);
193 }
194
195 bool ElementaryEdge::intresincEqCoarse(const Edge *other) const
196 {
197   return _ptr==other;
198 }
199
200 bool ElementaryEdge::isEqual(const ElementaryEdge& other) const
201 {
202   return _ptr->isEqual(*other._ptr);
203 }
204
205 /*!
206  * Called by QuadraticPolygon::splitAbs method.
207  */
208 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,
209                                        std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const
210 {
211   _ptr->fillGlobalInfoAbs(_direction,mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesThis,addCoo,mapAddCoo);
212 }
213
214 /*!
215  * 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
216  * unsorted because the "other" mesh is not subdivided yet.
217  */
218 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,
219                                         std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const
220 {
221   _ptr->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesOther,addCoo,mapAddCoo);
222 }
223
224 /*!
225  * 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
226  * orientation of edge. Called by QuadraticPolygon::buildFromCrudeDataArray.
227  */
228 ElementaryEdge *ElementaryEdge::BuildEdgeFromCrudeDataArray(bool direction, INTERP_KERNEL::Node *start, INTERP_KERNEL::Node *end)
229 {
230   Edge *ptr=Edge::BuildEdgeFrom(start,end);
231   return new ElementaryEdge(ptr,direction);
232 }