31#include "TGLIncludes.h"
66 static char null[] = {
"" };
81 switch (
fCoord->GetCoordType()) {
126 py =
fCamera->GetHeight() - py;
158 if (surfPos + 4 < option.
Length() && isdigit(option[surfPos + 4])) {
159 switch (option[surfPos + 4] -
'0') {
216 gROOT->ProcessLineFast(
Form(
"((TGLPlotPainter *)0x%zx)->Paint()", (
size_t)
this));
221 Info(
"ProcessEvent",
"Switch to true color to use box cut");
234 glEnable(GL_LIGHTING);
236 glEnable(GL_DEPTH_TEST);
237 glDisable(GL_CULL_FACE);
238 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
246 glDisable(GL_LIGHTING);
247 glDisable(GL_LIGHT0);
248 glDisable(GL_DEPTH_TEST);
249 glDisable(GL_CULL_FACE);
250 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
270 for (
Int_t i = 0; i < nX - 1; ++i) {
271 for (
Int_t j = 0; j < nY - 1; ++j) {
286 for (
Int_t i = 0; i < nX; ++i) {
287 for (
Int_t j = 0; j < nY; ++j) {
297 if (!norm.
X() && !norm.
Y() && !norm.
Z())
310 Float_t diffColor[] = {0.8f, 0.8f, 0.8f, 0.35f};
314 c->GetRGB(diffColor[0], diffColor[1], diffColor[2]);
316 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffColor);
317 const Float_t specColor[] = {1.f, 1.f, 1.f, 1.f};
318 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specColor);
319 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 70.f);
339 glEnable(GL_POLYGON_OFFSET_FILL);
340 glPolygonOffset(1.f, 1.f);
346 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
357 fPalette.EnableTexture(GL_MODULATE);
363 Int_t i = 0, firstJ = 0;
364 const Int_t addI = frontPoint == 2 || frontPoint == 1 ? i = 0, 1 : (i = nX - 2, -1);
365 const Int_t addJ = frontPoint == 2 || frontPoint == 3 ? firstJ = 0, 1 : (firstJ = nY - 2, -1);
370 for (; addI > 0 ? i < nX - 1 : i >= 0; i += addI) {
371 for (
Int_t j = firstJ; addJ > 0 ? j < nY - 1 : j >= 0; j += addJ) {
381 if (
fBoxCut.IsActive() &&
fBoxCut.IsInCut(xMin, xMax, yMin, yMax, zMin, zMax))
415 glDisable(GL_POLYGON_OFFSET_FILL);
431 glDepthMask(GL_FALSE);
433 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
434 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
436 glColor4d(0., 0., 0., 0.5);
438 for (i = 0; i < nX - 1; ++i) {
439 for (
Int_t j = 0; j < nY - 1; ++j) {
444 glDepthMask(GL_TRUE);
449 fPalette.EnableTexture(GL_MODULATE);
451 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
460 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
462 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
465 glColor4d(1.f, 0.f, 0.4f, 0.6f);
466 glBegin(GL_LINE_STRIP);
467 for (i = 0; i < nX; ++i)
468 glVertex3dv(
fMesh[i][0].CArr());
469 for (
Int_t j = 0; j < nY; ++j)
470 glVertex3dv(
fMesh[nX - 1][j].CArr());
471 for (i = nX - 1; i >= 0; --i)
472 glVertex3dv(
fMesh[i][nY - 1].CArr());
473 for (
Int_t j = nY - 1; j >= 0; --j)
474 glVertex3dv(
fMesh[0][j].CArr());
502 fMesh.resize(nX * nY);
505 for (
Int_t i = 0, ir =
fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
506 for (
Int_t j = 0, jr =
fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
523 for (
Int_t j =
fCoord->GetFirstYBin(), e1 =
fCoord->GetLastYBin(); j <= e1; ++j) {
577 fMesh.resize(nX * nY);
584 for (
Int_t i = 0, ir =
fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
585 for (
Int_t j = 0, jr =
fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
588 rRange *
fCoord->GetYScale();
604 for (
Int_t j =
fCoord->GetFirstYBin(), e1 =
fCoord->GetLastYBin(); j <= e1; ++j) {
643 fMesh.resize(nX * nY);
647 if (legoR > 1. || legoR < 0.)
651 legoR *=
fCoord->GetXScale();
657 for (
Int_t i = 0, ir =
fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
658 for (
Int_t j = 0, jr =
fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
675 for (
Int_t j =
fCoord->GetFirstYBin(), e1 =
fCoord->GetLastYBin(); j <= e1; ++j) {
716 fMesh.resize(nX * nY);
720 if (legoR > 1. || legoR < 0.)
724 legoR *=
fCoord->GetXScale();
733 for (
Int_t i = 0, ir =
fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
737 for (
Int_t j = 0, jr =
fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
754 for (
Int_t j =
fCoord->GetFirstYBin(), e1 =
fCoord->GetLastYBin(); j <= e1; ++j) {
778 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
779 glDepthMask(GL_FALSE);
782 typedef std::list<Projection_t>::const_iterator CLI_t;
783 for (CLI_t begin =
fXOZProj.begin(), end =
fXOZProj.end(); begin != end; ++begin) {
788 glBegin(GL_LINE_STRIP);
789 glVertex3dv(proj.
fVertices[i * 3].CArr());
790 glVertex3dv(proj.
fVertices[i * 3 + 1].CArr());
791 glVertex3dv(proj.
fVertices[i * 3 + 2].CArr());
796 glBegin(GL_LINE_STRIP);
798 glVertex3d(
v1.X(),
y,
v1.Z());
800 glVertex3d(
v2.X(),
y,
v2.Z());
802 glVertex3d(
v3.X(),
y,
v3.Z());
807 for (CLI_t begin =
fYOZProj.begin(), end =
fYOZProj.end(); begin != end; ++begin) {
812 glBegin(GL_LINE_STRIP);
813 glVertex3dv(proj.
fVertices[i * 3].CArr());
814 glVertex3dv(proj.
fVertices[i * 3 + 1].CArr());
815 glVertex3dv(proj.
fVertices[i * 3 + 2].CArr());
821 glBegin(GL_LINE_STRIP);
823 glVertex3d(
x,
v1.Y(),
v1.Z());
825 glVertex3d(
x,
v2.Y(),
v2.Z());
827 glVertex3d(
x,
v3.Y(),
v3.Z());
832 for (CLI_t begin =
fXOYProj.begin(), end =
fXOYProj.end(); begin != end; ++begin) {
838 glVertex3dv(proj.
fVertices[i * 2].CArr());
839 glVertex3dv(proj.
fVertices[i * 2 + 1].CArr());
855 glDepthMask(GL_TRUE);
878 glColor3d(1., 0., 0.);
882 glBegin(GL_LINE_STRIP);
890 fProj.fVertices.clear();
896 if (!
fProj.fVertices.empty()) {
900 fProj.fRGBA[3] = 150;
928 glColor3d(1., 0., 0.);
931 glBegin(GL_LINE_STRIP);
939 fProj.fVertices.clear();
945 if (!
fProj.fVertices.empty()) {
949 fProj.fRGBA[3] = 150;
972 fProj.fVertices.clear();
974 glColor3d(1., 0., 0.);
978 for (
Int_t i = 0; i < nX - 1; ++i) {
979 for (
Int_t j = 0; j < nY - 1; ++j) {
1001 glVertex3dv(intersection[0].CArr());
1002 glVertex3dv(intersection[1].CArr());
1005 fProj.fVertices.push_back(intersection[0]);
1006 fProj.fVertices.push_back(intersection[1]);
1029 glVertex3dv(intersection[0].CArr());
1030 glVertex3dv(intersection[1].CArr());
1033 fProj.fVertices.push_back(intersection[0]);
1034 fProj.fVertices.push_back(intersection[1]);
1045 fProj.fRGBA[3] = 150;
1064 zVal = frame[0].
Z();
1068 zVal *=
fCoord->GetZScale();
1070 if (zVal > frame[4].Z())
1071 zVal = frame[4].
Z();
1072 else if (zVal < frame[0].Z())
1073 zVal = frame[0].
Z();
1081 py =
fCamera->GetHeight() - py;
1085 Int_t k = selected / 2;
1089 const Bool_t odd = selected & 1;
1097 glGetDoublev(GL_MODELVIEW_MATRIX, mvMatrix);
1099 glGetDoublev(GL_PROJECTION_MATRIX, prMatrix);
1100 Int_t viewport[4] = {0};
1101 glGetIntegerv(GL_VIEWPORT, viewport);
1103 gluProject(
v1.X(),
v1.Y(),
v1.Z(), mvMatrix, prMatrix, viewport, &winV1.
X(), &winV1.
Y(), &winV1.
Z());
1104 gluProject(
v2.X(),
v2.Y(),
v2.Z(), mvMatrix, prMatrix, viewport, &winV2.
X(), &winV2.
Y(), &winV2.
Z());
1105 gluProject(
v3.X(),
v3.Y(),
v3.Z(), mvMatrix, prMatrix, viewport, &winV3.
X(), &winV3.
Y(), &winV3.
Z());
1109 planeABCD[3] = - winV1.
X() * planeABCD[0] - winV1.
Y() * planeABCD[1] - winV1.
Z() * planeABCD[2];
1110 Double_t pz = (-planeABCD[3] - planeABCD[0] * px - planeABCD[1] * py) / planeABCD[2];
1113 gluUnProject(px, py, pz, mvMatrix, prMatrix, viewport, rez, rez + 1, rez + 2);
1116 rez[0] /
fCoord->GetXScale(),
1117 rez[1] /
fCoord->GetYScale(),
1118 rez[2] /
fCoord->GetZScale());
1163 for (
Int_t i = 0, ir =
fCoord->GetFirstXBin(); i < nX; ++i, ++ir) {
1164 for (
Int_t j = 0, jr =
fCoord->GetFirstYBin(); j < nY; ++j, ++jr) {
1178 static const Float_t whiteDiffuse[] = {0.8f, 0.8f, 0.8f, 0.65f};
1179 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, whiteDiffuse);
1180 for (
Int_t i = 0, ei =
fCoord->GetNXBins() - 1; i < ei; ++i) {
1181 for (
Int_t j = 0, ej =
fCoord->GetNYBins() - 1; j < ej; ++j) {
int Int_t
Signed integer 4 bytes (int).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
int Ssiz_t
String size (currently int).
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.
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
float Float_t
Float 4 bytes (float).
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
std::pair< Bool_t, TGLLine3 > Intersection(const TGLPlane &p1, const TGLPlane &p2)
Find 3D line interestion of this plane with 'other'.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
3D space, fixed length, line class, with direction / length 'vector', passing through point 'vertex'.
3D plane class - of format Ax + By + Cz + D = 0
Camera for TGLPlotPainter and sub-classes.
Helper class for plot-painters holding information about axis ranges, numbers of bins and flags if ce...
void DrawSections() const
Draw sections (if any).
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 Paint() override
Draw lego/surf/whatever you can.
void SaveProjectionMatrix() const
void SaveModelviewMatrix() const
void MoveSection(Int_t px, Int_t py)
Create dynamic profile using selected plane.
void RestoreProjectionMatrix() const
char * GetPlotInfo(Int_t px, Int_t py) override
Coords for point on surface under cursor.
char * WindowPointTo3DPoint(Int_t px, Int_t py) const
Find 3d coords using mouse cursor coords.
void Pan(Int_t px, Int_t py) override
User's moving mouse cursor, with middle mouse button pressed (for pad).
void InitGL() const override
Initialize some OpenGL state variables.
TGL2DArray< Double_t > fTexMap
void ProcessEvent(Int_t event, Int_t px, Int_t py) override
Remove all profiles/sections.
Bool_t InitGeometryPolar()
Find bin ranges for X and Y axes, axes ranges for X, Y and Z.
void AddOption(const TString &stringOption) override
Additional options for surfaces.
void DrawProjections() const
Draw projections.
Bool_t HasProjections() const
Any projection exists.
Bool_t Textured() const
Checks, if surf requires texture.
void DrawSectionXOY() const override
Draw section Z.
std::list< Projection_t > fXOYProj
void DrawPalette() const
Draw.
TGL2DArray< TGLVector3 > fAverageNormals
void SetSurfaceColor() const
Set color for surface.
void DrawPaletteAxis() const override
Draw. Palette. Axis.
void DrawSectionXOZ() const override
Draw section X.
void DrawPlot() const override
Draw surf/surf1/surf2/surf4.
void DeInitGL() const override
Initialize some OpenGL state variables.
void DrawSectionYOZ() const override
Draw section Y.
TGL2DArray< std::pair< TGLVector3, TGLVector3 > > fFaceNormals
void DrawContoursProjection() const
Draw flat textured surface.
std::list< Projection_t > fXOZProj
Bool_t InitGeometrySpherical()
Find bin ranges for X and Y axes, axes ranges for X, Y and Z.
TGLSurfacePainter(TH1 *hist, TGLPlotCamera *camera, TGLPlotCoordinates *coord)
Constructor.
void ClampZ(Double_t &zVal) const
Clamp z value.
TGL2DArray< TGLVertex3 > fMesh
Bool_t InitGeometryCartesian()
Find bin ranges for X and Y axes, axes ranges for X, Y and Z.
Bool_t PreparePalette() const
Generate palette.
Bool_t InitGeometry() override
Set mesh, normals.
static TRandom * fgRandom
void GenTexMap() const
Find texture coordinates.
void SetNormals()
One normal per vertex; this normal is average of neighbouring triangles normals.
void StartPan(Int_t px, Int_t py) override
User clicks right mouse button (in a pad).
Bool_t InitGeometryCylindrical()
Find bin ranges for X and Y axes, axes ranges for X, Y and Z.
std::list< Projection_t > fYOZProj
Bool_t HasSections() const
Any section exists.
3 component (x/y/z) vector class.
3 component (x/y/z) vertex class.
const Double_t * CArr() const
TH1 is the base class of all histogram classes in ROOT.
@ kUserContour
User specified contour levels.
This is the base class for the ROOT Random number generators.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void DrawFaceTextured(const TGLVertex3 &v1, const TGLVertex3 &v2, const TGLVertex3 &v3, Double_t t1, Double_t t2, Double_t t3, const TGLVector3 &norm1, const TGLVector3 &norm2, const TGLVector3 &norm3)
Draw textured triangle.
void ObjectIDToColor(Int_t objectID, Bool_t highColor)
Object id encoded as rgb triplet.
void SetZLevels(TAxis *zAxis, Double_t zMin, Double_t zMax, Double_t zScale, std::vector< Double_t > &zLevels)
void DrawPalette(const TGLPlotCamera *camera, const TGLLevelPalette &palette)
Draw. Palette.
void DrawPaletteAxis(const TGLPlotCamera *camera, const Range_t &minMax, Bool_t logZ)
void DrawQuadOutline(const TGLVertex3 &v1, const TGLVertex3 &v2, const TGLVertex3 &v3, const TGLVertex3 &v4)
Draw quad outline.
void DrawSmoothFace(const TGLVertex3 &v1, const TGLVertex3 &v2, const TGLVertex3 &v3, const TGLVector3 &norm1, const TGLVector3 &norm2, const TGLVector3 &norm3)
Draws triangle face, each vertex has its own averaged normal.
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Calculates a normal vector of a plane.
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.
Double_t Cos(Double_t)
Returns the cosine of an angle of x radians.
Double_t Sin(Double_t)
Returns the sine of an angle of x radians.
Double_t Log10(Double_t x)
Returns the common (base-10) logarithm of x.
constexpr Double_t TwoPi()
void Swap(Projection_t &rhs)
Constructor.
std::vector< TGLVertex3 > fVertices