]> SALOME platform Git repositories - tools/medcoupling.git/blob - src/INTERP_KERNEL/Geometric2D/Node.hxx
Salome HOME
Merge from BR_V5_DEV 16Feb09
[tools/medcoupling.git] / src / INTERP_KERNEL / Geometric2D / Node.hxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #ifndef __NODE_HXX__
20 #define __NODE_HXX__
21
22 #include "Precision.hxx"
23 #include "INTERPKERNELGEOMETRIC2DDefines.hxx"
24
25 #include <cmath>
26 #include <vector>
27 #include <iostream>
28
29 namespace INTERP_KERNEL
30 {
31   typedef enum
32     {
33       IN_1      =  7,
34       ON_1      =  8,
35       ON_LIM_1  = 12,
36       ON_TANG_1 =  9,
37       OUT_1     = 10,
38       UNKNOWN   = 11
39     } TypeOfLocInPolygon;
40
41   class Bounds;
42   
43   /*!
44    * As nodes can be shared between edges it is dealed with ref counting.
45    */
46   class INTERPKERNELGEOMETRIC2D_EXPORT Node
47   {
48   public:
49     Node(double x, double y);
50     Node(const double *coords);
51     Node(std::istream& stream);
52     void incrRef() const { _cnt++; }
53     bool decrRef();
54     void initLocs() const { _loc=UNKNOWN; }
55     void setLoc(TypeOfLocInPolygon loc) const { _loc=loc; }
56     TypeOfLocInPolygon getLoc() const { return _loc; }
57     void declareIn() const { if(_loc==UNKNOWN) _loc=IN_1; }
58     void declareOn() const { if(_loc==UNKNOWN) _loc=ON_1; }
59     void declareOnLim() const { if(_loc==UNKNOWN || _loc==ON_1) _loc=ON_LIM_1; }
60     void declareOut() { if(_loc==UNKNOWN) _loc=OUT_1; }
61     void declareOnTangent() { _loc=ON_TANG_1; }
62     operator const double*() const { return _coords; }
63     bool isEqual(const Node& other) const;
64     //returns an angle in -Pi/2;Pi/2.
65     double getSlope(const Node& other) const;
66     bool isEqualAndKeepTrack(const Node& other, std::vector<Node *>& track) const;
67     void dumpInXfigFile(std::ostream& stream, int resolution, const Bounds& box) const;
68     double distanceWithSq(const Node& other) const;
69     double operator[](int i) const { return _coords[i]; }
70     //! use with caution
71     void setNewCoords(double x, double y) { _coords[0]=x; _coords[1]=y; }
72     //returns an angle in -Pi/2;Pi/2.
73     static double computeSlope(const double *pt1, const double *pt2);
74     //returns an angle in -Pi;Pi
75     static double computeAngle(const double *pt1, const double *pt2);
76     void applySimilarity(double xBary, double yBary, double dimChar);
77     static double dot(const double *vect1, const double *vect2) { return vect1[0]*vect2[0]+vect1[1]*vect2[1]; }
78     static double sign(double val) { if(val>=0) return 1.; else return -1.; }
79     static double norm(const double *vect) { return sqrt(vect[0]*vect[0]+vect[1]*vect[1]); }
80     static bool areDoubleEquals(double a, double b) { return fabs(a-b) < QUADRATIC_PLANAR::_precision; }
81     //! idem areDoubleEquals except that precision of comparison is modified.
82     static bool areDoubleEqualsWP(double a, double b, double k) { return fabs(a-b) < k*QUADRATIC_PLANAR::_precision; }
83     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])); }
84     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]); }
85   protected:
86     ~Node();
87   protected:
88     mutable unsigned char _cnt;
89     mutable TypeOfLocInPolygon _loc;
90     double _coords[2];
91   };
92 }
93
94 #endif