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:
- 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".
- 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.
namespace {
{
return 0.08;
if (*
x > -1.5 && *
x < -0.5)
return 0.015;
if (*
x < -0.5 && *
x < 0.)
return 0.02;
return 0.03;
return 0.01;
return 0.2;
}
}
void glvox2()
{
const Double_t xMin = -1., xMax = 1., xStep = (xMax - xMin) / (nX - 1);
const Double_t yMin = -1., yMax = 1., yStep = (yMax - yMin) / (nY - 1);
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.);
for (
UInt_t i = 0; i < nZ; ++i) {
for (
UInt_t j = 0; j < nY; ++j) {
for (
UInt_t k = 0; k < nX; ++k) {
}
}
}
if (lf) {
TF1 * tf =
new TF1(
"TransferFunction", my_transfer_function);
}
}
R__EXTERN TStyle * gStyle
TList * GetListOfFunctions() const
virtual void Draw(Option_t *option="")
Draw this histogram with options.
3-D histogram with a float per channel (see TH1 documentation)}
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content.
virtual void Add(TObject *obj)
void SetCanvasPreferGL(Bool_t prefer=kTRUE)
- Author
- Timur Pocheptsov
Definition in file glvox2.C.