00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef WFMATH_AXIS_BOX_H
00030 #define WFMATH_AXIS_BOX_H
00031
00032 #include <wfmath/const.h>
00033 #include <wfmath/vector.h>
00034 #include <wfmath/point.h>
00035 #include <wfmath/intersect_decls.h>
00036
00037 namespace WFMath {
00038
00039 template<const int dim> class AxisBox;
00040 template<const int dim> class Ball;
00041
00042 template<const int dim>
00043 bool Intersection(const AxisBox<dim>& a1, const AxisBox<dim>& a2, AxisBox<dim>& out);
00044 template<const int dim>
00045 AxisBox<dim> Union(const AxisBox<dim>& a1, const AxisBox<dim>& a2);
00046
00047 template<const int dim>
00048 std::ostream& operator<<(std::ostream& os, const AxisBox<dim>& m);
00049 template<const int dim>
00050 std::istream& operator>>(std::istream& is, AxisBox<dim>& m);
00051
00052 #ifndef WFMATH_NO_TEMPLATES_AS_TEMPLATE_PARAMETERS
00053
00054 template<const int dim, template<class> class container>
00055 AxisBox<dim> BoundingBox(const container<AxisBox<dim> >& c);
00056
00058 template<const int dim, template<class> class container>
00059 AxisBox<dim> BoundingBox(const container<Point<dim> >& c);
00060 #endif
00061
00063
00067 template<const int dim>
00068 class AxisBox
00069 {
00070 public:
00072 AxisBox() {}
00074 AxisBox(const Point<dim>& p1, const Point<dim>& p2, bool ordered = false)
00075 {setCorners(p1, p2, ordered);}
00077 AxisBox(const AxisBox& a) : m_low(a.m_low), m_high(a.m_high) {}
00079 explicit AxisBox(const Atlas::Message::Object& a) {fromAtlas(a);}
00080
00081 friend std::ostream& operator<< <dim>(std::ostream& os, const AxisBox& a);
00082 friend std::istream& operator>> <dim>(std::istream& is, AxisBox& a);
00083
00085 Atlas::Message::Object toAtlas() const;
00087 void fromAtlas(const Atlas::Message::Object& a);
00088
00089 AxisBox& operator=(const AxisBox& a)
00090 {m_low = a.m_low; m_high = a.m_high; return *this;}
00091
00092 bool isEqualTo(const AxisBox& b, double epsilon = WFMATH_EPSILON) const;
00093 bool operator==(const AxisBox& a) const {return isEqualTo(a);}
00094 bool operator!=(const AxisBox& a) const {return !isEqualTo(a);}
00095
00096 bool isValid() const {return m_low.isValid() && m_high.isValid();}
00097
00098 bool operator< (const AxisBox& a) const
00099 {return m_low < a.m_low || (m_low != a.m_low && m_high < a.m_high);}
00100
00101
00102
00103 int numCorners() const {return 1 << dim;}
00104 Point<dim> getCorner(int i) const;
00105 Point<dim> getCenter() const {return Midpoint(m_low, m_high);}
00106
00108 const Point<dim>& lowCorner() const {return m_low;}
00110 const Point<dim>& highCorner() const {return m_high;}
00111
00113 CoordType lowerBound(const int axis) const {return m_low[axis];}
00115 CoordType upperBound(const int axis) const {return m_high[axis];}
00116
00118
00123 AxisBox& setCorners(const Point<dim>& p1, const Point<dim>& p2,
00124 bool ordered = false);
00125
00126
00127
00128 AxisBox& shift(const Vector<dim>& v)
00129 {m_low += v; m_high += v; return *this;}
00130 AxisBox& moveCornerTo(const Point<dim>& p, int corner)
00131 {return shift(p - getCorner(corner));}
00132 AxisBox& moveCenterTo(const Point<dim>& p)
00133 {return shift(p - getCenter());}
00134
00135
00136
00137
00138
00139 AxisBox boundingBox() const {return *this;}
00140 Ball<dim> boundingSphere() const;
00141 Ball<dim> boundingSphereSloppy() const;
00142
00144 friend bool Intersection<dim>(const AxisBox& a1, const AxisBox& a2, AxisBox& out);
00146 friend AxisBox Union<dim>(const AxisBox& a1, const AxisBox& a2);
00147
00148 friend bool Intersect<dim>(const AxisBox& b, const Point<dim>& p, bool proper);
00149 friend bool Contains<dim>(const Point<dim>& p, const AxisBox& b, bool proper);
00150
00151 friend bool Intersect<dim>(const AxisBox& b1, const AxisBox& b2, bool proper);
00152 friend bool Contains<dim>(const AxisBox& outer, const AxisBox& inner, bool proper);
00153
00154 friend bool Intersect<dim>(const Ball<dim>& b, const AxisBox& a, bool proper);
00155 friend bool Contains<dim>(const Ball<dim>& b, const AxisBox& a, bool proper);
00156 friend bool Contains<dim>(const AxisBox& a, const Ball<dim>& b, bool proper);
00157
00158 friend bool Intersect<dim>(const Segment<dim>& s, const AxisBox& b, bool proper);
00159 friend bool Contains<dim>(const Segment<dim>& s, const AxisBox& b, bool proper);
00160
00161 friend bool Intersect<dim>(const RotBox<dim>& r, const AxisBox& b, bool proper);
00162 friend bool Contains<dim>(const RotBox<dim>& r, const AxisBox& b, bool proper);
00163 friend bool Contains<dim>(const AxisBox& b, const RotBox<dim>& r, bool proper);
00164
00165 friend bool Intersect<dim>(const Polygon<dim>& p, const AxisBox& b, bool proper);
00166 friend bool Contains<dim>(const Polygon<dim>& p, const AxisBox& b, bool proper);
00167 friend bool Contains<dim>(const AxisBox& b, const Polygon<dim>& p, bool proper);
00168
00169 private:
00170
00171 Point<dim> m_low, m_high;
00172 };
00173
00174 }
00175
00176 #include <wfmath/axisbox_funcs.h>
00177
00178 #endif // WFMATH_AXIS_BOX_H