Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00074 static double computeSlope(const double *pt1, const double *pt2);
00075
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