length 1 segments should be drawn as lines
authorDiane Trout <diane@caltech.edu>
Thu, 5 Oct 2006 21:05:56 +0000 (21:05 +0000)
committerDiane Trout <diane@caltech.edu>
Thu, 5 Oct 2006 21:05:56 +0000 (21:05 +0000)
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.

alg/glseqbrowser.cpp
alg/glsequence.cpp

index e82cfe1f48fab2cd13fb3f82dba47e6d62bef5f9..79acb4068c64fd224def7b6f06dc93ee11bacdba 100644 (file)
@@ -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();
     }
index 60e14e959772dfd6e06ddbd4ed1a36498ee2f358..678b1000d2c9940bc5c0bfa520a7519e0e2f6fdb 100644 (file)
@@ -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);