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
40 void setViewportCenter(float x);
41 //! return world coordinate of the left side of the viewport
42 float viewportLeft() const;
43 //! return world coordinate of the center of the viewport
44 float viewportCenter() const;
45 //! return world coordinate of the right side of the viewport
46 float viewportRight() const;
47 //! return height of the viewport in world coordinates
48 float viewportHeight() const;
49 //! return width of the viewport in world coordinates
50 float viewportWidth() const;
52 //! zoom out far enough to show the full size of the sequence
54 //! zoom in to a reasonable sequence view
55 double zoomToSequence();
56 //! set the current zoom level in (base pairs / pix )
57 //! its a double as zoom levels of [0.01, 1.0] make nice sequence views
58 void setZoom(double zoom_level);
59 //! returns the current zoom level as basepairs per pixel
61 //! center the provided path in the current viewport
62 void centerOnPath(const std::vector<int>&);
64 void setColorMapper(boost::shared_ptr<AnnotationColors> cm);
65 const AnnotationColors& colorMapper();
67 //! clear our tracks and connections
69 //! clear everything related to a selection
70 void clear_selection();
72 //! add a sequence to the back of our track container (makes copy of s)
73 void push_sequence(const Sequence& s);
74 //! add a sequence to the back of our track container
75 void push_sequence(boost::shared_ptr<Sequence> s);
76 //! add a glsequence to the back of our track container
77 void push_sequence(GlSequence s);
78 //! add a glsequence to the back of our track container
79 void push_sequence(boost::shared_ptr<GlSequence> gs);
80 //! return our track container
81 const std::vector<boost::shared_ptr<GlSequence> >& sequences() const;
83 //! clear all the line segments between all the sequences
86 void link(const std::vector<int>& path, const std::vector<bool>& isRC, int length);
87 //! set selected paths (it'd be nice if this could be a templated function)
88 void setSelectedPaths(std::vector<int> c);
89 //! returns the index of pathids based on order added by link
90 const std::set<int>& selectedPaths() const;
92 //! set selected tracks (it'd be nice if this could be a templated function)
93 void appendSelectedTrack(GLuint track_index, int left, int right);
95 //! return list of selected tracks
96 std::list<TrackRegion> selectedTracks() const;
98 //! copy sequence from selected track using formating function
100 void copySelectedTracks(std::list<Item>& result,
101 Item (*format_track)(boost::shared_ptr<Sequence> s,
104 //! copy sequence from selected tracks as FASTA sequences
105 void copySelectedTracksAsFasta(std::string& copy_buffer);
106 //! copy sequence from selected tracks as a list of sequences
107 void copySelectedTracksAsSequences(std::list<Sequence>& result);
108 //! copy sequence from selected tracks as plain sequences
109 void copySelectedTracksAsString(std::string& copy_buffer);
111 //! copy tracks as a sequence and its coordinates
112 void copySelectedTracksAsSeqLocation(std::list<SequenceLocation>& result);
115 //! Provide a logical name for a type discriminator for our glName stack
116 enum FeatureType { MussaTrack, MussaSegment };
118 //! a useful point class
119 template<class T> struct point {
123 point(T x_, T y_):x(x_), y(y_) {}
126 //! a useful rectangle, where 0,0 is in the lower left
127 template<class T> struct rect {
134 rect(T t, T l, T b, T r) : top(t), left(l), bottom(b), right(r) {}
135 T width() { return right - left; }
136 T height() { return top - bottom; }
137 void clear() { top=0; left=0; bottom=0; right=0; }
145 std::set<int> path_ids;
147 Segment() : start(0.0, 0.0), end(0.0, 0.0) {}
148 Segment(float x1, float y1, float x2, float y2, bool isRC)
149 : start(x1, y1), end(x2, y2), reversed(isRC) {}
152 //! data structure holding our line segments
153 /*! the vector is of size track_container.size()-1
154 * it's indexed by the pair x1, x2 (the two x coordinates between
157 typedef std::pair<int, int> segment_key;
158 typedef std::map<segment_key, Segment> pair_segment_map;
159 typedef std::vector<pair_segment_map> path_segment_map_vector;
160 path_segment_map_vector path_segments;
163 //! recalculate the viewable world
164 /*! depending on the size of our canvas, our zoom level and
165 * how far we've been offset
167 void update_viewport(float center, double new_zoom);
169 //! determine where all the tracks should be placed
170 void update_layout();
172 //! convert opengl selections into the list of paths we should highlight
173 void processSelection(GLuint hits,
176 const rect<float>& r);
178 //! master scene drawing function
179 /*! draw is broken out for the opengl selection code
182 //! draw glsequence tracks
183 void draw_tracks() const;
184 //! draw line segments between tracks
185 void draw_segments() const;
186 //! draw selection box
187 void draw_selection() const;
189 //! number of pixels to reserve around the edges of our canvas
190 const int border_width;
191 //! the current viewable region (world coord)
192 rect<float> cur_ortho;
193 //! how many pixels our viewport is (screen coord)
194 point<int> viewport_size;
195 //! the center of our current viewport (world coord) (used for scrollbar)
196 float viewport_center;
198 boost::shared_ptr<AnnotationColors> color_mapper;
199 //! container of all the GlSequences loaded into our scene
200 std::vector<boost::shared_ptr<GlSequence> > track_container;
201 //! counter for each path added to us via connect
205 //! where to draw our box (world coordinates)
206 rect<float> selectedRegion;
207 //! true if we have a selection
209 //! indicate which paths are selected
210 std::set<int> selected_paths;
211 //! which track is selected (it only makes sense to have one track selected).
212 std::list<TrackRegion> selected_tracks;
213 typedef std::list<TrackRegion>::iterator selected_track_iterator;