Logo ROOT  
Reference Guide
glvox1.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_gl
3/// This macro demonstrates how to use "glcol" option for TH3.
4///
5/// \macro_image(nobatch)
6/// \macro_code
7///
8/// \author Timur Pocheptsov
9
10void glvox1()
11{
12 //Create and fill TH3.
13 const UInt_t nX = 30;
14 const Double_t xMin = -1., xMax = 1., xStep = (xMax - xMin) / (nX - 1);
15
16 const UInt_t nY = 30;
17 const Double_t yMin = -1., yMax = 1., yStep = (yMax - yMin) / (nY - 1);
18
19 const UInt_t nZ = 30;
20 const Double_t zMin = -1., zMax = 1., zStep = (zMax - zMin) / (nZ - 1);
21
22 TH3F *hist = new TH3F("glvoxel", "glvoxel", 30, -1., 1., 30, -1., 1., 30, -1., 1.);
23
24 //Fill the histogram to create a "sphere".
25 for (UInt_t i = 0; i < nZ; ++i) {
26 const Double_t z = zMin + i * zStep;
27
28 for (UInt_t j = 0; j < nY; ++j) {
29 const Double_t y = yMin + j * yStep;
30
31 for (UInt_t k = 0; k < nX; ++k) {
32 const Double_t x = xMin + k * xStep;
33
34 const Double_t val = 1. - (x * x + y * y + z * z);
35 hist->SetBinContent(k + 1, j + 1, i + 1, val);
36 }
37 }
38 }
39
41
42 hist->Draw("glcol");
43}
unsigned int UInt_t
Definition: RtypesCore.h:42
double Double_t
Definition: RtypesCore.h:55
R__EXTERN TStyle * gStyle
Definition: TStyle.h:407
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
3-D histogram with a float per channel (see TH1 documentation)}
Definition: TH3.h:267
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
Definition: TH3.cxx:3198
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
Definition: TStyle.h:320
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17