Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4OpenGLViewer Class Reference

#include <G4OpenGLViewer.hh>

Inheritance diagram for G4OpenGLViewer:

Public Member Functions

virtual void ClearView ()
void ClearViewWithoutFlush ()
virtual bool exportImage (std::string name="", int width=-1, int height=-1)
bool setExportImageFormat (std::string format, bool quiet=false)
Public Member Functions inherited from G4VViewer
 G4VViewer (G4VSceneHandler &, G4int id, const G4String &name="")
virtual ~G4VViewer ()
virtual void Initialise ()
virtual void DrawView ()=0
void RefreshView ()
virtual void ShowView ()
virtual void FinishView ()
virtual G4bool ReadyToDraw ()
std::vector< G4ThreeVectorComputeFlyThrough (G4Vector3D *)
virtual void DoneWithMasterThread ()
virtual void MovingToVisSubThread ()
virtual void SwitchToVisSubThread ()
virtual void DoneWithVisSubThread ()
virtual void MovingToMasterThread ()
virtual void SwitchToMasterThread ()
void InsertModelInSceneTree (G4VModel *)
const G4SceneTreeItemGetSceneTree ()
G4SceneTreeItemAccessSceneTree ()
void UpdateGUISceneTree ()
void UpdateGUIControlWidgets ()
void UpdateGUIDrawingStyle ()
void UpdateGUIProjectionStyle ()
void UpdateGUITransparencySlider ()
const G4StringGetName () const
const G4StringGetShortName () const
void SetName (const G4String &)
G4int GetViewId () const
G4VSceneHandlerGetSceneHandler () const
const G4ViewParametersGetViewParameters () const
const G4ViewParametersGetDefaultViewParameters () const
G4double GetKernelVisitElapsedTimeSeconds () const
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers () const
void SetViewParameters (const G4ViewParameters &vp)
void SetDefaultViewParameters (const G4ViewParameters &vp)
const G4VisAttributesGetApplicableVisAttributes (const G4VisAttributes *) const
void SetNeedKernelVisit (G4bool need)
void NeedKernelVisit ()
void ProcessView ()
void ProcessTransients ()
void ZoomFromMouseWheel (G4double delta, G4bool shift=false, G4double xPos=0, G4double yPos=0)
virtual G4bool GetWindowSize (unsigned int &a_w, unsigned int &a_h)

Protected Member Functions

 G4OpenGLViewer (G4OpenGLSceneHandler &scene)
