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