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