1 #include "alg/glsequence.h"
9 GlSequence::GlSequence(const Sequence &s)
15 seq_height(gl_track_height)
17 assert (seq.size() == seq_width);
20 GlSequence::GlSequence(const GlSequence &s)
25 seq_width(s.seq_width),
26 seq_height(s.seq_height)
28 assert (seq.size() == seq_width);
31 GlSequence &GlSequence::operator=(const GlSequence & s)
34 const_cast<Sequence &>(seq) = s.seq;
38 seq_width = s.seq_width;
39 seq_height = s.seq_height;
44 const Sequence& GlSequence::sequence() const
49 void GlSequence::setX(GLfloat value)
54 GLfloat GlSequence::x() const
59 void GlSequence::setY(GLfloat value)
64 GLfloat GlSequence::y() const
69 void GlSequence::setWidth(GLfloat value)
74 GLfloat GlSequence::width() const
80 void GlSequence::draw(GLfloat left, GLfloat right) const
82 glLineWidth(seq_height);
83 glColor3f(0.0, 0.0, 0.0);
84 // draw main sequence track
86 glVertex3f(seq_x, seq_y, seq_z);
87 glVertex3f(seq_x+seq_width, seq_y, seq_z);
88 //clog << "drawing " << seq_x << " " << seq_y << " " << seq_width
92 GLfloat annotation_z = seq_z + 1.0;
93 std::list<annot> annots = seq.annotations();
94 for (std::list<annot>::const_iterator annot_itor = annots.begin();
95 annot_itor != annots.end();
96 ++annot_itor, ++annotation_z)
98 glColor3f(0.0, 0.5, 0.0);
100 glVertex3f(annot_itor->start, seq_y, annotation_z);
101 glVertex3f(annot_itor->end , seq_y, annotation_z);
104 draw_sequence(left, right);
108 const int STROKE = 2;
111 typedef struct charpoint {
117 {0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT},
118 {5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
122 {2.5, 0, PT}, {2.5,10, STROKE}, {0, 10, PT}, {5,10, END}
126 {5, 9, PT}, {4, 10, PT}, {1, 10, PT}, {0, 9, PT}, {0, 1, PT},
127 {1, 0, PT}, {5, 0, PT}, {5, 4, PT}, {3.5, 4, END}
131 {5, 8, PT}, {3, 10, PT}, {2, 10, PT}, {0, 8, PT}, {0, 2, PT},
132 {2, 0, PT}, {3, 0, PT}, {5, 2, END}
135 CP Xdata[] = {{ 0, 10, PT}, {5,0,STROKE},{0,0,PT},{5,10,END}};
136 CP Ndata[] = {{ 0, 0, PT}, {0, 10, PT}, {5, 0, PT}, {5, 10, END}};
138 static void drawLetter(CP *l)
140 glBegin(GL_LINE_STRIP);
149 glBegin(GL_LINE_STRIP);
157 throw runtime_error("data structure failure");
163 void GlSequence::draw_sequence(GLfloat left, GLfloat right) const
166 glGetIntegerv(GL_VIEWPORT, viewport);
167 int port_width = viewport[3]; // grab the viewport width
168 GLfloat world_width = right - left;
169 int left_base = (left > 0) ? (int)ceil(left) : 0;
170 int right_base = (int)floor(right);
171 int render_count = (right_base < seq.size()) ? right_base : seq.size();
172 render_count -= left_base;
175 GLfloat char_width = 1.1;
176 GLfloat pixels_needed = char_width * world_width;
178 cout << "seq width needed " << pixels_needed
179 << " port width " << port_width
180 << " count " << render_count
181 << " left " << left_base
182 << " right " << right_base
183 << " size " << seq.size() << endl;
184 // if the number of pixels taken up by rendering the characters
185 // that'd show up in the current ortho width is less than the window
186 // width we can actually draw something
187 if (pixels_needed < port_width and render_count > 0) {
188 cout << "rendering: ";
189 string bases = seq.subseq(left_base, render_count);
190 glColor3f(0.1, 0.1, 0.1);
191 for (string::size_type basepair = 0; basepair != bases.size(); ++basepair)
194 glTranslatef( left_base + basepair, seq_y+20, 1.0 );
195 glScalef(0.1, 1.0, 1.0);
196 switch (bases[basepair]) {
216 cout << bases[basepair];