tclpkg-canvas.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2004-2007 University of Southern California
00006 // Rob Peters <rjpeters at usc dot edu>
00007 //
00008 // created: Sat Oct 23 19:24:11 2004
00009 // commit: $Id: tclpkg-canvas.cc 10065 2007-04-12 05:54:56Z rjpeters $
00010 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/tcl-gfx/tclpkg-canvas.cc $
00011 //
00012 // --------------------------------------------------------------------
00013 //
00014 // This file is part of GroovX.
00015 //   [http://ilab.usc.edu/rjpeters/groovx/]
00016 //
00017 // GroovX is free software; you can redistribute it and/or modify it
00018 // under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 //
00022 // GroovX is distributed in the hope that it will be useful, but
00023 // WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 // General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with GroovX; if not, write to the Free Software Foundation,
00029 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00030 //
00032 
00033 #ifndef GROOVX_GFX_TCLPKG_CANVAS_CC_UTC20050628170310_DEFINED
00034 #define GROOVX_GFX_TCLPKG_CANVAS_CC_UTC20050628170310_DEFINED
00035 
00036 #include "tcl-gfx/tclpkg-canvas.h"
00037 
00038 #include "gfx/canvas.h"
00039 #include "gfx/glcanvas.h"
00040 
00041 #include "media/bmapdata.h"
00042 
00043 #include "tcl/objpkg.h"
00044 #include "tcl/pkg.h"
00045 
00046 #include "tcl-gfx/recttcl.h"
00047 #include "tcl-gfx/vectcl.h"
00048 
00049 #include "rutz/trace.h"
00050 
00051 namespace
00052 {
00053   //--------------------------------------------------------------------
00054   //
00055   // pixelCheckSum --
00056   //
00057   // This command returns the sum of the color indices of all the pixels
00058   // in a specified rectangle. It can be used as an easy way to see if
00059   // something is present within a given rectangle on the screen. For
00060   // example, if the background is index 0, and the foreground is index
00061   // 1, than this command can tell how many pixels were drawn by a
00062   // particular drawing command. However-- it is not at all speedy, so
00063   // it is best used for testing only.
00064   //
00065   //--------------------------------------------------------------------
00066 
00067   long int pixelCheckSum(nub::soft_ref<GLCanvas> canvas,
00068                          int x, int y, int w, int h)
00069   {
00070     media::bmap_data data;
00071 
00072     const geom::rect<int> bounds = geom::rect<int>().set_lbwh(x, y, w, h);
00073 
00074     canvas->grabPixels(bounds, data);
00075 
00076     return data.bytes_sum();
00077   }
00078 
00079   long int pixelCheckSumAll(nub::soft_ref<GLCanvas> canvas)
00080   {
00081     const geom::rect<int> viewport = canvas->getScreenViewport();
00082     return pixelCheckSum(canvas,
00083                          viewport.left(),
00084                          viewport.bottom(),
00085                          viewport.width(),
00086                          viewport.height());
00087   }
00088 
00089   geom::vec3d topLeft(nub::soft_ref<GLCanvas> canvas)
00090   {
00091     const geom::recti vp = canvas->getScreenViewport();
00092     const geom::vec2i tl = vp.top_left();
00093     return canvas->worldFromScreen3(geom::vec3d(tl.x(), tl.y(), 0.5));
00094   }
00095 }
00096 
00097 extern "C"
00098 int Canvas_Init(Tcl_Interp* interp)
00099 {
00100 GVX_TRACE("Canvas_Init");
00101 
00102   GVX_PKG_CREATE(pkg, interp, "Canvas", "4.$Revision: 10065 $");
00103   pkg->inherit_pkg("Obj");
00104   tcl::def_basic_type_cmds<Gfx::Canvas>(pkg, SRC_POS);
00105 
00106   using rutz::bind_last;
00107   using rutz::mem_func;
00108 
00109   pkg->def_getter("viewport", &Gfx::Canvas::getScreenViewport, SRC_POS);
00110   pkg->def("topLeft", "canvas", &topLeft, SRC_POS);
00111 
00112   pkg->def("throwIfError", "",
00113            bind_last(bind_last(mem_func(&Gfx::Canvas::throwIfError), SRC_POS), ""),
00114            SRC_POS);
00115 
00116   GVX_PKG_RETURN(pkg);
00117 }
00118 
00119 extern "C"
00120 int Glcanvas_Init(Tcl_Interp* interp)
00121 {
00122 GVX_TRACE("Glcanvas_Init");
00123 
00124   GVX_PKG_CREATE(pkg, interp, "GLCanvas", "4.$Revision: 10065 $");
00125   pkg->inherit_pkg("Canvas");
00126   tcl::def_basic_type_cmds<GLCanvas>(pkg, SRC_POS);
00127 
00128   pkg->def( "pixelCheckSum", "glcanvas x y w h", &pixelCheckSum, SRC_POS );
00129   pkg->def( "pixelCheckSum", "glcanvas", &pixelCheckSumAll, SRC_POS );
00130 
00131   GVX_PKG_RETURN(pkg);
00132 }
00133 
00134 static const char __attribute__((used)) vcid_groovx_gfx_tclpkg_canvas_cc_utc20050628170310[] = "$Id: tclpkg-canvas.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00135 #endif // !GROOVX_GFX_TCLPKG_CANVAS_CC_UTC20050628170310_DEFINED

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