gaborarray.h

Go to the documentation of this file.
00001 
00004 
00005 //
00006 // Copyright (c) 2002-2004 California Institute of Technology
00007 // Copyright (c) 2004-2007 University of Southern California
00008 // Rob Peters <rjpeters at usc dot edu>
00009 //
00010 // created: Mon May 12 11:15:51 2003
00011 // commit: $Id: gaborarray.h 10065 2007-04-12 05:54:56Z rjpeters $
00012 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/visx/gaborarray.h $
00013 //
00014 // --------------------------------------------------------------------
00015 //
00016 // This file is part of GroovX.
00017 //   [http://ilab.usc.edu/rjpeters/groovx/]
00018 //
00019 // GroovX is free software; you can redistribute it and/or modify it
00020 // under the terms of the GNU General Public License as published by
00021 // the Free Software Foundation; either version 2 of the License, or
00022 // (at your option) any later version.
00023 //
00024 // GroovX is distributed in the hope that it will be useful, but
00025 // WITHOUT ANY WARRANTY; without even the implied warranty of
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00027 // General Public License for more details.
00028 //
00029 // You should have received a copy of the GNU General Public License
00030 // along with GroovX; if not, write to the Free Software Foundation,
00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00032 //
00034 
00035 #ifndef GROOVX_VISX_GABORARRAY_H_UTC20050626084016_DEFINED
00036 #define GROOVX_VISX_GABORARRAY_H_UTC20050626084016_DEFINED
00037 
00038 #include "gfx/gxshapekit.h"
00039 
00040 #include "gfx/gbvec.h"
00041 
00042 #include "rutz/arrays.h"
00043 #include "rutz/shared_ptr.h"
00044 
00045 class GaborArrayElement;
00046 class Snake;
00047 
00048 namespace media
00049 {
00050   class bmap_data;
00051 }
00052 
00053 namespace rutz
00054 {
00055   class urand;
00056 }
00057 
00058 template <class T>
00059 class Cached
00060 {
00061 public:
00062   Cached(const T& v) throw() : val(v), oldval(v), changed(true) {}
00063 
00064   operator       T&()       throw() { return val; }
00065   operator const T&() const throw() { return val; }
00066 
00067   void save()  const throw() { oldval = val; changed = false; }
00068   bool ok()    const throw() { return (val == oldval) && !changed; }
00069   void touch() const throw() { changed = true; }
00070 
00071   T val;
00072   mutable T oldval;
00073   mutable bool changed;
00074 };
00075 
00076 namespace rutz
00077 {
00078   template <class T>
00079   struct type_traits<Cached<T> > : public type_traits<T>
00080   {};
00081 }
00082 
00084 
00085 class GaborArray : public GxShapeKit
00086 {
00087 public:
00088   GaborArray(double gaborPeriod = 15.0, double gaborSigma = 7.5,
00089              int foregNumber = 24, double foregSpacing = 45.0,
00090              int sizeX = 512, int sizeY = 512,
00091              double gridSpacing = 48.0,
00092              double minSpacing = 36.0);
00093 
00094   virtual ~GaborArray() throw();
00095 
00096   static GaborArray* make() { return new GaborArray; }
00097 
00099   static const FieldMap& classFields();
00100 
00101   virtual io::version_id class_version_id() const;
00102   virtual void read_from(io::reader& reader);
00103   virtual void write_to(io::writer& writer) const;
00104 
00105   void saveImage(const char* filename) const;
00106 
00107   void saveContourOnlyImage(const char* filename) const;
00108 
00109 protected:
00110   virtual void grGetBoundingBox(Gfx::Bbox& bbox) const;
00111 
00112   virtual void grRender(Gfx::Canvas& canvas) const;
00113 
00114 private:
00115   GaborArray(const GaborArray&);
00116   GaborArray& operator=(const GaborArray&);
00117 
00118   rutz::shared_ptr<media::bmap_data> generateBmap(bool doTagLast = false) const;
00119 
00120   void updateForeg() const;
00121   void updateBackg() const;
00122   void updateBmap() const;
00123   void update() const;
00124   bool tryPush(const GaborArrayElement& e) const;
00125   bool tooClose(const geom::vec2<double>& v, int except) const;
00126   void backgHexGrid() const;
00127   void backgFill() const;
00128   void backgJitter(rutz::urand& urand) const;
00129 
00130   Cached<int> itsForegSeed;
00131   Cached<int> itsForegNumber;
00132   Cached<double> itsForegSpacing;
00133   Cached<int> itsForegPosX;
00134   Cached<int> itsForegPosY;
00135 
00136   Cached<int> itsBackgSeed;
00137   Cached<int> itsSizeX;
00138   Cached<int> itsSizeY;
00139   Cached<double> itsGridSpacing;
00140   Cached<double> itsMinSpacing;
00141   Cached<double> itsFillResolution;
00142 
00143   Cached<int> itsThetaSeed;
00144   Cached<int> itsPhaseSeed;
00145   Cached<double> itsThetaJitter;
00146   Cached<double> itsGaborPeriod;
00147   Cached<double> itsGaborSigma;
00148   Cached<int> itsContrastSeed;
00149   Cached<double> itsContrastJitter;
00150 
00151   mutable int itsTotalNumber;
00152   mutable rutz::fixed_block<GaborArrayElement> itsArray;
00153   mutable rutz::shared_ptr<media::bmap_data> itsBmap;
00154 
00155   bool itsDumpingFrames;
00156   unsigned int itsFrameDumpPeriod;
00157 };
00158 
00159 static const char __attribute__((used)) vcid_groovx_visx_gaborarray_h_utc20050626084016[] = "$Id: gaborarray.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00160 #endif // !GROOVX_VISX_GABORARRAY_H_UTC20050626084016_DEFINED

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