make the path view independent of type of connection
[mussa.git] / alg / gltracks.hpp
1 #ifndef _GLTRACKS_H_
2 #define _GLTRACKS_H_
3
4 #include <map>
5 #include <vector>
6
7 #include "alg/annotation_colors.hpp"
8 #include "alg/sequence.hpp"
9 #include "alg/glsequence.hpp"
10
11 //! Manage rendering a collection of glSequences
12 class GlTracks
13 {
14 public:
15   GlTracks();
16   GlTracks(const GlTracks&);
17
18   //! setup the opengl canvas
19   void initializeGL();
20   //! called when our screen canvas is resized
21   void resizeGL(int width, int height);
22   //! render our scene
23   void paintGL() const;
24
25   //! max world left coordinate
26   float left() const;
27   //! max world right coordinate
28   float right() const;
29
30   void setViewportCenter(float x);
31   float viewportLeft() const;
32   float viewportCenter() const;
33   float viewportRight() const;
34   float viewportHeight() const;
35   float viewportWidth() const;
36
37   void setZoom(int zoom_level);
38   int zoom() const;
39
40   void setColorMapper(AnnotationColors& cm);
41   AnnotationColors& colorMapper();
42
43   //! clear our tracks and connections
44   void clear();
45
46   //! add a sequence to the back of our track container
47   void push_sequence(const Sequence &s);
48   //! add a glsequence to the back of our track container
49   void push_sequence(GlSequence &s);
50   //! return our track container
51   const std::vector<GlSequence>& tracks() const;
52
53   //! clear all the line segments between all the sequences
54   void clear_links();
55   //! define a path
56   void link(std::vector<int> path, std::vector<bool> isRC, int length);
57
58   //! a useful point class
59   template<class T> struct point {
60     T x;
61     T y;
62
63     point(T x_, T y_):x(x_), y(y_) {}
64   };
65
66   //! a useful rectangle, where 0,0 is in the lower left
67   template<class T> struct rect {
68     T top;
69     T left;
70     T bottom;
71     T right;
72
73     rect(T t, T l, T b, T r) : top(t), left(l), bottom(b), right(r) {}
74     T width() { return right - left; }
75     T height() { return top - bottom; }
76   };
77
78   struct Segment
79   {
80     point<float> start;
81     point<float> end;
82     bool reversed;
83     std::list<int> path_ids;
84
85     Segment() : start(0.0, 0.0), end(0.0, 0.0) {}
86     Segment(float x1, float y1, float x2, float y2, bool isRC) 
87       : start(x1, y1), end(x2, y2), reversed(isRC) {}
88   };
89
90   //! data structure holding our line segments
91   /*! the vector is of size track_container.size()-1
92    *  it's indexed by the pair x1, x2 (the two x coordinates between
93    *  the two tracks
94    */
95   typedef std::pair<int, int> segment_key;
96   typedef std::map<segment_key, Segment> pair_segment_map;
97   typedef std::vector<pair_segment_map> path_segment_map_vector;
98   path_segment_map_vector path_segments;
99 private:
100   //! recalculate the viewable world
101   /*! depending on the size of our canvas, our zoom level and
102    *  how far we've been offset
103    */
104   void update_viewport(float center, int new_zoom);
105
106   //! determine where all the tracks should be placed
107   void update_layout();
108
109   //! master scene drawing function
110   /*! draw is broken out for the opengl selection code
111    */
112   void draw() const;
113   //! draw glsequence tracks
114   void draw_tracks() const;
115   //! draw line segments between tracks
116   void draw_segments() const;
117   //! draw selection box
118   void draw_selection() const;
119
120   //! number of pixels to reserve around the edges of our canvas
121   const int border;
122   //! the maximum dimensions that our scene is taking up (world coord)
123   rect<float> max_ortho;
124   //! the current viewable region (world coord)
125   rect<float> cur_ortho;
126   //! how many pixels our viewport is (screen coord)
127   point<int> viewport_size;
128   //! the center of our current viewport (world coord) (used for scrollbar)
129   float viewport_center;
130   int zoom_level;
131   AnnotationColors color_mapper;
132   //! container of all the GlSequences loaded into our scene
133   std::vector<GlSequence> track_container;
134   //! counter for each path added to us via connect
135   int pathid;
136 };
137 #endif