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/fmatSpatial.h"
00006 #include "Shared/BoundingBox.h"
00007 #include "Vision/colors.h"  // for rgb and yuv structs
00008 
00009 #include "SketchTypes.h"
00010 #include "ShapeTypes.h"
00011 #include "SketchPool.h"
00012 #include "SketchIndices.h"
00013 
00014 namespace DualCoding {
00015 
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   unsigned int width;   //!< pixels along x axis
00033   unsigned int height;  //!< pixels along y axis
00034   unsigned int numPixels; //!< total pixels = width * height
00035   fmat::Transform Tmat; //!< transformation matrix for rendering shapes
00036   fmat::Transform 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<usint> usintPool;
00048   SketchPool<uint> uintPool;
00049   SketchPool<float> floatPool; 
00050   SketchPool<yuv> yuvPool; 
00051   //@}
00052   
00053 public:
00054   //! The value assigned to out-of-bounds indices: @a numPixels, i.e., one beyond the last image pixel.
00055   int dummy;
00056 
00057   //!@name Pre-generated indices for different directions
00058   //@{
00059   Sketch<skindex> *idx;
00060   Sketch<skindex> *idxN;
00061   Sketch<skindex> *idxS;
00062   Sketch<skindex> *idxE;
00063   Sketch<skindex> *idxW;
00064   Sketch<skindex> *idxNE;
00065   Sketch<skindex> *idxNW;
00066   Sketch<skindex> *idxSE;
00067   Sketch<skindex> *idxSW;
00068   //@}
00069   
00070   SketchSpace(std::string const _name, ReferenceFrameType_t _refFrameType,
00071         int const init_id, size_t const _width, size_t const _height);
00072   
00073   ~SketchSpace();
00074   
00075   ShapeSpace& getDualSpace() const { return *dualSpace; }
00076   
00077   //! dumps contents of sketch space
00078   void dumpSpace() const;
00079   
00080   //! Clears out viewable Sketches, and also retained sketches if argument is true
00081   void clear(bool clearRetained=true);
00082 
00083   //! returns the width of contained images, in pixels
00084   unsigned int getWidth() const { return width; }
00085   //! returns the height of contained images, in pixels
00086   unsigned int getHeight() const { return height; }
00087   //! returns the number of pixels of images in this space
00088   unsigned int getNumPixels() const { return numPixels; }
00089   
00090   int getRefreshCounter() const { return refreshCounter; }
00091   void bumpRefreshCounter() { ++refreshCounter; }
00092 
00093   //! creates #idx if needed
00094   void requireIdx();
00095   
00096   //! creates #idxN, #idxS, #idxE, and #idxW if needed
00097   void requireIdx4way();
00098 
00099   //! creates #idxNE, #idxNW, #idxSE, and #idxSW, plus NSEW cases via requireIdx4way(), if needed
00100   void requireIdx8way();
00101   
00102   //! frees the idx members
00103   void freeIndexes();
00104 
00105   //! change the size of sketches in this sketch space (discards all existing sketches)
00106   void resize(const size_t new_width, const size_t new_height);
00107 
00108   //! return the ShapeSpace-to-SketchSpace coordinate transformation matrix
00109   fmat::Transform& getTmat() { return Tmat; }
00110 
00111   //! return the SketchSpace-to-ShapeSpace coordinate transformation matrix
00112   fmat::Transform& getTmatinv() { return Tmatinv; }
00113 
00114   //! set the ShapeSpace-to-SketchSpace coordinate transformation matrix
00115   void setTmat(const fmat::Transform &mat);
00116 
00117   void setTmat(float scale=1, float tx=0, float ty=0);
00118 
00119   void setTmat(const BoundingBox2D &b);
00120 
00121   //! apply the ShapeSpace-to-SketchSpace coordinate transformation to a vector
00122   void applyTmat(fmat::Column<3> &vec);
00123 
00124   //! apply the SketchSpace-to-ShapeSpace coordinate transformation to a vector
00125   void applyTmatinv(fmat::Column<3> &vec);
00126 
00127   //! Returns the SketchPool of appropriate type for the calling Sketch
00128   //@{
00129   SketchPool<bool>&  get_pool(const Sketch<bool>&)  { return boolPool; }
00130   SketchPool<uchar>& get_pool(const Sketch<uchar>&) { return ucharPool; }
00131   SketchPool<usint>& get_pool(const Sketch<usint>&){ return usintPool; }
00132   SketchPool<uint>&  get_pool(const Sketch<uint>&)  { return uintPool; }
00133   SketchPool<float>& get_pool(const Sketch<float>&) { return floatPool; }
00134   SketchPool<yuv>& get_pool(const Sketch<yuv>&) { return yuvPool; }
00135   
00136   //@}
00137   
00138   //!@name SketchGUI interface
00139   //@{
00140   
00141   //! Socket and port info for communication with a sketch viewer GUI.
00142   ViewerConnection *viewer;
00143 
00144   //! Returns a string describing the shape-to-sketch transformation matrix.
00145   std::string getTmatForGUI();
00146 
00147   //! Returns a string containing a list of all the sketches and their attributes
00148   std::string getSketchListForGUI();
00149 
00150   //! Returns a pointer to the sketch with specified ID number; null if not found
00151   SketchDataRoot* retrieveSketch(int const id);
00152   //@}
00153   
00154 protected:
00155   //! helper function to ensure indices of idx Sketches are proper
00156   void setIdx(Sketch<skindex>& indices, int const x, int const y, int const indexval);
00157   
00158   // We don't want clients accidentally copying or assigning SketchSpace.
00159   SketchSpace(const SketchSpace&); //!< never call this
00160   SketchSpace& operator= (const SketchSpace&); //!< never call this
00161 };
00162 
00163 } // namespace
00164 
00165 #endif

DualCoding 5.1CVS
Generated Sat May 4 06:29:28 2013 by Doxygen 1.6.3