Back to index

salome-med  6.5.0
InterpKernelGeo2DNode.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 "InterpKernelGeo2DNode.hxx"
00021 #include "InterpKernelGeo2DEdgeArcCircle.hxx"
00022 
00023 using namespace INTERP_KERNEL;
00024 
00025 Node::Node(double x, double y):_cnt(1),_loc(UNKNOWN)
00026 {
00027   _coords[0]=x; _coords[1]=y;
00028 }
00029 
00030 Node::Node(const double *coords):_cnt(1),_loc(UNKNOWN)
00031 {
00032   _coords[0]=coords[0];
00033   _coords[1]=coords[1];
00034 }
00035 
00036 Node::Node(std::istream& stream):_cnt(1),_loc(UNKNOWN)
00037 {
00038   int tmp;
00039   stream >> tmp;
00040   _coords[0]=((double) tmp)/1e4;
00041   stream >> tmp;
00042   _coords[1]=((double) tmp)/1e4;
00043 }
00044 
00045 Node::~Node()
00046 {
00047 }
00048 
00049 bool Node::decrRef()
00050 {
00051   bool ret=(--_cnt==0);
00052   if(ret)
00053     delete this;
00054   return ret;
00055 }
00056 
00057 bool Node::isEqual(const Node& other) const
00058 {
00059   const unsigned SPACEDIM=2;
00060   bool ret=true;
00061   for(unsigned i=0;i<SPACEDIM;i++)
00062     ret&=areDoubleEquals((*this)[i],other[i]);
00063   return ret;
00064 }
00065 
00066 double Node::getSlope(const Node& other) const
00067 {
00068   return computeSlope(*this, other);
00069 }
00070 
00075 bool Node::isEqualAndKeepTrack(const Node& other, std::vector<Node *>& track) const
00076 {
00077   bool ret=isEqual(other);
00078   if(ret)
00079     track.push_back(const_cast<Node *>(&other));
00080   return ret;
00081 }
00082 
00083 void Node::dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const
00084 {
00085   stream << box.fitXForXFig(_coords[0],resolution) << " " << box.fitYForXFig(_coords[1],resolution) << " ";
00086 }
00087 
00088 double Node::distanceWithSq(const Node& other) const
00089 {
00090   return (_coords[0]-other._coords[0])*(_coords[0]-other._coords[0])+(_coords[1]-other._coords[1])*(_coords[1]-other._coords[1]);
00091 }
00092 
00098 double Node::computeSlope(const double *pt1, const double *pt2)
00099 {
00100   double x=pt2[0]-pt1[0];
00101   double y=pt2[1]-pt1[1];
00102   double norm=sqrt(x*x+y*y);
00103   double ret=EdgeArcCircle::SafeAcos(fabs(x)/norm);
00104   if( (x>=0. && y>=0.) || (x<0. && y<0.) )
00105     return ret;
00106   else
00107     return M_PI-ret;
00108 }
00109 
00114 double Node::computeAngle(const double *pt1, const double *pt2)
00115 {
00116   double x=pt2[0]-pt1[0];
00117   double y=pt2[1]-pt1[1];
00118   double norm=sqrt(x*x+y*y);
00119   return EdgeArcCircle::GetAbsoluteAngleOfNormalizedVect(x/norm,y/norm);
00120 }
00121 
00128 void Node::applySimilarity(double xBary, double yBary, double dimChar)
00129 {
00130   _coords[0]=(_coords[0]-xBary)/dimChar;
00131   _coords[1]=(_coords[1]-yBary)/dimChar;
00132 }
00133 
00141 void Node::unApplySimilarity(double xBary, double yBary, double dimChar)
00142 {
00143   _coords[0]=_coords[0]*dimChar+xBary;
00144   _coords[1]=_coords[1]*dimChar+yBary;
00145 }
00146 
00150 void Node::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,
00151                              std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo, int *nodeId) const
00152 {
00153   std::map<INTERP_KERNEL::Node *,int>::const_iterator it=mapThis.find(const_cast<Node *>(this));
00154   if(it!=mapThis.end())
00155     {
00156       *nodeId=(*it).second;
00157       return;
00158     }
00159   it=mapOther.find(const_cast<Node *>(this));
00160   if(it!=mapOther.end())
00161     {
00162       *nodeId=(*it).second+offset1;
00163       return;
00164     }
00165   it=mapAddCoo.find(const_cast<Node *>(this));
00166   if(it!=mapAddCoo.end())
00167     {
00168       *nodeId=(*it).second;
00169       return;
00170     }
00171   int id=(int)addCoo.size()/2;
00172   addCoo.push_back(fact*_coords[0]+baryX);
00173   addCoo.push_back(fact*_coords[1]+baryY);
00174   *nodeId=offset2+id;
00175   mapAddCoo[const_cast<Node *>(this)]=offset2+id;
00176 }
00177 
00181 void Node::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,
00182                               std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo, std::vector<int>& pointsOther) const
00183 {
00184   int tmp;
00185   std::size_t sz1=addCoo.size();
00186   fillGlobalInfoAbs(mapThis,mapOther,offset1,offset2,fact,baryX,baryY,addCoo,mapAddCoo,&tmp);
00187   if(sz1!=addCoo.size())
00188     {
00189       pointsOther.push_back(tmp);
00190       return ;
00191     }
00192   std::vector<int>::const_iterator it=std::find(pointsOther.begin(),pointsOther.end(),tmp);
00193   if(it!=pointsOther.end())
00194     return ;
00195   if(tmp<offset1)
00196     pointsOther.push_back(tmp);
00197 }