box.h

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2002-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Wed Jul  3 15:03:23 2002
00010 // commit: $Id: box.h 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/geom/box.h $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_GEOM_BOX_H_UTC20050626084023_DEFINED
00035 #define GROOVX_GEOM_BOX_H_UTC20050626084023_DEFINED
00036 
00037 #include "geom/span.h"
00038 #include "geom/vec3.h"
00039 #include "geom/rect.h"
00040 
00041 #include "rutz/algo.h"
00042 
00043 #include "rutz/debug.h"
00044 GVX_DBG_REGISTER
00045 
00046 namespace geom
00047 {
00048   //  #######################################################
00049   //  =======================================================
00050 
00052   template <class V>
00053   class box
00054   {
00055   private:
00056     geom::span<V> xx, yy, zz;
00057 
00058   public:
00059     box() : xx(), yy(), zz() {}
00060 
00061     box(const geom::span<V>& x,
00062         const geom::span<V>& y,
00063         const geom::span<V>& z)
00064       :
00065       xx(x), yy(y), zz(z)
00066     {}
00067 
00068     explicit box(const geom::rect<V>& rect) :
00069       xx(rect.x_span()),
00070       yy(rect.y_span()),
00071       zz()
00072     {}
00073 
00074     geom::rect<V> rect() const
00075     {
00076       return geom::rect<V>(xx, yy);
00077     }
00078 
00079     V x0() const { return xx.lo; }
00080     V x1() const { return xx.hi; }
00081     V y0() const { return yy.lo; }
00082     V y1() const { return yy.hi; }
00083     V z0() const { return zz.lo; }
00084     V z1() const { return zz.hi; }
00085 
00086     vec3<V> point000() const { return geom::vec3<V>(xx.lo, yy.lo, zz.lo); }
00087     vec3<V> point001() const { return geom::vec3<V>(xx.lo, yy.lo, zz.hi); }
00088     vec3<V> point010() const { return geom::vec3<V>(xx.lo, yy.hi, zz.lo); }
00089     vec3<V> point011() const { return geom::vec3<V>(xx.lo, yy.hi, zz.hi); }
00090     vec3<V> point100() const { return geom::vec3<V>(xx.hi, yy.lo, zz.lo); }
00091     vec3<V> point101() const { return geom::vec3<V>(xx.hi, yy.lo, zz.hi); }
00092     vec3<V> point110() const { return geom::vec3<V>(xx.hi, yy.hi, zz.lo); }
00093     vec3<V> point111() const { return geom::vec3<V>(xx.hi, yy.hi, zz.hi); }
00094 
00095     V size_x() const { return xx.width(); }
00096     V size_y() const { return yy.width(); }
00097     V size_z() const { return zz.width(); }
00098 
00099     V center_x() const { return xx.center(); }
00100     V center_y() const { return yy.center(); }
00101     V center_z() const { return zz.center(); }
00102 
00103     geom::vec3<V> center() const
00104     { return geom::vec3<V>(center_x(), center_y(), center_z()); }
00105 
00106     void set_xx_yy_zz(V x0, V x1, V y0, V y1, V z0, V z1)
00107     {
00108       xx = span<V>(x0,x1);
00109       yy = span<V>(y0,y1);
00110       zz = span<V>(z0,z1);
00111     }
00112 
00114     void set_any_xx_yy_zz(V x0, V x1, V y0, V y1, V z0, V z1)
00115     {
00116       xx = span<V>::from_any(x0,x1);
00117       yy = span<V>::from_any(y0,y1);
00118       zz = span<V>::from_any(z0,z1);
00119     }
00120 
00121     void set_corners(const geom::vec3<V>& p1, const geom::vec3<V>& p2)
00122     {
00123       set_any_xx_yy_zz(p1.x(), p2.x(), p1.y(), p2.y(), p1.z(), p2.z());
00124     }
00125 
00126     void size_x(V s) { xx = xx.with_width(s); }
00127     void size_y(V s) { yy = yy.with_width(s); }
00128     void size_z(V s) { zz = zz.with_width(s); }
00129 
00130     void scale_x(V factor) { xx = xx.scaled_by(factor); }
00131     void scale_y(V factor) { yy = yy.scaled_by(factor); }
00132     void scale_z(V factor) { zz = zz.scaled_by(factor); }
00133 
00134     void scale(const geom::vec3<V>& factors)
00135     {
00136       scale_x(factors.x());
00137       scale_y(factors.y());
00138       scale_z(factors.z());
00139     }
00140 
00141     void scale(V factor)
00142     {
00143       scale_x(factor);
00144       scale_y(factor);
00145       scale_z(factor);
00146     }
00147 
00148     void translate(const geom::vec3<V>& dist)
00149     {
00150       xx = xx.shifted_by(dist.x());
00151       yy = yy.shifted_by(dist.y());
00152       zz = zz.shifted_by(dist.z());
00153     }
00154 
00155     void set_center(const geom::vec3<V>& point)
00156     {
00157       geom::vec3<V> diff = point - center();
00158       translate(diff);
00159     }
00160 
00161     bool is_void() const
00162     {
00163       return (xx.is_void() || yy.is_void() || zz.is_void());
00164     }
00165 
00166     box<V> union_with(const box<V>& other) const
00167     {
00168       return box<V>(xx.union_with(other.xx),
00169                     yy.union_with(other.yy),
00170                     zz.union_with(other.zz));
00171     }
00172 
00173     void merge(const geom::vec2<V>& p)
00174     {
00175       xx = xx.including(p.x());
00176       yy = yy.including(p.y());
00177     }
00178 
00179     void merge(const geom::vec3<V>& p)
00180     {
00181       xx = xx.including(p.x());
00182       yy = yy.including(p.y());
00183       zz = zz.including(p.z());
00184     }
00185 
00186     void merge(const geom::rect<V>& r)
00187     {
00188       xx = xx.union_with(r.x_span());
00189       yy = yy.union_with(r.y_span());
00190     }
00191 
00192     void debug_dump() const
00193     {
00194       dbg_eval(0, xx.lo); dbg_eval_nl(0, xx.hi);
00195       dbg_eval(0, yy.lo); dbg_eval_nl(0, yy.hi);
00196       dbg_eval(0, zz.lo); dbg_eval_nl(0, zz.hi);
00197     }
00198   };
00199 
00200 } // end namespace geom
00201 
00202 static const char __attribute__((used)) vcid_groovx_geom_box_h_utc20050626084023[] = "$Id: box.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00203 #endif // !GROOVX_GEOM_BOX_H_UTC20050626084023_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:38 2008 by Doxygen version 1.5.5.