35 #ifdef G4VIS_BUILD_OPENGL_DRIVER
47 G4OpenGLStoredViewer::G4OpenGLStoredViewer
48 (G4OpenGLStoredSceneHandler& sceneHandler):
50 G4OpenGLViewer (sceneHandler),
51 fG4OpenGLStoredSceneHandler (sceneHandler),
52 fDepthTestEnable(true)
58 G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
60 void G4OpenGLStoredViewer::KernelVisitDecision () {
65 if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
66 CompareForKernelVisit(fLastVP)) {
77 (lastVP.
IsCulling () != fVP.IsCulling ()) ||
81 (lastVP.
IsSection () != fVP.IsSection ()) ||
85 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
88 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
91 fVP.GetDefaultVisAttributes()->
GetColour()) ||
93 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
95 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
97 fVP.GetVisAttributesModifiers().size())
132 void G4OpenGLStoredViewer::DrawDisplayLists () {
134 const G4Planes& cutaways = fVP.GetCutawayPlanes();
135 G4bool cutawayUnion = fVP.IsCutaway() &&
137 const size_t nCutaways = cutawayUnion? cutaways.size(): 1;
139 G4bool secondPassForTransparencyRequested =
false;
140 G4bool thirdPassForNonHiddenMarkersRequested =
false;
141 fDepthTestEnable =
true;
142 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
145 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
149 a[0] = cutaways[iCutaway].a();
150 a[1] = cutaways[iCutaway].b();
151 a[2] = cutaways[iCutaway].c();
152 a[3] = cutaways[iCutaway].d();
153 glClipPlane (GL_CLIP_PLANE2, a);
154 glEnable (GL_CLIP_PLANE2);
157 G4bool isPicking = fVP.IsPicking();
160 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
161 if (POSelected(iPO)) {
162 G4OpenGLStoredSceneHandler::PO& po =
163 fG4OpenGLStoredSceneHandler.fPOList[iPO];
165 DisplayTimePOColourModification(c,iPO);
168 if (isTransparent && transparency_enabled) {
169 secondPassForTransparencyRequested =
true;
172 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
173 thirdPassForNonHiddenMarkersRequested =
true;
176 }
else if (iPass == 2) {
177 if (!isTransparent) {
181 if (!po.fMarkerOrPolyline) {
185 if (isPicking) glLoadName(po.fPickName);
186 if ((iPO == 0) || (c != fOldDisplayListColor)) {
187 fOldDisplayListColor = c;
188 if (transparency_enabled) {
194 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
195 if (fDepthTestEnable !=
false) {
196 glDisable (GL_DEPTH_TEST);
197 fDepthTestEnable =
false;
200 if (fDepthTestEnable !=
true) {
201 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
202 fDepthTestEnable =
true;
205 if (po.fpG4TextPlus) {
206 if (po.fpG4TextPlus->fProcessing2D) {
207 glMatrixMode (GL_PROJECTION);
210 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
211 glMatrixMode (GL_MODELVIEW);
214 G4OpenGLTransform3D oglt (po.fTransform);
215 glMultMatrixd (oglt.GetGLMatrix ());
216 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
217 (po.fpG4TextPlus->fG4Text);
220 G4OpenGLTransform3D oglt (po.fTransform);
221 glMultMatrixd (oglt.GetGLMatrix ());
222 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
223 (po.fpG4TextPlus->fG4Text);
227 if (po.fpG4TextPlus->fProcessing2D) {
228 glMatrixMode (GL_PROJECTION);
230 glMatrixMode (GL_MODELVIEW);
235 G4OpenGLTransform3D oglt (po.fTransform);
236 glMultMatrixd (oglt.GetGLMatrix ());
237 glCallList (po.fDisplayListId);
247 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
248 if (TOSelected(iTO)) {
249 G4OpenGLStoredSceneHandler::TO& to =
250 fG4OpenGLStoredSceneHandler.fTOList[iTO];
254 if (isTransparent && transparency_enabled) {
255 secondPassForTransparencyRequested =
true;
258 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
259 thirdPassForNonHiddenMarkersRequested =
true;
262 }
else if (iPass == 2) {
263 if (!isTransparent) {
267 if (!to.fMarkerOrPolyline) {
271 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
272 if (fDepthTestEnable !=
false) {
273 glDisable (GL_DEPTH_TEST);
274 fDepthTestEnable =
false;
277 if (fDepthTestEnable !=
true) {
278 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
279 fDepthTestEnable =
true;
282 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
283 if (fVP.IsPicking()) glLoadName(to.fPickName);
284 if (to.fpG4TextPlus) {
285 if (to.fpG4TextPlus->fProcessing2D) {
286 glMatrixMode (GL_PROJECTION);
289 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
290 glMatrixMode (GL_MODELVIEW);
294 G4OpenGLTransform3D oglt (to.fTransform);
295 glMultMatrixd (oglt.GetGLMatrix ());
296 if (transparency_enabled) {
301 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
302 (to.fpG4TextPlus->fG4Text);
303 if (to.fpG4TextPlus->fProcessing2D) {
304 glMatrixMode (GL_PROJECTION);
306 glMatrixMode (GL_MODELVIEW);
310 if (to.fTransform != lastMatrixTransform) {
316 G4OpenGLTransform3D oglt (to.fTransform);
317 glMultMatrixd (oglt.GetGLMatrix ());
320 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
323 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
324 const G4Colour& bg = fVP.GetBackgroundColour();
325 if (transparency_enabled) {
327 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
328 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
329 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
330 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
333 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
334 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
335 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
338 if (transparency_enabled) {
344 glCallList (to.fDisplayListId);
346 if (to.fTransform != lastMatrixTransform) {
347 lastMatrixTransform = to.fTransform;
356 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
359 if (iPass == 2) secondPassForTransparencyRequested =
false;
360 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
362 if (secondPassForTransparencyRequested) iPass = 2;
363 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
369 if (fDisplayHeadTime && fEndTime <
DBL_MAX) {
370 glMatrixMode (GL_PROJECTION);
373 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
374 glMatrixMode (GL_MODELVIEW);
378 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
379 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
381 (fDisplayHeadTimeRed,
382 fDisplayHeadTimeGreen,
383 fDisplayHeadTimeBlue));
384 headTimeText.SetVisAttributes(&visAtts);
385 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(headTimeText);
386 glMatrixMode (GL_PROJECTION);
388 glMatrixMode (GL_MODELVIEW);
393 if (fDisplayLightFront && fEndTime <
DBL_MAX) {
394 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
395 if (lightFrontRadius > 0.) {
396 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
397 G4Point3D circleCentre = lightFrontCentre;
398 G4double circleRadius = lightFrontRadius;
399 if (fVP.GetFieldHalfAngle() > 0.) {
401 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
402 fVP.GetCurrentTargetPoint();
403 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
404 if(sceneRadius <= 0.) sceneRadius = 1.;
405 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
406 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
407 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
408 G4double lightFrontCentreDistance = lightFrontToCameraDirection.mag();
417 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
419 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
420 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.unit();
421 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
432 if (circleRadius > 0.) {
434 lightFront.SetWorldRadius(circleRadius);
435 glColor3d(fDisplayLightFrontRed,
436 fDisplayLightFrontGreen,
437 fDisplayLightFrontBlue);
438 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(lightFront);
const G4Colour & GetBackgroundColour() const
G4double GetAlpha() const
G4double GetVisibleDensity() const
G4bool IsCullingInvisible() const
G4double GetExplodeFactor() const
static G4bool GetColour(const G4String &key, G4Colour &result)
const G4Colour & GetColour() const
G4bool IsDensityCulling() const
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4bool IsAuxEdgeVisible() const
G4double GetGreen() const
std::vector< G4Plane3D > G4Planes
G4bool IsCullingCovered() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4int GetNoOfSides() const
DrawingStyle GetDrawingStyle() const
const G4VisAttributes * GetDefaultVisAttributes() const