use lines if a quad would be smaller than a pixel
authorDiane Trout <diane@caltech.edu>
Wed, 11 Oct 2006 00:06:25 +0000 (00:06 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 11 Oct 2006 00:06:25 +0000 (00:06 +0000)
closes ticket:147
Mussa looks nicer when there's a minimum width to segments
connecting tracks.

alg/glseqbrowser.cpp
alg/glseqbrowser.hpp

index 79acb4068c64fd224def7b6f06dc93ee11bacdba..3342042755d16ca411a5ea5bce39e4657342c57a 100644 (file)
@@ -1,6 +1,7 @@
 #include "alg/glseqbrowser.hpp"
 #include "mussa_exceptions.hpp"
 
+#include <math.h>
 #include <iostream>
 #include <sstream>
 #include <stdexcept>
@@ -223,6 +224,15 @@ float GlSeqBrowser::right() const
   }
 }
 
+float GlSeqBrowser::get_pixel_width() const
+{
+  GLint viewport[4];
+  glGetIntegerv(GL_VIEWPORT, viewport);
+  GLint vp_width = viewport[3]; // grab the viewport width
+  
+  return round((cur_ortho.right-cur_ortho.left)/vp_width);
+}  
+
 void GlSeqBrowser::setViewportCenter(float x)
 {
   update_viewport(x, zoom_level);
@@ -650,6 +660,8 @@ void GlSeqBrowser::draw_segments() const
   glEnable(GL_BLEND);
   glDepthMask(GL_FALSE);
   const float zdepth = -1.0;
+  const float min_segment_width = max((float)(1.0), get_pixel_width());
+  
   // each vector contains path_segment_maps of all the connections
   // between this track and the next
   path_segment_map_vector::const_iterator psmv_i;
@@ -695,10 +707,10 @@ void GlSeqBrowser::draw_segments() const
                         + track_container[path_index]->x();
       float seq_end_x = s.end.x
                       + track_container[path_index+1]->x();
-      if (s.length <= 1) {
-        // use lines for elements of length <=1.
+      if (s.length <= min_segment_width) {
+        // use lines for elements of length <=1 or < 1 pixel.
         // and try to center the line
-        const float offset = 0.5;
+        const float offset = s.length * 0.5;
         glBegin(GL_LINES);
           glVertex3f(seq_start_x+offset, s.start.y, -1);
           glVertex3f(seq_end_x  +offset, s.end.y, -1);
index 9b2e16f26572bf4d1d55afdb0113b226cba822a9..40f158ba7b01467d49ca55e3d09c7244cd398c80 100644 (file)
@@ -36,6 +36,8 @@ public:
   float left() const;
   //! max world right coordinate
   float right() const;
+  // return how wide is a pixel in world coordinates?
+  float get_pixel_width() const;
 
   void setViewportCenter(float x);
   //! return world coordinate of the left side of the viewport