Go to the documentation of this file.00001
00007 #ifndef P_SPOLYGON_HH
00008 #define P_SPOLYGON_HH
00009
00010
00011
00012 #include <float.h>
00013 #include <map>
00014 #include <blort/Recognizer3D/Vector2.hh>
00015 #include <blort/Recognizer3D/PNamespace.hh>
00016 #include <blort/Recognizer3D/Array.hh>
00017
00018 #ifdef USE_VS_CLOSURES
00019 #include <blort/Recognizer3D/Closure.hh>
00020 #endif
00021
00022 namespace P
00023 {
00024
00025 class SPolygon
00026 {
00027 public:
00028 Array<Vector2> v;
00029 Vector2 center;
00030 unsigned p;
00031
00032 SPolygon();
00033 #ifdef USE_VS_CLOSURES
00034 SPolygon(Closure *c);
00035 #endif
00036 SPolygon(Array<Vector2> &p);
00037 ~SPolygon(){};
00038 void SetConvexHull(Array<Vector2> &p);
00039 void Expand(double d);
00040 bool Inside(double x, double y);
00041 bool OnContour(double x, double y, double eps);
00042 inline bool Inside(Vector2 &p) {return Inside(p.x,p.y);}
00043 inline void Clear(){v.Clear();}
00044 inline unsigned Size(){return v.Size();}
00045 inline void PushBack(Vector2 &p){v.PushBack(p);}
00046 inline unsigned NumVertices(){return v.Size();}
00047 inline void Insert(Vector2 &p){v.PushBack(p);}
00048 inline void Move(Vector2 &dist);
00049 inline double Area(){return Area(v);}
00050 void CenterOfGravity();
00051
00052 static bool Inside(Array<Vector2> &vs, Vector2 &p);
00053 static double NearestLine(Vector2 &p, Array<Vector2> &vs, unsigned &id);
00054 static double NearestNeighbour(Vector2 &p, Array<Vector2> &vs, unsigned &id);
00055 static double Match(Array<Vector2> &vs1, Array<Vector2> &vs2);
00056 static void CenterOfGravity(Array<Vector2> &vs, Vector2 &vc);
00057 static double Area ( Array<Vector2> &vs );
00058 static void Load(ifstream &is, SPolygon &p);
00059 static void Save(ofstream &os, const SPolygon &p);
00060
00061 SPolygon &operator=(const SPolygon &p);
00062 Vector2& operator[](unsigned i){return v[i];}
00063 };
00064
00065
00066
00067 inline void SPolygon::CenterOfGravity()
00068 {
00069 if (v.Size()>0){
00070 center=P::Vector2(0.,0.);
00071 for (unsigned i=0; i<v.Size(); i++)
00072 center+=v[i];
00073 center/=v.Size();
00074 }
00075 }
00076
00080 inline void SPolygon::Move(Vector2 &dist)
00081 {
00082 if (center.x!=DBL_MAX)
00083 center+=dist;
00084 for (unsigned i=0; i<v.Size(); i++)
00085 v[i]+=dist;
00086 }
00087
00088
00089 }
00090
00091 #endif
00092
blort
Author(s): Michael Zillich,
Thomas Mörwald,
Johann Prankl,
Andreas Richtsfeld,
Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:25