Thicker bars, better letters
authorDiane Trout <diane@caltech.edu>
Sat, 11 Mar 2006 09:54:19 +0000 (09:54 +0000)
committerDiane Trout <diane@caltech.edu>
Sat, 11 Mar 2006 09:54:19 +0000 (09:54 +0000)
Aparently there's a limit to how thick an OpenGL line can be, so to get
lines of sufficient thickness I switched to drawing large polygons.

Also to help with getting the text and sequence view to line up correctly,
I pushed all the font letters down so they're centered at the midline.

There's also more work that needs to be done for z-order, the window
connections z is currently just hardcoded.

Also I made my hacked vector  A, G, and Cs look a little bit better.

alg/glsequence.cxx
alg/glsequence.h
qui/PathScene.cxx
qui/PathWidget.cxx

index 0e3a0c3dbe9dd0e83ebfa82eb72935d77bf2e299..3aad53a30cbab0b0e9662d86b223e077542ca527 100644 (file)
@@ -11,7 +11,7 @@ GlSequence::GlSequence(const Sequence &s)
     seq_x(0.0), 
     seq_y(0.0), 
     seq_z(1.0), 
-    seq_height(gl_track_height),
+    seq_height(12.0),
     drawColor(0.0, 0.0, 0.0),
     char_pix_per_world_unit(5.0)
 {
@@ -170,29 +170,38 @@ bool GlSequence::is_sequence_renderable(GLfloat left,
 void GlSequence::draw(GLfloat left, GLfloat right) const
 {
   if ( not is_sequence_renderable(left, right) ) {
-    draw_bar(left, right);
+    draw_track(left, right);
   } else {
     draw_sequence(left, right);
   }
   draw_annotations(left, right);
 }
 
-void GlSequence::draw_bar(GLfloat left, GLfloat right) const
+void GlSequence::draw_box(GLfloat left, GLfloat right, 
+                          GLfloat height, GLfloat z) const
+{
+  GLfloat offset = height/2.0;
+  GLfloat top = seq_y + offset;
+  GLfloat bottom = seq_y - offset;
+    
+  glBegin(GL_QUADS);
+    glVertex3f(left,  top,    z);
+    glVertex3f(left,  bottom, z);
+    glVertex3f(right, bottom, z);
+    glVertex3f(right, top,    z);
+  glEnd();
+}
+void GlSequence::draw_track(GLfloat left, GLfloat right) const
 {
-  glLineWidth(seq_height);
   glColor3fv(drawColor.get());
   // draw main sequence track
-  glBegin(GL_LINES);
-    glVertex3f(seq_x,            seq_y, seq_z);
-    glVertex3f(seq_x+seq.size(), seq_y, seq_z);
-    //clog << "drawing " << seq_x << " " << seq_y << " " << seq.size()
-    //     << std::endl;
-  glEnd();
+  draw_box(seq_x, seq_x+seq.size(), seq_height, 0.0);
 }
 
 void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
 {
   // draw annotations
+  glLineWidth(seq_height);
   GLfloat annotation_z = seq_z + 1.0;
   std::list<annot> annots = seq.annotations();
   for (std::list<annot>::const_iterator annot_itor = annots.begin();
@@ -200,10 +209,8 @@ void GlSequence::draw_annotations(GLfloat left, GLfloat right) const
        ++annot_itor, ++annotation_z)
   {
     glColor3f(0.0, 0.5, 0.0);
-    glBegin(GL_LINES);
-      glVertex3f(annot_itor->start, seq_y, annotation_z);
-      glVertex3f(annot_itor->end  , seq_y, annotation_z);
-    glEnd();
+    draw_box(seq_x+annot_itor->start, seq_x+annot_itor->end, 
+             seq_height, annotation_z);
   }
 }
 
@@ -217,42 +224,43 @@ typedef struct charpoint {
 } CP;
 
 CP Adata[] = {
-  {0, 0, PT}, {0, 9, PT}, {1, 10, PT}, {4, 10, PT}, 
-  {5, 9, PT}, {5, 0, STROKE}, {0, 5, PT}, {5, 5, END}
+  {0, -5, PT}, {2.5, 5, PT}, {5, -5, STROKE}, 
+  {0.75, -2, PT}, {4.25, -2, END}
 };
 
 CP Tdata[] = {
-  {2.5, 0, PT}, {2.5,10, STROKE}, {0, 10, PT}, {5,10, END}
+  {2.5, -5, PT}, {2.5,5, STROKE}, {0, 5, PT}, {5, 5, END}
 };
 
 CP Gdata[] = {
-  {5, 9, PT}, {4, 10, PT}, {1, 10, PT}, {0, 9, PT}, {0, 1, PT},
-  {1, 0, PT}, {5, 0, PT}, {5, 4, PT}, {3.5, 4, END}
+  {5, 3, PT}, {3, 5, PT}, {2, 5, PT}, {0, 3, PT}, {0, -3, PT},
+  {2, -5, PT}, {3, -5, PT}, {5, -3, STROKE}, 
+  {2.5, -1, PT}, {5, -1,PT}, {5, -5, END}
 };
 
 CP Cdata[] = {
-  {5, 8, PT}, {3, 10, PT}, {2, 10, PT}, {0, 8, PT}, {0, 2, PT},
-  {2, 0, PT}, {3, 0, PT}, {5, 2, END}
+  {4.9, 3, PT}, {3, 5, PT}, {2, 5, PT}, {0, 3, PT}, {0, -3, PT},
+  {2, -5, PT}, {3, -5, PT}, {5, -3, END}
 };
 
-CP Xdata[] = {{ 0, 10, PT}, {5,0,STROKE},{0,0,PT},{5,10,END}};
-CP Ndata[] = {{ 0, 0, PT}, {0, 10, PT}, {5, 0, PT}, {5, 10, END}};
+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}};
 
