Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SketchSpace.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SketchSpace_h
00003 #define INCLUDED_SketchSpace_h
00004 
00005 #include "Shared/newmat/newmat.h"
00006 
00007 #include "Macrodefs.h"
00008 #include "SketchTypes.h"
00009 #include "ShapeTypes.h"
00010 #include "SketchPool.h"
00011 #include "SketchIndices.h"
00012 
00013 namespace DualCoding {
00014 
00015 class BoundingBox;
00016 class ShapeSpace;
00017 template<typename T> class Sketch;
00018 class ViewerConnection;
00019 
00020 //! Holds a collection of sketches of various types
00021 /*! All the sketches in a SketchSpace have the same dimensions (width and height).
00022    They are organized into pools, managed by SketchPool<T> instances.
00023    Each SketchSpace has a dual, called a ShapeSpace.  Several standard
00024    SketchSpace/ShapeSpace pairs are built in to VisualRoutinesBehavior.
00025    The most basic is @a camSkS, the camera sketch space.   */
00026 
00027 class SketchSpace {
00028 public:
00029   std::string name;    //!< name of this SketchSpace
00030 
00031 private:
00032   size_t width;   //!< pixels along x axis
00033   size_t height;  //!< pixels along y axis
00034   size_t numPixels; //!< total pixels = width * height
00035   NEWMAT::Matrix Tmat; //!< transformation matrix for rendering shapes
00036   NEWMAT::Matrix Tmatinv; //!< inverse transformation matrix for extracting shapes
00037     
00038   int idCounter; //!< Incremented with each new Sketch, to guarantee a unique ID.
00039   int refreshCounter; //!< Incremented each time SketchGUI refreshes the sketch/shape list
00040   
00041   ShapeSpace* dualSpace; //!< Pointer to the ShapeSpace associated with this SketchSpace
00042   
00043   //! Pool for one of the SketchData<T> classes
00044   //@{
00045   SketchPool<bool>  boolPool;
00046   SketchPool<uchar> ucharPool;
00047   SketchPool<uint> uintPool;
00048   SketchPool<float> floatPool; 
00049   //@}
00050   
00051 public:
00052   //! The value assigned to out-of-bounds indices: @a numPixels, i.e., one beyond the last image pixel.
00053   int dummy;
00054 
00055   //!@name Pre-generated indices for different directions
00056   //@{
00057   Sketch<uint> *idx;
00058   Sketch<uint> *idxN;
00059   Sketch<uint> *idxS;
00060   Sketch<uint> *idxE;
00061   Sketch<uint> *idxW;
00062   Sketch<uint> *idxNE;
00063   Sketch<uint> *idxNW;
00064   Sketch<uint> *idxSE;
00065   Sketch<uint> *idxSW;
00066   //@}
00067   
00068   SketchSpace(std::string const _name, ReferenceFrameType_t _refFrameType,
00069         int const init_id, size_t const _width, size_t const _height);
00070   
00071   ~SketchSpace();
00072   
00073   ShapeSpace& getDualSpace() const { return *dualSpace; }
00074   
00075   //! dumps contents of sketch space
00076   void dumpSpace() const;
00077   
00078   //! Clears out viewable Sketches.
00079   void clear();
00080 
00081   //! returns the width of contained images, in pixels
00082   size_t getWidth() const { return width; }
00083   //! returns the height of contained images, in pixels
00084   size_t getHeight() const { return height; }
00085   //! returns the number of pixels of images in this space
00086   size_t getNumPixels() const { return numPixels; }
00087   
00088   int getRefreshCounter() const { return refreshCounter; }
00089   void bumpRefreshCounter() { ++refreshCounter; }
00090 
00091   //! creates #idx if needed
00092   void requireIdx();
00093   
00094   //! creates #idxN, #idxS, #idxE, and #idxW if needed
00095   void requireIdx4way();
00096 
00097   //! creates #idxNE, #idxNW, #idxSE, and #idxSW, plus NSEW cases via requireIdx4way(), if needed
00098   void requireIdx8way();
00099   
00100   //! frees the idx members
00101   void freeIndexes();
00102 
00103   //! change the size of sketches in this sketch space (discards all existing sketches)
00104   void resize(const size_t new_width, const size_t new_height);
00105 
00106   //! return the ShapeSpace-to-SketchSpace coordinate transformation matrix
00107   NEWMAT::Matrix& getTmat() { return Tmat; }
00108 
00109   //! return the SketchSpace-to-ShapeSpace coordinate transformation matrix
00110   NEWMAT::Matrix& getTmatinv() { return Tmatinv; }
00111 
00112   //! set the ShapeSpace-to-SketchSpace coordinate transformation matrix
00113   void setTmat(const NEWMAT::Matrix &mat);
00114 
00115   void setTmat(float scale=1, float tx=0, float ty=0);
00116 
00117   void setTmat(const BoundingBox &b);
00118 
00119   //! apply the ShapeSpace-to-SketchSpace coordinate transformation to a vector
00120   void applyTmat(NEWMAT::ColumnVector &vec);
00121 
00122   //! apply the SketchSpace-to-ShapeSpace coordinate transformation to a vector
00123   void applyTmatinv(NEWMAT::ColumnVector &vec);
00124 
00125   //! Returns the SketchPool of appropriate type for the calling Sketch
00126   //@{
00127   SketchPool<bool>&  get_pool(const Sketch<bool>&)  { return boolPool; }
00128   SketchPool<uchar>& get_pool(const Sketch<uchar>&) { return ucharPool; }
00129   SketchPool<uint>&  get_pool(const Sketch<uint>&)  { return uintPool; }
00130   SketchPool<float>& get_pool(const Sketch<float>&) { return floatPool; }
00131   
00132   //@}
00133   
00134   //!@name SketchGUI interface
00135   //@{
00136   
00137   //! Socket and port info for communication with a sketch viewer GUI.
00138   ViewerConnection *viewer;
00139 
00140   //! Returns a string describing the shape-to-sketch transformation matrix.
00141   std::string getTmatForGUI();
00142 
00143   //! Returns a string containing a list of all the sketches and their attributes
00144   std::string getSketchListForGUI();
00145 
00146   //! Returns a pointer to the sketch with specified ID number; null if not found
00147   SketchDataRoot* retrieveSketch(int const id);
00148   //@}
00149   
00150 protected:
00151   //! helper function to ensure indices of idx Sketches are proper
00152   void setIdx(Sketch<uint>& indices, int const x, int const y, int const indexval);
00153   
00154   // We don't want clients accidentally copying or assigning SketchSpace.
00155   SketchSpace(const SketchSpace&); //!< never call this
00156   SketchSpace& operator= (const SketchSpace&); //!< never call this
00157 };
00158 
00159 } // namespace
00160 
00161 #endif

DualCoding 4.0
Generated Thu Nov 22 00:52:36 2007 by Doxygen 1.5.4