3 #include <boost/shared_ptr.hpp>
9 #include "alg/annotation_colors.hpp"
10 #include "alg/sequence.hpp"
11 #include "alg/glsequence.hpp"
12 #include "alg/sequence_location.hpp"
13 #include "alg/track_region.hpp"
15 //! Manage rendering a collection of glSequences
20 GlSeqBrowser(const GlSeqBrowser&);
22 //! setup the opengl canvas
24 //! called when our screen canvas is resized
25 void resizeGL(int width, int height);
29 //! select a region (using canvas coordinates)
30 void selectRegion(int top, int left, int bottom, int right);
35 //! max world left coordinate
37 //! max world right coordinate
39 // return how wide is a pixel in world coordinates?
40 float get_pixel_width() const;
42 void setViewportCenter(float x);
43 //! return world coordinate of the left side of the viewport
44 float viewportLeft() const;
45 //! return world coordinate of the center of the viewport
46 float viewportCenter() const;
47 //! return world coordinate of the right side of the viewport
48 float viewportRight() const;
49 //! return height of the viewport in world coordinates
50 float viewportHeight() const;
51 //! return width of the viewport in world coordinates
52 float viewportWidth() const;
54 //! zoom out far enough to show the full size of the sequence
56 //! zoom in to a reasonable sequence view
57 double zoomToSequence();
58 //! set the current zoom level in (base pairs / pix )
59 //! its a double as zoom levels of [0.01, 1.0] make nice sequence views
60 void setZoom(double zoom_level);
61 //! returns the current zoom level as basepairs per pixel
63 //! center the provided path in the current viewport
64 void centerOnPath(const std::vector<int>&);
66 void setColorMapper(boost::shared_ptr<AnnotationColors> cm);
67 const AnnotationColors& colorMapper();
69 //! clear our tracks and connections
71 //! clear everything related to a selection
72 void clear_selection();
74 //! add a sequence to the back of our track container (makes copy of s)
75 void push_sequence(const Sequence& s);
76 //! add a sequence to the back of our track container
77 void push_sequence(boost::shared_ptr<Sequence> s);
78 //! add a glsequence to the back of our track container
79 void push_sequence(GlSequence s);
80 //! add a glsequence to the back of our track container
81 void push_sequence(boost::shared_ptr<GlSequence> gs);
82 //! return our track container
83 const std::vector<boost::shared_ptr<GlSequence> >& sequences() const;
85 //! clear all the line segments between all the sequences
88 void link(const std::vector<int>& path, const std::vector<bool>& isRC, int length);
89 //! set selected paths (it'd be nice if this could be a templated function)
90 void setSelectedPaths(std::vector<int> c);
91 //! returns the index of pathids based on order added by link
92 const std::set<int>& selectedPaths() const;
94 //! set selected tracks (it'd be nice if this could be a templated function)
95 void appendSelectedTrack(GLuint track_index, int left, int right);
97 //! return list of selected tracks
98 std::list<TrackRegion> selectedTracks() const;
100 //! copy sequence from selected track using formating function
102 size_t copySelectedTracks(std::list<Item>& result,
103 Item (*format_track)(boost::shared_ptr<Sequence> s,
106 //! copy sequence from selected tracks as FASTA sequences
107 /*! \return number of base pairs copied
109 size_t copySelectedTracksAsFasta(std::string& copy_buffer);
110 //! copy sequence from selected tracks as a list of sequences
111 /*! \return number of base pairs copied
113 size_t copySelectedTracksAsSequences(std::list<Sequence>& result);
114 //! copy sequence from selected tracks as plain sequences
115 /*! \return number of base pairs copied
117 size_t copySelectedTracksAsString(std::string& copy_buffer);
119 //! copy tracks as a sequence and its coordinates
120 size_t copySelectedTracksAsSeqLocation(std::list<SequenceLocation>& result);
123 //! Provide a logical name for a type discriminator for our glName stack
124 enum FeatureType { MussaTrack, MussaSegment };
126 //! a useful point class
127 template<class T> struct point {
131 point(T x_, T y_):x(x_), y(y_) {}
134 //! a useful rectangle, where 0,0 is in the lower left
135 template<class T> struct rect {
142 rect(T t, T l, T b, T r) : top(t), left(l), bottom(b), right(r) {}
143 T width() { return right - left; }
144 T height() { return top - bottom; }
145 void clear() { top=0; left=0; bottom=0; right=0; }
154 // each integer represents an index into our list of paths
155 std::set<int> path_ids;
157 Segment() : start(0.0, 0.0), end(0.0, 0.0), reversed(false), length(0) {}
158 Segment(float x1, float y1, float x2, float y2, bool isRC, int length_)
159 : start(x1, y1), end(x2, y2), reversed(isRC), length(length_) {}
162 //! data structure holding our line segments
163 /*! the vector is of size track_container.size()-1
164 * it's indexed by the pair x1, x2 (the two x coordinates between
167 typedef std::pair<int, int> segment_key;
168 typedef std::map<segment_key, Segment> pair_segment_map;
169 typedef std::vector<pair_segment_map> path_segment_map_vector;
170 path_segment_map_vector path_segments;
173 //! recalculate the viewable world
174 /*! depending on the size of our canvas, our zoom level and
175 * how far we've been offset
177 void update_viewport(float center, double new_zoom);
179 //! determine where all the tracks should be placed
180 void update_layout();
182 //! convert opengl selections into the list of paths we should highlight
183 void processSelection(GLuint hits,
186 const rect<float>& r);
188 //! master scene drawing function
189 /*! draw is broken out for the opengl selection code
192 //! draw glsequence tracks
193 void draw_tracks() const;
194 //! draw line segments between tracks
195 void draw_segments() const;
196 //! draw selection box
197 void draw_selection() const;
199 //! number of pixels to reserve around the edges of our canvas
200 const int border_width;
201 //! the current viewable region (world coord)
202 rect<float> cur_ortho;
203 //! how many pixels our viewport is (screen coord)
204 point<int> viewport_size;
205 //! the center of our current viewport (world coord) (used for scrollbar)
206 float viewport_center;
208 boost::shared_ptr<AnnotationColors> color_mapper;
209 //! container of all the GlSequences loaded into our scene
210 std::vector<boost::shared_ptr<GlSequence> > track_container;
211 //! counter for each path added to us via connect
215 //! where to draw our box (world coordinates)
216 rect<float> selectedRegion;
217 //! true if we have a selection
219 //! indicate which paths are selected
220 std::set<int> selected_paths;
221 //! which track is selected (it only makes sense to have one track selected).
222 std::list<TrackRegion> selected_tracks;
223 typedef std::list<TrackRegion>::iterator selected_track_iterator;