Point.h
Go to the documentation of this file.00001
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"
00011 #include "ShapeTypes.h"
00012
00013 namespace DualCoding {
00014
00015 class LineData;
00016 template<typename T> class Shape;
00017
00018
00019
00020
00021
00022
00023 class Point {
00024
00025 public:
00026 fmat::Column<3> coords;
00027 ReferenceFrameType_t refFrameType;
00028
00029
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
00039 Point(const Point& otherPt) : coords(otherPt.coords), refFrameType(otherPt.refFrameType) {}
00040
00041
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
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
00057 void setRefFrameType(const ReferenceFrameType_t ref) { refFrameType = ref; }
00058
00059
00060 float distanceFrom(const Point& other) const;
00061
00062
00063 float xyDistanceFrom(const Point& other) const;
00064
00065
00066 AngSignPi atanYX() const;
00067
00068
00069 float xyNorm() const;
00070
00071
00072 float xyzNorm() const;
00073
00074
00075 Point unitVector() const;
00076
00077
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
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
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 }
00166
00167 #endif