ab96239374e08f3b9a4263f0e0c622112d152a56
[mussa.git] / alg / glsequence.hpp
1 #ifndef _GL_SEQUENCE_H_
2 #define _GL_SEQUENCE_H_
3
4 #include <boost/shared_ptr.hpp>
5
6 #include "alg/annotation_colors.hpp"
7 #include "alg/sequence.hpp"
8 #include "alg/color.hpp"
9 // isn't it lovely how the header file can live in different places?
10 #ifdef __APPLE__
11 #include <OpenGL/gl.h>
12 #else
13 #include <GL/gl.h>
14 #endif
15
16 //! Manage rendering a mussa sequence track
17 /*! The idea is this will keep track of the location of where the sequence
18  *  is being rendered, and handle displaying annotations on that track
19  */
20 class GlSequence
21 {
22 public: 
23   GlSequence(boost::shared_ptr<Sequence> s, 
24              boost::shared_ptr<AnnotationColors> cm);
25   GlSequence(const GlSequence & s);
26   GlSequence &operator=(const GlSequence &s);
27
28   //! draw a track 
29   /*! left and right are the edges of the current viewport
30    */
31   void draw(GLfloat left, GLfloat right) const;
32
33   boost::shared_ptr<Sequence> sequence();
34   //! set our starting x (horizontal) coordinate
35   void setX(GLfloat);
36   //! get our starting x (horizontal) coordinate
37   GLfloat x() const;
38   //! get our right (horizontal) coordinate (size-x)
39   GLfloat right() const;
40   //! set our current y (vertical) position
41   void setY(GLfloat);
42   //! get our current y (vertical) position
43   GLfloat y() const;
44   //! how thick (high) the track we're drawing is
45   GLfloat height() const;
46   //! how long is our sequence track? (computed from the sequence)
47   GLfloat size() const;
48  
49   //! return the left (lowest) base index that is fully visible
50   Sequence::size_type leftbase(GLfloat left) const;
51   //! return one past rightmost (highest ) base index that is fully visible
52   //! done mostly so all the iterator logic continues to work correctly.
53   Sequence::size_type rightbase(GLfloat right) const;
54
55   //! return iterator to the start of the stored sequence
56   Sequence::const_iterator sequence_begin() const;
57   //! return iterator to the end of the stored sequence
58   Sequence::const_iterator sequence_end() const;
59   //! provide an iterator to the sequence starting at world coordinate left
60   Sequence::const_iterator sequence_begin(GLfloat left, GLfloat right) const;
61   //! provide an iterator to the sequence ending at world coordinate right
62   Sequence::const_iterator sequence_end(GLfloat left, GLfloat right) const;
63
64   //! set track color 
65   void setColor(Color &);
66   Color color();
67
68   //! how big is a pixel in world coordinats
69   GLfloat get_pixel_width(GLfloat, GLfloat) const;
70   //! how big is a pixel in world coordinats (specifying viewport size)
71   GLfloat get_pixel_width(GLfloat, GLfloat, int) const;
72
73   //! are we close enough that it would make sense to view the base pairs?
74   bool is_sequence_renderable(GLfloat left, GLfloat right) const;
75   //! are we close enough that it would make sense to view the base pairs?
76   /*! though we don't actually check to see if there's sequence in our
77    *  view, just that there's enough pixels to render something if 
78    *  there were.
79    *  \param[in] left the left edge of the viewable region in world coordinates
80    *  \param[in] right the right edge of the viewable region in world 
81    *             coordinates
82    *  \param[in] pixel_width allow setting the current viewport pixel width
83    */
84   bool is_sequence_renderable(GLfloat, GLfloat, int) const;
85
86   friend bool operator==(const GlSequence &left, const GlSequence &right);
87
88 protected:
89   boost::shared_ptr<Sequence> seq;
90   GLfloat seq_x;
91   GLfloat seq_y;
92   GLfloat seq_z;
93   GLfloat seq_height;
94   boost::shared_ptr<AnnotationColors> color_mapper;
95   Color drawColor;
96   const GLfloat char_pix_per_world_unit;
97
98   //! Return the pixel width of the opengl viewport.
99   static int get_viewport_width_in_pixels();
100   //! draw a from left to right +/- height/2
101   void draw_box(GLfloat world_left, GLfloat world_right, GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
102   //! draw sequence as a bar
103   void draw_track(GLfloat, GLfloat) const;
104   void draw_annotations(GLfloat, GLfloat) const;
105   //! render a sequence as ATGC
106   /*! left and right are the current edges of the viewable world
107    */
108   void draw_sequence(GLfloat, GLfloat) const;
109 };
110 #endif