Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
display.hpp
00001 #ifndef DISPLAY_HPP
00002 #define DISPLAY_HPP
00003 
00004 #include <boost/shared_ptr.hpp>
00005 #include <boost/graph/adjacency_list.hpp>
00006 
00007 #include "qdisplay/ImageView.hpp"
00008 #include "qdisplay/Viewer.hpp"
00009 #include "qdisplay/Shape.hpp"
00010 #include "qdisplay/Ellipsoid.hpp"
00011 #include "qdisplay/Line.hpp"
00012 #include "qdisplay/init.hpp"
00013 
00014 #include <QGraphicsItem>
00015 #include <QList>
00016 
00017 namespace jafar{
00018 namespace graphmap{
00019 namespace display{
00020 
00021 class Node;
00022 class Edge;
00023 
00024 class Viewer: public QObject
00025 {
00033     //Q_OBJECT
00034 
00035 public:
00036   Viewer();
00037   virtual ~Viewer();
00038 
00039   void itemMoved();
00040 
00041   template <typename Graph>
00042   void bufferize(const Graph& g)
00043   {
00044     using namespace boost;
00045     typedef typename graph_traits<Graph>::edge_iterator Edge;
00046 
00047     // Loop into graph's edges
00048     Edge ei, ei_end;
00049     for (tie(ei, ei_end) = edges(g); ei != ei_end; ++ei)
00050     {
00051       int from_id = ((g)[source(*ei,g)].getId().second),
00052           to_id = ((g)[boost::target(*ei,g)].getId()).second;
00053       if(!existDisplayEdge(from_id,to_id)) // Check if the edge exists
00054       {
00055         addDisplayEdge(from_id,to_id); // If not, add new edge to edge display list
00056       }
00057     }
00058 
00060   }
00061 
00062   void render();
00063   void view();
00064 
00065 public slots:
00066   void shuffle();
00067   void zoomIn();
00068   void zoomOut();
00069 
00070 
00071 public:
00072   //cv::Size _size;
00073   unsigned int _width;
00074   unsigned int _height;
00075   qdisplay::Viewer* _viewer;
00076 
00077 protected:
00078 
00079   bool existDisplayEdge(int from_id, int to_id);
00080   void addDisplayEdge(int from_id, int to_id);
00081 
00082   void timerEvent(QTimerEvent *event);
00083   void wheelEvent(QWheelEvent *event);
00084   void drawBackground(QPainter *painter, const QRectF &rect);
00085 
00086   void scaleView(qreal scaleFactor);
00087   Node* getNodeWithId(int id);
00088 
00089 private:
00090   int timerId;
00091   std::list<Node*> node_list;
00092   std::list<Edge*> edge_list;
00093 
00094 };
00095 
00096 class Edge : public QGraphicsItem
00097 {
00098 public:
00099   Edge(Node *sourceNode, Node *destNode);
00100 
00101   Node *sourceNode() const;
00102   Node *destNode() const;
00103 
00104   void adjust();
00105 
00106   enum { Type = UserType + 2 };
00107   int type() const { return Type; }
00108 
00109 protected:
00110   QRectF boundingRect() const;
00111   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00112 
00113 private:
00114   Node *source, *dest;
00115   QPointF sourcePoint;
00116   QPointF destPoint;
00117   qreal arrowSize;
00118 };
00119 
00120 class Node : public QGraphicsItem
00121 {
00122 public:
00123   Node(int id, Viewer *graphWidget);
00124 
00125   void addEdge(Edge *edge);
00126   QList<Edge*> edges() const;
00127 
00128   enum { Type = UserType + 1 };
00129   int type() const { return Type; }
00130 
00131   void calculateForces();
00132   bool advance();
00133 
00134   QRectF boundingRect() const;
00135   QPainterPath shape() const;
00136   void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
00137 
00138 protected:
00139   QVariant itemChange(GraphicsItemChange change, const QVariant &value);
00140 
00141   void mousePressEvent(QGraphicsSceneMouseEvent *event);
00142   void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
00143 
00144 private:
00145   QList<Edge*> edgeList;
00146   QPointF newPos;
00147   Viewer *graph;
00148 public:
00149   int _id;
00150 };
00151 
00152 }
00153 }
00154 }
00155 
00156 
00157 #endif // DISPLAY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:18 for Jafar by doxygen 1.7.6.1
LAAS-CNRS