Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/med.git] / src / INTERP_KERNEL / Geometric2D / InterpKernelGeo2DEdgeArcCircle.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 __INTERPKERNELGEO2DEDGEARCCIRCLE_HXX__
21 #define __INTERPKERNELGEO2DEDGEARCCIRCLE_HXX__
22
23 #include "INTERPKERNELDefines.hxx"
24 #include "InterpKernelGeo2DEdge.hxx"
25
26 namespace INTERP_KERNEL
27 {
28   class INTERPKERNEL_EXPORT ArcCArcCIntersector : public SameTypeEdgeIntersector
29   {
30   public:
31     ArcCArcCIntersector(const EdgeArcCircle& e1, const EdgeArcCircle& e2);
32     bool haveTheySameDirection() const;
33     void getPlacements(Node *start, Node *end, TypeOfLocInEdge& whereStart, TypeOfLocInEdge& whereEnd, MergePoints& commonNode) const;
34     void areOverlappedOrOnlyColinears(const Bounds *whereToFind, bool& obviousNoIntersection, bool& areOverlapped);
35     std::list< IntersectElement > getIntersectionsCharacteristicVal() const;
36   private:
37     //! return angle in ]-Pi;Pi[ - 'node' must be on curve of '_e1'
38     double getAngle(Node *node) const;
39     static bool areArcsOverlapped(const EdgeArcCircle& a1, const EdgeArcCircle& a2);
40   private:
41     const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
42     const EdgeArcCircle& getE2() const { return (const EdgeArcCircle&)_e2; }
43   private:
44     double _dist;
45   };
46
47   class INTERPKERNEL_EXPORT ArcCSegIntersector : public CrossTypeEdgeIntersector
48   {
49   public:
50     ArcCSegIntersector(const EdgeArcCircle& e1, const EdgeLin& e2, bool reverse=true);
51     //virtual overloading
52     void getPlacements(Node *start, Node *end, TypeOfLocInEdge& whereStart, TypeOfLocInEdge& whereEnd, MergePoints& commonNode) const;
53     void areOverlappedOrOnlyColinears(const Bounds *whereToFind, bool& obviousNoIntersection, bool& areOverlapped);
54     std::list< IntersectElement > getIntersectionsCharacteristicVal() const;
55   private:
56     const EdgeArcCircle& getE1() const { return (const EdgeArcCircle&)_e1; }
57     const EdgeLin& getE2() const { return (const EdgeLin&)_e2; }
58   private:
59     double _dx;
60     double _dy;
61     double _drSq;
62     double _cross;
63     double _determinant;
64   };
65   
66   class INTERPKERNEL_EXPORT EdgeArcCircle : public Edge
67   {
68   public:
69     EdgeArcCircle(std::istream& lineInXfig);
70     EdgeArcCircle(Node *start, Node *middle, Node *end, bool direction = true);
71     EdgeArcCircle(double sX, double sY, double mX, double mY, double eX, double eY);
72     EdgeArcCircle(Node *start, Node *end, const double *center, double radius, double angle0, double deltaAngle, bool direction=true);
73     //! for tests
74     void changeMiddle(Node *newMiddle);
75     void dumpInXfigFile(std::ostream& stream, bool direction, int resolution, const Bounds& box) const;
76     void update(Node *m);
77     double getAreaOfZone() const;
78     double getCurveLength() const;
79     void getBarycenter(double *bary) const;
80     void getBarycenterOfZone(double *bary) const;
81     bool isIn(double characterVal) const;
82     Node *buildRepresentantOfMySelf() const;
83     bool isLower(double val1, double val2) const;
84     double getCharactValue(const Node& node) const;
85     double getCharactValueBtw0And1(const Node& node) const;
86     double getDistanceToPoint(const double *pt) const;
87     bool isNodeLyingOn(const double *coordOfNode) const;
88     TypeOfFunction getTypeOfFunc() const { return ARC_CIRCLE; }
89     void dynCastFunction(const EdgeLin * &seg,
90                          const EdgeArcCircle * &arcSeg) const { arcSeg=this; }
91     const double *getCenter() const { return _center; }
92     void getCenter(double *center) const { center[0]=_center[0]; center[1]=_center[1]; }
93     bool doIHaveSameDirectionAs(const Edge& other) const { return false; }
94     void applySimilarity(double xBary, double yBary, double dimChar);
95     void unApplySimilarity(double xBary, double yBary, double dimChar);
96     double getAngle0() const { return _angle0; }
97     double getRadius() const { return _radius; }
98     double getAngle() const { return _angle; }
99     void tesselate(const int *conn, int offset, double eps, std::vector<int>& newConn, std::vector<double>& addCoo) const;
100     static EdgeArcCircle *BuildFromNodes(Node *start, Node *middle, Node *end);
101     static double GetAbsoluteAngle(const double *vect, double& normVect);
102     static double GetAbsoluteAngleOfNormalizedVect(double ux, double uy);
103     static void GetArcOfCirclePassingThru(const double *start, const double *middle, const double *end, 
104                                           double *center, double& radius, double& angleInRad, double& angleInRad0);
105     //! To avoid in aggressive optimizations nan.
106     static double SafeSqrt(double val) { double ret=std::max(val,0.); return sqrt(ret); }
107     static double SafeAcos(double cosAngle) { double ret=std::min(cosAngle,1.); ret=std::max(ret,-1.); return acos(ret); }
108     static double SafeAsin(double sinAngle) { double ret=std::min(sinAngle,1.); ret=std::max(ret,-1.); return asin(ret); }
109     //! @param start and @param angleIn in ]-Pi;Pi] and @param delta in ]-2*Pi,2*Pi[
110     static bool IsIn2Pi(double start, double delta, double angleIn);
111     //! 'delta' 'start' in ]-Pi;Pi[
112     static bool IsAngleNotIn(double start, double delta, double angleIn);
113     //! for an angle 'angle' in ]-3*Pi;3*Pi[ returns angle in ]-Pi;Pi[
114     static double NormalizeAngle(double angle) { if(angle>M_PI) return angle-2.*M_PI; if(angle<-M_PI) return angle+2.*M_PI; return angle; }
115   protected:
116     void updateBounds();
117     Edge *buildEdgeLyingOnMe(Node *start, Node *end, bool direction=true) const;
118     void fillGlobalInfoAbs(bool direction, 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,
119                            std::vector<int>& edgesThis, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int> mapAddCoo) const;
120     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,
121                             std::vector<int>& edgesOther, std::vector<double>& addCoo, std::map<INTERP_KERNEL::Node *,int>& mapAddCoo) const;
122   protected:
123     //!Value between -2Pi and 2Pi
124     double _angle;
125     //!Value between -Pi and Pi
126     double _angle0;
127     double _radius;
128     double _center[2];
129   };
130 }
131
132 #endif