-static void drawLetter(CP *l)
+static void drawLetter(CP *l, GLfloat z)
 {
   glBegin(GL_LINE_STRIP);
   while(1) {
     switch (l->type) {
       case PT:
-        glVertex2fv(&l->x);
+        glVertex3f(l->x, l->y, z);
         break;
       case STROKE:
-        glVertex2fv(&l->x);
+        glVertex3f(l->x, l->y, z);
         glEnd();
         glBegin(GL_LINE_STRIP);
         break;
       case END:
-        glVertex2fv(&l->x);
+        glVertex3f(l->x, l->y, z);
         glEnd();
         return;
         break;
@@ -265,7 +273,9 @@ static void drawLetter(CP *l)
 
 void GlSequence::draw_sequence(GLfloat left, GLfloat right) const
 {
-  glLineWidth(0.1);
+  // FIXME: basically this needs to be greater than the number of annotations
+  const GLfloat z = 30;
+  glLineWidth(0.3);
   glColor3fv(drawColor.get());
 
   Sequence::const_iterator seq_itor = sequence_begin(left, right);
@@ -281,22 +291,22 @@ void GlSequence::draw_sequence(GLfloat left, GLfloat right) const
     glScalef(0.1, 1.0, 1.0);
     switch (*seq_itor) {
       case 'A': case 'a':
-        drawLetter(Adata);
+        drawLetter(Adata, z);
         break;
       case 'T': case 't':
-        drawLetter(Tdata);
+        drawLetter(Tdata, z);
         break;
       case 'G': case 'g':
-        drawLetter(Gdata);
+        drawLetter(Gdata, z);
         break;
       case 'C': case 'c':
-        drawLetter(Cdata);
+        drawLetter(Cdata, z);
         break;
       case 'N': case 'n':
-        drawLetter(Ndata);
+        drawLetter(Ndata, z);
         break;
       default:
-        drawLetter(Xdata);
+        drawLetter(Xdata, z);
         break;
     }
     glPopMatrix();
index 319517b98dfedf45bce505191dce9095a83bb28d..9ccc4e31564d1403a1b1277f80f6a534a5457539 100644 (file)
@@ -78,13 +78,14 @@ protected:
 
   //! Return the pixel width of the opengl viewport.
   static int get_viewport_pixel_width();
-  void draw_bar(GLfloat, GLfloat) const;
+  //! draw a from left to right +/- height/2
+  void draw_box(GLfloat left, GLfloat right, GLfloat height, GLfloat z) const;
+  //! draw sequence as a bar
+  void draw_track(GLfloat, GLfloat) const;
   void draw_annotations(GLfloat, GLfloat) const;
-  //! render a sequence (if we have enough space
+  //! render a sequence as ATGC
   /*! left and right are the current edges of the viewable world
    */
   void draw_sequence(GLfloat, GLfloat) const;
 };
-
-const float gl_track_height = 10.0;
 #endif
index 683b7b8cd882dbe5f324d41d30c16a6c3963e27b..175915ebf47f0800b863f6c3ac2fc7fb206e4820 100644 (file)
@@ -86,7 +86,6 @@ void PathScene::updateViewport(float center, int new_zoom)
 
 void PathScene::setViewportX(float x)
 {
-  cout << "setViewportX " << x << " " << curOrtho2d.left() << endl;
   //hopefully this calculates a sufficiently reasonable == for a float
   if (x != viewport_center )
   {
@@ -221,10 +220,9 @@ void PathScene::paintGL()
   glEnable(GL_BLEND);
   glDepthMask(GL_FALSE);
   if (selectedMode && !drawingBand) {
-    glColor4f(0.4, 0.4, 0.4, 0.9);
+    glColor4f(0.6, 0.6, 0.6, 0.9);
     glRectf(previousBand.x(), previousBand.y(),
             previousBand.right(), previousBand.bottom());
-    cout << "x: " << previousBand.x() << " r:" << previousBand.right() << endl;
   }
   glDepthMask(GL_TRUE);
   glDisable(GL_BLEND);
@@ -473,7 +471,7 @@ void PathScene::draw_lines() const
         }
       }
       prevReversed = reversed;
-      glVertex3f(x, y, 0.0);
+      glVertex3f(x, y, -1.0);
     }
     glEnd();
     glLoadName(++pathid);
index 7c72971e238c53d51882ff3b29d6098117dbc88a..3f327707111f06a1a2fb9c6daa0d17c02bb06a3b 100644 (file)
@@ -48,7 +48,6 @@ void PathWidget::setViewportX(int x)
 {
   if (x != thumb) {
     thumb = x;
-    cout << "pathwidget " << x << " " << thumb << " " << viewportBar.value() << endl;
     scene->setViewportX(thumb);
   }
 }