ROOT logo
// @(#)root/gl:$Id: TGLSphere.cxx 26250 2008-11-17 20:56:44Z matevz $
// Author:  Timur Pocheptsov  03/08/2004
// NOTE: This code moved from obsoleted TGLSceneObject.h / .cxx - see these
// attic files for previous CVS history

/*************************************************************************
 * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/
#include "TGLSphere.h"
#include "TGLRnrCtx.h"
#include "TGLQuadric.h"
#include "TGLIncludes.h"

#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"

// For debug tracing
#include "TClass.h"
#include "TError.h"

//______________________________________________________________________________
//
// Implements a native ROOT-GL sphere that can be rendered at
// different levels of detail.

ClassImp(TGLSphere);

//______________________________________________________________________________
TGLSphere::TGLSphere(const TBuffer3DSphere &buffer) :
   TGLLogicalShape(buffer)
{
   // Default ctor

   fDLSize = 14;

   fRadius = buffer.fRadiusOuter;

   // TODO:
   // Support hollow & cut spheres
   // buffer.fRadiusInner;
   // buffer.fThetaMin;
   // buffer.fThetaMax;
   // buffer.fPhiMin;
   // buffer.fPhiMax;
}

//______________________________________________________________________________
UInt_t TGLSphere::DLOffset(Short_t lod) const
{
   // Return display-list offset for given LOD.
   // Calculation based on what is done in virtual QuantizeShapeLOD below.

   UInt_t  off = 0;
   if      (lod >= 100) off = 0;
   else if (lod <  10)  off = lod / 2;
   else                 off = lod / 10 + 4;
   return off;
}

//______________________________________________________________________________
Short_t TGLSphere::QuantizeShapeLOD(Short_t shapeLOD, Short_t combiLOD) const
{
   // Factor in scene/viewer LOD and quantize.

   Int_t lod = ((Int_t)shapeLOD * (Int_t)combiLOD) / 100;

   if (lod >= 100)
   {
      lod = 100;
   }
   else if (lod > 10)
   {  // Round LOD above 10 to nearest 10
      Double_t quant = 0.1 * ((static_cast<Double_t>(lod)) + 0.5);
      lod            = 10  *   static_cast<Int_t>(quant);
   }
   else
   {  // Round LOD below 10 to nearest 2
      Double_t quant = 0.5 * ((static_cast<Double_t>(lod)) + 0.5);
      lod            = 2   *   static_cast<Int_t>(quant);
   }
   return static_cast<Short_t>(lod);
}

//______________________________________________________________________________
void TGLSphere::DirectDraw(TGLRnrCtx & rnrCtx) const
{
   // Debug tracing
   if (gDebug > 4) {
      Info("TGLSphere::DirectDraw", "this %d (class %s) LOD %d", this, IsA()->GetName(), rnrCtx.ShapeLOD());
   }

   // 4 stack/slice min for gluSphere to work
   UInt_t divisions = rnrCtx.ShapeLOD();
   if (divisions < 4) {
      divisions = 4;
   }
   gluSphere(rnrCtx.GetGluQuadric(), fRadius, divisions, divisions);
}
 TGLSphere.cxx:1
 TGLSphere.cxx:2
 TGLSphere.cxx:3
 TGLSphere.cxx:4
 TGLSphere.cxx:5
 TGLSphere.cxx:6
 TGLSphere.cxx:7
 TGLSphere.cxx:8
 TGLSphere.cxx:9
 TGLSphere.cxx:10
 TGLSphere.cxx:11
 TGLSphere.cxx:12
 TGLSphere.cxx:13
 TGLSphere.cxx:14
 TGLSphere.cxx:15
 TGLSphere.cxx:16
 TGLSphere.cxx:17
 TGLSphere.cxx:18
 TGLSphere.cxx:19
 TGLSphere.cxx:20
 TGLSphere.cxx:21
 TGLSphere.cxx:22
 TGLSphere.cxx:23
 TGLSphere.cxx:24
 TGLSphere.cxx:25
 TGLSphere.cxx:26
 TGLSphere.cxx:27
 TGLSphere.cxx:28
 TGLSphere.cxx:29
 TGLSphere.cxx:30
 TGLSphere.cxx:31
 TGLSphere.cxx:32
 TGLSphere.cxx:33
 TGLSphere.cxx:34
 TGLSphere.cxx:35
 TGLSphere.cxx:36
 TGLSphere.cxx:37
 TGLSphere.cxx:38
 TGLSphere.cxx:39
 TGLSphere.cxx:40
 TGLSphere.cxx:41
 TGLSphere.cxx:42
 TGLSphere.cxx:43
 TGLSphere.cxx:44
 TGLSphere.cxx:45
 TGLSphere.cxx:46
 TGLSphere.cxx:47
 TGLSphere.cxx:48
 TGLSphere.cxx:49
 TGLSphere.cxx:50
 TGLSphere.cxx:51
 TGLSphere.cxx:52
 TGLSphere.cxx:53
 TGLSphere.cxx:54
 TGLSphere.cxx:55
 TGLSphere.cxx:56
 TGLSphere.cxx:57
 TGLSphere.cxx:58
 TGLSphere.cxx:59
 TGLSphere.cxx:60
 TGLSphere.cxx:61
 TGLSphere.cxx:62
 TGLSphere.cxx:63
 TGLSphere.cxx:64
 TGLSphere.cxx:65
 TGLSphere.cxx:66
 TGLSphere.cxx:67
 TGLSphere.cxx:68
 TGLSphere.cxx:69
 TGLSphere.cxx:70
 TGLSphere.cxx:71
 TGLSphere.cxx:72
 TGLSphere.cxx:73
 TGLSphere.cxx:74
 TGLSphere.cxx:75
 TGLSphere.cxx:76
 TGLSphere.cxx:77
 TGLSphere.cxx:78
 TGLSphere.cxx:79
 TGLSphere.cxx:80
 TGLSphere.cxx:81
 TGLSphere.cxx:82
 TGLSphere.cxx:83
 TGLSphere.cxx:84
 TGLSphere.cxx:85
 TGLSphere.cxx:86
 TGLSphere.cxx:87
 TGLSphere.cxx:88
 TGLSphere.cxx:89
 TGLSphere.cxx:90
 TGLSphere.cxx:91
 TGLSphere.cxx:92
 TGLSphere.cxx:93
 TGLSphere.cxx:94
 TGLSphere.cxx:95
 TGLSphere.cxx:96
 TGLSphere.cxx:97
 TGLSphere.cxx:98
 TGLSphere.cxx:99
 TGLSphere.cxx:100
 TGLSphere.cxx:101
 TGLSphere.cxx:102