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