17#include "TGLIncludes.h"
34 if(!
dynamic_cast<TH2Poly *
>(hist)) {
35 Error(
"TGLH2PolyPainter::TGLH2PolyPainter",
"bad histogram, must be a valid TH2Poly *");
36 throw std::runtime_error(
"bad TH2Poly");
55 fBinInfo.
Form(
"%s (bin = %d; binc = %f)",
h->GetBinTitle(binIndex), binIndex,
h->GetBinContent(binIndex));
57 fBinInfo =
"Switch to true-color mode to obtain the correct info";
169 glEnable(GL_DEPTH_TEST);
170 glEnable(GL_LIGHTING);
173 glEnable(GL_CULL_FACE);
176 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,
GL_TRUE);
184 glDisable(GL_DEPTH_TEST);
185 glDisable(GL_LIGHTING);
186 glDisable(GL_LIGHT0);
187 glDisable(GL_CULL_FACE);
188 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,
GL_FALSE);
266 for (
Int_t j = 0; j < nV - 1; ++j) {
270 if (Distance(
v0,
v1) < 1
e-10)
284 if (Distance(
v0,
v1) > 1
e-10) {
328 const TList *gs = mg->GetListOfGraphs();
330 for (; graphLink && cap !=
fCaps.end(); graphLink = graphLink->
Next(), ++cap) {
355 glNormal3d(0., 0., bottomCap ? -1. : 1.);
361 typedef std::list<Rgl::Pad::MeshPatch_t>::const_iterator CMIter_t;
363 for (CMIter_t
p = t.begin();
p != t.end(); ++
p) {
364 const std::vector<Double_t> &vs =
p->fPatch;
365 glBegin(
GLenum(
p->fPatchType));
366 for (
UInt_t i = 0; i < vs.size(); i += 3)
367 glVertex3d(vs[i], vs[i + 1],
fZMin);
371 for (CMIter_t
p = t.begin();
p != t.end(); ++
p) {
372 const std::vector<Double_t> &vs =
p->fPatch;
373 glBegin(
GLenum(
p->fPatchType));
374 for (
UInt_t i = 0; i < vs.size(); i += 3)
396 Error(
"TGLH2PolyPainter::CacheGeometry",
"Empty list of bins in TH2Poly");
414 Error(
"TGH2PolyPainter::InitGeometry",
"Null bin or polygon pointer in a list of bins");
420 Error(
"TGLH2PolyPainter::CacheGeometry",
"Negative bin content and log scale");
431 Error(
"TGLH2PolyPainter::CacheGeometry",
"Bin contains object of unknown type");
451 Error(
"TGLH2PolyPainter::BuildTesselation",
"null array(s) in a polygon");
455 const Int_t nV =
g->GetN();
457 Error(
"TGLH2PolyPainter::BuildTesselation",
"number of vertices in a polygon must be >= 3");
470 glNormal3d(0., 0., 1.);
472 for (
Int_t j = 0; j < nV; ++j) {
487 Error(
"TGLH2PolyPainter::BuildTesselation",
"null list of graphs in a multigraph");
494 Error(
"TGLH2PolyPainter::BuildTesselation",
"TGraph expected inside a multigraph, got something else");
515 std::list<Rgl::Pad::Tesselation_t>::iterator cap =
fCaps.
begin();
525 if (
dynamic_cast<TGraph *
>(
b->GetPolygon())) {
528 Rgl::Pad::Tesselation_t::iterator patch = tess.begin();
529 for (; patch != tess.end(); ++patch) {
530 std::vector<Double_t> &mesh = patch->fPatch;
531 for (
UInt_t i = 0,
e = mesh.size() / 3; i <
e; ++i)
537 const TList *gs = mg->GetListOfGraphs();
540 Rgl::Pad::Tesselation_t::iterator patch = tess.
begin();
541 for (; patch != tess.end(); ++patch) {
542 std::vector<Double_t> &mesh = patch->fPatch;
543 for (
UInt_t i = 0,
e = mesh.size() / 3; i <
e; ++i)
559 Error(
"TGLH2PolyPainter::SetBinColor",
"bin index is out of range %d, must be <= %d",
565 Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.15f};
568 c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);
570 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffColor);
571 const Float_t specColor[] = {0.2f, 0.2f, 0.2f, 0.2f};
572 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
573 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.f);
620 for (
Int_t j = 0; j < nV; ++j) {
622 fPolygon[j * 3 + 1] = ys[j] * yScale;
626 if (IsPolygonCW(xs, ys, nV))
636 for (
Int_t a = 0;
a <= (nV / 2) - 1;
a++) {
658 if (zVal > frame[4].Z())
660 else if (zVal < frame[0].Z())
674 return TMath::Sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) +
675 (p1[1] - p2[1]) * (p1[1] - p2[1]) +
676 (p1[2] - p2[2]) * (p1[2] - p2[2]));
687 for (
Int_t j = 0; j <
n - 1; ++j)
688 signedArea += xs[j] * ys[j + 1] - ys[j] * xs[j + 1];
690 return signedArea < 0.;
void gluNextContour(GLUtesselator *tess, GLenum type)
void gluBeginPolygon(GLUtesselator *tess)
void gluEndPolygon(GLUtesselator *tess)
void gluTessVertex(GLUtesselator *tess, GLdouble *location, GLvoid *data)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
winID h TVirtualViewer3D TVirtualGLPainter p
R__EXTERN TStyle * gStyle
static void SetDump(Tesselation_t *t)
virtual Int_t GetEntries() const
The color creation and management class.
static Int_t GetColor(const char *hexcolor)
Static method returning color number for color specified by hex color string of form: "#rrggbb",...
void MoveBox(Int_t px, Int_t py, Int_t axisID)
Move box cut along selected direction.
void StartMovement(Int_t px, Int_t py)
Start cut's movement.
void Pan(Int_t px, Int_t py) override
Mouse events handler.
char * GetPlotInfo(Int_t px, Int_t py) override
Show number of bin and bin contents, if bin is under the cursor.
void FillTemporaryPolygon(const Double_t *xs, const Double_t *ys, Double_t z, Int_t n) const
Since I probably have to re-orient polygon, I need a temporary polygon.
void DrawCaps() const
Caps on bins.
void InitGL() const override
Initialize some gl state variables.
void MakePolygonCCW() const
Code taken from the original TH2Poly.
Bool_t InitGeometry() override
Tesselate polygons, if not done yet.
void DeInitGL() const override
Return some gl states to original values.
std::list< Rgl::Pad::Tesselation_t > fCaps
void DrawSectionXOY() const override
No sections.
Bool_t BuildTesselation(Rgl::Pad::Tesselator &tess, const TGraph *g, Double_t z)
Tesselate a polygon described by TGraph.
std::list< Rgl::Pad::Tesselation_t >::const_iterator CIter_t
void DrawPlot() const override
Draw extruded polygons and plot's frame.
void AddOption(const TString &stringOption) override
No additional options.
void DrawCap(CIter_t cap, Int_t bin, bool bottomCap) const
Draw a cap on top of a bin.
TGLH2PolyPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord)
Ctor.
void DrawPalette() const
Not yet.
Bool_t UpdateGeometry()
Update cap's z-coordinates for all caps.
std::vector< Double_t > fPolygon
Bool_t ClampZ(Double_t &zVal) const
Clamp z value.
Bool_t CacheGeometry()
Cache all data for TH2Poly object.
void DrawSectionXOZ() const override
No sections.
void SetBinColor(Int_t bin) const
Set bin's color.
void DrawPaletteAxis() const override
Not yet.
void DrawSectionYOZ() const override
No sections.
void ProcessEvent(Int_t event, Int_t px, Int_t py) override
No events.
void DrawExtrusion() const
Extruded part of bins.
std::vector< Int_t > fBinColors
void StartPan(Int_t px, Int_t py) override
User clicks on a lego with middle mouse button (middle for pad).
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.
void DrawBox(Int_t selectedPart, Bool_t selectionPass, const std::vector< Double_t > &zLevels, Bool_t highColor) const
Draw back box for a plot.
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]
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
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.
const Rgl::Range_t & GetYRangeScaled() const
Scaled range.
Bool_t GetZLog() const
Get Z log.
Double_t GetXScale() const
Double_t GetZScale() const
const Rgl::Range_t & GetZRangeScaled() const
Scaled range.
Base class for plot-painters that provide GL rendering of various 2D and 3D histograms,...
std::vector< Double_t > fZLevels
void RestoreModelviewMatrix() const
TGLPlotCoordinates * fCoord
void SaveProjectionMatrix() const
void SaveModelviewMatrix() const
void RestoreProjectionMatrix() const
3 component (x/y/z) vertex class.
A TGraph is an object made of two arrays X and Y with npoints each.
TH1 is the base class of all histogram classes in ROOT.
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...
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...
Helper class to represent a bin in the TH2Poly histogram.
Double_t GetContent() const
TObject * GetPolygon() const
2D Histogram with Polygonal Bins
TList * GetBins()
Returns the TList of all bins in the histogram.
Bool_t GetBinContentChanged() const
void SetBinContentChanged(Bool_t flag)
void SetNewBinAdded(Bool_t flag)
Bool_t GetNewBinAdded() const
virtual TObjLink * FirstLink() const
A TMultiGraph is a collection of TGraph (or derived) objects.
TList * GetListOfGraphs() const
const char * GetName() const override
Returns name of object.
Wrapper around a TObject so it can be stored in a TList.
const char * Data() const
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Int_t GetColorPalette(Int_t i) const
Return color number i in current palette.
Int_t GetNumberOfColors() const
Return number of colors in the color palette.
std::list< MeshPatch_t > Tesselation_t
void DrawQuadFilled(const TGLVertex3 &v0, const TGLVertex3 &v1, const TGLVertex3 &v2, const TGLVertex3 &v3, const TGLVector3 &normal)
Draw quad face.
const Float_t gNullEmission[]
void ObjectIDToColor(Int_t objectID, Bool_t highColor)
Object id encoded as rgb triplet.
const Double_t gH2PolyScaleXY
const Float_t gOrangeEmission[]
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Calculates a normal vector of a plane.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.