Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SketchDataRoot.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 
00003 #ifndef INCLUDED_SketchDataRoot_h
00004 #define INCLUDED_SketchDataRoot_h
00005 
00006 #include <string>
00007 
00008 #include "Shared/ProjectInterface.h"
00009 
00010 #include "SketchTypes.h"
00011 #include "SketchSpace.h"
00012 #include "ShapeRoot.h"
00013 
00014 namespace DualCoding {
00015 
00016 //! Parent class for SketchData<T>
00017 class SketchDataRoot {
00018 private:
00019   //! The SketchSpace that owns the pool containing this SketchData object.
00020   SketchSpace *space;
00021   
00022   //! Name of this sketch.
00023   std::string name;
00024 
00025   //! Sketch-specific integer ID, for unique identification
00026   int id;
00027 
00028   //! Integer ID of the "parent" Sketch, 0 if no parent; used in GUI
00029   int parentId;
00030 
00031   //! Reference count for the sketch. When SketchPool detects this as 0, it may reuse it.
00032   int refcount;
00033 
00034   //! True if the Sketch is currently viewable.
00035   bool viewable;
00036 
00037   //! Last time this sketch was included in a sketch list sent to the GUI
00038   int refreshTag;
00039 
00040   //! True if we've tried to clear this sketch but the SketchGUI was looking at it
00041   bool clearPending;
00042 
00043   //! Color to use for displaying this sketch.  Only meaningful for Sketch<bool>,
00044   //! but info is preserved in case we coerce bool to int or float and then back to bool.
00045   rgb color;
00046 
00047   //! Which color map to use; default is to use the robot's own color table.
00048   //! Other tables are used for displaying grayscale images, or scaled quantities like
00049   //! distance or area using a continuous color scale from red to blue.
00050   ColorMapType_t colormap;
00051 
00052   template<typename T> friend class SketchPool;
00053   template<typename T> friend class Sketch;
00054   template<typename T> friend class SketchData;
00055   friend class SketchRoot;
00056 
00057 public:
00058   SketchDataRoot(SketchSpace *s) : 
00059     space(s), name(), id(0), parentId(0), 
00060     refcount(0), viewable(false), refreshTag(0), clearPending(false),
00061     color((ProjectInterface::getNumColors() != -1U) ? ProjectInterface::getColorRGB(1) : rgb(0,0,255)), // color 0 is invalid, so use color 1 as default, or blue if colors aren't loaded yet
00062     colormap(segMap) {}
00063 
00064   virtual ~SketchDataRoot() {};
00065 
00066   //! Returns the SketchSpace that owns the pool containing this SketchData object.
00067   SketchSpace& getSpace() const { return *space; }
00068 
00069   //! Returns the ShapeSpace associated with the SketchSpace for this Sketch
00070   ShapeSpace& getDualSpace() const { return space->getDualSpace(); }
00071 
00072   int getId() const { return id; }
00073   int getParentId() const { return parentId; }
00074   int getViewableId() const { return (isViewable() ? getId() : getParentId()); }
00075   void setParentId(int const _id) { parentId = _id; }
00076   bool isViewable() const { return viewable; }
00077   void setViewable(bool const v) { viewable=v; }
00078   int getRefcount() const { return refcount; }
00079   rgb getColor() const { return color; }
00080   void setColor(const rgb &_color) { color = _color; }
00081   void setColor(const std::string &colorname);
00082   void setColor(const color_index cindex);
00083   ColorMapType_t getColorMap() const { return colormap; }
00084   void setColorMap(const ColorMapType_t _map) { colormap = _map; }
00085   const std::string& getName() const { return name; }
00086   void setName(const std::string &_name) { name = _name; }
00087 
00088   virtual SketchType_t getType() const=0;
00089 
00090   void V(std::string const &_name="");
00091   void N(std::string const &_name="");
00092 
00093   void inheritFrom(const SketchDataRoot &parent);
00094   void inheritFrom(const ShapeRoot &parent);
00095   void inheritFrom(const BaseData &parent);
00096 
00097   //@{
00098   //! Width and height of sketches in this space.
00099   const size_t getWidth() const;
00100   const size_t getHeight() const;
00101   const size_t getNumPixels() const;
00102   //@}
00103 
00104   //! X coordinate encoded by sketch index
00105   int indexX(int index) { return index % getWidth(); }
00106 
00107   //! Y coordinate encoded by sketch index
00108   int indexY(int index) { return index / getWidth(); }
00109 
00110   //! converts (x,y) into a sketch index
00111   int indexOf(int x, int y) { return y*getWidth() + x; }
00112 
00113   virtual unsigned int saveBuffer(char buf[], unsigned int avail) const=0;
00114 
00115 private:
00116   SketchDataRoot(const SketchDataRoot&); //!< never call this
00117   SketchDataRoot& operator=(const SketchDataRoot&); //!< never call this
00118 };
00119 
00120 } // namespace
00121 
00122 #endif

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