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