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(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
00058 void setRefFrameType(const ReferenceFrameType_t ref) { refFrameType = ref; }
00059
00060
00061 float distanceFrom(const Point& other) const;
00062
00063
00064 float xyDistanceFrom(const Point& other) const;
00065
00066
00067 AngSignPi atanYX() const;
00068
00069
00070 float xyNorm() const;
00071
00072
00073 float xyzNorm() const;
00074
00075
00076 Point unitVector() const;
00077
00078
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
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
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 }
00167
00168 #endif