Missed part of "Store Sequence sequence location in a shared_ptr class"
[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 : public Sequence
21 {
22 public: 
23   GlSequence(const Sequence & s,
24              boost::shared_ptr<AnnotationColors> cm);
25   GlSequence(const GlSequence & s);
26   GlSequence(const GlSequence *);
27   GlSequence &operator=(const GlSequence &s);
28
29   //! draw a track 
30   /*! left and right are the edges of the current viewport
31    */
32   void draw(GLfloat left, GLfloat right) const;
33
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   //! provide an iterator to the sequence starting at world coordinate left
56   Sequence::const_iterator region_begin(GLfloat left, GLfloat right) const;
57   //! provide an iterator to the sequence ending at world coordinate right
58   Sequence::const_iterator region_end(GLfloat left, GLfloat right) const;
59
60   //! return a subsequence as a GlSequence (instead of a Sequence subsequence)
61   GlSequence subseq(size_type start, size_type count) const;
62   
63   //! set track color 
64   void setColor(boost::shared_ptr<Color> &);
65   boost::shared_ptr<Color> color();
66
67   //! how big is a pixel in world coordinats
68   GLfloat pixelWidth(GLfloat, GLfloat) const;
69   //! how big is a pixel in world coordinats (specifying viewport size)
70   GLfloat pixelWidth(GLfloat, GLfloat, int) const;
71
72   //! are we close enough that it would make sense to view the base pairs?
73   bool is_sequence_renderable(GLfloat left, GLfloat right) const;
74   //! are we close enough that it would make sense to view the base pairs?
75   /*! though we don't actually check to see if there's sequence in our
76    *  view, just that there's enough pixels to render something if 
77    *  there were.
78    *  \param[in] left the left edge of the viewable region in world coordinates
79    *  \param[in] right the right edge of the viewable region in world 
80    *             coordinates
81    *  \param[in] pixel_width allow setting the current viewport pixel width
82    */
83   bool is_sequence_renderable(GLfloat, GLfloat, int) const;
84
85   friend bool operator==(const GlSequence &left, const GlSequence &right);
86
87 protected:
88   GLfloat seq_x;
89   GLfloat seq_y;
90   GLfloat seq_z;
91   GLfloat seq_height;
92   boost::shared_ptr<AnnotationColors> color_mapper;
93   boost::shared_ptr<Color> drawColor;
94   const GLfloat char_pix_per_world_unit;
95
96   //! Return the pixel width of the opengl viewport.
97   static int get_viewport_width_in_pixels();
98   //! draw a from left to right +/- height/2
99   void draw_box(GLfloat world_left, GLfloat world_right, GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
100   //! draw sequence as a bar
101   void draw_track(GLfloat, GLfloat) const;
102   void draw_annotations(GLfloat, GLfloat) const;
103   //! render a sequence as ATGC
104   /*! left and right are the current edges of the viewable world
105    */
106   void draw_sequence(GLfloat, GLfloat) const;
107 };
108 #endif