From 6b8ac8d01b6639eae0ec9ad151e5e981e69dcfa1 Mon Sep 17 00:00:00 2001
From: Timur Pocheptsov <Timur.Pocheptsov@cern.ch>
Date: Fri, 9 Dec 2011 12:22:02 +0000
Subject: [PATCH] Draw axes for parametric surface.

git-svn-id: http://root.cern.ch/svn/root/trunk@42449 27541ba8-7e3a-0410-8455-c3a389f83636
---
 graf3d/gl/inc/TGLParametric.h   |  9 +++++++
 graf3d/gl/src/TGLParametric.cxx | 46 +++++++++++++++++++++------------
 2 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/graf3d/gl/inc/TGLParametric.h b/graf3d/gl/inc/TGLParametric.h
index cdeafefa487..751732733f0 100644
--- a/graf3d/gl/inc/TGLParametric.h
+++ b/graf3d/gl/inc/TGLParametric.h
@@ -20,6 +20,9 @@
 #ifndef ROOT_TGLUtil
 #include "TGLUtil.h"
 #endif
+#ifndef ROOT_TAxis
+#include "TAxis.h"
+#endif
 #ifndef ROOT_TF2
 #include "TF2.h"
 #endif
@@ -107,6 +110,12 @@ private:
    Int_t                  fColorScheme;
 
    TGLParametricEquation *fEquation;
+   
+   TAxis                  fCartesianXAxis;
+   TAxis                  fCartesianYAxis;
+   TAxis                  fCartesianZAxis;
+
+   TGLPlotCoordinates     fCartesianCoord;
 
 public:
    TGLParametricPlot(TGLParametricEquation *equation, TGLPlotCamera *camera);
diff --git a/graf3d/gl/src/TGLParametric.cxx b/graf3d/gl/src/TGLParametric.cxx
index a2f71cdd980..d89c5617fb5 100644
--- a/graf3d/gl/src/TGLParametric.cxx
+++ b/graf3d/gl/src/TGLParametric.cxx
@@ -8,8 +8,6 @@
  * For the licensing terms see $ROOTSYS/LICENSE.                         *
  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
  *************************************************************************/
-
-#include "Riostream.h"
 #include <cctype>
 
 #ifdef WIN32
@@ -19,6 +17,7 @@
 #include "TVirtualX.h"
 #include "TString.h"
 #include "TROOT.h"
+#include "TH3.h"
 
 #include "TGLPlotCamera.h"
 #include "TGLParametric.h"
@@ -276,6 +275,12 @@ TGLParametricPlot::TGLParametricPlot(TGLParametricEquation *eq,
                         fEquation(eq)
 {
    //Constructor.
+   fXAxis = &fCartesianXAxis;
+   fYAxis = &fCartesianYAxis;
+   fZAxis = &fCartesianZAxis;
+   
+   fCoord = &fCartesianCoord;
+
    InitGeometry();
    InitColors();
 }
@@ -329,22 +334,30 @@ Bool_t TGLParametricPlot::InitGeometry()
          }
          u += dU;
       }
-
-      const Double_t xRange = max.X() - min.X(), yRange = max.Y() - min.Y(), zRange = max.Z() - min.Z();
-      const Double_t xS = 1. / xRange, yS = 1. / yRange, zS = 1. / zRange;
+      
+      TH3F hist("tmp", "tmp", 2, -1., 1., 2, -1., 1., 2, -1., 1.);
+      hist.SetDirectory(0);
+      //TAxis has a lot of attributes, defaults, set by ctor,
+      //are not enough to be correctly painted by TGaxis object.
+      //To simplify their initialization - I use temporary histogram.
+      hist.GetXaxis()->Copy(fCartesianXAxis);
+      hist.GetYaxis()->Copy(fCartesianYAxis);
+      hist.GetZaxis()->Copy(fCartesianZAxis);
+   
+      fCartesianXAxis.Set(fMeshSize, min.X(), max.X());
+      fCartesianYAxis.Set(fMeshSize, min.Y(), max.Y());
+      fCartesianZAxis.Set(fMeshSize, min.Z(), max.Z());
+
+      if (!fCoord->SetRanges(&fCartesianXAxis, &fCartesianYAxis, &fCartesianZAxis))
+         return kFALSE;
 
       for (Int_t i = 0; i < fMeshSize; ++i) {
          for (Int_t j = 0; j < fMeshSize; ++j) {
             TGLVertex3 &ver = fMesh[i][j].fPos;
-            ver.X() *= xS, ver.Y() *= yS, ver.Z() *= zS;
+            ver.X() *= fCoord->GetXScale(), ver.Y() *= fCoord->GetYScale(), ver.Z() *= fCoord->GetZScale();
          }
       }
 
-      if (!xRange || !yRange || !zRange) {
-         Error("InitGeometry", "Zero axis range");
-         return kFALSE;
-      }
-
       u = uRange.first;
       for (Int_t i = 0; i < fMeshSize; ++i) {
          Double_t v = vRange.first;
@@ -352,18 +365,17 @@ Bool_t TGLParametricPlot::InitGeometry()
             TGLVertex3 &ver = fMesh[i][j].fPos;
             fEquation->EvalVertex(v1, u + dd, v);
             fEquation->EvalVertex(v2, u, v + dd);
-            v1.X() *= xS, v1.Y() *= yS, v1.Z() *= zS;
-            v2.X() *= xS, v2.Y() *= yS, v2.Z() *= zS;
+            v1.X() *= fCoord->GetXScale(), v1.Y() *= fCoord->GetYScale(), v1.Z() *= fCoord->GetZScale();
+            v2.X() *= fCoord->GetXScale(), v2.Y() *= fCoord->GetYScale(), v2.Z() *= fCoord->GetZScale();
             Normal2Plane(ver.CArr(), v1.CArr(), v2.CArr(), fMesh[i][j].fNormal.Arr());
             v += dV;
          }
          u += dU;
       }
 
-      using Rgl::Range_t;
-      fBackBox.SetPlotBox(Range_t(min.X() * xS, max.X() * xS),
-                          Range_t(min.Y() * yS, max.Y() * yS),
-                          Range_t(min.Z() * zS, max.Z() * zS));
+      fBackBox.SetPlotBox(fCoord->GetXRangeScaled(),
+                          fCoord->GetYRangeScaled(),
+                          fCoord->GetZRangeScaled());
       if (fCamera) fCamera->SetViewVolume(fBackBox.Get3DBox());
    }
 
-- 
GitLab