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/intersect_decls.h>
00034
00035 #include <memory>
00036 #include <iosfwd>
00037
00038 namespace WFMath {
00039
00040 template<const int dim>
00041 bool Intersection(const AxisBox<dim>& a1, const AxisBox<dim>& a2, AxisBox<dim>& out);
00042 template<const int dim>
00043 AxisBox<dim> Union(const AxisBox<dim>& a1, const AxisBox<dim>& a2);
00044
00045 template<const int dim>
00046 std::ostream& operator<<(std::ostream& os, const AxisBox<dim>& m);
00047 template<const int dim>
00048 std::istream& operator>>(std::istream& is, AxisBox<dim>& m);
00049
00050 #ifndef WFMATH_NO_TEMPLATES_AS_TEMPLATE_PARAMETERS
00052 template<const int dim, template<class, class> class container>
00053 AxisBox<dim> BoundingBox(const container<AxisBox<dim>, std::allocator<AxisBox<dim> > >& c);
00054
00056 template<const int dim, template<class, class> class container>
00057 AxisBox<dim> BoundingBox(const container<Point<dim>, std::allocator<Point<dim> > >& c);
00058 #endif
00059
00061
00065 template<const int dim>
00066 class AxisBox
00067 {
00068 public:
00070 AxisBox() {}
00072 AxisBox(const Point<dim>& p1, const Point<dim>& p2, bool ordered = false)
00073 {setCorners(p1, p2, ordered);}
00075 AxisBox(const AxisBox& a) : m_low(a.m_low), m_high(a.m_high) {}
00077 explicit AxisBox(const AtlasInType& a);
00078
00079 friend std::ostream& operator<< <dim>(std::ostream& os, const AxisBox& a);
00080 friend std::istream& operator>> <dim>(std::istream& is, AxisBox& a);
00081
00083 AtlasOutType toAtlas() const;
00085 void fromAtlas(const AtlasInType& a);
00086
00087 AxisBox& operator=(const AxisBox& a)
00088 {m_low = a.m_low; m_high = a.m_high; return *this;}
00089
00090 bool isEqualTo(const AxisBox& b, double epsilon = WFMATH_EPSILON) const;
00091 bool operator==(const AxisBox& a) const {return isEqualTo(a);}
00092 bool operator!=(const AxisBox& a) const {return !isEqualTo(a);}
00093
00094 bool isValid() const {return m_low.isValid() && m_high.isValid();}
00095
00096
00097
00098 int numCorners() const {return 1 << dim;}
00099 Point<dim> getCorner(int i) const;
00100 Point<dim> getCenter() const {return Midpoint(m_low, m_high);}
00101
00103 const Point<dim>& lowCorner() const {return m_low;}
00105 const Point<dim>& highCorner() const {return m_high;}
00106
00108 CoordType lowerBound(const int axis) const {return m_low[axis];}
00110 CoordType upperBound(const int axis) const {return m_high[axis];}
00111
00113
00118 AxisBox& setCorners(const Point<dim>& p1, const Point<dim>& p2,
00119 bool ordered = false);
00120
00121
00122
00123 AxisBox& shift(const Vector<dim>& v)
00124 {m_low += v; m_high += v; return *this;}
00125 AxisBox& moveCornerTo(const Point<dim>& p, int corner)
00126 {return shift(p - getCorner(corner));}
00127 AxisBox& moveCenterTo(const Point<dim>& p)
00128 {return shift(p - getCenter());}
00129
00130
00131
00132
00133
00134 AxisBox boundingBox() const {return *this;}
00135 Ball<dim> boundingSphere() const;
00136 Ball<dim> boundingSphereSloppy() const;
00137
00138 AxisBox toParentCoords(const Point<dim>& origin) const
00139 {return AxisBox(m_low.toParentCoords(origin), m_high.toParentCoords(origin), true);}
00140 AxisBox toParentCoords(const AxisBox<dim>& coords) const
00141 {return AxisBox(m_low.toParentCoords(coords), m_high.toParentCoords(coords), true);}
00142
00143
00144
00145
00146
00147 AxisBox toLocalCoords(const Point<dim>& origin) const
00148 {return AxisBox(m_low.toLocalCoords(origin), m_high.toLocalCoords(origin), true);}
00149 AxisBox toLocalCoords(const AxisBox<dim>& coords) const
00150 {return AxisBox(m_low.toLocalCoords(coords), m_high.toLocalCoords(coords), true);}
00151
00153 friend bool Intersection<dim>(const AxisBox& a1, const AxisBox& a2, AxisBox& out);
00155 friend AxisBox Union<dim>(const AxisBox& a1, const AxisBox& a2);
00156
00157 friend bool Intersect<dim>(const AxisBox& b, const Point<dim>& p, bool proper);
00158 friend bool Contains<dim>(const Point<dim>& p, const AxisBox& b, bool proper);
00159
00160 friend bool Intersect<dim>(const AxisBox& b1, const AxisBox& b2, bool proper);
00161 friend bool Contains<dim>(const AxisBox& outer, const AxisBox& inner, bool proper);
00162
00163 friend bool Intersect<dim>(const Ball<dim>& b, const AxisBox& a, bool proper);
00164 friend bool Contains<dim>(const Ball<dim>& b, const AxisBox& a, bool proper);
00165 friend bool Contains<dim>(const AxisBox& a, const Ball<dim>& b, bool proper);
00166
00167 friend bool Intersect<dim>(const Segment<dim>& s, const AxisBox& b, bool proper);
00168 friend bool Contains<dim>(const Segment<dim>& s, const AxisBox& b, bool proper);
00169
00170 friend bool Intersect<dim>(const RotBox<dim>& r, const AxisBox& b, bool proper);
00171 friend bool Contains<dim>(const RotBox<dim>& r, const AxisBox& b, bool proper);
00172 friend bool Contains<dim>(const AxisBox& b, const RotBox<dim>& r, bool proper);
00173
00174 friend bool Intersect<dim>(const Polygon<dim>& p, const AxisBox& b, bool proper);
00175 friend bool Contains<dim>(const Polygon<dim>& p, const AxisBox& b, bool proper);
00176 friend bool Contains<dim>(const AxisBox& b, const Polygon<dim>& p, bool proper);
00177
00178 private:
00179
00180 Point<dim> m_low, m_high;
00181 };
00182
00183 }
00184
00185 #endif // WFMATH_AXIS_BOX_H