00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef VRS_BOUNDS_H
00021 #define VRS_BOUNDS_H
00022
00023 #include <vrs/matrix.h>
00024 #include <vrs/serializationmanager.h>
00025
00026 namespace VRS {
00027
00029 class VRS_CORE_API Bounds {
00030
00031 public:
00032 Bounds();
00034 explicit Bounds(const Vector& point);
00036 Bounds(const Vector& llf, const Vector& urb);
00038
00041 bool operator==(const Bounds&) const;
00043
00044 bool operator!=(const Bounds&) const;
00046
00047 void addPoint(const Vector& point);
00049 void addVolume(const Bounds& bound);
00051 Bounds& operator+=(const Vector& point);
00053 Bounds& operator+=(const Bounds& bound);
00055 Bounds operator+(const Vector& point) const;
00057 Bounds operator+(const Bounds& bound) const;
00059
00060 Vector getLLF() const;
00062 Vector getURB() const;
00064 Vector point(double x, double y, double z) const;
00066 Vector center() const;
00068
00069 Vector diagonal() const;
00071 double volume() const;
00073
00074 bool isDefined() const;
00076
00077 bool containsPoint(const Vector& p) const;
00079 bool containsPointInPlane(const Vector& p, unsigned int a = 0, unsigned int b = 1) const;
00082 bool containsVolume(const Bounds& b) const;
00084 bool intersects(const Bounds& b) const;
00086 bool intersectsInPlane(const Bounds& bounds, unsigned int a = 0, unsigned int b = 1) const;
00090 Bounds intersection(const Bounds& bounds) const;
00092
00094 void transform(const Matrix& matrix);
00096
00100 void expand(double factor);
00102
00103 friend VRS_CORE_API std::ostream& operator<<(std::ostream&, const Bounds&);
00104 friend VRS_CORE_API std::istream& operator>>(std::istream&, Bounds&);
00105
00106
00107 VRS_SERIALIZABLE_NO_SO_CLASS(Bounds);
00108
00109 private:
00110 Vector llf_;
00111 Vector urb_;
00112 };
00113
00114 inline Bounds::Bounds() : llf_(INF,INF,INF), urb_(-INF,-INF,-INF) { }
00115 inline Bounds::Bounds(const Vector& point) : llf_(point), urb_(point) { }
00116
00117 inline bool Bounds::operator==(const Bounds& v) const { return llf_==v.llf_ && urb_==v.urb_; }
00118 inline bool Bounds::operator!=(const Bounds& v) const { return llf_!=v.llf_ || urb_!=v.urb_; }
00119
00120 inline void Bounds::addVolume(const Bounds& v) { *this += v; }
00121 inline void Bounds::addPoint(const Vector& v) { *this += v; }
00122
00123 inline Bounds Bounds::operator+(const Vector& point) const { Bounds res = *this; return(res += point); }
00124 inline Bounds Bounds::operator+(const Bounds& bound) const { Bounds res = *this; return(res += bound); }
00125
00126 inline Bounds operator*(const Matrix& mat, const Bounds& bounds) { Bounds res = bounds; res.transform(mat); return res; }
00127
00128 inline Vector Bounds::getLLF() const { return llf_; }
00129 inline Vector Bounds::getURB() const { return urb_; }
00130
00131 inline bool Bounds::isDefined() const {
00132 return llf_[0] <= urb_[0] && llf_[1] <= urb_[1] && llf_[2] <= urb_[2];
00133 }
00134
00135 }
00136
00137 #endif // VRS_BOUNDS_H