line rendering fixes
authorDiane Trout <diane@caltech.edu>
Wed, 1 Mar 2006 01:18:23 +0000 (01:18 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 1 Mar 2006 01:18:23 +0000 (01:18 +0000)
Get the reversed versus forward conservation lines correct. The color is
blue if the orientation of the current vertex differs from the previous
vertex, and red if they have the same oreintation. I also (hopefully)
adjusted the x position so the line points to the center of the conserved
window (adjusting to the right for forward and left for reverse compliment
sequences).

Also we discovered that you can't use both depth testing and alpha blending
at the same time, and so now the selection highlighter is hopefully alpha
blended while all the various lines are depth ordered.

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

index e9f8600ae4d707a56eec459f01496f5671390978..81b604223dafe16b7dcec09f52748d9e41221380 100644 (file)
@@ -5,9 +5,9 @@ using namespace std;
 
 GlSequence::GlSequence(const Sequence &s) 
   : seq(s),
-    seq_x(0), 
-    seq_y(0), 
-    seq_z(0), 
+    seq_x(0.0), 
+    seq_y(0.0), 
+    seq_z(1.0), 
     seq_width(s.size()),
     seq_height(gl_track_height) 
 {
@@ -84,15 +84,16 @@ void GlSequence::draw() const
          << std::endl;
   glEnd();
   // draw annotations
+  GLfloat annotation_z = seq_z + 1.0;
   std::list<annot> annots = seq.annotations();
   for (std::list<annot>::const_iterator annot_itor = annots.begin();
        annot_itor != annots.end();
-       ++annot_itor)
+       ++annot_itor, ++annotation_z)
   {
     glColor3f(0.0, 0.5, 0.0);
     glBegin(GL_LINES);
-      glVertex3f(annot_itor->start, seq_y, seq_z);
-      glVertex3f(annot_itor->end  , seq_y, seq_z);
+      glVertex3f(annot_itor->start, seq_y, annotation_z);
+      glVertex3f(annot_itor->end  , seq_y, annotation_z);
     glEnd();
   }
 }
index 798ac53aab4b85f0501548cc14efaafce13b3519..4fb37da049457784e11da11d9435a52e0d8ac4f7 100644 (file)
@@ -34,6 +34,6 @@ private:
   GLfloat seq_height;
 };
 
-const float gl_track_height = 5.0;
+const float gl_track_height = 10.0;
 
 #endif
index 9d5d8412d5ce404cde865dfecb36040e6a065ab8..3fcc9d0f380763ee4997489adb194c2ab352ed50 100644 (file)
@@ -104,12 +104,10 @@ void PathScene::setSoftThreshold(int threshold)
 
 void PathScene::initializeGL()
 {
-  glEnable(GL_DEPTH_TEST|GL_BLEND);
+  glEnable(GL_DEPTH_TEST);
   glClearColor(1.0, 1.0, 1.0, 0.0);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   glShadeModel(GL_FLAT);
-  glLoadIdentity();
-  glPushMatrix();
 }
 
 void PathScene::resizeGL(int width, int height)
@@ -122,7 +120,6 @@ void PathScene::resizeGL(int width, int height)
   glOrtho(curOrtho2d.left(), curOrtho2d.right(), 
           curOrtho2d.top(), curOrtho2d.bottom(), 
           -50.0, clipZ);
-  glMatrixMode(GL_MODELVIEW);
 }
 
 void PathScene::paintGL()
@@ -136,14 +133,16 @@ void PathScene::paintGL()
           curOrtho2d.top(), curOrtho2d.bottom(), 
           -50.0, clipZ);
   glMatrixMode(GL_MODELVIEW);
+  mussaesque();
+  glEnable(GL_BLEND);
+  glDepthMask(GL_FALSE);
   if (debugBand && !drawingBand) {
     glColor4f(0.4, 0.4, 0.4, 0.9);
     glRectf(previousBand.x(), previousBand.y(),
             previousBand.right(), previousBand.bottom());
   }
-  glTranslatef(-X*1000, 0.0, 0.0);
-  mussaesque();
-
+  glDepthMask(GL_TRUE);
+  glDisable(GL_BLEND);
   glPopMatrix();
   glFlush();
 }
@@ -287,21 +286,29 @@ void PathScene::draw_tracks() const
 void PathScene::draw_lines() const
 {
   GLfloat x;
-  GLfloat y; 
+  GLfloat y;
+  bool reversed = false;
+  bool prevReversed = false;
   const Nway_Paths& nway = mussaAnalysis.paths();
 
-  glLineWidth(0.1);
-  glColor3f(0.9, 0.0, 0.0);
+  glLineWidth(0.5);
   vector<GlSequence>::const_iterator track_itor;
-  // To use the refined_pathz, change pathz to refined_pathz, and
-  // change path_itor->begin() to path_itor->begin()+1
-  for(list<vector<int> >::const_iterator path_itor = nway.pathz.begin();
-      path_itor != nway.pathz.end();
+  for(list<vector<int> >::const_iterator path_itor = nway.refined_pathz.begin();
+      path_itor != nway.refined_pathz.end();
       ++path_itor)
   {
     track_itor = tracks.begin();
+    vector<int>::const_iterator sp_itor = path_itor->begin();
+    // since we were drawing to the start of a window, and opengl lines
+    // are centered around the two connecting points our lines were slightly
+    // offset. the idea of window_offset is to adjust them to the
+    // right for forward compliment or left for reverse compliment
+    // FIXME: figure out how to unit test these computations
+    GLfloat window_offset = (*sp_itor)/2.0;
+    sp_itor++;
+
     glBegin(GL_LINE_STRIP);
-    for (vector<int>::const_iterator sp_itor = path_itor->begin();
+    for (;
          sp_itor != path_itor->end();
          ++sp_itor, ++track_itor)
     {
@@ -309,13 +316,28 @@ void PathScene::draw_lines() const
       y = track_itor->y();
       // at some point when we modify the pathz data structure to keep
       // track of the score we can put grab the depth here.
-      if (x >= 0) { 
-        glColor3f(0.9, 0.0, 0.0);
+      //
+      // are we reverse complimented? 
+      if ( x>=0) {
+        reversed = false;
       } else {
-        x *= -1;
-        glColor3f(0.0, 0.0, 0.9);
+        reversed = true;
+        x = -x; // make positive
       }
-      glVertex3f(x, y, -1.0);
+      if (!reversed)
+        x += window_offset; // move right for forward compliment
+      else
+        x -= window_offset; // move left for reverse compliment
+      // the following boolean implements logical xor
+      if ( (reversed || prevReversed) && (!reversed || !prevReversed)) { 
+        // we have a different orientation
+        glColor3f(0.0, 0.0, 0.8);
+      } else {
+        // both current and previous path have the same orientation
+        glColor3f(0.8, 0.0, 0.0);
+      }
+      prevReversed = reversed;
+      glVertex3f(x, y, 0.0);
     }
     glEnd();
   }
@@ -335,14 +357,14 @@ GLuint PathScene::make_line_list()
 
 void PathScene::mussaesque()
 {
-  //static GLuint theLines = make_line_list();
+  static GLuint theLines = make_line_list();
 
   glInitNames();
-  glPushName(0);
+  glPushName(10);
+  glCallList(theLines);
+  //draw_lines();
+  glLoadName(0);
   draw_tracks();
-  glLoadName(10);
-  //glCallList(theLines);
-  draw_lines();
   glPopName();
 }