Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLVoxelPainter.cxx
Go to the documentation of this file.
1#include <algorithm>
2
3#include "KeySymbols.h"
4#include "TVirtualX.h"
5#include "Buttons.h"
6#include "TString.h"
7#include "TROOT.h"
8#include "TList.h"
9#include "TStyle.h"
10#include "TH3.h"
11#include "TF1.h"
12
13#include "TGLVoxelPainter.h"
14#include "TGLPlotCamera.h"
15#include "TGLIncludes.h"
16
17/** \class TGLVoxelPainter
18\ingroup opengl
19Paint TH3 histograms as "voxels" - colored boxes, transparent if transfer function was specified.
20*/
21
23
24////////////////////////////////////////////////////////////////////////////////
25/// Constructor.
26///This plot always needs a palette.
27
34
35
36////////////////////////////////////////////////////////////////////////////////
37///Show box info (i, j, k, binContent).
38
40{
41 fPlotInfo = "";
42
43 if (fSelectedPart) {
45 if (fHist->Class())
46 fPlotInfo += fHist->Class()->GetName();
47 fPlotInfo += "::";
49 } else if (!fHighColor){
54
55 fPlotInfo.Form("(binx = %d; biny = %d; binz = %d; binc = %f)", binI, binJ, binK,
57 } else
58 fPlotInfo = "Switch to true color mode to get correct info";
59 }
60
61 return (Char_t *)fPlotInfo.Data();
62}
63
64
65////////////////////////////////////////////////////////////////////////////////
66///Set ranges, find min and max bin content.
67
69{
73
74 if (!fCoord->SetRanges(fHist, kFALSE, kTRUE))//kFALSE == drawErrors, kTRUE == zAsBins
75 return kFALSE;
76
79
81 fMinMaxVal.first = fMinMaxVal.second;
82 //Bad. You can up-date some bin value and get wrong picture.
83 for (Int_t ir = fCoord->GetFirstXBin(); ir <= fCoord->GetLastXBin(); ++ir) {
84 for (Int_t jr = fCoord->GetFirstYBin(); jr <= fCoord->GetLastYBin(); ++jr) {
85 for (Int_t kr = fCoord->GetFirstZBin(); kr <= fCoord->GetLastZBin(); ++kr) {
88 }
89 }
90 }
91
92 if (fCoord->Modified()) {
98 }
99
100 const TList *funcList = fHist->GetListOfFunctions();
101 fTransferFunc = dynamic_cast<TF1*>(funcList->FindObject("TransferFunction"));
102
103 return kTRUE;
104}
105
106
107////////////////////////////////////////////////////////////////////////////////
108/// User clicks right mouse button (in a pad).
109
111{
112 fMousePosition.fX = px;
114 fCamera->StartPan(px, py);
116}
117
118
119////////////////////////////////////////////////////////////////////////////////
120/// User's moving mouse cursor, with middle mouse button pressed (for pad).
121/// Calculate 3d shift related to 2d mouse movement.
122
124{
125 // User's moving mouse cursor, with middle mouse button pressed (for pad).
126 // Calculate 3d shift related to 2d mouse movement.
127 if (fSelectedPart >= fSelectionBase) {//Pan camera.
130
133 fCamera->Pan(px, py);
134
137 } else if (fSelectedPart > 0) {
138 //Convert py into bottom-top orientation.
139 //Possibly, move box here
140 py = fCamera->GetHeight() - py;
143
146
147
148 if (!fHighColor) {
151 else
152 MoveSection(px, py);
153 } else {
154 MoveSection(px, py);
155 }
156
159 }
160
163}
164
165
166////////////////////////////////////////////////////////////////////////////////
167/// "z" draw palette or not.
168
170{
171 option.Index("z") == kNPOS ? fDrawPalette = kFALSE : fDrawPalette = kTRUE;
172
173}
174
175////////////////////////////////////////////////////////////////////////////////
176/// Remove sections, switch on/off box cut.
177
179{
180 if (event == kButton1Double && fBoxCut.IsActive()) {
181 if (fBoxCut.IsActive())
183 if (!gVirtualX->IsCmdThread())
184 gROOT->ProcessLineFast(Form("((TGLPlotPainter *)0x%zx)->Paint()", (size_t)this));
185 else
186 Paint();
187 } else if (event == kKeyPress && (py == kKey_c || py == kKey_C)) {
188 if (fHighColor)
189 Info("ProcessEvent", "Switch to true color mode to use box cut");
190 else {
193 }
194 }
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Initialize some gl state variables.
199
211
212////////////////////////////////////////////////////////////////////////////////
213/// Return back some gl state variables.
214
223
224////////////////////////////////////////////////////////////////////////////////
225/// Draw "voxels".
226
228{
229 //Shift plot to point of origin.
230 const Rgl::PlotTranslation trGuard(this);
231
232 if (!fSelectionPass)
234
236
238
239 if (!fSelectionPass) {
240 glEnable(GL_BLEND);//[1
242 }
243
244 //Using front point, find the correct order to draw boxes from
245 //back to front/from bottom to top (it's important only for semi-transparent boxes).
248 const Int_t nX = fCoord->GetNXBins();
250 const Int_t nY = fCoord->GetNYBins();
251 Int_t krInit = fCoord->GetFirstZBin(), kInit = 0;
252 const Int_t nZ = fCoord->GetNZBins();
253
254 const Int_t addI = frontPoint == 2 || frontPoint == 1 ? 1 : (iInit = nX - 1, irInit = fCoord->GetLastXBin(), -1);
255 const Int_t addJ = frontPoint == 2 || frontPoint == 3 ? 1 : (jInit = nY - 1, jrInit = fCoord->GetLastYBin(), -1);
256 const Int_t addK = fBackBox.Get2DBox()[frontPoint + 4].Y() > fBackBox.Get2DBox()[frontPoint].Y() ? 1
257 : (kInit = nZ - 1, krInit = fCoord->GetLastZBin(),-1);
258 const Double_t xScale = fCoord->GetXScale();
259 const Double_t yScale = fCoord->GetYScale();
260 const Double_t zScale = fCoord->GetZScale();
261 const TAxis *xA = fXAxis;
262 const TAxis *yA = fYAxis;
263 const TAxis *zA = fZAxis;
264
267
269 if(!maxContent)//bad, find better way to check zero.
270 maxContent = 1.;
271
272 Float_t rgba[4] = {};
273
278
279 for(Int_t ir = irInit, i = iInit; addI > 0 ? i < nX : i >= 0; ir += addI, i += addI) {
280 for(Int_t jr = jrInit, j = jInit; addJ > 0 ? j < nY : j >= 0; jr += addJ, j += addJ) {
281 for(Int_t kr = krInit, k = kInit; addK > 0 ? k < nZ : k >= 0; kr += addK, k += addK) {
282 const Double_t xMin = xScale * xA->GetBinLowEdge(ir);
283 const Double_t xMax = xScale * xA->GetBinUpEdge(ir);
284 const Double_t yMin = yScale * yA->GetBinLowEdge(jr);
285 const Double_t yMax = yScale * yA->GetBinUpEdge(jr);
286 const Double_t zMin = zScale * zA->GetBinLowEdge(kr);
287 const Double_t zMax = zScale * zA->GetBinUpEdge(kr);
288
290 continue;
291
293 if (binContent < wmin) continue;
295
297
298 if (rgba[3] < 0.01f)
299 continue;
300
301 if (!fSelectionPass)
303
304 const Int_t binID = fSelectionBase + i * fCoord->GetNZBins() * fCoord->GetNYBins() + j * fCoord->GetNZBins() + k;
305
308 else if(!fHighColor && fSelectedPart == binID)
310
312
315 }
316 }
317 }
318
319 if (fBoxCut.IsActive())
321
322 if (!fSelectionPass) {
323 if (fDrawPalette)
324 DrawPalette();
325 glDisable(GL_BLEND);//1]
326 }
327}
328
329////////////////////////////////////////////////////////////////////////////////
330/// Noop.
331
335
336////////////////////////////////////////////////////////////////////////////////
337/// Noop.
338
342
343
344////////////////////////////////////////////////////////////////////////////////
345/// Noop.
346
350
351////////////////////////////////////////////////////////////////////////////////
352///Draw. Palette.
353
355{
357 return;
358
361 else
363
364 glFinish();
365
368}
369
370////////////////////////////////////////////////////////////////////////////////
371///Draw. Palette. Axis.
372
374{
375 if (fCamera) {
376 gVirtualX->SetDrawMode(TVirtualX::kCopy);//TCanvas by default sets in kInverse
378 }
379}
380
381////////////////////////////////////////////////////////////////////////////////
382///Generate palette.
383
385{
386 if(fMinMaxVal.first == fMinMaxVal.second)
387 return;//must be std::abs(fMinMaxVal.second - fMinMaxVal.first) < ...
388
389 fLevels.clear();
391
393 if (const UInt_t trySize = fHist->GetContour()) {
394 fLevels.reserve(trySize);
395
396 for (UInt_t i = 0; i < trySize; ++i) {
397 const Double_t level = fHist->GetContourLevel(Int_t(i));
399 continue;
400 fLevels.push_back(level);
401 }
402 //sort levels
403 if (!fLevels.empty()) {
404 std::sort(fLevels.begin(), fLevels.end());
405 fLevels.push_back(fMinMaxVal.second);
406 fLevels.insert(fLevels.begin(), fMinMaxVal.first);
408 paletteSize = fLevels.size() - 1;
409 }
410 }
411
412 if (!paletteSize)
414 }
415
417 paletteSize = 20;
418
420}
421
422////////////////////////////////////////////////////////////////////////////////
423/// Find box color.
424
426{
428 rgba[3] = 0.06f; //Just a constant transparency.
429
430
431 if (fTransferFunc) {
433 }
434
435 rgba[0] = tc[0] / 255.f;
436 rgba[1] = tc[1] / 255.f;
437 rgba[2] = tc[2] / 255.f;
438}
439
440
441////////////////////////////////////////////////////////////////////////////////
442/// Set box color.
443
@ kKeyPress
Definition Buttons.h:20
@ kButton1Double
Definition Buttons.h:24
@ kKey_C
Definition KeySymbols.h:128
@ kKey_c
Definition KeySymbols.h:160
int Int_t
Definition RtypesCore.h:45
char Char_t
Definition RtypesCore.h:37
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Ssiz_t kNPOS
Definition RtypesCore.h:117
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:374
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t option
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmin
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t wmax
#define gROOT
Definition TROOT.h:406
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
R__EXTERN TStyle * gStyle
Definition TStyle.h:442
#define gVirtualX
Definition TVirtualX.h:337
Class to manage histogram axis.
Definition TAxis.h:32
1-Dim function class
Definition TF1.h:233
virtual Double_t Eval(Double_t x, Double_t y=0, Double_t z=0, Double_t t=0) const
Evaluate this function.
Definition TF1.cxx:1439
void MoveBox(Int_t px, Int_t py, Int_t axisID)
Move box cut along selected direction.
Bool_t IsInCut(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax) const
Check, if box defined by xmin/xmax etc. is in cut.
void DrawBox(Bool_t selectionPass, Int_t selected) const
Draw cut as a semi-transparent box.
void TurnOnOff()
Turn the box cut on/off.
void StartMovement(Int_t px, Int_t py)
Start cut's movement.
Bool_t IsActive() const
const UChar_t * GetColour(Double_t z) const
Get color.
Definition TGLUtil.cxx:4300
Int_t GetPaletteSize() const
Get. Palette. Size.
Definition TGLUtil.cxx:4263
void SetContours(const std::vector< Double_t > *contours)
Clear :)
Definition TGLUtil.cxx:4227
Bool_t GeneratePalette(UInt_t paletteSize, const Rgl::Range_t &zRange, Bool_t checkSize=kTRUE)
Try to find colors for palette.
Definition TGLUtil.cxx:4170
void SetPlotBox(const Rgl::Range_t &xRange, const Rgl::Range_t &yRange, const Rgl::Range_t &zRange)
Set up a frame box.
const TGLVertex3 * Get3DBox() const
Get 3D box.
const TGLVertex3 * Get2DBox() const
Get 2D box.
void DrawBox(Int_t selectedPart, Bool_t selectionPass, const std::vector< Double_t > &zLevels, Bool_t highColor) const
Draw back box for a plot.
Int_t GetFrontPoint() const
The nearest point.
Camera for TGLPlotPainter and sub-classes.
void StartPan(Int_t px, Int_t py)
User clicks somewhere (px, py).
void Apply(Double_t phi, Double_t theta) const
Applies rotations and translations before drawing.
void SetCamera() const
Viewport and projection.
void Pan(Int_t px, Int_t py)
Pan camera.
Int_t GetHeight() const
viewport[3]
void SetViewVolume(const TGLVertex3 *box)
'box' is the TGLPlotPainter's back box's coordinates.
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
void SetXLog(Bool_t xLog)
If log changed, sections must be reset, set fModified.
Bool_t SetRanges(const TH1 *hist, Bool_t errors=kFALSE, Bool_t zBins=kFALSE)
Set bin ranges, ranges.
Double_t GetYScale() const
const Rgl::Range_t & GetXRangeScaled() const
Scaled range.
Int_t GetFirstXBin() const
Int_t GetFirstYBin() const
const Rgl::Range_t & GetYRangeScaled() const
Scaled range.
void ResetModified()
Reset modified.
Bool_t Modified() const
Modified.
Double_t GetXScale() const
Double_t GetZScale() const
Int_t GetLastZBin() const
Int_t GetNXBins() const
Number of X bins.
Int_t GetFirstZBin() const
const Rgl::Range_t & GetZRangeScaled() const
Scaled range.
void SetZLog(Bool_t zLog)
If log changed, sections must be reset, set fModified.
void SetYLog(Bool_t yLog)
If log changed, sections must be reset, set fModified.
Int_t GetLastYBin() const
Int_t GetNYBins() const
Number of Y bins.
Int_t GetLastXBin() const
Int_t GetNZBins() const
Number of Z bins.
Base class for plot-painters that provide GL rendering of various 2D and 3D histograms,...
std::vector< Double_t > fZLevels
Double_t fXOYSectionPos
void RestoreModelviewMatrix() const
Double_t fXOZSectionPos
TGLPlotCoordinates * fCoord
void Paint() override
Draw lego/surf/whatever you can.
TGLPlotBox fBackBox
void SaveProjectionMatrix() const
void SaveModelviewMatrix() const
void MoveSection(Int_t px, Int_t py)
Create dynamic profile using selected plane.
TGLPlotCamera * fCamera
void RestoreProjectionMatrix() const
Double_t fYOZSectionPos
Paint TH3 histograms as "voxels" - colored boxes, transparent if transfer function was specified.
void DrawPlot() const override
Draw "voxels".
void SetVoxelColor(const Float_t *rgba) const
Set box color.
void DrawSectionXOZ() const override
Noop.
void ProcessEvent(Int_t event, Int_t px, Int_t py) override
Remove sections, switch on/off box cut.
void Pan(Int_t px, Int_t py) override
User's moving mouse cursor, with middle mouse button pressed (for pad).
void AddOption(const TString &stringOption) override
"z" draw palette or not.
Rgl::Range_t fMinMaxVal
void PreparePalette() const
Generate palette.
void DrawPalette() const
Draw. Palette.
TGLVoxelPainter(const TGLVoxelPainter &)=delete
void DeInitGL() const override
Return back some gl state variables.
void InitGL() const override
Initialize some gl state variables.
void DrawSectionYOZ() const override
Noop.
char * GetPlotInfo(Int_t px, Int_t py) override
Show box info (i, j, k, binContent).
Bool_t InitGeometry() override
Set ranges, find min and max bin content.
TGLLevelPalette fPalette
void DrawPaletteAxis() const override
Draw. Palette. Axis.
void FindVoxelColor(Double_t binContent, Float_t *rgba) const
Find box color.
void StartPan(Int_t px, Int_t py) override
User clicks right mouse button (in a pad).
std::vector< Double_t > fLevels
void DrawSectionXOY() const override
Noop.
TH1 is the base class of all histogram classes in ROOT.
Definition TH1.h:59
static TClass * Class()
@ kUserContour
User specified contour levels.
Definition TH1.h:176
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition TH1.cxx:8547
TList * GetListOfFunctions() const
Definition TH1.h:260
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
Definition TH1.cxx:5059
virtual Int_t GetContour(Double_t *levels=nullptr)
Return contour values into array levels if pointer levels is non zero.
Definition TH1.cxx:8413
virtual Double_t GetContourLevel(Int_t level) const
Return value of contour number level.
Definition TH1.cxx:8432
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition TH1.cxx:8637
A doubly linked list.
Definition TList.h:38
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition TList.cxx:576
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
void ResetBit(UInt_t f)
Definition TObject.h:198
SCoord_t fY
Definition TPoint.h:36
SCoord_t fX
Definition TPoint.h:35
Basic string class.
Definition TString.h:139
const char * Data() const
Definition TString.h:376
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Definition TString.cxx:2356
Int_t GetNumberContours() const
Definition TStyle.h:243
std::ostream & Info()
Definition hadd.cxx:171
const Float_t gNullEmission[]
Definition TGLUtil.cxx:2856
void ObjectIDToColor(Int_t objectID, Bool_t highColor)
Object id encoded as rgb triplet.
Definition TGLUtil.cxx:2900
void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette)
Draw. Palette.
void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ)
void DrawBoxFront(Double_t xMin, Double_t xMax, Double_t yMin, Double_t yMax, Double_t zMin, Double_t zMax, Int_t fp)
Draws lego's bar as a 3d box.
Definition TGLUtil.cxx:3016
const Float_t gOrangeEmission[]
Definition TGLUtil.cxx:2853
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Definition TMathBase.h:250
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Definition TMathBase.h:198
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123