// @(#)root/gl:$Id$
// Author:  Timur Pocheptsov  31/08/2006

/*************************************************************************
 * 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.             *
 *************************************************************************/

#ifndef ROOT_TGLSurfacePainter
#define ROOT_TGLSurfacePainter

#include <vector>
#include <list>

#ifndef ROOT_TGLPlotPainter
#include "TGLPlotPainter.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TGLUtil
#include "TGLUtil.h"
#endif

class TRandom;

class TGLSurfacePainter : public TGLPlotPainter {
private:
   enum ESurfaceType {
      kSurf,
      kSurf1,
      kSurf2,
      kSurf3,
      kSurf4,
      kSurf5
   };

   mutable ESurfaceType fType;

   TGL2DArray<TGLVertex3>                         fMesh;
   mutable TGL2DArray<Double_t>                   fTexMap;
   TGL2DArray<std::pair<TGLVector3, TGLVector3> > fFaceNormals;
   TGL2DArray<TGLVector3>                         fAverageNormals;

   mutable TString                 fObjectInfo;

   struct Projection_t {
      UChar_t fRGBA[4];
      std::vector<TGLVertex3> fVertices;
      void Swap(Projection_t &rhs);
   };

   mutable Projection_t            fProj;

   mutable std::list<Projection_t> fXOZProj;
   mutable std::list<Projection_t> fYOZProj;
   mutable std::list<Projection_t> fXOYProj;

   mutable TGLLevelPalette         fPalette;
   mutable std::vector<Double_t>   fColorLevels;
   Rgl::Range_t                    fMinMaxVal;

   Bool_t                          fSectionPass;
   mutable Bool_t                  fUpdateTexMap;

public:
   TGLSurfacePainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord);

   //TGLPlotPainter's final-overriders.
   char  *GetPlotInfo(Int_t px, Int_t py);
   Bool_t InitGeometry();
   void   StartPan(Int_t px, Int_t py);
   void   Pan(Int_t px, Int_t py);
   void   AddOption(const TString &stringOption);
   void   ProcessEvent(Int_t event, Int_t px, Int_t py);

private:
   void   InitGL()const;
   void   DeInitGL()const;

   void   DrawPlot()const;

   void   SetNormals();
   void   SetSurfaceColor()const;

   Bool_t InitGeometryCartesian();
   Bool_t InitGeometryPolar();
   Bool_t InitGeometryCylindrical();
   Bool_t InitGeometrySpherical();

   void   DrawProjections()const;
   void   DrawSectionXOZ()const;
   void   DrawSectionYOZ()const;
   void   DrawSectionXOY()const;

   void   ClampZ(Double_t &zVal)const;

   char  *WindowPointTo3DPoint(Int_t px, Int_t py)const;

   Bool_t PreparePalette()const;
   void   GenTexMap()const;
   void   DrawContoursProjection()const;

   Bool_t Textured()const;
   Bool_t HasSections()const;
   Bool_t HasProjections()const;

   void   DrawPalette()const;
   void   DrawPaletteAxis()const;

   static TRandom *fgRandom;

   ClassDef(TGLSurfacePainter, 0)//Surface painter.
};

