1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay (CEA/DEN)
21 #include "InterpKernelGeo2DElementaryEdge.hxx"
22 #include "InterpKernelException.hxx"
23 #include "InterpKernelGeo2DEdge.hxx"
24 #include "InterpKernelGeo2DComposedEdge.hxx"
26 using namespace INTERP_KERNEL;
28 ElementaryEdge::ElementaryEdge(const ElementaryEdge& other):_direction(other._direction),_ptr(other._ptr)
33 ElementaryEdge::~ElementaryEdge()
39 bool ElementaryEdge::isNodeIn(Node *n) const
41 return _ptr->getStartNode()==n || _ptr->getEndNode()==n;
45 * \b WARNING contrary to INTERP_KERNEL::Edge::getBarycenterOfZone method called,
46 * this one is cumulative.
48 void ElementaryEdge::getBarycenterOfZone(double *bary) const
51 _ptr->getBarycenterOfZone(tmp);
64 void ElementaryEdge::fillBounds(Bounds& output) const
66 output.aggregate(_ptr->getBounds());
69 void ElementaryEdge::getAllNodes(std::set<Node *>& output) const
71 output.insert(_ptr->getStartNode());
72 output.insert(_ptr->getEndNode());
75 bool ElementaryEdge::hasSameExtremities(const ElementaryEdge& other) const
77 std::set<Node *> s1, s2;
79 other.getAllNodes(s2);
83 void ElementaryEdge::getBarycenter(double *bary, double& weigh) const
85 _ptr->getBarycenter(bary);
86 weigh=_ptr->getCurveLength();
89 ElementaryEdge *ElementaryEdge::clone() const
91 return new ElementaryEdge(*this);
94 void ElementaryEdge::initLocations() const
100 * WARNING use this method if and only if this is so that it is completely in/out/on of @param pol.
102 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelf(const ComposedEdge& pol, TypeOfEdgeLocInPolygon precEdgeLoc) const
104 if(getLoc()!=FULL_UNKNOWN)
107 if(precEdgeLoc==FULL_IN_1)
109 if(getStartNode()->getLoc()==ON_1)
114 else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
120 if(precEdgeLoc==FULL_OUT_1)
122 if(getStartNode()->getLoc()==ON_1)
127 else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
133 if(getStartNode()->getLoc()==IN_1 || getEndNode()->getLoc()==IN_1)
138 if(getStartNode()->getLoc()==OUT_1 || getEndNode()->getLoc()==OUT_1)
143 //a seek is requested
144 return locateFullyMySelfAbsolute(pol);
147 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelfAbsolute(const ComposedEdge& pol) const
149 Node *node=_ptr->buildRepresentantOfMySelf(); // build barycenter used to detect if the edge is IN or OUT
150 if(pol.isInOrOut(node))
158 Node *ElementaryEdge::getEndNode() const
161 return _ptr->getEndNode();
162 else return _ptr->getStartNode();
165 Node *ElementaryEdge::getStartNode() const
168 return _ptr->getStartNode();
170 return _ptr->getEndNode();
173 bool ElementaryEdge::changeEndNodeWith(Node *node) const
176 return _ptr->changeEndNodeWith(node);
178 return _ptr->changeStartNodeWith(node);
181 bool ElementaryEdge::changeStartNodeWith(Node *node) const
184 return _ptr->changeStartNodeWith(node);
186 return _ptr->changeEndNodeWith(node);
189 void ElementaryEdge::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
191 _ptr->dumpInXfigFile(stream,_direction,resolution,box);
194 void ElementaryEdge::dumpToCout(const std::map<INTERP_KERNEL::Node *,int>& mapp, int index) const
196 _ptr->dumpToCout(mapp, index);
199 bool ElementaryEdge::intresicEqual(const ElementaryEdge *other) const
201 return _ptr==other->_ptr;
204 bool ElementaryEdge::intresicEqualDirSensitive(const ElementaryEdge *other) const
206 return ( _direction==other->_direction ) && (_ptr==other->_ptr);
209 bool ElementaryEdge::intresincEqCoarse(const Edge *other) const
214 bool ElementaryEdge::isEqual(const ElementaryEdge& other) const
216 return _ptr->isEqual(*other._ptr);
220 * Called by QuadraticPolygon::splitAbs method.
222 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,
223 std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const
225 _ptr->fillGlobalInfoAbs(_direction,mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesThis,addCoo,mapAddCoo);
229 * 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
230 * unsorted because the "other" mesh is not subdivided yet.
232 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,
233 short skipStartOrEnd,
234 std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const
237 skipStartOrEnd *= -1; // invert value - see QuadraticPolygon::splitAbs()
238 _ptr->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,skipStartOrEnd,edgesOther,addCoo,mapAddCoo);
242 * This method builds from a \a start node, an \a end node and a direction a new ElementaryEdge.
244 ElementaryEdge *ElementaryEdge::BuildEdgeFromStartEndDir(bool direction, INTERP_KERNEL::Node *start, INTERP_KERNEL::Node *end)
246 Edge *ptr=Edge::BuildEdgeFrom(start,end);
247 return new ElementaryEdge(ptr,direction);