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


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12