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())
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);
144 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
148 a[0] = cutaways[iCutaway].a();
149 a[1] = cutaways[iCutaway].b();
150 a[2] = cutaways[iCutaway].c();
151 a[3] = cutaways[iCutaway].d();
152 glClipPlane (GL_CLIP_PLANE2, a);
153 glEnable (GL_CLIP_PLANE2);
156 G4bool isPicking = fVP.IsPicking();
159 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
160 if (POSelected(iPO)) {
161 G4OpenGLStoredSceneHandler::PO& po =
162 fG4OpenGLStoredSceneHandler.fPOList[iPO];
164 DisplayTimePOColourModification(c,iPO);
167 if (isTransparent && transparency_enabled) {
168 secondPassForTransparencyRequested =
true;
171 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
172 thirdPassForNonHiddenMarkersRequested =
true;
175 }
else if (iPass == 2) {
176 if (!isTransparent) {
180 if (!po.fMarkerOrPolyline) {
184 if (isPicking) glLoadName(po.fPickName);
185 if (transparency_enabled) {
190 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
191 if (fDepthTestEnable !=
false) {
192 glDisable (GL_DEPTH_TEST);
193 fDepthTestEnable =
false;
196 if (fDepthTestEnable !=
true) {
197 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
198 fDepthTestEnable =
true;
201 if (po.fpG4TextPlus) {
202 if (po.fpG4TextPlus->fProcessing2D) {
203 glMatrixMode (GL_PROJECTION);
206 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
207 glMatrixMode (GL_MODELVIEW);
210 G4OpenGLTransform3D oglt (po.fTransform);
211 glMultMatrixd (oglt.GetGLMatrix ());
212 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
213 (po.fpG4TextPlus->fG4Text);
216 G4OpenGLTransform3D oglt (po.fTransform);
217 glMultMatrixd (oglt.GetGLMatrix ());
218 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
219 (po.fpG4TextPlus->fG4Text);
223 if (po.fpG4TextPlus->fProcessing2D) {
224 glMatrixMode (GL_PROJECTION);
226 glMatrixMode (GL_MODELVIEW);
231 G4OpenGLTransform3D oglt (po.fTransform);
232 glMultMatrixd (oglt.GetGLMatrix ());
233 glCallList (po.fDisplayListId);
243 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
244 if (TOSelected(iTO)) {
245 G4OpenGLStoredSceneHandler::TO& to =
246 fG4OpenGLStoredSceneHandler.fTOList[iTO];
250 if (isTransparent && transparency_enabled) {
251 secondPassForTransparencyRequested =
true;
254 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
255 thirdPassForNonHiddenMarkersRequested =
true;
258 }
else if (iPass == 2) {
259 if (!isTransparent) {
263 if (!to.fMarkerOrPolyline) {
267 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
268 if (fDepthTestEnable !=
false) {
269 glDisable (GL_DEPTH_TEST);
270 fDepthTestEnable =
false;
273 if (fDepthTestEnable !=
true) {
274 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
275 fDepthTestEnable =
true;
278 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
279 if (fVP.IsPicking()) glLoadName(to.fPickName);
280 if (to.fpG4TextPlus) {
281 if (to.fpG4TextPlus->fProcessing2D) {
282 glMatrixMode (GL_PROJECTION);
285 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
286 glMatrixMode (GL_MODELVIEW);
290 G4OpenGLTransform3D oglt (to.fTransform);
291 glMultMatrixd (oglt.GetGLMatrix ());
292 if (transparency_enabled) {
297 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
298 (to.fpG4TextPlus->fG4Text);
299 if (to.fpG4TextPlus->fProcessing2D) {
300 glMatrixMode (GL_PROJECTION);
302 glMatrixMode (GL_MODELVIEW);
306 if (to.fTransform != lastMatrixTransform) {
312 G4OpenGLTransform3D oglt (to.fTransform);
313 glMultMatrixd (oglt.GetGLMatrix ());
316 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
319 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
320 const G4Colour& bg = fVP.GetBackgroundColour();
321 if (transparency_enabled) {
323 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
324 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
325 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
326 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
329 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
330 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
331 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
334 if (transparency_enabled) {
340 glCallList (to.fDisplayListId);
342 if (to.fTransform != lastMatrixTransform) {
343 lastMatrixTransform = to.fTransform;
352 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
355 if (iPass == 2) secondPassForTransparencyRequested =
false;
356 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
358 if (secondPassForTransparencyRequested) iPass = 2;
359 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
365 if (fDisplayHeadTime && fEndTime <
DBL_MAX) {
366 glMatrixMode (GL_PROJECTION);
369 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
370 glMatrixMode (GL_MODELVIEW);
374 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
375 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
377 (fDisplayHeadTimeRed,
378 fDisplayHeadTimeGreen,
379 fDisplayHeadTimeBlue));
380 headTimeText.SetVisAttributes(&visAtts);
381 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(headTimeText);
382 glMatrixMode (GL_PROJECTION);
384 glMatrixMode (GL_MODELVIEW);
389 if (fDisplayLightFront && fEndTime <
DBL_MAX) {
390 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) *
c_light;
391 if (lightFrontRadius > 0.) {
392 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
393 G4Point3D circleCentre = lightFrontCentre;
394 G4double circleRadius = lightFrontRadius;
395 if (fVP.GetFieldHalfAngle() > 0.) {
397 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
398 fVP.GetCurrentTargetPoint();
399 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
400 if(sceneRadius <= 0.) sceneRadius = 1.;
401 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
402 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().
unit();
403 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
404 G4double lightFrontCentreDistance = lightFrontToCameraDirection.
mag();
413 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
415 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
416 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.
unit();
417 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
428 if (circleRadius > 0.) {
430 lightFront.SetWorldRadius(circleRadius);
431 glColor3d(fDisplayLightFrontRed,
432 fDisplayLightFrontGreen,
433 fDisplayLightFrontBlue);
434 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(lightFront);
const G4Colour & GetBackgroundColour() const
G4double GetAlpha() const
G4double GetVisibleDensity() const
std::vector< ExP01TrackerHit * > a
G4bool IsCullingInvisible() const
G4double GetExplodeFactor() const
BasicVector3D< T > unit() const
static G4bool GetColour(const G4String &key, G4Colour &result)
const G4Colour & GetColour() const
G4bool IsDensityCulling() const
HepGeom::Point3D< G4double > G4Point3D
#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