190401a956644ddc3aed36af42857be5bba7715f
[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   //! search through sequence and add an annotation highlighting all the non AGCT characters
39   void add_annotations_for_undefined_sequence(Drawable::draw_func_ptr draw=0);
40   //! set our starting x (horizontal) coordinate
41   void setX(float x);
42   //! get our starting x (horizontal) coordinate
43   float x() const;
44   //! set our current y (vertical) position
45   void setY(float y);
46   //! get our current y (vertical) position
47   float y() const;
48   //! get our current z (depth) position
49   float z() const;
50   //! how thick (high) the track we're drawing is
51   float height() const;
52
53   //! set our default draw color
54   void setColor(ColorRef &c );
55   //! return our draw color
56   const ColorRef color() const;
57   //! return our draw color
58   ColorRef color();
59   //! return our annotation color mapper
60   AnnotationColorsRef colorMapper() { return color_mapper; }
61
62   //! draw a from left to right +/- height/2
63   static
64   void draw_box(GLfloat world_left, GLfloat world_right, 
65                 GLfloat left, GLfloat right, GLfloat height,
66                 GLfloat y, GLfloat z);
67   //! draw a track 
68   /*! left and right are the edges of the current viewport
69    */
70   void draw(GLfloat left, GLfloat right) const;
71
72   //! get our right (horizontal) coordinate (size-x)
73   float right() const;
74   //! how long is our sequence track? (computed from the sequence)
75   GLfloat size() const;
76  
77   //! return the left (lowest) base index that is fully visible
78   Sequence::size_type leftbase(GLfloat left) const;
79   //! return one past rightmost (highest ) base index that is fully visible
80   //! done mostly so all the iterator logic continues to work correctly.
81   Sequence::size_type rightbase(GLfloat right) const;
82
83   //! provide an iterator to the sequence starting at world coordinate left
84   Sequence::const_iterator region_begin(GLfloat left, GLfloat right) const;
85   //! provide an iterator to the sequence ending at world coordinate right
86   Sequence::const_iterator region_end(GLfloat left, GLfloat right) const;
87
88   //! return a subsequence as a GlSequence (instead of a Sequence subsequence)
89   GlSequence subseq(size_type start, size_type count) const;
90   
91   //! Return the pixel width of the opengl viewport.
92   static int get_viewport_width_in_pixels();
93   //! how big is a pixel in world coordinats
94   static GLfloat pixelWidth(GLfloat, GLfloat);
95   //! how big is a pixel in world coordinats (specifying viewport size)
96   static GLfloat pixelWidth(GLfloat, GLfloat, int);
97
98   //! are we close enough that it would make sense to view the base pairs?
99   bool is_sequence_renderable(GLfloat left, GLfloat right) const;
100   //! are we close enough that it would make sense to view the base pairs?
101   /*! though we don't actually check to see if there's sequence in our
102    *  view, just that there's enough pixels to render something if 
103    *  there were.
104    *  \param[in] left the left edge of the viewable region in world coordinates
105    *  \param[in] right the right edge of the viewable region in world 
106    *             coordinates
107    *  \param[in] pixel_width allow setting the current viewport pixel width
108    */
109   bool is_sequence_renderable(GLfloat, GLfloat, int) const;
110
111   friend bool operator==(const GlSequence &left, const GlSequence &right);
112
113 protected:
114   AnnotationColorsRef color_mapper;
115   const GLfloat char_pix_per_world_unit;
116
117   //! initalize a SeqSpanRef covering start, count
118   SeqSpanRef make_undefined_sequence_annotation(
119     Drawable::draw_func_ptr draw,
120     size_type start,
121     size_type count);
122
123   //! draw sequence as a bar
124   void draw_track(GLfloat, GLfloat) const;
125   void draw_annotations(GLfloat, GLfloat) const;
126   //! render a sequence as ATGC
127   /*! left and right are the current edges of the viewable world
128    */
129   void draw_sequence(GLfloat, GLfloat) const;
130 };
131
132 void draw_narrow_track(SeqSpanRef ref, float left, float right);
133 #endif