34#ifdef G4VIS_BUILD_OPENGL_DRIVER
46G4OpenGLStoredViewer::G4OpenGLStoredViewer
47(G4OpenGLStoredSceneHandler& sceneHandler):
49G4OpenGLViewer (sceneHandler),
50fG4OpenGLStoredSceneHandler (sceneHandler),
56G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
58void G4OpenGLStoredViewer::KernelVisitDecision () {
63 if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
64 CompareForKernelVisit(fLastVP)) {
75 (lastVP.
IsCulling () != fVP.IsCulling ()) ||
80 fVP.GetCBDAlgorithmNumber()) ||
81 (lastVP.
IsSection () != fVP.IsSection ()) ||
85 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
88 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
94 fVP.GetDefaultVisAttributes()->
GetColour()) ||
96 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
98 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
100 fVP.GetVisAttributesModifiers())
127 if (lastVP.
GetCBDParameters().size() != fVP.GetCBDParameters().size())
return true;
141void G4OpenGLStoredViewer::DrawDisplayLists () {
145#define CONVENIENT_DOUBLE_ALIAS(q) const G4double& f##q = fVP.Get##q();
146#define CONVENIENT_BOOL_ALIAS(q) const G4bool& f##q = fVP.Is##q();
147 CONVENIENT_DOUBLE_ALIAS(StartTime)
148 CONVENIENT_DOUBLE_ALIAS(EndTime)
149 CONVENIENT_DOUBLE_ALIAS(FadeFactor)
150 CONVENIENT_BOOL_ALIAS(DisplayHeadTime)
151 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeX)
152 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeY)
153 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeSize)
154 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeRed)
155 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeGreen)
156 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeBlue)
157 CONVENIENT_BOOL_ALIAS(DisplayLightFront)
158 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontX)
159 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontY)
160 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontZ)
161 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontT)
162 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontRed)
163 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontGreen)
164 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontBlue)
166 const G4Planes& cutaways = fVP.GetCutawayPlanes();
167 G4bool cutawayUnion = fVP.IsCutaway() &&
169 const size_t nCutaways = cutawayUnion? cutaways.size(): 1;
171 G4bool secondPassForTransparencyRequested =
false;
172 G4bool thirdPassForNonHiddenMarkersRequested =
false;
173 fDepthTestEnable =
true;
174 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
176 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
180 a[0] = cutaways[iCutaway].a();
181 a[1] = cutaways[iCutaway].b();
182 a[2] = cutaways[iCutaway].c();
183 a[3] = cutaways[iCutaway].d();
184 glClipPlane (GL_CLIP_PLANE2, a);
185 glEnable (GL_CLIP_PLANE2);
188 G4bool isPicking = fVP.IsPicking();
191 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
192 if (POSelected(iPO)) {
193 G4OpenGLStoredSceneHandler::PO& po =
194 fG4OpenGLStoredSceneHandler.fPOList[iPO];
196 DisplayTimePOColourModification(c,iPO);
199 if (isTransparent && transparency_enabled) {
200 secondPassForTransparencyRequested =
true;
203 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
204 thirdPassForNonHiddenMarkersRequested =
true;
207 }
else if (iPass == 2) {
208 if (!isTransparent) {
212 if (!po.fMarkerOrPolyline) {
216 if (isPicking) glLoadName(po.fPickName);
217 if (transparency_enabled) {
222 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
223 if (fDepthTestEnable !=
false) {
224 glDisable (GL_DEPTH_TEST);
225 fDepthTestEnable =
false;
228 if (fDepthTestEnable !=
true) {
229 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
230 fDepthTestEnable =
true;
233 if (po.fpG4TextPlus) {
234 if (po.fpG4TextPlus->fProcessing2D) {
235 glMatrixMode (GL_PROJECTION);
238 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
239 glMatrixMode (GL_MODELVIEW);
242 G4OpenGLTransform3D oglt (po.fTransform);
243 glMultMatrixd (oglt.GetGLMatrix ());
245 AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
248 G4OpenGLTransform3D oglt (po.fTransform);
249 glMultMatrixd (oglt.GetGLMatrix ());
251 AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
255 if (po.fpG4TextPlus->fProcessing2D) {
256 glMatrixMode (GL_PROJECTION);
258 glMatrixMode (GL_MODELVIEW);
263 G4OpenGLTransform3D oglt (po.fTransform);
264 glMultMatrixd (oglt.GetGLMatrix ());
265 glCallList (po.fDisplayListId);
275 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
276 if (TOSelected(iTO)) {
277 G4OpenGLStoredSceneHandler::TO& to =
278 fG4OpenGLStoredSceneHandler.fTOList[iTO];
282 if (isTransparent && transparency_enabled) {
283 secondPassForTransparencyRequested =
true;
286 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
287 thirdPassForNonHiddenMarkersRequested =
true;
290 }
else if (iPass == 2) {
291 if (!isTransparent) {
295 if (!to.fMarkerOrPolyline) {
299 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
300 if (fDepthTestEnable !=
false) {
301 glDisable (GL_DEPTH_TEST);
302 fDepthTestEnable =
false;
305 if (fDepthTestEnable !=
true) {
306 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
307 fDepthTestEnable =
true;
310 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
311 if (fVP.IsPicking()) glLoadName(to.fPickName);
312 if (to.fpG4TextPlus) {
313 if (to.fpG4TextPlus->fProcessing2D) {
314 glMatrixMode (GL_PROJECTION);
317 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
318 glMatrixMode (GL_MODELVIEW);
322 G4OpenGLTransform3D oglt (to.fTransform);
323 glMultMatrixd (oglt.GetGLMatrix ());
325 AddPrimitiveForASingleFrame(to.fpG4TextPlus->fG4Text);
326 if (to.fpG4TextPlus->fProcessing2D) {
327 glMatrixMode (GL_PROJECTION);
329 glMatrixMode (GL_MODELVIEW);
333 if (to.fTransform != lastMatrixTransform) {
339 G4OpenGLTransform3D oglt (to.fTransform);
340 glMultMatrixd (oglt.GetGLMatrix ());
343 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
346 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
347 const G4Colour& bg = fVP.GetBackgroundColour();
348 if (transparency_enabled) {
350 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
351 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
352 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
353 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
356 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
357 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
358 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
361 if (transparency_enabled) {
367 glCallList (to.fDisplayListId);
369 if (to.fTransform != lastMatrixTransform) {
370 lastMatrixTransform = to.fTransform;
379 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
382 if (iPass == 2) secondPassForTransparencyRequested =
false;
383 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
385 if (secondPassForTransparencyRequested) iPass = 2;
386 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
393 glMatrixMode (GL_PROJECTION);
396 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
397 glMatrixMode (GL_MODELVIEW);
401 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
402 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
404 (fDisplayHeadTimeRed,
405 fDisplayHeadTimeGreen,
406 fDisplayHeadTimeBlue));
407 headTimeText.SetVisAttributes(&visAtts);
408 AddPrimitiveForASingleFrame(headTimeText);
409 glMatrixMode (GL_PROJECTION);
411 glMatrixMode (GL_MODELVIEW);
417 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
418 if (lightFrontRadius > 0.) {
419 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
420 G4Point3D circleCentre = lightFrontCentre;
421 G4double circleRadius = lightFrontRadius;
422 if (fVP.GetFieldHalfAngle() > 0.) {
424 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
425 fVP.GetCurrentTargetPoint();
426 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
427 if(sceneRadius <= 0.) sceneRadius = 1.;
428 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
429 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().
unit();
430 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
431 G4double lightFrontCentreDistance = lightFrontToCameraDirection.
mag();
440 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
442 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
443 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.
unit();
444 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
455 if (circleRadius > 0.) {
457 lightFront.SetWorldRadius(circleRadius);
459 (fDisplayLightFrontRed,
460 fDisplayLightFrontGreen,
461 fDisplayLightFrontBlue));
462 lightFront.SetVisAttributes(visAtts);
463 AddPrimitiveForASingleFrame(lightFront);
469void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(
const G4Text& text)
473 G4bool memoryForDisplayListsKeep = fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists;
474 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists =
false;
475 fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(text);
476 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists = memoryForDisplayListsKeep;
479void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(
const G4Circle& circle)
483 G4bool memoryForDisplayListsKeep = fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists;
484 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists =
false;
485 fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(circle);
486 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists = memoryForDisplayListsKeep;
HepGeom::Point3D< G4double > G4Point3D
std::vector< G4Plane3D > G4Planes
static G4bool GetColour(const G4String &key, G4Colour &result)
G4double GetAlpha() const
G4double GetGreen() const
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4int GetNoOfSides() const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
const G4Colour & GetBackgroundColour() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
static constexpr G4double fVeryLongTime
BasicVector3D< T > unit() const