Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

Point.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _POINT_H_
00003 #define _POINT_H_
00004 
00005 #include <iostream>
00006 #include <vector>
00007 
00008 #include "Shared/fmatSpatial.h"
00009 
00010 #include "Shared/Measures.h"   // coordinate_t, AngPi
00011 #include "ShapeTypes.h" // ReferenceFrameType_t
00012 
00013 namespace DualCoding {
00014 
00015 class LineData;
00016 template<typename T> class Shape;
00017 
00018 /*! We define Point as a separate lightweight class because it is used
00019  * as a component of all the xxxData classes, and we don't want to nest
00020  * these structures.
00021  */
00022 
00023 class Point {
00024 
00025 public:
00026   fmat::Column<3> coords;
00027   ReferenceFrameType_t refFrameType;
00028 
00029   //! Constructors
00030   //@{
00031   Point() : coords(), refFrameType(unspecified) {}
00032   Point(coordinate_t const &xp, coordinate_t const &yp, coordinate_t zp=0, ReferenceFrameType_t ref=unspecified)
00033   : coords(fmat::pack(xp, yp, zp)), refFrameType(ref) {}
00034   Point(const fmat::SubVector<3,const float>& c, ReferenceFrameType_t ref=unspecified)
00035   : coords(c), refFrameType(ref) {}
00036   //@}
00037 
00038   //! Copy constructor
00039   Point(const Point& otherPt) : coords(otherPt.coords), refFrameType(otherPt.refFrameType) {}
00040 
00041   //! Destructor
00042   virtual ~Point() { }
00043 
00044   fmat::Column<3>& getCoords() const { return const_cast<Point*>(this)->coords; }
00045   coordinate_t coordX() const { return coords[0]; }
00046   coordinate_t coordY() const { return coords[1]; }
00047   coordinate_t coordZ() const { return coords[2]; }
00048   ReferenceFrameType_t getRefFrameType() const { return refFrameType; }
00049 
00050   //! Set position.
00051   //@{
00052   void setCoords(const Point& otherPt) { coords = otherPt.coords; }
00053   void setCoords(coordinate_t x, coordinate_t y, coordinate_t z=0) { coords[0]=x; coords[1]=y; coords[2]=z; }
00054   //@}
00055 
00056   //! Set reference frame type
00057   void setRefFrameType(const ReferenceFrameType_t ref) { refFrameType = ref; }
00058 
00059   //! Euclidean distance from another point to this one
00060   float distanceFrom(const Point& other) const;
00061 
00062   //! Euclidean distance from another point to this one, looking only at the x-y projection; z coordinates are ignored
00063   float xyDistanceFrom(const Point& other) const;
00064 
00065   //! Angle in xy-plane encoded by this vector
00066   AngSignPi atanYX() const;
00067 
00068   //! Length of the vector's projection in the x-y plane z coordinate is ignored
00069   float xyNorm() const;
00070 
00071   //! Length of the xyz vector
00072   float xyzNorm() const;
00073 
00074   //! Unit vector in the direction of this point
00075   Point unitVector() const;
00076 
00077   //! These functions need a ShapeSpace argument because left/right depends on reference frame type.
00078   //@{
00079   bool isLeftOf(const Point& other, float distance=0) const;
00080   bool isRightOf(const Point& other, float distance=0) const;
00081   bool isAbove(const Point& other, float distance=0) const;
00082   bool isBelow(const Point& other, float distance=0) const;
00083 //@}
00084 
00085   //! These functions return true based on relative positions, assuming points lie in some x-y plane (z coordinate is ignored).
00086   //@{
00087   bool isBetween(const Point& other1, const Point& other2) const;
00088   bool isBetween(const Shape<LineData>& line1, const Shape<LineData>& line2) const;
00089   bool isBetween(const LineData& line1, const LineData& line2) const;
00090   bool isInside(const std::vector<LineData>& bound) const;
00091 //@}
00092 
00093   float getHeightAbovePoint(const Point& groundPoint, const PlaneEquation& groundplane);
00094   
00095 
00096   void applyTransform(const fmat::Transform& T, const ReferenceFrameType_t newref=unspecified);
00097   
00098   //! projects this to ground plane according to camToBase matrix
00099   bool projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane);
00100 
00101   bool projectToGround(int xres, int yres, const PlaneEquation& groundplane);
00102 
00103   Point operator+(const Point& b) const;
00104   Point& operator+=(const Point& b);
00105 
00106   Point operator-(const Point& b) const;
00107   Point& operator-=(const Point& b);
00108 
00109   Point operator*(float b) const;
00110   Point& operator*=(float b);
00111 
00112   Point operator/(float b) const;
00113   Point& operator/=(float b);
00114 
00115   bool operator==(const Point& b) const;
00116   bool operator!=(const Point& b) const { return !operator==(b); }
00117 
00118   Point& operator=(const Point& b) {
00119     if (&b==this) return *this;
00120     setCoords(b);
00121     refFrameType = b.refFrameType;
00122     return *this;
00123   }
00124 
00125   void printData() const;
00126 
00127   friend class EndPoint;
00128 
00129   friend std::ostream& operator<< (std::ostream& out, const Point &p) {
00130     switch ( p.refFrameType ) {
00131       case unspecified:
00132         out << "u:";
00133         break;
00134       case camcentric:
00135         out << "c:";
00136         break;
00137       case egocentric:
00138         out << "e:";
00139         break;
00140       case allocentric:
00141         out << "a:";
00142         break;
00143       default:
00144         out <<"?:";
00145     }
00146     out << "[" << p.coordX() << ", " << p.coordY() 
00147     << ", " << p.coordZ() << "]";
00148     return out;
00149   }
00150   
00151 private:
00152   void makeRefFrameCompatible(const Point &other);
00153 
00154 };
00155 
00156 inline Point& leftMost(Point &pt1, Point &pt2) { return pt1.isLeftOf(pt2) ? pt1 : pt2; }
00157 inline Point& rightMost(Point &pt1, Point &pt2) { return pt1.isLeftOf(pt2) ? pt2 : pt1; }
00158 inline Point& topMost(Point &pt1, Point &pt2) { return pt1.isAbove(pt2) ? pt1 : pt2; }
00159 inline Point& bottomMost(Point &pt1, Point &pt2) { return pt1.isAbove(pt2) ? pt2 : pt1; }
00160 inline const Point& leftMost(const Point &pt1, const Point &pt2) { return pt1.isLeftOf(pt2) ? pt1 : pt2; }
00161 inline const Point& rightMost(const Point &pt1, const Point &pt2) { return pt1.isLeftOf(pt2) ? pt2 : pt1; }
00162 inline const Point& topMost(const Point &pt1, const Point &pt2) { return pt1.isAbove(pt2) ? pt1 : pt2; }
00163 inline const Point& bottomMost(const Point &pt1, const Point &pt2) { return pt1.isAbove(pt2) ? pt2 : pt1; }
00164 
00165 } // namespace
00166 
00167 #endif

DualCoding 5.1CVS
Generated Sat May 4 06:29:28 2013 by Doxygen 1.6.3