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(const fmat::Column<3> otherCoords) { coords = otherCoords; }
00054   void setCoords(coordinate_t x, coordinate_t y, coordinate_t z=0) { coords[0]=x; coords[1]=y; coords[2]=z; }
00055   //@}
00056 
00057   //! Set reference frame type
00058   void setRefFrameType(const ReferenceFrameType_t ref) { refFrameType = ref; }
00059 
00060   //! Euclidean distance from another point to this one
00061   float distanceFrom(const Point& other) const;
00062 
00063   //! Euclidean distance from another point to this one, looking only at the x-y projection; z coordinates are ignored
00064   float xyDistanceFrom(const Point& other) const;
00065 
00066   //! Angle in xy-plane encoded by this vector
00067   AngSignPi atanYX() const;
00068 
00069   //! Length of the vector's projection in the x-y plane z coordinate is ignored
00070   float xyNorm() const;
00071 
00072   //! Length of the xyz vector
00073   float xyzNorm() const;
00074 
00075   //! Unit vector in the direction of this point
00076   Point unitVector() const;
00077 
00078   //! These functions need a ShapeSpace argument because left/right depends on reference frame type.
00079   //@{
00080   bool isLeftOf(const Point& other, float distance=0) const;
00081   bool isRightOf(const Point& other, float distance=0) const;
00082   bool isAbove(const Point& other, float distance=0) const;
00083   bool isBelow(const Point& other, float distance=0) const;
00084 //@}
00085 
00086   //! These functions return true based on relative positions, assuming points lie in some x-y plane (z coordinate is ignored).
00087   //@{
00088   bool isBetween(const Point& other1, const Point& other2) const;
00089   bool isBetween(const Shape<LineData>& line1, const Shape<LineData>& line2) const;
00090   bool isBetween(const LineData& line1, const LineData& line2) const;
00091   bool isInside(const std::vector<LineData>& bound) const;
00092 //@}
00093 
00094   float getHeightAbovePoint(const Point& groundPoint, const PlaneEquation& groundplane);
00095   
00096 
00097   void applyTransform(const fmat::Transform& T, const ReferenceFrameType_t newref=unspecified);
00098   
00099   //! projects this to ground plane according to camToBase matrix
00100   bool projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane);
00101 
00102   bool projectToGround(int xres, int yres, const PlaneEquation& groundplane);
00103 
00104   Point operator+(const Point& b) const;
00105   Point& operator+=(const Point& b);
00106 
00107   Point operator-(const Point& b) const;
00108   Point& operator-=(const Point& b);
00109 
00110   Point operator*(float b) const;
00111   Point& operator*=(float b);
00112 
00113   Point operator/(float b) const;
00114   Point& operator/=(float b);
00115 
00116   bool operator==(const Point& b) const;
00117   bool operator!=(const Point& b) const { return !operator==(b); }
00118 
00119   Point& operator=(const Point& b) {
00120     if (&b==this) return *this;
00121     setCoords(b);
00122     refFrameType = b.refFrameType;
00123     return *this;
00124   }
00125 
00126   void printData() const;
00127 
00128   friend class EndPoint;
00129 
00130   friend std::ostream& operator<< (std::ostream& out, const Point &p) {
00131     switch ( p.refFrameType ) {
00132       case unspecified:
00133         out << "u:";
00134         break;
00135       case camcentric:
00136         out << "c:";
00137         break;
00138       case egocentric:
00139         out << "e:";
00140         break;
00141       case allocentric:
00142         out << "a:";
00143         break;
00144       default:
00145         out <<"?:";
00146     }
00147     out << "[" << p.coordX() << ", " << p.coordY() 
00148     << ", " << p.coordZ() << "]";
00149     return out;
00150   }
00151   
00152 private:
00153   void makeRefFrameCompatible(const Point &other);
00154 
00155 };
00156 
00157 inline Point& leftMost(Point &pt1, Point &pt2) { return pt1.isLeftOf(pt2) ? pt1 : pt2; }
00158 inline Point& rightMost(Point &pt1, Point &pt2) { return pt1.isLeftOf(pt2) ? pt2 : pt1; }
00159 inline Point& topMost(Point &pt1, Point &pt2) { return pt1.isAbove(pt2) ? pt1 : pt2; }
00160 inline Point& bottomMost(Point &pt1, Point &pt2) { return pt1.isAbove(pt2) ? pt2 : pt1; }
00161 inline const Point& leftMost(const Point &pt1, const Point &pt2) { return pt1.isLeftOf(pt2) ? pt1 : pt2; }
00162 inline const Point& rightMost(const Point &pt1, const Point &pt2) { return pt1.isLeftOf(pt2) ? pt2 : pt1; }
00163 inline const Point& topMost(const Point &pt1, const Point &pt2) { return pt1.isAbove(pt2) ? pt1 : pt2; }
00164 inline const Point& bottomMost(const Point &pt1, const Point &pt2) { return pt1.isAbove(pt2) ? pt2 : pt1; }
00165 
00166 } // namespace
00167 
00168 #endif

DualCoding 5.1CVS
Generated Mon May 9 04:56:27 2016 by Doxygen 1.6.3