incorporate drawable and annotations
[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 class GlSequence;
17 typedef boost::shared_ptr<GlSequence> GlSequenceRef;
18
19 //! Manage rendering a mussa sequence track
20 /*! The idea is this will keep track of the location of where the sequence
21  *  is being rendered, and handle displaying annotations on that track
22  */
23 class GlSequence : public Sequence
24 {
25 public: 
26   GlSequence(const Sequence & s,
27              boost::shared_ptr<AnnotationColors> cm);
28   GlSequence(const GlSequence & s);
29   GlSequence(const GlSequence *);
30   //! Make a new GlSequence, using a copy of SeqSpan
31   GlSequence(const GlSequenceRef);
32   
33   GlSequence &operator=(const GlSequence &s);
34
35   static DrawableRef default_drawable();
36   static DrawableRef copy_drawable(DrawableRef s);
37   
38   //! set our starting x (horizontal) coordinate
39   void setX(float x);
40   //! get our starting x (horizontal) coordinate
41   float x() const;
42   //! set our current y (vertical) position
43   void setY(float y);
44   //! get our current y (vertical) position
45   float y() const;
46   //! get our current z (depth) position
47   float z() const;
48   //! how thick (high) the track we're drawing is
49   float height() const;
50
51   //! set our default draw color
52   void setColor(ColorRef &c );
53   //! return our draw color
54   const ColorRef color() const;
55   //! return our draw color
56   ColorRef color();
57
58   //! draw a track 
59   /*! left and right are the edges of the current viewport
60    */
61   void draw(GLfloat left, GLfloat right) const;
62
63   //! get our right (horizontal) coordinate (size-x)
64   float right() const;
65   //! how long is our sequence track? (computed from the sequence)
66   GLfloat size() const;
67  
68   //! return the left (lowest) base index that is fully visible
69   Sequence::size_type leftbase(GLfloat left) const;
70   //! return one past rightmost (highest ) base index that is fully visible
71   //! done mostly so all the iterator logic continues to work correctly.
72   Sequence::size_type rightbase(GLfloat right) const;
73
74   //! provide an iterator to the sequence starting at world coordinate left
75   Sequence::const_iterator region_begin(GLfloat left, GLfloat right) const;
76   //! provide an iterator to the sequence ending at world coordinate right
77   Sequence::const_iterator region_end(GLfloat left, GLfloat right) const;
78
79   //! return a subsequence as a GlSequence (instead of a Sequence subsequence)
80   GlSequence subseq(size_type start, size_type count) const;
81   
82   //! how big is a pixel in world coordinats
83   GLfloat pixelWidth(GLfloat, GLfloat) const;
84   //! how big is a pixel in world coordinats (specifying viewport size)
85   GLfloat pixelWidth(GLfloat, GLfloat, int) const;
86
87   //! are we close enough that it would make sense to view the base pairs?
88   bool is_sequence_renderable(GLfloat left, GLfloat right) const;
89   //! are we close enough that it would make sense to view the base pairs?
90   /*! though we don't actually check to see if there's sequence in our
91    *  view, just that there's enough pixels to render something if 
92    *  there were.
93    *  \param[in] left the left edge of the viewable region in world coordinates
94    *  \param[in] right the right edge of the viewable region in world 
95    *             coordinates
96    *  \param[in] pixel_width allow setting the current viewport pixel width
97    */
98   bool is_sequence_renderable(GLfloat, GLfloat, int) const;
99
100   friend bool operator==(const GlSequence &left, const GlSequence &right);
101
102 protected:
103   boost::shared_ptr<AnnotationColors> color_mapper;
104   const GLfloat char_pix_per_world_unit;
105
106   //! Return the pixel width of the opengl viewport.
107   static int get_viewport_width_in_pixels();
108   //! draw a from left to right +/- height/2
109   void draw_box(GLfloat world_left, GLfloat world_right, GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
110   //! draw sequence as a bar
111   void draw_track(GLfloat, GLfloat) const;
112   void draw_annotations(GLfloat, GLfloat) const;
113   //! render a sequence as ATGC
114   /*! left and right are the current edges of the viewable world
115    */
116   void draw_sequence(GLfloat, GLfloat) const;
117 };
118 #endif