From e20d3ff88fa25ca190e3dd1fbb0d4ce52954afe7 Mon Sep 17 00:00:00 2001
From: Sven Buijssen <sven.buijssen@tu-dortmund.de>
Date: Mon, 13 Sep 2010 14:48:08 +0200
Subject: [PATCH 1/3] BUG: Axis of symmetry claimed to be the global z axis, but was the y-axis.

     Additionally, the code to change the axis of symmetry to be aligned with
     the global x-axis had the correct rotation formula z->x, but used the
     faulty y-axis based input and consequently did not yield a superquadric
     with an axis aligned to the global x-axis.
     Thirdly, location of poles of a superquadric was assumed to be independent
     of the axis of symmetry. The problem merely became evident for the parameter 
     subspace with toroidal = 0, theta = 1, phi < 1 and a superquadric 
     symmetric to the x-axis: the poles got positioned at the center of 
     gravity of the superquadric. A planar capping is intended, though.
     
---
 Graphics/vtkSuperquadricSource.cxx |   44 ++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/Graphics/vtkSuperquadricSource.cxx b/Graphics/vtkSuperquadricSource.cxx
index 366a04e..43388b2 100644
--- a/Graphics/vtkSuperquadricSource.cxx
+++ b/Graphics/vtkSuperquadricSource.cxx
@@ -274,7 +274,7 @@ int vtkSuperquadricSource::RequestData(
             thetaOffset =  0.0;
             }
 
-          //This give you superquadric with axis of symmetry: z
+          // This gives a superquadric with axis of symmetry: z
           evalSuperquadric(theta, phi,
                            thetaOffset, phiOffset,
                            this->ThetaRoundness, this->PhiRoundness,
@@ -282,16 +282,16 @@ int vtkSuperquadricSource::RequestData(
           switch (this->AxisOfSymmetry)
             {
             case 0:
-              //x-axis
-              tmp = pt[0];
+              // x-axis
+              tmp   = pt[0];
               pt[0] = pt[2];
               pt[2] = tmp;
               pt[1] = -pt[1];
 
-              tmp = nv[0];
-              nv[0]=nv[2];
-              nv[2]=tmp;
-              nv[1]=-nv[1];
+              tmp   = nv[0];
+              nv[0] = nv[2];
+              nv[2] = tmp;
+              nv[1] = -nv[1];
               break;
             case 1:
               //y-axis
@@ -314,9 +314,19 @@ int vtkSuperquadricSource::RequestData(
             // make sure the pole is at the same location for all evals
             // (the superquadric evaluation is numerically unstable
             // at the poles)
-
-            pt[0] = pt[2] = 0.0;
-          }
+            switch (this->AxisOfSymmetry)
+              {
+              case 0:
+                // x-axis
+                pt[1] = pt[2] = 0.0;
+                break;
+
+              case 2:
+                // z-axis
+                pt[0] = pt[1] = 0.0;
+                break;
+              }
+            }
 
           pt[0] += this->Center[0];
           pt[1] += this->Center[1];
@@ -416,16 +426,18 @@ static void evalSuperquadric(double theta, double phi,  // parametric coords
                              double xyz[3],      // output coords
                              double nrm[3])      // output normals
 {
+  // axis of symmetry: z
+
   double cf1, cf2;
 
   cf1 = cf(phi, rphi, alpha);
-  xyz[0] = dims[0] * cf1 * sf(theta, rtheta);
-  xyz[1] = dims[1]       * sf(phi, rphi);
-  xyz[2] = dims[2] * cf1 * cf(theta, rtheta);
+  xyz[0] =  dims[0] * cf1 * cf(theta, rtheta);
+  xyz[1] =  dims[1] * cf1 * sf(theta, rtheta);
+  xyz[2] =  dims[2]       * sf(phi, rphi);
 
   cf2 = cf(phi+dphi, 2.0-rphi);
-  nrm[0] = 1.0/dims[0] * cf2 * sf(theta+dtheta, 2.0-rtheta);
-  nrm[1] = 1.0/dims[1]       * sf(phi+dphi, 2.0-rphi);
-  nrm[2] = 1.0/dims[2] * cf2 * cf(theta+dtheta, 2.0-rtheta);
+  nrm[0] = 1.0/dims[0] * cf2 * cf(theta+dtheta, 2.0-rtheta);
+  nrm[1] = 1.0/dims[1] * cf2 * sf(theta+dtheta, 2.0-rtheta);
+  nrm[2] = 1.0/dims[2]       * sf(phi+dphi, 2.0-rphi);
 }
 
-- 
1.7.2.2

