load and display a motif list
[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   //! set our current y (vertical) position
30   void setY(GLfloat);
31   //! get our current y (vertical) position
32   GLfloat y() const;
33   //! how long is our sequence track? (computed from the sequence)
34   GLfloat length() const;
35  
36   //! return the left (lowest) base index that is fully visible
37   Sequence::size_type GlSequence::leftbase(GLfloat left) const;
38   //! return one past rightmost (highest ) base index that is fully visible
39   /*! done mostly so all the iterator logic continues to work correctly.
40    */
41   Sequence::size_type GlSequence::rightbase(GLfloat right) const;
42
43   //! return iterator to the start of the stored sequence
44   Sequence::const_iterator sequence_begin() const;
45   //! return iterator to the end of the stored sequence
46   Sequence::const_iterator sequence_end() const;
47   //! provide an iterator to the sequence starting at world coordinate left
48   Sequence::const_iterator sequence_begin(GLfloat left, GLfloat right) const;
49   //! provide an iterator to the sequence ending at world coordinate right
50   Sequence::const_iterator sequence_end(GLfloat left, GLfloat right) const;
51
52   //! set track color 
53   void setColor(Color &);
54   Color color();
55
56   //! are we close enough that it would make sense to view the base pairs?
57   /*! though we don't actually check to see if there's sequence in our
58    *  view, just that there's enough pixels to render something if 
59    *  there were.
60    *  \param[in] left the left edge of the viewable region in world coordinates
61    *  \param[in] right the right edge of the viewable region in world 
62    *             coordinates
63    *  \param[in] pixel_width allow setting the current viewport pixel width
64    */
65   bool is_sequence_renderable(GLfloat left, 
66                               GLfloat right, 
67                               int pixel_width=-1) const;
68
69   friend bool operator==(const GlSequence &left, const GlSequence &right);
70
71 protected:
72   const Sequence& seq;
73   GLfloat seq_x;
74   GLfloat seq_y;
75   GLfloat seq_z;
76   GLfloat seq_height;
77   AnnotationColors& color_mapper;
78   Color drawColor;
79   const GLfloat char_pix_per_world_unit;
80
81   //! Return the pixel width of the opengl viewport.
82   static int get_viewport_pixel_width();
83   //! draw a from left to right +/- height/2
84   void draw_box(GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
85   //! draw sequence as a bar
86   void draw_track(GLfloat, GLfloat) const;
87   void draw_annotations(GLfloat, GLfloat) const;
88   //! render a sequence as ATGC
89   /*! left and right are the current edges of the viewable world
90    */
91   void draw_sequence(GLfloat, GLfloat) const;
92 };
93 #endif