Back to index

salome-med  6.5.0
InterpKernelGeo2DNode.hxx
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 #ifndef __INTERPKERNELGEO2DNODE_HXX__
00021 #define __INTERPKERNELGEO2DNODE_HXX__
00022 
00023 #include "InterpKernelGeo2DPrecision.hxx"
00024 #include "INTERPKERNELDefines.hxx"
00025 
00026 #include <map>
00027 #include <cmath>
00028 #include <vector>
00029 #include <iostream>
00030 
00031 namespace INTERP_KERNEL
00032 {
00033   typedef enum
00034     {
00035       IN_1      =  7,
00036       ON_1      =  8,
00037       ON_LIM_1  = 12,
00038       ON_TANG_1 =  9,
00039       OUT_1     = 10,
00040       UNKNOWN   = 11
00041     } TypeOfLocInPolygon;
00042 
00043   class Bounds;
00044   
00048   class INTERPKERNEL_EXPORT Node
00049   {
00050   public:
00051     Node(double x, double y);
00052     Node(const double *coords);
00053     Node(std::istream& stream);
00054     void incrRef() const { _cnt++; }
00055     bool decrRef();
00056     void initLocs() const { _loc=UNKNOWN; }
00057     void setLoc(TypeOfLocInPolygon loc) const { _loc=loc; }
00058     TypeOfLocInPolygon getLoc() const { return _loc; }
00059     void declareIn() const { if(_loc==UNKNOWN) _loc=IN_1; }
00060     void declareOn() const { if(_loc==UNKNOWN) _loc=ON_1; }
00061     void declareOnLim() const { if(_loc==UNKNOWN || _loc==ON_1) _loc=ON_LIM_1; }
00062     void declareOut() { if(_loc==UNKNOWN) _loc=OUT_1; }
00063     void declareOnTangent() { _loc=ON_TANG_1; }
00064     operator const double*() const { return _coords; }
00065     bool isEqual(const Node& other) const;
00066     //returns an angle in -Pi/2;Pi/2.
00067     double getSlope(const Node& other) const;
00068     bool isEqualAndKeepTrack(const Node& other, std::vector<Node *>& track) const;
00069     void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const;
00070     double distanceWithSq(const Node& other) const;
00071     double operator[](int i) const { return _coords[i]; }
00073     void setNewCoords(double x, double y) { _coords[0]=x; _coords[1]=y; }
00074     //returns an angle in -Pi/2;Pi/2.
00075     static double computeSlope(const double *pt1, const double *pt2);
00076     //returns an angle in -Pi;Pi
00077     static double computeAngle(const double *pt1, const double *pt2);
00078     void applySimilarity(double xBary, double yBary, double dimChar);
00079     void unApplySimilarity(double xBary, double yBary, double dimChar);
00080     static double dot(const double *vect1, const double *vect2) { return vect1[0]*vect2[0]+vect1[1]*vect2[1]; }
00081     static double sign(double val) { if(val>=0) return 1.; else return -1.; }
00082     static double norm(const double *vect) { return sqrt(vect[0]*vect[0]+vect[1]*vect[1]); }
00083     static bool areDoubleEquals(double a, double b) { return fabs(a-b) < QUADRATIC_PLANAR::_precision; }
00085     static bool areDoubleEqualsWP(double a, double b, double k) { return fabs(a-b) < k*QUADRATIC_PLANAR::_precision; }
00086     static double distanceBtw2Pt(const double *a, const double *b) { return sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1])); }
00087     static double distanceBtw2PtSq(const double *a, const double *b) { return (a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1]); }
00088     //
00089     void 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,
00090                            std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo, int *nodeId) const;
00091     void 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,
00092                             std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo, std::vector<int>& pointsOther) const;
00093   protected:
00094     ~Node();
00095   protected:
00096     mutable unsigned char _cnt;
00097     mutable TypeOfLocInPolygon _loc;
00098     double _coords[2];
00099   };
00100 }
00101 
00102 #endif