libidx
|
00001 /*************************************************************************** 00002 * Copyright (C) 2008 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef GEOMETRY_H_ 00034 #define GEOMETRY_H_ 00035 00036 #include "defines.h" 00037 #include "stl.h" 00038 00039 namespace ebl { 00040 00042 template <typename T = uint> class EXPORT rect { 00043 public: 00045 // constructors/destructors 00046 00048 rect(T h0, T w0, T height, T width); 00050 rect(); 00052 rect(const rect<T> &r); 00054 virtual ~rect(); 00055 00058 T h1() const; 00060 T w1() const; 00062 float hcenter() const; 00064 float wcenter() const; 00066 T area() const; 00068 T intersection_area(const rect<T> &r) const; 00071 T union_area(const rect<T> &r) const; 00075 float match(const rect<T> &r) const; 00079 float min_match(const rect<T> &r); 00081 float center_distance(const rect<T> &r) const; 00084 float center_hdistance(const rect<T> &r) const; 00087 float center_wdistance(const rect<T> &r) const; 00089 bool overlap(const rect<T> &r) const; 00092 float overlap_ratio(const rect<T> &r) const; 00098 bool min_overlap(const rect<T> &r, float hmin, float wmin) const; 00101 float min_overlap(const rect<T> &r) const; 00106 bool min_overlap(const rect<T> &r, float minarea) const; 00108 bool is_within(const rect<T> &r); 00110 void shift(T h, T w); 00114 void scale_centered(float sh, float sw); 00117 void scale_width(float woverh_ratio); 00120 void scale_height(float woverh_ratio); 00122 float radius(); 00126 void rotate(float degree_angle); 00127 00129 // operators 00130 00132 rect<T> operator/(double d); 00134 rect<T> operator*(double d); 00136 template <typename T2> 00137 rect<T> operator=(rect<T2> &r2); 00138 00139 // internal methods //////////////////////////////////////////////////////// 00140 00142 void rotate_point(float alpha, float &h, float &w); 00143 00144 // members ///////////////////////////////////////////////////////////////// 00145 public: 00146 T h0, w0, height, width; 00147 }; 00148 00149 template <typename T> 00150 EXPORT std::string& operator<<(std::string& out, rect<T>& r); 00151 template <typename T> 00152 EXPORT std::string& operator<<(std::string& out, const rect<T>& r); 00153 template <typename T> 00154 EXPORT std::ostream& operator<<(std::ostream& out, rect<T>& r); 00155 template <typename T> 00156 EXPORT std::ostream& operator<<(std::ostream& out, const rect<T>& r); 00157 00158 } // end namespace ebl 00159 00160 #include "geometry.hpp" 00161 00162 #endif /* GEOMETRY_H_ */