Back to index

salome-med  6.5.0
InterpKernelGeo2DElementaryEdge.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include "InterpKernelGeo2DElementaryEdge.hxx"
00021 #include "InterpKernelException.hxx"
00022 #include "InterpKernelGeo2DEdge.hxx"
00023 
00024 using namespace INTERP_KERNEL;
00025 
00026 ElementaryEdge::ElementaryEdge(const ElementaryEdge& other):_direction(other._direction),_ptr(other._ptr)
00027 {
00028   _ptr->incrRef(); 
00029 }
00030 
00031 ElementaryEdge::~ElementaryEdge()
00032 {
00033   if(_ptr)
00034     _ptr->decrRef();
00035 }
00036 
00037 bool ElementaryEdge::isNodeIn(Node *n) const
00038 {
00039   return _ptr->getStartNode()==n || _ptr->getEndNode()==n;
00040 }
00041 
00046 void ElementaryEdge::getBarycenterOfZone(double *bary) const
00047 {
00048   double tmp[2];
00049   _ptr->getBarycenterOfZone(tmp);
00050   if(_direction)
00051     {
00052       bary[0]+=tmp[0];
00053       bary[1]+=tmp[1];
00054     }
00055   else
00056     {
00057       bary[0]-=tmp[0];
00058       bary[1]-=tmp[1];
00059     }
00060 }
00061 
00062 void ElementaryEdge::fillBounds(Bounds& output) const
00063 {
00064   output.aggregate(_ptr->getBounds());
00065 }
00066 
00067 void ElementaryEdge::getAllNodes(std::set<Node *>& output) const
00068 {
00069   output.insert(_ptr->getStartNode());
00070   output.insert(_ptr->getEndNode());
00071 }
00072 
00073 void ElementaryEdge::getBarycenter(double *bary, double& weigh) const
00074 {
00075   _ptr->getBarycenter(bary);
00076   weigh=_ptr->getCurveLength();
00077 }
00078 
00079 ElementaryEdge *ElementaryEdge::clone() const
00080 {
00081   return new ElementaryEdge(*this);
00082 }
00083 
00084 void ElementaryEdge::initLocations() const
00085 {
00086   _ptr->initLocs();
00087 }
00088 
00092 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelf(const ComposedEdge& pol, TypeOfEdgeLocInPolygon precEdgeLoc) const
00093 {
00094   if(getLoc()!=FULL_UNKNOWN)
00095     return getLoc();
00096   //obvious cases
00097   if(precEdgeLoc==FULL_IN_1)
00098     {
00099       if(getStartNode()->getLoc()==ON_1)
00100         {
00101           declareOut();
00102           return getLoc();
00103         }
00104       else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
00105         {
00106           declareIn();
00107           return getLoc();
00108         }
00109     }
00110   if(precEdgeLoc==FULL_OUT_1)
00111     {
00112       if(getStartNode()->getLoc()==ON_1)
00113         {
00114           declareIn();
00115           return getLoc();
00116         }
00117       else if(getStartNode()->getLoc()==IN_1 || getStartNode()->getLoc()==ON_TANG_1)
00118         {
00119           declareOut();
00120           return getLoc();
00121         }
00122     }
00123   if(getStartNode()->getLoc()==IN_1 || getEndNode()->getLoc()==IN_1)
00124     {
00125       declareIn();
00126       return getLoc();
00127     }
00128   if(getStartNode()->getLoc()==OUT_1 || getEndNode()->getLoc()==OUT_1)
00129     {
00130       declareOut();
00131       return getLoc();
00132     }
00133   //a seek is requested
00134   return locateFullyMySelfAbsolute(pol);
00135 }
00136 
00137 TypeOfEdgeLocInPolygon ElementaryEdge::locateFullyMySelfAbsolute(const ComposedEdge& pol) const
00138 {
00139   Node *node=_ptr->buildRepresentantOfMySelf();
00140   if(pol.isInOrOut(node))
00141     declareIn(); 
00142   else
00143     declareOut();
00144   node->decrRef();
00145   return getLoc();
00146 }
00147 
00148 Node *ElementaryEdge::getEndNode() const
00149 { 
00150   if(_direction)
00151     return _ptr->getEndNode();
00152   else return _ptr->getStartNode();
00153 }
00154 
00155 Node *ElementaryEdge::getStartNode() const
00156 {
00157   if(_direction)
00158     return _ptr->getStartNode();
00159   else 
00160     return _ptr->getEndNode();
00161 }
00162 
00163 bool ElementaryEdge::changeEndNodeWith(Node *node) const
00164 {
00165   if(_direction)
00166     return _ptr->changeEndNodeWith(node);
00167   else 
00168     return _ptr->changeStartNodeWith(node);
00169 }
00170 
00171 bool ElementaryEdge::changeStartNodeWith(Node *node) const
00172 {
00173   if(_direction)
00174     return _ptr->changeStartNodeWith(node);
00175   else 
00176     return _ptr->changeEndNodeWith(node);
00177 }
00178 
00179 void ElementaryEdge::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
00180 {
00181   _ptr->dumpInXfigFile(stream,_direction,resolution,box);
00182 }
00183 
00184 bool ElementaryEdge::intresicEqual(const ElementaryEdge *other) const
00185 {
00186   return _ptr==other->_ptr;
00187 }
00188 
00189 bool ElementaryEdge::intresicEqualDirSensitive(const ElementaryEdge *other) const
00190 {
00191   return ( _direction==other->_direction ) && (_ptr==other->_ptr);
00192 }
00193 
00194 bool ElementaryEdge::intresincEqCoarse(const Edge *other) const
00195 {
00196   return _ptr==other;
00197 }
00198 
00199 bool ElementaryEdge::isEqual(const ElementaryEdge& other) const
00200 {
00201   return _ptr->isEqual(*other._ptr);
00202 }
00203 
00207 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,
00208                                        std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const
00209 {
00210   _ptr->fillGlobalInfoAbs(_direction,mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesThis,addCoo,mapAddCoo);
00211 }
00212 
00217 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,
00218                                         std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const
00219 {
00220   _ptr->fillGlobalInfoAbs2(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,edgesOther,addCoo,mapAddCoo);
00221 }
00222 
00227 ElementaryEdge *ElementaryEdge::BuildEdgeFromCrudeDataArray(bool direction, INTERP_KERNEL::Node *start, INTERP_KERNEL::Node *end)
00228 {
00229   Edge *ptr=Edge::BuildEdgeFrom(start,end);
00230   return new ElementaryEdge(ptr,direction);
00231 }