glvox1.C: This macro demonstrates how to use "glcol" option for TH3. | OpenGL examples | gviz3d.C: Simple TStructViewer tutorial |
// This macro demonstrates how to use "glcol" option for TH3 // and how to create user defined TRANSFER FUNCTION: // transfer function maps bin value to voxel's opacity. // codomain is [0, 1] (1. - non-transparent, 0.5 is semitransparent, etc.) // To pass transparency function into painting algorithm, you have to: // 1) Create TF1 object (with symbolic expression like "0.5 * (sin(x) + 1)": // ... // TF1 * tf = new TF1("TransferFunction", "0.5 * (sin(x) + 1)", -10., 10.); // ... // IMPORTANT, the name of TF1 object MUST be "TransferFunction". // 2) Add this function into a hist's list of functions: // ... // TList * lof = hist->GetListOfFunctions(); // if (lof) lof->Add(tf); // ... // It's also possible to use your own function and pass it into TF1, please read // TF1 documentation to learn how. // // This macro is to be compiled: TF1 is extremely slow with CINT's function // as an argument. // // // Author: Timur Pocheptsov // #if defined(__CINT__) && !defined(__MAKECINT__) { //gSystem->AddIncludePath("-I$ROOTSYS/include"); TString macroName; const char *rootSysPath = gSystem->Getenv("ROOTSYS"); if (rootSysPath) { macroName = rootSysPath; if (!macroName.EndsWith("/") && !macroName.EndsWith("\\")) macroName += "/"; macroName += "tutorials/gl/"; } macroName += "glvox2.C++"; gROOT->LoadMacro(macroName.Data()); glvox2(); } #else #include "TStyle.h" #include "TList.h" #include "TH3.h" #include "TF1.h" namespace { Double_t my_transfer_function(const Double_t *x, const Double_t * /*param*/) { // Bin values in our example range from -2 to 1. // Let's make values from -2. to -1.5 more transparent: if (*x < -1.5) return 0.08; if (*x > -1.5 && *x < -0.5) return 0.015; if (*x < -0.5 && *x < 0.) return 0.02; if (*x > 0 && *x < 0.5) return 0.03; if (*x > 0.8) return 0.01; return 0.2; } } void glvox2() { //Create and fill TH3. const UInt_t nX = 30; const Double_t xMin = -1., xMax = 1., xStep = (xMax - xMin) / (nX - 1); const UInt_t nY = 30; const Double_t yMin = -1., yMax = 1., yStep = (yMax - yMin) / (nY - 1); const UInt_t nZ = 30; const Double_t zMin = -1., zMax = 1., zStep = (zMax - zMin) / (nZ - 1); TH3F *hist = new TH3F("glvoxel", "glvoxel", nX, -1., 1., nY, -1., 1., nZ, -1., 1.); //Fill the histogram to create a "sphere". for (UInt_t i = 0; i < nZ; ++i) { const Double_t z = zMin + i * zStep; for (UInt_t j = 0; j < nY; ++j) { const Double_t y = yMin + j * yStep; for (UInt_t k = 0; k < nX; ++k) { const Double_t x = xMin + k * xStep; const Double_t val = 1. - (x * x + y * y + z * z); hist->SetBinContent(k + 1, j + 1, i + 1, val); } } } //Now, specify the transfer function. TList * lf = hist->GetListOfFunctions(); if (lf) { TF1 * tf = new TF1("TransferFunction", my_transfer_function); lf->Add(tf); } gStyle->SetCanvasPreferGL(1); gStyle->SetPalette(1); hist->Draw("glcol"); } #endif glvox2.C:1 glvox2.C:2 glvox2.C:3 glvox2.C:4 glvox2.C:5 glvox2.C:6 glvox2.C:7 glvox2.C:8 glvox2.C:9 glvox2.C:10 glvox2.C:11 glvox2.C:12 glvox2.C:13 glvox2.C:14 glvox2.C:15 glvox2.C:16 glvox2.C:17 glvox2.C:18 glvox2.C:19 glvox2.C:20 glvox2.C:21 glvox2.C:22 glvox2.C:23 glvox2.C:24 glvox2.C:25 glvox2.C:26 glvox2.C:27 glvox2.C:28 glvox2.C:29 glvox2.C:30 glvox2.C:31 glvox2.C:32 glvox2.C:33 glvox2.C:34 glvox2.C:35 glvox2.C:36 glvox2.C:37 glvox2.C:38 glvox2.C:39 glvox2.C:40 glvox2.C:41 glvox2.C:42 glvox2.C:43 glvox2.C:44 glvox2.C:45 glvox2.C:46 glvox2.C:47 glvox2.C:48 glvox2.C:49 glvox2.C:50 glvox2.C:51 glvox2.C:52 glvox2.C:53 glvox2.C:54 glvox2.C:55 glvox2.C:56 glvox2.C:57 glvox2.C:58 glvox2.C:59 glvox2.C:60 glvox2.C:61 glvox2.C:62 glvox2.C:63 glvox2.C:64 glvox2.C:65 glvox2.C:66 glvox2.C:67 glvox2.C:68 glvox2.C:69 glvox2.C:70 glvox2.C:71 glvox2.C:72 glvox2.C:73 glvox2.C:74 glvox2.C:75 glvox2.C:76 glvox2.C:77 glvox2.C:78 glvox2.C:79 glvox2.C:80 glvox2.C:81 glvox2.C:82 glvox2.C:83 glvox2.C:84 glvox2.C:85 glvox2.C:86 glvox2.C:87 glvox2.C:88 glvox2.C:89 glvox2.C:90 glvox2.C:91 glvox2.C:92 glvox2.C:93 glvox2.C:94 glvox2.C:95 glvox2.C:96 glvox2.C:97 glvox2.C:98 glvox2.C:99 glvox2.C:100 glvox2.C:101 glvox2.C:102 glvox2.C:103 glvox2.C:104 glvox2.C:105 glvox2.C:106 glvox2.C:107 glvox2.C:108 glvox2.C:109 glvox2.C:110 glvox2.C:111 glvox2.C:112 glvox2.C:113 glvox2.C:114 glvox2.C:115 glvox2.C:116 glvox2.C:117 glvox2.C:118 glvox2.C:119 glvox2.C:120 glvox2.C:121 |
|