#endif
 TGLSurfacePainter.h:1
 TGLSurfacePainter.h:2
 TGLSurfacePainter.h:3
 TGLSurfacePainter.h:4
 TGLSurfacePainter.h:5
 TGLSurfacePainter.h:6
 TGLSurfacePainter.h:7
 TGLSurfacePainter.h:8
 TGLSurfacePainter.h:9
 TGLSurfacePainter.h:10
 TGLSurfacePainter.h:11
 TGLSurfacePainter.h:12
 TGLSurfacePainter.h:13
 TGLSurfacePainter.h:14
 TGLSurfacePainter.h:15
 TGLSurfacePainter.h:16
 TGLSurfacePainter.h:17
 TGLSurfacePainter.h:18
 TGLSurfacePainter.h:19
 TGLSurfacePainter.h:20
 TGLSurfacePainter.h:21
 TGLSurfacePainter.h:22
 TGLSurfacePainter.h:23
 TGLSurfacePainter.h:24
 TGLSurfacePainter.h:25
 TGLSurfacePainter.h:26
 TGLSurfacePainter.h:27
 TGLSurfacePainter.h:28
 TGLSurfacePainter.h:29
 TGLSurfacePainter.h:30
 TGLSurfacePainter.h:31
 TGLSurfacePainter.h:32
 TGLSurfacePainter.h:33
 TGLSurfacePainter.h:34
 TGLSurfacePainter.h:35
 TGLSurfacePainter.h:36
 TGLSurfacePainter.h:37
 TGLSurfacePainter.h:38
 TGLSurfacePainter.h:39
 TGLSurfacePainter.h:40
 TGLSurfacePainter.h:41
 TGLSurfacePainter.h:42
 TGLSurfacePainter.h:43
 TGLSurfacePainter.h:44
 TGLSurfacePainter.h:45
 TGLSurfacePainter.h:46
 TGLSurfacePainter.h:47
 TGLSurfacePainter.h:48
 TGLSurfacePainter.h:49
 TGLSurfacePainter.h:50
 TGLSurfacePainter.h:51
 TGLSurfacePainter.h:52
 TGLSurfacePainter.h:53
 TGLSurfacePainter.h:54
 TGLSurfacePainter.h:55
 TGLSurfacePainter.h:56
 TGLSurfacePainter.h:57
 TGLSurfacePainter.h:58
 TGLSurfacePainter.h:59
 TGLSurfacePainter.h:60
 TGLSurfacePainter.h:61
 TGLSurfacePainter.h:62
 TGLSurfacePainter.h:63
 TGLSurfacePainter.h:64
 TGLSurfacePainter.h:65
 TGLSurfacePainter.h:66
 TGLSurfacePainter.h:67
 TGLSurfacePainter.h:68
 TGLSurfacePainter.h:69
 TGLSurfacePainter.h:70
 TGLSurfacePainter.h:71
 TGLSurfacePainter.h:72
 TGLSurfacePainter.h:73
 TGLSurfacePainter.h:74
 TGLSurfacePainter.h:75
 TGLSurfacePainter.h:76
 TGLSurfacePainter.h:77
 TGLSurfacePainter.h:78
 TGLSurfacePainter.h:79
 TGLSurfacePainter.h:80
 TGLSurfacePainter.h:81
 TGLSurfacePainter.h:82
 TGLSurfacePainter.h:83
 TGLSurfacePainter.h:84
 TGLSurfacePainter.h:85
 TGLSurfacePainter.h:86
 TGLSurfacePainter.h:87
 TGLSurfacePainter.h:88
 TGLSurfacePainter.h:89
 TGLSurfacePainter.h:90
 TGLSurfacePainter.h:91
 TGLSurfacePainter.h:92
 TGLSurfacePainter.h:93
 TGLSurfacePainter.h:94
 TGLSurfacePainter.h:95
 TGLSurfacePainter.h:96
 TGLSurfacePainter.h:97
 TGLSurfacePainter.h:98
 TGLSurfacePainter.h:99
 TGLSurfacePainter.h:100
 TGLSurfacePainter.h:101
 TGLSurfacePainter.h:102
 TGLSurfacePainter.h:103
 TGLSurfacePainter.h:104
 TGLSurfacePainter.h:105
 TGLSurfacePainter.h:106
 TGLSurfacePainter.h:107
 TGLSurfacePainter.h:108
 TGLSurfacePainter.h:109
 TGLSurfacePainter.h:110
 TGLSurfacePainter.h:111
 TGLSurfacePainter.h:112
 TGLSurfacePainter.h:113
 TGLSurfacePainter.h:114
 TGLSurfacePainter.h:115
 TGLSurfacePainter.h:116
 TGLSurfacePainter.h:117
 TGLSurfacePainter.h:118
 TGLSurfacePainter.h:119