virtual ~G4OpenGLViewer ()
virtual void SetView ()
virtual void ResetView ()
virtual void DrawText (const G4Text &)
void ChangePointSize (G4double size)
void ChangeLineWidth (G4double width)
void HaloingFirstPass ()
void HaloingSecondPass ()
void HLRFirstPass ()
void HLRSecondPass ()
void HLRThirdPass ()
void InitializeGLView ()
void ResizeGLView ()
void ResizeWindow (unsigned int, unsigned int)
virtual G4String Pick (GLdouble x, GLdouble y)
const std::vector< G4OpenGLViewerPickMap * > & GetPickDetails (GLdouble x, GLdouble y)
virtual void CreateFontLists ()
void rotateScene (G4double dx, G4double dy)
void rotateSceneToggle (G4double dx, G4double dy)
void setExportSize (G4int, G4int)
bool setExportFilename (G4String name, G4bool inc=true)
std::string getRealPrintFilename ()
unsigned int getWinWidth () const
unsigned int getWinHeight () const
G4bool sizeHasChanged ()
G4double GetSceneNearWidth ()
GLdouble getSceneFarWidth ()
GLdouble getSceneDepth ()
void addExportImageFormat (std::string format)
G4bool isGl2psWriting ()
G4bool isFramebufferReady ()
void g4GluPickMatrix (GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4])
void g4GluLookAt (GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz)
void g4GlOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
void g4GlFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
bool IsGettingPickInfos () const
Protected Member Functions inherited from G4VViewer
void SetTouchable (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
void TouchableSetVisibility (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
void TouchableSetColour (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)

Protected Attributes

G4bool fPrintColour
G4bool fVectoredPs
G4OpenGLSceneHandlerfOpenGLSceneHandler
G4Colour background
G4bool transparency_enabled
G4bool antialiasing_enabled
G4bool haloing_enabled
G4gl2psfGL2PSAction
G4double fRot_sens
G4double fPan_sens
unsigned int fWinSize_x
unsigned int fWinSize_y
std::vector< std::string > fExportImageFormatVector
std::string fDefaultExportImageFormat
std::string fExportImageFormat
int fExportFilenameIndex
G4int fPrintSizeX
G4int fPrintSizeY
Protected Attributes inherited from G4VViewer
G4VSceneHandlerfSceneHandler
G4int fViewId
G4String fName
G4String fShortName
G4ViewParameters fVP
G4ViewParameters fDefaultVP
G4double fKernelVisitElapsedTimeSeconds = 999.
G4SceneTreeItem fSceneTree
G4bool fNeedKernelVisit
G4bool fTransientsNeedRedrawing

Friends

class G4OpenGLSceneHandler
class G4OpenGLImmediateSceneHandler
class G4OpenGLStoredSceneHandler
class G4OpenGLFileSceneHandler
class G4OpenGLViewerMessenger

Additional Inherited Members

Public Attributes inherited from G4VViewer
const G4int fMaxAllTouchables = 10000
G4bool fCurtailDescent = false

Detailed Description

Definition at line 95 of file G4OpenGLViewer.hh.

Constructor & Destructor Documentation

◆ G4OpenGLViewer()

G4OpenGLViewer::G4OpenGLViewer ( G4OpenGLSceneHandler & scene)
protected

Definition at line 58 of file G4OpenGLViewer.cc.

58 :
59G4VViewer (scene, -1),
60fPrintColour (true),
61fVectoredPs (true),
63background (G4Colour(0.,0.,0.)),
66haloing_enabled (false),
67fRot_sens(1.),
68fPan_sens(0.01),
69fWinSize_x(0),
70fWinSize_y(0),
74fPrintSizeX(-1),
75fPrintSizeY(-1),
76fPointSize (0),
77fDefaultExportFilename("G4OpenGL"),
78fSizeHasChanged(0),
79fGl2psDefaultLineWith(1),
80fGl2psDefaultPointSize(2),
81fGlViewInitialized(false),
82fIsGettingPickInfos(false)
83{
84 // Make changes to view parameters for OpenGL...
85 fVP.SetAutoRefresh(true);
86 fDefaultVP.SetAutoRefresh(true);
87 fGL2PSAction = new G4gl2ps();
88 tools_gl2ps_gl_funcs_t _funcs = {
89 (tools_glIsEnabled_func)glIsEnabled,
90 (tools_glBegin_func)glBegin,
91 (tools_glEnd_func)glEnd,
92 (tools_glGetFloatv_func)glGetFloatv,
93 (tools_glVertex3f_func)glVertex3f,
94 (tools_glGetBooleanv_func)glGetBooleanv,
95 (tools_glGetIntegerv_func)glGetIntegerv,
96 (tools_glRenderMode_func)glRenderMode,
97 (tools_glFeedbackBuffer_func)glFeedbackBuffer,
98 (tools_glPassThrough_func)glPassThrough
99 };
100 fGL2PSAction->setOpenGLFunctions(&_funcs);
101
102 // add supported export image format
107
108 // Change the default name
109 fExportFilename += fDefaultExportFilename + "_" + GetShortName().data();
110
111 // glClearColor (0.0, 0.0, 0.0, 0.0);
112 // glClearDepth (1.0);
113 // glDisable (GL_BLEND);
114 // glDisable (GL_LINE_SMOOTH);
115 // glDisable (GL_POLYGON_SMOOTH);
116
117}
unsigned int fWinSize_y
std::string fExportImageFormat
std::string fDefaultExportImageFormat
void addExportImageFormat(std::string format)
G4bool antialiasing_enabled
G4bool transparency_enabled
G4gl2ps * fGL2PSAction
G4OpenGLSceneHandler & fOpenGLSceneHandler
unsigned int fWinSize_x
G4ViewParameters fDefaultVP
Definition G4VViewer.hh:273
const G4String & GetShortName() const
G4ViewParameters fVP
Definition G4VViewer.hh:272
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition G4VViewer.cc:49
tools_GLint(* tools_glRenderMode_func)(tools_GLenum)
Definition gl2ps_def.h:195
void(* tools_glVertex3f_func)(tools_GLfloat, tools_GLfloat, tools_GLfloat)
Definition gl2ps_def.h:192
void(* tools_glGetFloatv_func)(tools_GLenum, tools_GLfloat *)
Definition gl2ps_def.h:191
void(* tools_glBegin_func)(tools_GLenum)
Definition gl2ps_def.h:189
void(* tools_glFeedbackBuffer_func)(tools_GLsizei, tools_GLenum, tools_GLfloat *)
Definition gl2ps_def.h:196
void(* tools_glPassThrough_func)(tools_GLfloat)
Definition gl2ps_def.h:197
void(* tools_glGetBooleanv_func)(tools_GLenum, tools_GLboolean *)
Definition gl2ps_def.h:193
void(* tools_glEnd_func)()
Definition gl2ps_def.h:190
void(* tools_glGetIntegerv_func)(tools_GLenum, tools_GLint *)
Definition gl2ps_def.h:194
tools_GLboolean(* tools_glIsEnabled_func)(tools_GLenum)
Definition gl2ps_def.h:188

Referenced by G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer(), G4OpenGLImmediateViewer::G4OpenGLImmediateViewer(), G4OpenGLImmediateWin32Viewer::G4OpenGLImmediateWin32Viewer(), G4OpenGLImmediateXmViewer::G4OpenGLImmediateXmViewer(), G4OpenGLImmediateXViewer::G4OpenGLImmediateXViewer(), G4OpenGLQtViewer::G4OpenGLQtViewer(), G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer(), G4OpenGLStoredViewer::G4OpenGLStoredViewer(), G4OpenGLStoredWin32Viewer::G4OpenGLStoredWin32Viewer(), G4OpenGLStoredXmViewer::G4OpenGLStoredXmViewer(), G4OpenGLStoredXViewer::G4OpenGLStoredXViewer(), G4OpenGLViewerMessenger, G4OpenGLWin32Viewer::G4OpenGLWin32Viewer(), G4OpenGLXmViewer::G4OpenGLXmViewer(), and G4OpenGLXViewer::G4OpenGLXViewer().

◆ ~G4OpenGLViewer()

G4OpenGLViewer::~G4OpenGLViewer ( )
protectedvirtual

Definition at line 119 of file G4OpenGLViewer.cc.

120{
121 delete fGL2PSAction;
122}

Member Function Documentation

◆ addExportImageFormat()

void G4OpenGLViewer::addExportImageFormat ( std::string format)
protected

Definition at line 1244 of file G4OpenGLViewer.cc.

1244 {
1245 fExportImageFormatVector.push_back(format);
1246}
std::vector< std::string > fExportImageFormatVector

Referenced by G4OpenGLQtViewer::G4OpenGLQtViewer(), and G4OpenGLViewer().

◆ ChangeLineWidth()

void G4OpenGLViewer::ChangeLineWidth ( G4double width)
protected

Change LineSize on gl2ps if needed

Definition at line 757 of file G4OpenGLViewer.cc.

757 {
758
759 if (isGl2psWriting()) {
760 fGL2PSAction->setLineWidth(int(width));
761 } else {
762 glLineWidth (width);
763 }
764}
G4bool isGl2psWriting()

Referenced by G4OpenGLSceneHandler::AddPrimitive(), G4OpenGLSceneHandler::AddPrimitive(), G4OpenGLSceneHandler::AddPrimitive(), HaloingFirstPass(), and HaloingSecondPass().

◆ ChangePointSize()

void G4OpenGLViewer::ChangePointSize ( G4double size)
protected

Change PointSize on gl2ps if needed

Definition at line 745 of file G4OpenGLViewer.cc.

745 {
746
747 if (isGl2psWriting()) {
748 fGL2PSAction->setPointSize(int(size));
749 } else {
750 glPointSize (size);
751 }
752}

Referenced by G4OpenGLSceneHandler::AddPrimitive().

◆ ClearView()

◆ ClearViewWithoutFlush()

void G4OpenGLViewer::ClearViewWithoutFlush ( )

Definition at line 162 of file G4OpenGLViewer.cc.

162 {
163 // Ready for clear ?
164 // See : http://lists.apple.com/archives/mac-opengl/2012/Jul/msg00038.html
165 if(!isFramebufferReady()) {
166 return;
167 }
168
169 glClearColor (background.GetRed(),
170 background.GetGreen(),
171 background.GetBlue(),
172 1.);
173 glClearDepth (1.0);
174 //Below line does not compile with Mesa includes.
175 //glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
176 glClear (GL_COLOR_BUFFER_BIT);
177 glClear (GL_DEPTH_BUFFER_BIT);
178 glClear (GL_STENCIL_BUFFER_BIT);
179}

Referenced by ClearView().

◆ CreateFontLists()

virtual void G4OpenGLViewer::CreateFontLists ( )
inlineprotectedvirtual

◆ DrawText()

void G4OpenGLViewer::DrawText ( const G4Text & g4text)
protectedvirtual

Reimplemented in G4OpenGLQtViewer, and G4OpenGLXViewer.

Definition at line 705 of file G4OpenGLViewer.cc.

706{
707 // gl2ps or GL window ?
708 if (isGl2psWriting()) {
709
711 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType);
712 G4Point3D position = g4text.GetPosition();
713
714 G4String textString = g4text.GetText();
715
716 glRasterPos3d(position.x(),position.y(),position.z());
717 GLint align = GL2PS_TEXT_B;
718
719 switch (g4text.GetLayout()) {
720 case G4Text::left: align = GL2PS_TEXT_BL; break;
721 case G4Text::centre: align = GL2PS_TEXT_B; break;
722 case G4Text::right: align = GL2PS_TEXT_BR;
723 }
724
725 fGL2PSAction->addTextOpt(textString.c_str(),"Times-Roman",GLshort(size),align,0);
726
727 } else {
728
729 static G4int callCount = 0;
730 ++callCount;
731 //if (callCount <= 10 || callCount%100 == 0) {
732 if (callCount <= 1) {
733 G4cout <<
734 "G4OpenGLViewer::DrawText: Not implemented for \""
735 << fName <<
736 "\"\n Called with "
737 << g4text
738 << G4endl;
739 }
740 }
741}
#define GL2PS_TEXT_BL
#define GL2PS_TEXT_BR
#define GL2PS_TEXT_B
HepGeom::Point3D< G4double > G4Point3D
Definition G4Point3D.hh:34
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
Layout GetLayout() const
G4String GetText() const
@ centre
Definition G4Text.hh:76
@ right
Definition G4Text.hh:76
@ left
Definition G4Text.hh:76
G4Point3D GetPosition() const
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:268
G4String fName
Definition G4VViewer.hh:270

Referenced by G4OpenGLSceneHandler::AddPrimitive(), G4OpenGLQtViewer::DrawText(), and G4OpenGLXViewer::DrawText().

◆ exportImage()

bool G4OpenGLViewer::exportImage ( std::string name = "",
int width = -1,
int height = -1 )
virtual

Export image with the given name with width and height Several cases : If name is "", filename will have the default value If name is "toto.png", set the name to "toto" and the format to "png". No incremented suffix is added. If name is "toto", set the name to "toto" and the format to default (or current format if specify). Will also add an incremented suffix at the end of the file

Reimplemented in G4OpenGLQtViewer.

Definition at line 774 of file G4OpenGLViewer.cc.

774 {
775
776 if (! setExportFilename(name)) {
777 return false;
778 }
779
780 if ((width != -1) && (height != -1)) {
781 setExportSize(width, height);
782 }
783
784 if (fExportImageFormat == "eps") {
785 fGL2PSAction->setExportImageFormat_EPS();
786 } else if (fExportImageFormat == "ps") {
787 fGL2PSAction->setExportImageFormat_PS();
788 } else if (fExportImageFormat == "svg") {
789 fGL2PSAction->setExportImageFormat_SVG();
790 } else if (fExportImageFormat == "pdf") {
791 fGL2PSAction->setExportImageFormat_PDF();
792 } else {
793 setExportImageFormat(fExportImageFormat,true); // will display a message if this format is not correct for the current viewer
794 return false;
795 }
796
797 bool res;
798
799 // Change the LC_NUMERIC value in order to have "." separtor and not ","
800 // This case is only useful for French, Canadien...
801 size_t len = strlen(setlocale(LC_NUMERIC,NULL));
802 char* oldLocale = (char*)(malloc(len+1));
803 if(oldLocale!=NULL) strncpy(oldLocale,setlocale(LC_NUMERIC,NULL),len);
804 setlocale(LC_NUMERIC,"C");
805
806 if (((fExportImageFormat == "eps") || (fExportImageFormat == "ps")) && (!fVectoredPs)) {
807 res = printNonVectoredEPS();
808 } else {
809 res = printVectoredEPS();
810 }
811
812 // restore the local
813 if (oldLocale) {
814 setlocale(LC_NUMERIC,oldLocale);
815 free(oldLocale);
816 }
817
818 if (res == false) {
819 G4cerr << "Error saving file... " << getRealPrintFilename().c_str() << G4endl;
820 } else {
821 G4cout << "File " << getRealPrintFilename().c_str() << " size: " << getRealExportWidth() << "x" << getRealExportHeight() << " has been saved " << G4endl;
822
823 // increment index if necessary
824 if ( fExportFilenameIndex != -1) {
826 }
827 }
828
829 return res;
830}
G4GLOB_DLL std::ostream G4cerr
bool setExportImageFormat(std::string format, bool quiet=false)
bool setExportFilename(G4String name, G4bool inc=true)
void setExportSize(G4int, G4int)
std::string getRealPrintFilename()
void free(voidpf ptr)
voidp malloc(uInt size)

Referenced by G4OpenGLQtViewer::exportImage(), G4OpenGLXmViewer::print_callback(), and G4OpenGLViewerMessenger::SetNewValue().

◆ g4GlFrustum()

void G4OpenGLViewer::g4GlFrustum ( GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble near,
GLdouble far )
protected

Definition at line 1423 of file G4OpenGLViewer.cc.

1423 {
1424 // glFrustum (left, right, bottom, top, near, far);
1425
1426 GLdouble deltaX = right - left;
1427 GLdouble deltaY = top - bottom;
1428 GLdouble deltaZ = zFar - zNear;
1429
1430 GLdouble a = 2.0f * zNear / deltaX;
1431 GLdouble b = 2.0f * zNear / deltaY;
1432 GLdouble c = (right + left) / deltaX;
1433 GLdouble d = (top + bottom) / deltaY;
1434 GLdouble e = -(zFar + zNear) / (zFar - zNear);
1435 GLdouble f = -2.0f * zFar * zNear / deltaZ;
1436
1437 GLdouble proj[16] = {
1438 a, 0, 0, 0,
1439 0, b, 0, 0,
1440 c, d, e, -1.0f,
1441 0, 0, f, 0
1442 };
1443
1444 glMultMatrixd(proj);
1445
1446}

Referenced by SetView().

◆ g4GlOrtho()

void G4OpenGLViewer::g4GlOrtho ( GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble near,
GLdouble far )
protected

Definition at line 1401 of file G4OpenGLViewer.cc.

1401 {
1402 // glOrtho (left, right, bottom, top, near, far);
1403
1404 GLdouble a = 2.0 / (right - left);
1405 GLdouble b = 2.0 / (top - bottom);
1406 GLdouble c = -2.0 / (zFar - zNear);
1407
1408 GLdouble tx = - (right + left)/(right - left);
1409 GLdouble ty = - (top + bottom)/(top - bottom);
1410 GLdouble tz = - (zFar + zNear)/(zFar - zNear);
1411
1412 GLdouble ortho[16] = {
1413 a, 0, 0, 0,
1414 0, b, 0, 0,
1415 0, 0, c, 0,
1416 tx, ty, tz, 1
1417 };
1418 glMultMatrixd(ortho);
1419
1420}

Referenced by G4OpenGLImmediateSceneHandler::BeginPrimitives2D(), G4OpenGLStoredViewer::DrawDisplayLists(), and SetView().

◆ g4GluLookAt()

void G4OpenGLViewer::g4GluLookAt ( GLdouble eyex,
GLdouble eyey,
GLdouble eyez,
GLdouble centerx,
GLdouble centery,
GLdouble centerz,
GLdouble upx,
GLdouble upy,
GLdouble upz )
protected

Definition at line 1321 of file G4OpenGLViewer.cc.

1325{
1326 GLdouble mat[16];
1327 GLdouble x[3], y[3], z[3];
1328 GLdouble mag;
1329
1330 /* Make rotation matrix */
1331
1332 /* Z vector */
1333 z[0] = eyex - centerx;
1334 z[1] = eyey - centery;
1335 z[2] = eyez - centerz;
1336 mag = std::sqrt(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
1337 if (mag) { /* mpichler, 19950515 */
1338 z[0] /= mag;
1339 z[1] /= mag;
1340 z[2] /= mag;
1341 }
1342
1343 /* Y vector */
1344 y[0] = upx;
1345 y[1] = upy;
1346 y[2] = upz;
1347
1348 /* X vector = Y cross Z */
1349 x[0] = y[1] * z[2] - y[2] * z[1];
1350 x[1] = -y[0] * z[2] + y[2] * z[0];
1351 x[2] = y[0] * z[1] - y[1] * z[0];
1352
1353 /* Recompute Y = Z cross X */
1354 y[0] = z[1] * x[2] - z[2] * x[1];
1355 y[1] = -z[0] * x[2] + z[2] * x[0];
1356 y[2] = z[0] * x[1] - z[1] * x[0];
1357
1358 /* mpichler, 19950515 */
1359 /* cross product gives area of parallelogram, which is < 1.0 for
1360 * non-perpendicular unit-length vectors; so normalize x, y here
1361 */
1362
1363 mag = std::sqrt(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
1364 if (mag) {
1365 x[0] /= mag;
1366 x[1] /= mag;
1367 x[2] /= mag;
1368 }
1369
1370 mag = std::sqrt(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
1371 if (mag) {
1372 y[0] /= mag;
1373 y[1] /= mag;
1374 y[2] /= mag;
1375 }
1376
1377#define M(row,col) mat[col*4+row]
1378 M(0, 0) = x[0];
1379 M(0, 1) = x[1];
1380 M(0, 2) = x[2];
1381 M(0, 3) = 0.0;
1382 M(1, 0) = y[0];
1383 M(1, 1) = y[1];
1384 M(1, 2) = y[2];
1385 M(1, 3) = 0.0;
1386 M(2, 0) = z[0];
1387 M(2, 1) = z[1];
1388 M(2, 2) = z[2];
1389 M(2, 3) = 0.0;
1390 M(3, 0) = 0.0;
1391 M(3, 1) = 0.0;
1392 M(3, 2) = 0.0;
1393 M(3, 3) = 1.0;
1394#undef M
1395 glMultMatrixd(mat);
1396
1397 /* Translate Eye to Origin */
1398 glTranslated(-eyex, -eyey, -eyez);
1399}
#define M(row, col)

Referenced by SetView().

◆ g4GluPickMatrix()

void G4OpenGLViewer::g4GluPickMatrix ( GLdouble x,
GLdouble y,
GLdouble width,
GLdouble height,
GLint viewport[4] )
protected

Definition at line 1279 of file G4OpenGLViewer.cc.

1281 {
1282 GLdouble mat[16];
1283 GLdouble sx, sy;
1284 GLdouble tx, ty;
1285
1286 sx = viewport[2] / width;
1287 sy = viewport[3] / height;
1288 tx = (viewport[2] + 2.0 * (viewport[0] - x)) / width;
1289 ty = (viewport[3] + 2.0 * (viewport[1] - y)) / height;
1290
1291#define M(row, col) mat[col*4+row]
1292 M(0, 0) = sx;
1293 M(0, 1) = 0.0;
1294 M(0, 2) = 0.0;
1295 M(0, 3) = tx;
1296 M(1, 0) = 0.0;
1297 M(1, 1) = sy;
1298 M(1, 2) = 0.0;
1299 M(1, 3) = ty;
1300 M(2, 0) = 0.0;
1301 M(2, 1) = 0.0;
1302 M(2, 2) = 1.0;
1303 M(2, 3) = 0.0;
1304 M(3, 0) = 0.0;
1305 M(3, 1) = 0.0;
1306 M(3, 2) = 0.0;
1307 M(3, 3) = 1.0;
1308#undef M
1309
1310 glMultMatrixd(mat);
1311}

Referenced by GetPickDetails().

◆ GetPickDetails()

const std::vector< G4OpenGLViewerPickMap * > & G4OpenGLViewer::GetPickDetails ( GLdouble x,
GLdouble y )
protected

Definition at line 435 of file G4OpenGLViewer.cc.

436{
437 static std::vector < G4OpenGLViewerPickMap* > pickMapVector;
438 for (auto pickMap: pickMapVector) {
439 delete pickMap;
440 }
441 pickMapVector.clear();
442
443 const G4int BUFSIZE = 512;
444 GLuint selectBuffer[BUFSIZE];
445 glSelectBuffer(BUFSIZE, selectBuffer);
446 glRenderMode(GL_SELECT);
447 glInitNames();
448 glPushName(0);
449 glMatrixMode(GL_PROJECTION);
450 G4double currentProjectionMatrix[16];
451 glGetDoublev(GL_PROJECTION_MATRIX, currentProjectionMatrix);
452 glPushMatrix();
453 glLoadIdentity();
454 GLint viewport[4];
455 glGetIntegerv(GL_VIEWPORT, viewport);
456/* G4cout
457 << "viewport, x,y: "
458 << viewport[0] << ',' << viewport[1] << ',' << viewport[2] << ',' << viewport[3]
459 << ", " << x << ',' << y
460 << G4endl;
461*/
462 fIsGettingPickInfos = true;
463 // Define 5x5 pixel pick area
464 g4GluPickMatrix(x, viewport[3] - y, 5., 5., viewport);
465 glMultMatrixd(currentProjectionMatrix);
466 glMatrixMode(GL_MODELVIEW);
467 DrawView();
468 GLint hits = glRenderMode(GL_RENDER);
469 fIsGettingPickInfos = false;
470 if (hits < 0) {
471 G4cout << "Too many hits. Zoom in to reduce overlaps." << G4endl;
472 goto restoreMatrices;
473 }
474 if (hits > 0) {
475 GLuint* p = selectBuffer;
476 for (GLint i = 0; i < hits; ++i) {
477 GLuint nnames = *p++;
478 // This bit of debug code or...
479 //GLuint zmin = *p++;
480 //GLuint zmax = *p++;
481 //G4cout << "Hit " << i << ": " << nnames << " names"
482 // << "\nzmin: " << zmin << ", zmax: " << zmax << G4endl;
483 // ...just increment the pointer
484 p++;
485 p++;
486 for (GLuint j = 0; j < nnames; ++j) {
487 GLuint name = *p++;
488 std::map<GLuint, G4AttHolder*>::iterator iter =
489 fOpenGLSceneHandler.fPickMap.find(name);
490 if (iter != fOpenGLSceneHandler.fPickMap.end()) {
491 G4AttHolder* attHolder = iter->second;
492 if(attHolder && attHolder->GetAttDefs().size()) {
493 for (size_t iAtt = 0;
494 iAtt < attHolder->GetAttDefs().size(); ++iAtt) {
495 std::ostringstream oss;
496 oss << G4AttCheck(attHolder->GetAttValues()[iAtt],
497 attHolder->GetAttDefs()[iAtt]);
498 G4OpenGLViewerPickMap* pickMap = new G4OpenGLViewerPickMap();
499// G4cout
500// << "i,j, attHolder->GetAttDefs().size(): "
501// << i << ',' << j
502// << ", " << attHolder->GetAttDefs().size()
503// << G4endl;
504// G4cout << "G4OpenGLViewer::GetPickDetails: " << oss.str() << G4endl;
505 pickMap->addAttributes(oss.str());
506 pickMap->setHitNumber(i);
507 pickMap->setSubHitNumber(j);
508 pickMap->setPickName(name);
509 pickMapVector.push_back(pickMap);
510 }
511 }
512 }
513 }
514 }
515 }
516
517restoreMatrices:
518 glMatrixMode(GL_PROJECTION);
519 glPopMatrix();
520 glMatrixMode(GL_MODELVIEW);
521
522 return pickMapVector;
523}
const std::vector< const std::vector< G4AttValue > * > & GetAttValues() const
const std::vector< const std::map< G4String, G4AttDef > * > & GetAttDefs() const
void setSubHitNumber(G4int n)
void setHitNumber(G4int n)
void addAttributes(G4String att)
void setPickName(G4int n)
void g4GluPickMatrix(GLdouble x, GLdouble y, GLdouble width, GLdouble height, GLint viewport[4])
virtual void DrawView()=0
const char * name(G4int ptype)

Referenced by Pick(), and G4OpenGLQtViewer::updatePickInfosWidget().

◆ getRealPrintFilename()

std::string G4OpenGLViewer::getRealPrintFilename ( )
protected

Definition at line 1022 of file G4OpenGLViewer.cc.

1022 {
1023 std::string temp = fExportFilename;
1024 if (fExportFilenameIndex != -1) {
1025 temp += std::string("_");
1026 std::ostringstream os;
1027 os << std::setw(4) << std::setfill('0') << fExportFilenameIndex;
1028 std::string nb_str = os.str();
1029 temp += nb_str;
1030 }
1031 temp += "."+fExportImageFormat;
1032 return temp;
1033}

Referenced by G4OpenGLQtViewer::exportImage(), exportImage(), G4OpenGLXmViewer::misc_callback(), and setExportFilename().

◆ getSceneDepth()

GLdouble G4OpenGLViewer::getSceneDepth ( )
protected

Definition at line 1067 of file G4OpenGLViewer.cc.

1068{
1069 if (!fSceneHandler.GetScene()) {
1070 return 0;
1071 }
1072 const G4Point3D targetPoint
1073 = fSceneHandler.GetScene()->GetStandardTargetPoint()
1074 + fVP.GetCurrentTargetPoint ();
1075 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
1076 if(radius<=0.) radius = 1.;
1077 const G4double cameraDistance = fVP.GetCameraDistance (radius);
1078 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
1079 return fVP.GetFarDistance (cameraDistance, pnear, radius)- pnear;
1080}

Referenced by G4OpenGLQtViewer::moveScene().

◆ getSceneFarWidth()

GLdouble G4OpenGLViewer::getSceneFarWidth ( )
protected

Definition at line 1050 of file G4OpenGLViewer.cc.

1051{
1052 if (!fSceneHandler.GetScene()) {
1053 return 0;
1054 }
1055 const G4Point3D targetPoint
1056 = fSceneHandler.GetScene()->GetStandardTargetPoint()
1057 + fVP.GetCurrentTargetPoint ();
1058 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
1059 if(radius<=0.) radius = 1.;
1060 const G4double cameraDistance = fVP.GetCameraDistance (radius);
1061 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
1062 const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
1063 return 2 * fVP.GetFrontHalfHeight (pfar, radius);
1064}

◆ GetSceneNearWidth()

G4double G4OpenGLViewer::GetSceneNearWidth ( )
protectedvirtual

Reimplemented from G4VViewer.

Definition at line 1035 of file G4OpenGLViewer.cc.

1036{
1037 if (!fSceneHandler.GetScene()) {
1038 return 0;
1039 }
1040 const G4Point3D targetPoint
1041 = fSceneHandler.GetScene()->GetStandardTargetPoint()
1042 + fVP.GetCurrentTargetPoint ();
1043 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
1044 if(radius<=0.) radius = 1.;
1045 const G4double cameraDistance = fVP.GetCameraDistance (radius);
1046 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
1047 return 2 * fVP.GetFrontHalfHeight (pnear, radius);
1048}

Referenced by G4OpenGLQtViewer::G4MousePressEvent(), and G4OpenGLQtViewer::moveScene().

◆ getWinHeight()

◆ getWinWidth()

◆ HaloingFirstPass()

void G4OpenGLViewer::HaloingFirstPass ( )
protected

Definition at line 388 of file G4OpenGLViewer.cc.

388 {
389
390 //To perform haloing, first Draw all information to the depth buffer
391 //alone, using a chunky line width, and then Draw all info again, to
392 //the colour buffer, setting a thinner line width an the depth testing
393 //function to less than or equal, so if two lines cross, the one
394 //passing behind the other will not pass the depth test, and so not
395 //get rendered either side of the infront line for a short distance.
396
397 //First, disable writing to the colo(u)r buffer...
398 glColorMask (GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
399
400 //Now enable writing to the depth buffer...
401 glDepthMask (GL_TRUE);
402 glDepthFunc (GL_LESS);
403 glClearDepth (1.0);
404
405 //Finally, set the line width to something wide...
406 ChangeLineWidth(3.0);
407
408}
void ChangeLineWidth(G4double width)

Referenced by G4OpenGLImmediateWin32Viewer::DrawView(), G4OpenGLImmediateXmViewer::DrawView(), G4OpenGLImmediateXViewer::DrawView(), G4OpenGLStoredWin32Viewer::DrawView(), G4OpenGLStoredXmViewer::DrawView(), and G4OpenGLStoredXViewer::DrawView().

◆ HaloingSecondPass()

void G4OpenGLViewer::HaloingSecondPass ( )
protected

Definition at line 410 of file G4OpenGLViewer.cc.

410 {
411
412 //And finally, turn the colour buffer back on with a sesible line width...
413 glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
414 glDepthFunc (GL_LEQUAL);
415 ChangeLineWidth(1.0);
416
417}

Referenced by G4OpenGLImmediateWin32Viewer::DrawView(), G4OpenGLImmediateXmViewer::DrawView(), G4OpenGLImmediateXViewer::DrawView(), G4OpenGLStoredWin32Viewer::DrawView(), G4OpenGLStoredXmViewer::DrawView(), and G4OpenGLStoredXViewer::DrawView().

◆ HLRFirstPass()

void G4OpenGLViewer::HLRFirstPass ( )
protected

◆ HLRSecondPass()

void G4OpenGLViewer::HLRSecondPass ( )
protected

◆ HLRThirdPass()

void G4OpenGLViewer::HLRThirdPass ( )
protected

◆ InitializeGLView()

void G4OpenGLViewer::InitializeGLView ( )
protected

Definition at line 124 of file G4OpenGLViewer.cc.

125{
126 if (fWinSize_x == 0) {
127 fWinSize_x = fVP.GetWindowSizeHintX();
128 }
129 if (fWinSize_y == 0) {
130 fWinSize_y = fVP.GetWindowSizeHintY();
131 }
132
133 glClearColor (0.0, 0.0, 0.0, 0.0);
134 glClearDepth (1.0);
135 glDisable (GL_LINE_SMOOTH);
136 glDisable (GL_POLYGON_SMOOTH);
137 glDisable (GL_POINT_SMOOTH);
138
139// clear the buffers and window?
140 ClearView ();
141 FinishView ();
142
143 glDepthFunc (GL_LEQUAL);
144 glDepthMask (GL_TRUE);
145
146 glEnable (GL_BLEND);
147 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
148
149}
virtual void ClearView()
virtual void FinishView()
Definition G4VViewer.cc:108

Referenced by G4OpenGLImmediateXmViewer::Initialise(), G4OpenGLImmediateXViewer::Initialise(), G4OpenGLStoredXmViewer::Initialise(), G4OpenGLStoredXViewer::Initialise(), G4OpenGLImmediateQtViewer::initializeGL(), G4OpenGLStoredQtViewer::initializeGL(), G4OpenGLImmediateQtViewer::paintGL(), and G4OpenGLStoredQtViewer::paintGL().

◆ isFramebufferReady()

G4bool G4OpenGLViewer::isFramebufferReady ( )
protected

Definition at line 677 of file G4OpenGLViewer.cc.

677 {
678 bool check = false;
679#ifdef G4VIS_BUILD_OPENGLQT_DRIVER
680 check = true;
681#endif
682#ifdef G4VIS_BUILD_OPENGLX_DRIVER
683 check = false;
684#endif
685#ifdef G4VIS_BUILD_OPENGLXM_DRIVER
686 check = false;
687#endif
688#ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
689 check = false;
690#endif
691
692#if GL_ARB_framebuffer_object
693 if (check) {
694// if ( glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_UNDEFINED) {
695// return false;
696// }
697 }
698#endif
699 return true;
700}

Referenced by ClearView(), ClearViewWithoutFlush(), G4OpenGLImmediateQtViewer::paintEvent(), and G4OpenGLStoredQtViewer::paintEvent().

◆ IsGettingPickInfos()

bool G4OpenGLViewer::IsGettingPickInfos ( ) const
inlineprotected

Definition at line 181 of file G4OpenGLViewer.hh.

181{return fIsGettingPickInfos;}

Referenced by G4OpenGLImmediateQtViewer::DrawView(), and G4OpenGLStoredQtViewer::DrawView().

◆ isGl2psWriting()

bool G4OpenGLViewer::isGl2psWriting ( )
protected

Return if gl2ps is currently writing

Definition at line 667 of file G4OpenGLViewer.cc.

667 {
668
669 if (!fGL2PSAction) return false;
670 if (fGL2PSAction->fileWritingEnabled()) {
671 return true;
672 }
673 return false;
674}

Referenced by ChangeLineWidth(), ChangePointSize(), G4OpenGLQtViewer::DrawText(), DrawText(), and G4OpenGLXViewer::DrawText().

◆ Pick()

G4String G4OpenGLViewer::Pick ( GLdouble x,
GLdouble y )
protectedvirtual

Definition at line 419 of file G4OpenGLViewer.cc.

420{
421 const std::vector < G4OpenGLViewerPickMap* > & pickMap = GetPickDetails(x,y);
422 G4String txt = "";
423 if (pickMap.size() == 0) {
424// txt += "No hits recorded.";;
425 } else {
426 for (unsigned int a=0; a < pickMap.size(); a++) {
427 if (pickMap[a]->getAttributes().size() > 0) {
428 txt += pickMap[a]->print();
429 }
430 }
431 }
432 return txt;
433}
const std::vector< G4OpenGLViewerPickMap * > & GetPickDetails(GLdouble x, GLdouble y)

Referenced by G4OpenGLXViewer::ShowView().

◆ ResetView()

void G4OpenGLViewer::ResetView ( )
protectedvirtual

Reimplemented from G4VViewer.

Reimplemented in G4OpenGLQtViewer, and G4OpenGLXmViewer.

Definition at line 381 of file G4OpenGLViewer.cc.

381 {
383 fRot_sens = 1;
384 fPan_sens = 0.01;
385}
virtual void ResetView()

Referenced by G4OpenGLQtViewer::ResetView(), and G4OpenGLXmViewer::ResetView().

◆ ResizeGLView()

void G4OpenGLViewer::ResizeGLView ( )
protected

Set the viewport of the scene MAXIMUM SIZE is : GLint dims[2]; glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);

Definition at line 198 of file G4OpenGLViewer.cc.

199{
200 // Check size
201 GLint dims[2];
202 dims[0] = 0;
203 dims[1] = 0;
204
205 glGetIntegerv(GL_MAX_VIEWPORT_DIMS, dims);
206
207 if ((dims[0] !=0 ) && (dims[1] !=0)) {
208
209 if (fWinSize_x > (unsigned)dims[0]) {
210 G4cerr << "Try to resize view greater than max X viewport dimension. Desired size "<<fWinSize_x <<" is resize to "<< dims[0] << G4endl;
211 fWinSize_x = dims[0];
212 }
213 if (fWinSize_y > (unsigned)dims[1]) {
214 G4cerr << "Try to resize view greater than max Y viewport dimension. Desired size "<<fWinSize_y <<" is resize to "<< dims[1] << G4endl;
215 fWinSize_y = dims[1];
216 }
217 }
218
219 glViewport(0, 0, fWinSize_x,fWinSize_y);
220
221
222}

Referenced by G4OpenGLQtViewer::G4MouseReleaseEvent(), SetView(), and G4OpenGLQtViewer::updatePickInfosWidget().

◆ ResizeWindow()

void G4OpenGLViewer::ResizeWindow ( unsigned int aWidth,
unsigned int aHeight )
protected

Definition at line 182 of file G4OpenGLViewer.cc.

182 {
183 if ((fWinSize_x != aWidth) || (fWinSize_y != aHeight)) {
184 fWinSize_x = aWidth;
185 fWinSize_y = aHeight;
186 fSizeHasChanged = true;
187 } else {
188 fSizeHasChanged = false;
189 }
190}

Referenced by G4OpenGLQtViewer::CreateMainWindow(), G4OpenGLWin32Viewer::CreateMainWindow(), G4OpenGLXmViewer::CreateMainWindow(), G4OpenGLXViewer::CreateMainWindow(), G4OpenGLXmViewer::expose_callback(), G4OpenGLImmediateQtViewer::resizeGL(), and G4OpenGLStoredQtViewer::resizeGL().

◆ rotateScene()

void G4OpenGLViewer::rotateScene ( G4double dx,
G4double dy )
protected

Definition at line 1084 of file G4OpenGLViewer.cc.

1085{
1086 if (fVP.GetRotationStyle() == G4ViewParameters::freeRotation) {
1087 rotateSceneInViewDirection(dx,dy);
1088 } else {
1089 if( dx != 0) {
1090 rotateSceneThetaPhi(dx,0);
1091 }
1092 if( dy != 0) {
1093 rotateSceneThetaPhi(0,dy);
1094 }
1095 }
1096}

Referenced by G4OpenGLXmViewer::rotate_in_phi(), G4OpenGLXmViewer::rotate_in_theta(), and G4OpenGLQtViewer::rotateQtScene().

◆ rotateSceneToggle()

void G4OpenGLViewer::rotateSceneToggle ( G4double dx,
G4double dy )
protected

Definition at line 1099 of file G4OpenGLViewer.cc.

1100{
1101 if (fVP.GetRotationStyle() != G4ViewParameters::freeRotation) {
1102 rotateSceneInViewDirection(dx,dy);
1103 } else {
1104 if( dx != 0) {
1105 rotateSceneThetaPhi(dx,0);
1106 }
1107 if( dy != 0) {
1108 rotateSceneThetaPhi(0,dy);
1109 }
1110 }
1111}

Referenced by G4OpenGLQtViewer::rotateQtSceneToggle().

◆ setExportFilename()

bool G4OpenGLViewer::setExportFilename ( G4String name,
G4bool inc = true )
protected

If name is "" or "!", filename and extension will have the default value. If name is "toto.png", set the name to "toto" and the format to "png". No incremented suffix is added. If name is "toto", set the name to "toto" and the format to default (or current format if specify). If name is the same as previous, do not reset incremented suffix.

Definition at line 990 of file G4OpenGLViewer.cc.

990 {
991 if (name == "!") {
992 name = "";
993 }
994
995 if (inc) {
996 if ((name != "") && (fExportFilename != name)) {
998 }
999 } else {
1001 }
1002
1003 if (name.size() == 0) {
1004 name = getRealPrintFilename().c_str();
1005 } else {
1006 // guess format by extention
1007 std::string extension = name.substr(name.find_last_of(".") + 1);
1008 // If there is a dot in the name the above might find rubbish, so...
1009 if (extension.size() >= 3 && extension.size() <= 4) { // Possible extension
1010 if (setExportImageFormat(extension, false)) { // Extension found
1011 fExportFilename = name.substr(0,name.find_last_of("."));
1012 } else { // No viable extension found
1013 return false;
1014 }
1015 } else { // Assume name is already the required without-extension part
1016 fExportFilename = name;
1017 }
1018 }
1019 return true;
1020}

Referenced by G4OpenGLQtViewer::exportImage(), exportImage(), and G4OpenGLViewerMessenger::SetNewValue().

◆ setExportImageFormat()

bool G4OpenGLViewer::setExportImageFormat ( std::string format,
bool quiet = false )

Definition at line 1248 of file G4OpenGLViewer.cc.

1248 {
1249 bool found = false;
1250 std::string list;
1251 for (unsigned int a=0; a<fExportImageFormatVector.size(); a++) {
1252 list +=fExportImageFormatVector.at(a) + " ";
1253
1254 if (fExportImageFormatVector.at(a) == format) {
1255 if (! quiet) {
1256 G4cout << " Changing export format to \"" << format << "\"" << G4endl;
1257 }
1258 if (format != fExportImageFormat) {
1260 fExportImageFormat = format;
1261 }
1262 return true;
1263 }
1264 }
1265 if (! found) {
1266 if (format.size() == 0) {
1267 G4cout << " Current formats availables are : " << list << G4endl;
1268 } else {
1269 G4cerr << " Format \"" << format << "\" is not available for the selected viewer. Current formats availables are : " << list << G4endl;
1270 }
1271 }
1272 return false;
1273}

Referenced by exportImage(), G4OpenGLImmediateQtViewer::Initialise(), G4OpenGLStoredQtViewer::Initialise(), G4OpenGLImmediateQtViewer::initializeGL(), G4OpenGLStoredQtViewer::initializeGL(), setExportFilename(), and G4OpenGLViewerMessenger::SetNewValue().

◆ setExportSize()

void G4OpenGLViewer::setExportSize ( G4int X,
G4int Y )
protected

Definition at line 979 of file G4OpenGLViewer.cc.

979 {
980 fPrintSizeX = X;
981 fPrintSizeY = Y;
982}
G4double Y(G4double density)

Referenced by G4OpenGLQtViewer::exportImage(), exportImage(), and G4OpenGLViewerMessenger::SetNewValue().

◆ SetView()

void G4OpenGLViewer::SetView ( )
protectedvirtual

Implements G4VViewer.

Reimplemented in G4OpenGLWin32Viewer, and G4OpenGLXViewer.

Definition at line 225 of file G4OpenGLViewer.cc.

225 {
226 // if getting pick infos, should not resize the view.
227 if (fIsGettingPickInfos) return;
228
229 if (!fSceneHandler.GetScene()) {
230 return;
231 }
232 // Calculates view representation based on extent of object being
233 // viewed and (initial) viewpoint. (Note: it can change later due
234 // to user interaction via visualization system's GUI.)
235
236 // Lighting.
237 GLfloat lightPosition [4];
238 lightPosition [0] = fVP.GetActualLightpointDirection().x();
239 lightPosition [1] = fVP.GetActualLightpointDirection().y();
240 lightPosition [2] = fVP.GetActualLightpointDirection().z();
241 lightPosition [3] = 0.;
242 // Light position is "true" light direction, so must come after gluLookAt.
243 GLfloat ambient [] = { 0.2f, 0.2f, 0.2f, 1.f};
244 GLfloat diffuse [] = { 0.8f, 0.8f, 0.8f, 1.f};
245 glEnable (GL_LIGHT0);
246 glLightfv (GL_LIGHT0, GL_AMBIENT, ambient);
247 glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse);
248
249 G4double ratioX = 1;
250 G4double ratioY = 1;
251 if (fWinSize_y > fWinSize_x) {
252 ratioX = ((G4double)fWinSize_y) / ((G4double)fWinSize_x);
253 }
254 if (fWinSize_x > fWinSize_y) {
255 ratioY = ((G4double)fWinSize_x) / ((G4double)fWinSize_y);
256 }
257
258 // Get radius of scene, etc.
259 // Note that this procedure properly takes into account zoom, dolly and pan.
260 const G4Point3D targetPoint
261 = fSceneHandler.GetScene()->GetStandardTargetPoint()
262 + fVP.GetCurrentTargetPoint ();
263 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
264 if(radius<=0.) radius = 1.;
265 const G4double cameraDistance = fVP.GetCameraDistance (radius);
266 const G4Point3D cameraPosition =
267 targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
268 const GLdouble pnear = fVP.GetNearDistance (cameraDistance, radius);
269 const GLdouble pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
270 const GLdouble right = fVP.GetFrontHalfHeight (pnear, radius) * ratioY;
271 const GLdouble left = -right;
272 const GLdouble top = fVP.GetFrontHalfHeight (pnear, radius) * ratioX;
273 const GLdouble bottom = -top;
274
275 // FIXME
276 ResizeGLView();
277 //SHOULD SetWindowsSizeHint()...
278
279 glMatrixMode (GL_PROJECTION); // set up Frustum.
280 glLoadIdentity();
281
282 const G4Vector3D scaleFactor = fVP.GetScaleFactor();
283 glScaled(scaleFactor.x(),scaleFactor.y(),scaleFactor.z());
284
285 if (fVP.GetFieldHalfAngle() == 0.) {
286 g4GlOrtho (left, right, bottom, top, pnear, pfar);
287 }
288 else {
289 g4GlFrustum (left, right, bottom, top, pnear, pfar);
290 }
291
292 glMatrixMode (GL_MODELVIEW); // apply further transformations to scene.
293 glLoadIdentity();
294
295 const G4Normal3D& upVector = fVP.GetUpVector ();
296 G4Point3D gltarget;
297 if (cameraDistance > 1.e-6 * radius) {
298 gltarget = targetPoint;
299 }
300 else {
301 gltarget = targetPoint - radius * fVP.GetViewpointDirection().unit();
302 }
303
304 const G4Point3D& pCamera = cameraPosition; // An alias for brevity.
305
306 g4GluLookAt (pCamera.x(), pCamera.y(), pCamera.z(), // Viewpoint.
307 gltarget.x(), gltarget.y(), gltarget.z(), // Target point.
308 upVector.x(), upVector.y(), upVector.z()); // Up vector.
309 // Light position is "true" light direction, so must come after gluLookAt.
310 glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
311
312 // The idea is to use back-to-back clipping planes. This can cut an object
313 // down to just a few pixels, which can make it difficult to see. So, for
314 // now, comment this out and use the generic (Boolean) method, via
315 // G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
316 // { return G4VSceneHandler::CreateSectionSolid(); }
317// if (fVP.IsSection () ) { // pair of back to back clip planes.
318// const G4Plane3D& sp = fVP.GetSectionPlane ();
319// double sArray[4];
320// sArray[0] = sp.a();
321// sArray[1] = sp.b();
322// sArray[2] = sp.c();
323// sArray[3] = sp.d() + radius * 1.e-05;
324// glClipPlane (GL_CLIP_PLANE0, sArray);
325// glEnable (GL_CLIP_PLANE0);
326// sArray[0] = -sp.a();
327// sArray[1] = -sp.b();
328// sArray[2] = -sp.c();
329// sArray[3] = -sp.d() + radius * 1.e-05;
330// glClipPlane (GL_CLIP_PLANE1, sArray);
331// glEnable (GL_CLIP_PLANE1);
332// } else {
333// glDisable (GL_CLIP_PLANE0);
334// glDisable (GL_CLIP_PLANE1);
335// }
336
337 // What we call intersection of cutaways is easy in OpenGL. You
338 // just keep cutting. Unions are more tricky - you have to have
339 // multiple passes and this is handled in
340 // G4OpenGLImmediate/StoredViewer::ProcessView.
341 const G4Planes& cutaways = fVP.GetCutawayPlanes();
342 size_t nPlanes = cutaways.size();
343 if (fVP.IsCutaway() &&
344 fVP.GetCutawayMode() == G4ViewParameters::cutawayIntersection) {
345 double a[4];
346 a[0] = cutaways[0].a();
347 a[1] = cutaways[0].b();
348 a[2] = cutaways[0].c();
349 a[3] = cutaways[0].d();
350 glClipPlane (GL_CLIP_PLANE2, a);
351 glEnable (GL_CLIP_PLANE2);
352 if (nPlanes > 1) {
353 a[0] = cutaways[1].a();
354 a[1] = cutaways[1].b();
355 a[2] = cutaways[1].c();
356 a[3] = cutaways[1].d();
357 glClipPlane (GL_CLIP_PLANE3, a);
358 glEnable (GL_CLIP_PLANE3);
359 }
360 if (nPlanes > 2) {
361 a[0] = cutaways[2].a();
362 a[1] = cutaways[2].b();
363 a[2] = cutaways[2].c();
364 a[3] = cutaways[2].d();
365 glClipPlane (GL_CLIP_PLANE4, a);
366 glEnable (GL_CLIP_PLANE4);
367 }
368 } else {
369 glDisable (GL_CLIP_PLANE2);
370 glDisable (GL_CLIP_PLANE3);
371 glDisable (GL_CLIP_PLANE4);
372 }
373
374 // Background.
375 background = fVP.GetBackgroundColour ();
376
377}
HepGeom::Normal3D< G4double > G4Normal3D
Definition G4Normal3D.hh:34
HepGeom::Vector3D< G4double > G4Vector3D
Definition G4Vector3D.hh:34
std::vector< G4Plane3D > G4Planes
void g4GlFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
void g4GluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx, GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy, GLdouble upz)
void g4GlOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)

Referenced by G4OpenGLImmediateQtViewer::paintGL(), G4OpenGLStoredQtViewer::paintGL(), G4OpenGLWin32Viewer::SetView(), and G4OpenGLXViewer::SetView().

◆ sizeHasChanged()

G4bool G4OpenGLViewer::sizeHasChanged ( )
protected

Definition at line 937 of file G4OpenGLViewer.cc.

937 {
938 return fSizeHasChanged;
939}

Referenced by G4OpenGLImmediateQtViewer::resizeGL(), and G4OpenGLStoredQtViewer::resizeGL().

◆ G4OpenGLFileSceneHandler

friend class G4OpenGLFileSceneHandler
friend

Definition at line 100 of file G4OpenGLViewer.hh.

Referenced by G4OpenGLFileSceneHandler.

◆ G4OpenGLImmediateSceneHandler

◆ G4OpenGLSceneHandler

◆ G4OpenGLStoredSceneHandler

◆ G4OpenGLViewerMessenger

friend class G4OpenGLViewerMessenger
friend

Definition at line 101 of file G4OpenGLViewer.hh.

Referenced by G4OpenGLViewerMessenger.

Member Data Documentation

◆ antialiasing_enabled

G4bool G4OpenGLViewer::antialiasing_enabled
protected

◆ background

G4Colour G4OpenGLViewer::background
protected

◆ fDefaultExportImageFormat

std::string G4OpenGLViewer::fDefaultExportImageFormat
protected

Definition at line 199 of file G4OpenGLViewer.hh.

Referenced by G4OpenGLViewer().

◆ fExportFilenameIndex

int G4OpenGLViewer::fExportFilenameIndex
protected

◆ fExportImageFormat

std::string G4OpenGLViewer::fExportImageFormat
protected

◆ fExportImageFormatVector

std::vector< std::string > G4OpenGLViewer::fExportImageFormatVector
protected

Definition at line 198 of file G4OpenGLViewer.hh.

Referenced by addExportImageFormat(), and setExportImageFormat().

◆ fGL2PSAction

G4gl2ps* G4OpenGLViewer::fGL2PSAction
protected

◆ fOpenGLSceneHandler

G4OpenGLSceneHandler& G4OpenGLViewer::fOpenGLSceneHandler
protected

Definition at line 186 of file G4OpenGLViewer.hh.

Referenced by G4OpenGLViewer(), and GetPickDetails().

◆ fPan_sens

◆ fPrintColour

◆ fPrintSizeX

G4int G4OpenGLViewer::fPrintSizeX
protected

Definition at line 202 of file G4OpenGLViewer.hh.

Referenced by G4OpenGLViewer(), and setExportSize().

◆ fPrintSizeY

G4int G4OpenGLViewer::fPrintSizeY
protected

Definition at line 203 of file G4OpenGLViewer.hh.

Referenced by G4OpenGLViewer(), and setExportSize().

◆ fRot_sens

◆ fVectoredPs

◆ fWinSize_x

◆ fWinSize_y

◆ haloing_enabled

◆ transparency_enabled


The documentation for this class was generated from the following files: