From 59b40e99fb179a39328c2432263674b57e1f16cf Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 26 Jul 2010 10:11:33 +0000
Subject: [PATCH] enable 3D points in 2D graphs

---
 Graphics/drawContext.cpp |  3 ++-
 Graphics/drawGraph2d.cpp | 43 +++++++++++++++++++++-------------------
 2 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/Graphics/drawContext.cpp b/Graphics/drawContext.cpp
index 511df0c5dc..437ff8516d 100644
--- a/Graphics/drawContext.cpp
+++ b/Graphics/drawContext.cpp
@@ -265,7 +265,8 @@ void drawContext::draw2d()
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho((double)viewport[0], (double)viewport[2],
-          (double)viewport[1], (double)viewport[3], -1., 1.);
+          (double)viewport[1], (double)viewport[3], 
+          -100., 100.); // in pixels, so we can draw some 3D glyphs
 
   // hack to make the 2D primitives appear "in front" in GL2PS
   glTranslated(0., 0., CTX::instance()->clipFactor > 1. ? 
diff --git a/Graphics/drawGraph2d.cpp b/Graphics/drawGraph2d.cpp
index 22f58f38fa..73a6429cfe 100644
--- a/Graphics/drawGraph2d.cpp
+++ b/Graphics/drawGraph2d.cpp
@@ -310,7 +310,7 @@ static void drawGraphAxes(drawContext *ctx, PView *p, double xleft, double ytop,
 static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop, 
                           double width, double height, double x, double y, 
                           double xmin, double xmax, double ymin, double ymax, 
-                          bool numeric)
+                          bool numeric, bool sphere)
 {
   PViewOptions *opt = p->getOptions();
 
@@ -337,6 +337,8 @@ static void addGraphPoint(drawContext *ctx, PView *p, double xleft, double ytop,
       sprintf(label, opt->format.c_str(), y);
       ctx->drawString(label);
     }
+    else if(sphere)
+      ctx->drawSphere(opt->pointSize, px, py, 0, 10, 10, opt->light);
     else
       glVertex2d(px, py);
   }
@@ -355,24 +357,6 @@ static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double yto
   glLineWidth((float)opt->lineWidth);
   gl2psLineWidth((float)(opt->lineWidth * CTX::instance()->print.epsLineWidthFactor));
 
-  if(opt->intervalsType == PViewOptions::Numeric){
-    for(unsigned int i = 0; i < y.size(); i++)
-      for(unsigned int j = 0; j < x.size(); j++)
-        addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], 
-                      xmin, xmax, opt->tmpMin, opt->tmpMax, true);
-  }
-
-  if(opt->intervalsType == PViewOptions::Iso ||
-     opt->intervalsType == PViewOptions::Discrete ||
-     opt->intervalsType == PViewOptions::Numeric){
-    glBegin(GL_POINTS);
-    for(unsigned int i = 0; i < y.size(); i++)
-      for(unsigned int j = 0; j < x.size(); j++)
-        addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], 
-                      xmin, xmax, opt->tmpMin, opt->tmpMax, false);
-    glEnd();    
-  }
-
   if(opt->intervalsType == PViewOptions::Discrete ||
      opt->intervalsType == PViewOptions::Continuous){
     for(unsigned int i = 0; i < y.size(); i++){
@@ -384,7 +368,7 @@ static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double yto
       glBegin(GL_LINE_STRIP);
       for(unsigned int j = 0; j < x.size(); j++)
         addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], 
-                      xmin, xmax, opt->tmpMin, opt->tmpMax, false);
+                      xmin, xmax, opt->tmpMin, opt->tmpMax, false, false);
       glEnd();
       if(opt->useStipple){
         glDisable(GL_LINE_STIPPLE);
@@ -392,6 +376,25 @@ static void drawGraphCurves(drawContext *ctx, PView *p, double xleft, double yto
       }
     }
   }
+
+  if(opt->intervalsType == PViewOptions::Iso ||
+     opt->intervalsType == PViewOptions::Discrete ||
+     opt->intervalsType == PViewOptions::Numeric){
+    bool sphere =  (opt->pointType == 1 || opt->pointType == 3);
+    if(!sphere) glBegin(GL_POINTS);
+    for(unsigned int i = 0; i < y.size(); i++)
+      for(unsigned int j = 0; j < x.size(); j++)
+        addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], 
+                      xmin, xmax, opt->tmpMin, opt->tmpMax, false, sphere);
+    if(!sphere) glEnd();    
+  }
+
+  if(opt->intervalsType == PViewOptions::Numeric){
+    for(unsigned int i = 0; i < y.size(); i++)
+      for(unsigned int j = 0; j < x.size(); j++)
+        addGraphPoint(ctx, p, xleft, ytop, width, height, x[j], y[i][j], 
+                      xmin, xmax, opt->tmpMin, opt->tmpMax, true, false);
+  }
 }
 
 static void drawGraph(drawContext *ctx, PView *p, double xleft, double ytop,
-- 
GitLab