From: Diane Trout Date: Thu, 5 Oct 2006 21:05:56 +0000 (+0000) Subject: length 1 segments should be drawn as lines X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=mussa.git;a=commitdiff_plain;h=17b3ec9aa2816c0f4d515f933cbd7dc9f0939ebd length 1 segments should be drawn as lines I also tried to center both the line and the character glyph a bit. No I don't know why I needed to divide by 4.0 instead of 2.0. But it looked better--so there. --- diff --git a/alg/glseqbrowser.cpp b/alg/glseqbrowser.cpp index e82cfe1..79acb40 100644 --- a/alg/glseqbrowser.cpp +++ b/alg/glseqbrowser.cpp @@ -695,24 +695,30 @@ void GlSeqBrowser::draw_segments() const + track_container[path_index]->x(); float seq_end_x = s.end.x + track_container[path_index+1]->x(); - // add in length - float seq_start_x_length = s.start.x + if (s.length <= 1) { + // use lines for elements of length <=1. + // and try to center the line + const float offset = 0.5; + glBegin(GL_LINES); + glVertex3f(seq_start_x+offset, s.start.y, -1); + glVertex3f(seq_end_x +offset, s.end.y, -1); + glEnd(); + } else { + // otherwise use quads + // compute length + float seq_start_x_length = s.start.x + + s.length + + track_container[path_index]->x(); + float seq_end_x_length = s.end.x + s.length - + track_container[path_index]->x(); - float seq_end_x_length = s.end.x - + s.length - + track_container[path_index+1]->x(); - //glBegin(GL_LINES); - // glVertex3f(seq_start_x, s.start.y, -1); - // glVertex3f(seq_end_x , s.end.y, -1); - //glEnd(); - - glBegin(GL_QUADS); - glVertex3f(seq_start_x, s.start.y, zdepth); - glVertex3f(seq_end_x, s.end.y, zdepth); - glVertex3f(seq_end_x_length, s.end.y, zdepth); - glVertex3f(seq_start_x_length, s.start.y, zdepth); - glEnd(); + + track_container[path_index+1]->x(); + glBegin(GL_QUADS); + glVertex3f(seq_start_x, s.start.y, zdepth); + glVertex3f(seq_end_x, s.end.y, zdepth); + glVertex3f(seq_end_x_length, s.end.y, zdepth); + glVertex3f(seq_start_x_length, s.start.y, zdepth); + glEnd(); + } // clear the names glPopName(); glPopName(); glPopName(); } diff --git a/alg/glsequence.cpp b/alg/glsequence.cpp index 60e14e9..678b100 100644 --- a/alg/glsequence.cpp +++ b/alg/glsequence.cpp @@ -251,6 +251,7 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const } +// this way of drawing characters, came from the red open gl book const int PT = 1; const int STROKE = 2; const int END =3; @@ -283,6 +284,9 @@ CP Cdata[] = { CP Xdata[] = {{ 0, 5, PT}, {5, -5,STROKE},{0,-5,PT},{5, 5, END}}; CP Ndata[] = {{ 0, -5, PT}, {0, 5, PT}, {5, -5, PT}, {5, 5, END}}; +//! the maximum width used for a charcter glyph +const int max_glyph_width = 5; + static void drawLetter(CP *l, GLfloat z) { glBegin(GL_LINE_STRIP); @@ -318,14 +322,16 @@ void GlSequence::draw_sequence(GLfloat left, GLfloat right) const Sequence::const_iterator seq_itor = sequence_begin(left, right); Sequence::const_iterator seq_end = sequence_end(left, right); Sequence::size_type basepair = 0; + const float glyph_x_scale = 0.1; + const float glyph_margin = ((1.0 / glyph_x_scale) - max_glyph_width) / 4.0; assert(seq_end - seq_itor >= 0); while(seq_itor != seq_end) { assert ( basepair < seq->size() ); glPushMatrix(); - glTranslatef( seq_x+leftbase(left) + basepair, seq_y, 1.0 ); - glScalef(0.1, 1.0, 1.0); + glTranslatef( seq_x+leftbase(left) + basepair + glyph_margin, seq_y, 1.0 ); + glScalef(glyph_x_scale, 1.0, 1.0); switch (*seq_itor) { case 'A': case 'a': drawLetter(Adata, z);