gxbounds.cc

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 Nov 13 13:34:18 2002
00010 // commit: $Id: gxbounds.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/gfx/gxbounds.cc $
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_GFX_GXBOUNDS_CC_UTC20050626084023_DEFINED
00035 #define GROOVX_GFX_GXBOUNDS_CC_UTC20050626084023_DEFINED
00036 
00037 #include "gxbounds.h"
00038 
00039 #include "geom/box.h"
00040 #include "geom/rect.h"
00041 
00042 #include "gfx/bbox.h"
00043 #include "gfx/canvas.h"
00044 #include "gfx/rgbacolor.h"
00045 
00046 #include "io/reader.h"
00047 #include "io/writer.h"
00048 
00049 #include "rutz/trace.h"
00050 #include "rutz/debug.h"
00051 GVX_DBG_REGISTER
00052 
00053 GxBounds::GxBounds(nub::soft_ref<GxNode> child) :
00054   GxBin(child),
00055   isItVisible(false),
00056   isItAnimated(true),
00057   itsPercentBorder(4),
00058   itsStipple(0x0F0F), // 0000111100001111
00059   itsMask(0x3333)     // 0011001100110011
00060 {}
00061 
00062 GxBounds::~GxBounds() throw() {}
00063 
00064 void GxBounds::read_from(io::reader& reader)
00065 {
00066 GVX_TRACE("GxBounds::read_from");
00067   reader.read_value("isVisible", isItVisible);
00068   reader.read_value("isAnimated", isItAnimated);
00069   reader.read_value("percentBorder", itsPercentBorder);
00070 }
00071 
00072 void GxBounds::write_to(io::writer& writer) const
00073 {
00074 GVX_TRACE("GxBounds::write_to");
00075   writer.write_value("isVisible", isItVisible);
00076   writer.write_value("isAnimated", isItAnimated);
00077   writer.write_value("percentBorder", itsPercentBorder);
00078 }
00079 
00080 void GxBounds::draw(Gfx::Canvas& canvas) const
00081 {
00082 GVX_TRACE("GxBounds::draw");
00083 
00084   child()->draw(canvas);
00085 
00086   if (isItVisible)
00087     {
00088       Gfx::Bbox bbox(canvas);
00089       const double s = 1.0 + itsPercentBorder/100.0;
00090       bbox.scale(geom::vec3<double>(s,s,s));
00091       child()->getBoundingCube(bbox);
00092 
00093       geom::rect<double> bounds = bbox.rect();
00094 
00095       if (isItAnimated)
00096         {
00097           itsStipple ^= itsMask;
00098           itsMask = ~itsMask;
00099         }
00100 
00101       Gfx::AttribSaver saver(canvas);
00102 
00103       canvas.setColor(Gfx::RgbaColor(0.0, 0.0, 1.0, 1.0));
00104 
00105       canvas.setLineWidth(1.0);
00106       canvas.setLineStipple(itsStipple);
00107       canvas.setPolygonFill(false);
00108 
00109       canvas.drawRect(bounds);
00110 
00111       canvas.setPointSize(4.0);
00112 
00113       {
00114         Gfx::PointsBlock block(canvas);
00115 
00116         canvas.vertex2(bounds.bottom_left());
00117         canvas.vertex2(bounds.bottom_right());
00118         canvas.vertex2(bounds.top_right());
00119         canvas.vertex2(bounds.top_left());
00120         canvas.vertex2(bounds.center());
00121       }
00122     }
00123 }
00124 
00125 void GxBounds::getBoundingCube(Gfx::Bbox& bbox) const
00126 {
00127 GVX_TRACE("GxBounds::getBoundingCube");
00128 
00129   bbox.push();
00130 
00131   dbg_eval(3, itsPercentBorder);
00132 
00133   const double s = 1.0 + itsPercentBorder/100.0;
00134 
00135   bbox.scale(geom::vec3<double>(s,s,s));
00136 
00137   child()->getBoundingCube(bbox);
00138 
00139   bbox.pop();
00140 
00141   dbg_dump(2, bbox.cube());
00142 }
00143 
00144 static const char __attribute__((used)) vcid_groovx_gfx_gxbounds_cc_utc20050626084023[] = "$Id: gxbounds.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00145 #endif // !GROOVX_GFX_GXBOUNDS_CC_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.