17#include "TGLIncludes.h"
33 if(!
dynamic_cast<TH2Poly *
>(hist)) {
34 Error(
"TGLH2PolyPainter::TGLH2PolyPainter",
"bad histogram, must be a valid TH2Poly *");
35 throw std::runtime_error(
"bad TH2Poly");
54 fBinInfo.Form(
"%s (bin = %d; binc = %f)",
h->GetBinTitle(binIndex), binIndex,
h->GetBinContent(binIndex));
56 fBinInfo =
"Switch to true-color mode to obtain the correct info";
72 if (!
fCoord->SetRanges(hp))
77 fCoord->GetZRangeScaled(), 1.);
127 py =
fCamera->GetHeight() - py;
168 glEnable(GL_DEPTH_TEST);
169 glEnable(GL_LIGHTING);
172 glEnable(GL_CULL_FACE);
175 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
183 glDisable(GL_DEPTH_TEST);
184 glDisable(GL_LIGHTING);
185 glDisable(GL_LIGHT0);
186 glDisable(GL_CULL_FACE);
187 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
265 for (
Int_t j = 0; j < nV - 1; ++j) {
269 if (Distance(
v0,
v1) < 1
e-10)
283 if (Distance(
v0,
v1) > 1
e-10) {
327 const TList *gs = mg->GetListOfGraphs();
328 TObjLink *graphLink = gs->FirstLink();
329 for (; graphLink && cap !=
fCaps.end(); graphLink = graphLink->
Next(), ++cap) {
354 glNormal3d(0., 0., bottomCap ? -1. : 1.);
360 typedef std::list<Rgl::Pad::MeshPatch_t>::const_iterator CMIter_t;
362 for (CMIter_t p = t.begin(); p != t.end(); ++p) {
363 const std::vector<Double_t> &vs = p->fPatch;
364 glBegin(GLenum(p->fPatchType));
365 for (
UInt_t i = 0; i < vs.size(); i += 3)
366 glVertex3d(vs[i], vs[i + 1],
fZMin);
370 for (CMIter_t p = t.begin(); p != t.end(); ++p) {
371 const std::vector<Double_t> &vs = p->fPatch;
372 glBegin(GLenum(p->fPatchType));
373 for (
UInt_t i = 0; i < vs.size(); i += 3)
395 Error(
"TGLH2PolyPainter::CacheGeometry",
"Empty list of bins in TH2Poly");
413 Error(
"TGH2PolyPainter::InitGeometry",
"Null bin or polygon pointer in a list of bins");
419 Error(
"TGLH2PolyPainter::CacheGeometry",
"Negative bin content and log scale");
430 Error(
"TGLH2PolyPainter::CacheGeometry",
"Bin contains object of unknown type");
450 Error(
"TGLH2PolyPainter::BuildTesselation",
"null array(s) in a polygon");
454 const Int_t nV =
g->GetN();
456 Error(
"TGLH2PolyPainter::BuildTesselation",
"number of vertices in a polygon must be >= 3");
465 GLUtesselator *t = (GLUtesselator *)tess.
GetTess();
467 gluNextContour(t, (GLenum)GLU_UNKNOWN);
469 glNormal3d(0., 0., 1.);
471 for (
Int_t j = 0; j < nV; ++j) {
486 Error(
"TGLH2PolyPainter::BuildTesselation",
"null list of graphs in a multigraph");
491 const TGraph *graph =
dynamic_cast<TGraph *
>(link->GetObject());
493 Error(
"TGLH2PolyPainter::BuildTesselation",
"TGraph expected inside a multigraph, got something else");
514 std::list<Rgl::Pad::Tesselation_t>::iterator cap =
fCaps.begin();
524 if (
dynamic_cast<TGraph *
>(
b->GetPolygon())) {
527 Rgl::Pad::Tesselation_t::iterator patch = tess.begin();
528 for (; patch != tess.end(); ++patch) {
529 std::vector<Double_t> &mesh = patch->fPatch;
530 for (
UInt_t i = 0,
e = mesh.size() / 3; i <
e; ++i)
536 const TList *gs = mg->GetListOfGraphs();
537 for (
TObjLink * graphLink = gs->FirstLink(); graphLink && cap !=
fCaps.end(); graphLink = graphLink->Next(), ++cap) {
539 Rgl::Pad::Tesselation_t::iterator patch = tess.begin();
540 for (; patch != tess.end(); ++patch) {
541 std::vector<Double_t> &mesh = patch->fPatch;
542 for (
UInt_t i = 0,
e = mesh.size() / 3; i <
e; ++i)
558 Error(
"TGLH2PolyPainter::SetBinColor",
"bin index is out of range %d, must be <= %d",
564 Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.15f};
567 c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);
569 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffColor);
570 const Float_t specColor[] = {0.2f, 0.2f, 0.2f, 0.2f};
571 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
572 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.f);
619 for (
Int_t j = 0; j < nV; ++j) {
621 fPolygon[j * 3 + 1] = ys[j] * yScale;
625 if (IsPolygonCW(xs, ys, nV))
635 for (
Int_t a = 0;
a <= (nV / 2) - 1;
a++) {
653 zVal *=
fCoord->GetZScale();
657 if (zVal > frame[4].Z())
659 else if (zVal < frame[0].Z())
673 return TMath::Sqrt((p1[0] - p2[0]) * (p1[0] - p2[0]) +
674 (p1[1] - p2[1]) * (p1[1] - p2[1]) +
675 (p1[2] - p2[2]) * (p1[2] - p2[2]));
686 for (
Int_t j = 0; j <
n - 1; ++j)
687 signedArea += xs[j] * ys[j + 1] - ys[j] * xs[j + 1];
689 return signedArea < 0.;
int Int_t
Signed integer 4 bytes (int).
char Char_t
Character 1 byte (char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
bool Bool_t
Boolean (0=false, 1=true) (bool).
double Double_t
Double 8 bytes.
float Float_t
Float 4 bytes (float).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
static void SetDump(Tesselation_t *t)
virtual Int_t GetEntries() const
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).
Camera for TGLPlotPainter and sub-classes.
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
TGLPlotPainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord, Bool_t xoySelectable, Bool_t xozSelectable, Bool_t yozSelectable)
TGLPlotPainter's ctor.
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.
TH1 is the base class of all histogram classes in ROOT.
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
TList * GetListOfGraphs() const
Wrapper around a TObject so it can be stored in a TList.
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.