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 ()) ||
82 fVP.GetCBDAlgorithmNumber()) ||
83 (lastVP.
IsSection () != fVP.IsSection ()) ||
87 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
90 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
93 fVP.GetDefaultVisAttributes()->
GetColour()) ||
95 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
97 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
99 fVP.GetVisAttributesModifiers())
128 if (lastVP.
GetCBDParameters().size() != fVP.GetCBDParameters().size())
return true;
142 void G4OpenGLStoredViewer::DrawDisplayLists () {
146 #define CONVENIENT_DOUBLE_ALIAS(q) const G4double& f##q = fVP.Get##q();
147 #define CONVENIENT_BOOL_ALIAS(q) const G4bool& f##q = fVP.Is##q();
148 CONVENIENT_DOUBLE_ALIAS(StartTime)
149 CONVENIENT_DOUBLE_ALIAS(EndTime)
150 CONVENIENT_DOUBLE_ALIAS(FadeFactor)
151 CONVENIENT_BOOL_ALIAS(DisplayHeadTime)
152 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeX)
153 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeY)
154 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeSize)
155 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeRed)
156 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeGreen)
157 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeBlue)
158 CONVENIENT_BOOL_ALIAS(DisplayLightFront)
159 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontX)
160 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontY)
161 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontZ)
162 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontT)
163 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontRed)
164 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontGreen)
165 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontBlue)
168 G4bool cutawayUnion = fVP.IsCutaway() &&
170 const size_t nCutaways = cutawayUnion? cutaways.size(): 1;
172 G4bool secondPassForTransparencyRequested = false;
173 G4bool thirdPassForNonHiddenMarkersRequested = false;
174 fDepthTestEnable = true;
175 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
177 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
181 a[0] = cutaways[iCutaway].a();
182 a[1] = cutaways[iCutaway].b();
183 a[2] = cutaways[iCutaway].c();
184 a[3] = cutaways[iCutaway].d();
185 glClipPlane (GL_CLIP_PLANE2, a);
186 glEnable (GL_CLIP_PLANE2);
189 G4bool isPicking = fVP.IsPicking();
192 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
193 if (POSelected(iPO)) {
194 G4OpenGLStoredSceneHandler::PO& po =
195 fG4OpenGLStoredSceneHandler.fPOList[iPO];
197 DisplayTimePOColourModification(c,iPO);
200 if (isTransparent && transparency_enabled) {
201 secondPassForTransparencyRequested =
true;
204 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
205 thirdPassForNonHiddenMarkersRequested =
true;
208 }
else if (iPass == 2) {
209 if (!isTransparent) {
213 if (!po.fMarkerOrPolyline) {
217 if (isPicking) glLoadName(po.fPickName);
218 if (transparency_enabled) {
223 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
224 if (fDepthTestEnable !=
false) {
225 glDisable (GL_DEPTH_TEST);
226 fDepthTestEnable =
false;
229 if (fDepthTestEnable !=
true) {
230 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
231 fDepthTestEnable =
true;
234 if (po.fpG4TextPlus) {
235 if (po.fpG4TextPlus->fProcessing2D) {
236 glMatrixMode (GL_PROJECTION);
239 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
240 glMatrixMode (GL_MODELVIEW);
243 G4OpenGLTransform3D oglt (po.fTransform);
244 glMultMatrixd (oglt.GetGLMatrix ());
246 AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
249 G4OpenGLTransform3D oglt (po.fTransform);
250 glMultMatrixd (oglt.GetGLMatrix ());
252 AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
256 if (po.fpG4TextPlus->fProcessing2D) {
257 glMatrixMode (GL_PROJECTION);
259 glMatrixMode (GL_MODELVIEW);
264 G4OpenGLTransform3D oglt (po.fTransform);
265 glMultMatrixd (oglt.GetGLMatrix ());
266 glCallList (po.fDisplayListId);
276 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
277 if (TOSelected(iTO)) {
278 G4OpenGLStoredSceneHandler::TO& to =
279 fG4OpenGLStoredSceneHandler.fTOList[iTO];
283 if (isTransparent && transparency_enabled) {
284 secondPassForTransparencyRequested =
true;
287 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
288 thirdPassForNonHiddenMarkersRequested =
true;
291 }
else if (iPass == 2) {
292 if (!isTransparent) {
296 if (!to.fMarkerOrPolyline) {
300 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
301 if (fDepthTestEnable !=
false) {
302 glDisable (GL_DEPTH_TEST);
303 fDepthTestEnable =
false;
306 if (fDepthTestEnable !=
true) {
307 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
308 fDepthTestEnable =
true;
311 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
312 if (fVP.IsPicking()) glLoadName(to.fPickName);
313 if (to.fpG4TextPlus) {
314 if (to.fpG4TextPlus->fProcessing2D) {
315 glMatrixMode (GL_PROJECTION);
318 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
319 glMatrixMode (GL_MODELVIEW);
323 G4OpenGLTransform3D oglt (to.fTransform);
324 glMultMatrixd (oglt.GetGLMatrix ());
325 if (transparency_enabled) {
331 AddPrimitiveForASingleFrame(to.fpG4TextPlus->fG4Text);
332 if (to.fpG4TextPlus->fProcessing2D) {
333 glMatrixMode (GL_PROJECTION);
335 glMatrixMode (GL_MODELVIEW);
339 if (to.fTransform != lastMatrixTransform) {
345 G4OpenGLTransform3D oglt (to.fTransform);
346 glMultMatrixd (oglt.GetGLMatrix ());
349 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
352 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
353 const G4Colour& bg = fVP.GetBackgroundColour();
354 if (transparency_enabled) {
356 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
357 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
358 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
359 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
362 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
363 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
364 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
367 if (transparency_enabled) {
373 glCallList (to.fDisplayListId);
375 if (to.fTransform != lastMatrixTransform) {
376 lastMatrixTransform = to.fTransform;
385 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
388 if (iPass == 2) secondPassForTransparencyRequested =
false;
389 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
391 if (secondPassForTransparencyRequested) iPass = 2;
392 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
399 glMatrixMode (GL_PROJECTION);
402 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
403 glMatrixMode (GL_MODELVIEW);
407 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
408 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
410 (fDisplayHeadTimeRed,
411 fDisplayHeadTimeGreen,
412 fDisplayHeadTimeBlue));
413 headTimeText.SetVisAttributes(&visAtts);
414 AddPrimitiveForASingleFrame(headTimeText);
415 glMatrixMode (GL_PROJECTION);
417 glMatrixMode (GL_MODELVIEW);
423 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) *
c_light;
424 if (lightFrontRadius > 0.) {
425 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
426 G4Point3D circleCentre = lightFrontCentre;
427 G4double circleRadius = lightFrontRadius;
428 if (fVP.GetFieldHalfAngle() > 0.) {
430 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
431 fVP.GetCurrentTargetPoint();
432 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
433 if(sceneRadius <= 0.) sceneRadius = 1.;
434 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
435 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().
unit();
436 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
437 G4double lightFrontCentreDistance = lightFrontToCameraDirection.
mag();
446 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
448 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
449 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.
unit();
450 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
461 if (circleRadius > 0.) {
463 lightFront.SetWorldRadius(circleRadius);
464 glColor3d(fDisplayLightFrontRed,
465 fDisplayLightFrontGreen,
466 fDisplayLightFrontBlue);
467 AddPrimitiveForASingleFrame(lightFront);
473 void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(
const G4Text& text)
477 G4bool memoryForDisplayListsKeep = fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists;
478 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists =
false;
479 fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(text);
480 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists = memoryForDisplayListsKeep;
483 void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(
const G4Circle& circle)
487 G4bool memoryForDisplayListsKeep = fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists;
488 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists =
false;
489 fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(circle);
490 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists = memoryForDisplayListsKeep;
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
G4double GetExplodeFactor() const
std::vector< ExP01TrackerHit * > a
static constexpr G4double fVeryLongTime
G4bool IsDensityCulling() const
BasicVector3D< T > unit() const
G4bool IsAuxEdgeVisible() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
const G4VisAttributes * GetDefaultVisAttributes() const
G4int GetNoOfSides() const
G4bool IsCullingInvisible() const
const G4ThreeVector const G4double const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
DrawingStyle GetDrawingStyle() const
static constexpr double c_light
const G4Colour & GetBackgroundColour() const
G4double GetAlpha() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4double GetGreen() const
G4bool IsCullingCovered() const
G4double GetVisibleDensity() const
HepGeom::Point3D< G4double > G4Point3D
std::vector< G4Plane3D > G4Planes
const G4Colour & GetColour() const
static G4bool GetColour(const G4String &key, G4Colour &result)