Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

GraphicsData.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _GRAPHICSDATA_H_
00003 #define _GRAPHICSDATA_H_
00004 
00005 #include <vector>
00006 
00007 #include "BaseData.h"
00008 #include "Shared/Measures.h" // AngPi
00009 #include "Localization/ShapeBasedParticleFilter.h"
00010 #include "ShapeLocalizationParticle.h"
00011 
00012 namespace DualCoding {
00013 
00014   template<typename T> class Sketch;
00015 
00016   //! Graphical display of a collection of lines, ellipses, particles, and text objects
00017   class GraphicsData : public BaseData {
00018   public:
00019     typedef std::pair<float,float> xyPair;
00020     typedef fmat::Column<3> xyzPair;
00021 
00022     enum GraphicsElementType {
00023       lineGType,
00024       polygonGType,
00025       ellipseGType,
00026       textGType,
00027       locParticleGType,
00028       axisAngleGType,
00029       pointGType,
00030       boundingGType
00031     };
00032 
00033     class GraphicsElement {
00034     private:
00035       GraphicsElementType type;
00036       std::string name;
00037       rgb color;
00038     public:
00039       GraphicsElement(GraphicsElementType _type, std::string _name, rgb _color) :
00040   type(_type), name(_name), color(_color) {}
00041       virtual ~GraphicsElement() {};
00042       GraphicsElementType getType() const { return type; }
00043       const std::string& getName() const { return name; }
00044       void setName(const std::string &_name) { name=_name; }
00045       const rgb& getColor() const { return color; }
00046       void setColor(const rgb c) { color = c; }
00047       void setColor(const std::string &colorname);
00048     };
00049 
00050     class LineElement : public GraphicsElement {
00051     public:
00052       xyPair pt1, pt2;
00053       LineElement(const std::string &_name, const xyPair &_pt1, const xyPair &_pt2, const rgb _color=rgb(0,0,255))
00054   : GraphicsElement(lineGType, _name, _color), pt1(_pt1), pt2(_pt2) {}
00055       virtual ~LineElement() {}
00056     };
00057   
00058     class PolygonElement : public GraphicsElement {
00059     public:
00060       std::vector<xyPair> vertices;
00061       bool closed;
00062     
00063       PolygonElement(const std::string &_name, const std::vector<xyPair> &pts, bool _closed, rgb _color=rgb(255,0,0))
00064   : GraphicsElement(polygonGType, _name, _color), vertices(pts.size()>1 ? pts : std::vector<xyPair>()), closed(_closed) {}
00065       virtual ~PolygonElement() {}
00066     };
00067 
00068     class BoundingBoxElement : public GraphicsElement {
00069     public:
00070       fmat::Quaternion q;
00071       xyzPair centroid;
00072       float l, w, h;
00073       std::vector<std::vector<fmat::Column<3> > > vertices;
00074       BoundingBoxElement(const std::string &_name, const fmat::Quaternion &_q, 
00075        const xyzPair & _centroid, float _l, float _w, float _h, rgb _color=rgb(255,0,0)) :
00076   GraphicsElement(boundingGType, _name, _color), q(_q), centroid(_centroid),
00077   l(_l), w(_w), h(_h), vertices(std::vector<std::vector<fmat::Column<3> > >()){}
00078       BoundingBoxElement(const std::string &_name, const std::vector<std::vector<fmat::Column<3> > > &_vertices,
00079        rgb _color = rgb(255,0,0)) : 
00080   GraphicsElement(boundingGType, _name, _color), q(fmat::Quaternion()), 
00081   centroid(xyzPair()), l(0), w(0), h(0), vertices(_vertices) {}
00082       virtual ~BoundingBoxElement() {}
00083     };
00084 
00085     class EllipseElement : public GraphicsElement {
00086     public:
00087       xyPair center;
00088       float semimajor, semiminor;
00089       AngPi orientation;
00090       bool filled;
00091       EllipseElement(const std::string &_name, const xyPair &_center, float _semimajor, float _semiminor,
00092          AngTwoPi _orientation, bool _filled, const rgb _color=rgb(255,0,0)) :
00093   GraphicsElement(ellipseGType, _name, _color),
00094   center(_center), semimajor(_semimajor), semiminor(_semiminor),
00095   orientation(_orientation), filled(_filled) {}
00096       virtual ~EllipseElement() {}
00097     };
00098   
00099     class TextElement : public GraphicsElement {
00100     public:
00101       xyPair startpt;
00102       std::string msg;
00103     
00104       TextElement(const std::string &_name, const xyPair &_startpt, std::string const &_msg, const rgb _color=rgb(0,0,0)) :
00105   GraphicsElement(textGType, _name, _color), startpt(_startpt), msg(_msg) {}
00106       virtual ~TextElement() {}
00107     };
00108 
00109     class LocalizationParticleElement : public GraphicsElement {
00110     public:
00111       const ShapeBasedParticleFilter::particle_collection *particles;
00112       ShapeBasedParticleFilter::index_t index;
00113     
00114       LocalizationParticleElement(const std::string &_name, 
00115           const ParticleFilter<LocalizationParticle>::particle_collection &_particles,
00116           ParticleFilter<LocalizationParticle>::index_t _index, const rgb _color=rgb(0,0,0)) :
00117   GraphicsElement(locParticleGType, _name, _color), particles(&_particles), index(_index) {}
00118     
00119       LocalizationParticleElement(const LocalizationParticleElement &other) :
00120   GraphicsElement(other), particles(other.particles), index(other.index) {}
00121     
00122       virtual Point getCentroid() const { return Point((*particles)[index].x, (*particles)[index].y);}
00123 
00124       AngTwoPi getOrientation() const { return (*particles)[index].theta; }
00125       float getWeight() const { return (*particles)[index].weight; }
00126             
00127       LocalizationParticleElement& operator=(const LocalizationParticleElement &other) {
00128   if ( this != &other ) {
00129     particles = other.particles;
00130     index = other.index;
00131   }
00132   return *this;
00133       }
00134     
00135       virtual ~LocalizationParticleElement() {}
00136     };
00137 
00138     class AxisAngleElement : public GraphicsElement {
00139     public:
00140       fmat::Quaternion q;
00141       xyzPair centroid;
00142       AxisAngleElement(const std::string &_name, const fmat::Quaternion &_q, 
00143            const xyzPair &_centroid, const rgb _color = rgb(0,0,0)) :
00144   GraphicsElement(axisAngleGType, _name, _color), q(_q), centroid(_centroid) {}
00145       virtual ~AxisAngleElement() {}
00146     };
00147 
00148     class PointElement : public GraphicsElement {
00149     public:
00150       xyPair center;
00151       PointElement(const std::string &_name, const xyPair &_center, const rgb _color=rgb(255,0,0)) :
00152   GraphicsElement(pointGType, _name, _color), center(_center) {}
00153       virtual ~PointElement() {}
00154     };
00155 
00156     class CircleElement : public EllipseElement {
00157     public:
00158       CircleElement(const std::string &_name, const xyPair &_center, float _radius, bool _filled, const rgb _color=rgb(255,0,0)) : 
00159   EllipseElement(_name, _center, _radius, _radius, 0, _filled, _color) {}
00160       virtual ~CircleElement() {}
00161     };
00162 
00163     std::vector<const GraphicsElement*> elements;
00164 
00165     GraphicsData(ShapeSpace &_space);
00166 
00167     static ShapeType_t getStaticType() { return graphicsDataType; }
00168 
00169     DATASTUFF_H(GraphicsData);
00170 
00171     virtual ~GraphicsData();
00172 
00173     void add(const GraphicsElement *element);
00174 
00175     virtual bool isMatchFor(const ShapeRoot& other) const { return false; }
00176     virtual bool updateParams(const ShapeRoot& other, bool force=false) { return false; }
00177     Point getCentroid() const { return Point(); }
00178     virtual void printParams() const;
00179     void applyTransform(const fmat::Transform& Tmat, const ReferenceFrameType_t newref=unspecified) {}
00180     virtual void projectToGround(const fmat::Transform& camToBase, const PlaneEquation& groundplane) {}
00181 
00182     virtual unsigned short getDimension() const { return 2; }
00183 
00184   private:
00185     virtual Sketch<bool>* render() const;
00186 
00187   };
00188 
00189 } // namespace
00190 
00191 #endif
00192 

DualCoding 5.1CVS
Generated Mon May 9 04:56:26 2016 by Doxygen 1.6.3