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