Version: 6.3.1

src/INTERP_KERNEL/Geometric2D/InterpKernelGeo2DNode.hxx

Go to the documentation of this file.
00001 // Copyright (C) 2007-2011  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 "INTERPKERNELGEOMETRIC2DDefines.hxx"
00025 
00026 #include <cmath>
00027 #include <vector>
00028 #include <iostream>
00029 
00030 namespace INTERP_KERNEL
00031 {
00032   typedef enum
00033     {
00034       IN_1      =  7,
00035       ON_1      =  8,
00036       ON_LIM_1  = 12,
00037       ON_TANG_1 =  9,
00038       OUT_1     = 10,
00039       UNKNOWN   = 11
00040     } TypeOfLocInPolygon;
00041 
00042   class Bounds;
00043   
00047   class INTERPKERNELGEOMETRIC2D_EXPORT Node
00048   {
00049   public:
00050     Node(double x, double y);
00051     Node(const double *coords);
00052     Node(std::istream& stream);
00053     void incrRef() const { _cnt++; }
00054     bool decrRef();
00055     void initLocs() const { _loc=UNKNOWN; }
00056     void setLoc(TypeOfLocInPolygon loc) const { _loc=loc; }
00057     TypeOfLocInPolygon getLoc() const { return _loc; }
00058     void declareIn() const { if(_loc==UNKNOWN) _loc=IN_1; }
00059     void declareOn() const { if(_loc==UNKNOWN) _loc=ON_1; }
00060     void declareOnLim() const { if(_loc==UNKNOWN || _loc==ON_1) _loc=ON_LIM_1; }
00061     void declareOut() { if(_loc==UNKNOWN) _loc=OUT_1; }
00062     void declareOnTangent() { _loc=ON_TANG_1; }
00063     operator const double*() const { return _coords; }
00064     bool isEqual(const Node& other) const;
00065     //returns an angle in -Pi/2;Pi/2.
00066     double getSlope(const Node& other) const;
00067     bool isEqualAndKeepTrack(const Node& other, std::vector<Node *>& track) const;
00068     void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const;
00069     double distanceWithSq(const Node& other) const;
00070     double operator[](int i) const { return _coords[i]; }
00072     void setNewCoords(double x, double y) { _coords[0]=x; _coords[1]=y; }
00073     //returns an angle in -Pi/2;Pi/2.
00074     static double computeSlope(const double *pt1, const double *pt2);
00075     //returns an angle in -Pi;Pi
00076     static double computeAngle(const double *pt1, const double *pt2);
00077     void applySimilarity(double xBary, double yBary, double dimChar);
00078     static double dot(const double *vect1, const double *vect2) { return vect1[0]*vect2[0]+vect1[1]*vect2[1]; }
00079     static double sign(double val) { if(val>=0) return 1.; else return -1.; }
00080     static double norm(const double *vect) { return sqrt(vect[0]*vect[0]+vect[1]*vect[1]); }
00081     static bool areDoubleEquals(double a, double b) { return fabs(a-b) < QUADRATIC_PLANAR::_precision; }
00083     static bool areDoubleEqualsWP(double a, double b, double k) { return fabs(a-b) < k*QUADRATIC_PLANAR::_precision; }
00084     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])); }
00085     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]); }
00086   protected:
00087     ~Node();
00088   protected:
00089     mutable unsigned char _cnt;
00090     mutable TypeOfLocInPolygon _loc;
00091     double _coords[2];
00092   };
00093 }
00094 
00095 #endif
Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS