35 #ifdef G4VIS_BUILD_OPENGL_DRIVER
47 G4OpenGLStoredViewer::G4OpenGLStoredViewer
48 (G4OpenGLStoredSceneHandler& sceneHandler):
50 G4OpenGLViewer (sceneHandler),
51 fG4OpenGLStoredSceneHandler (sceneHandler)
57 G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
59 void G4OpenGLStoredViewer::KernelVisitDecision () {
64 if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
65 CompareForKernelVisit(fLastVP)) {
76 (lastVP.
IsCulling () != fVP.IsCulling ()) ||
80 (lastVP.
IsSection () != fVP.IsSection ()) ||
84 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
87 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
90 fVP.GetDefaultVisAttributes()->
GetColour()) ||
92 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
94 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
96 fVP.GetVisAttributesModifiers().size())
131 void G4OpenGLStoredViewer::DrawDisplayLists () {
132 #ifdef G4DEBUG_VIS_OGL
133 printf(
"G4OpenGLStoredViewer::DrawDisplayLists \n");
136 const G4Planes& cutaways = fVP.GetCutawayPlanes();
137 G4bool cutawayUnion = fVP.IsCutaway() &&
139 const size_t nCutaways = cutawayUnion? cutaways.size(): 1;
140 #ifdef G4DEBUG_VIS_OGL
141 printf(
"G4OpenGLStoredViewer::DrawDisplayLists");
144 G4bool secondPassForTransparencyRequested =
false;
145 G4bool thirdPassForNonHiddenMarkersRequested =
false;
146 fDepthTestEnable =
true;
147 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
150 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
154 a[0] = cutaways[iCutaway].a();
155 a[1] = cutaways[iCutaway].b();
156 a[2] = cutaways[iCutaway].c();
157 a[3] = cutaways[iCutaway].d();
158 glClipPlane (GL_CLIP_PLANE2, a);
159 glEnable (GL_CLIP_PLANE2);
162 G4bool isPicking = fVP.IsPicking();
165 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
166 if (POSelected(iPO)) {
167 G4OpenGLStoredSceneHandler::PO& po =
168 fG4OpenGLStoredSceneHandler.fPOList[iPO];
170 DisplayTimePOColourModification(c,iPO);
173 if (isTransparent && transparency_enabled) {
174 secondPassForTransparencyRequested =
true;
177 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
178 thirdPassForNonHiddenMarkersRequested =
true;
181 }
else if (iPass == 2) {
182 if (!isTransparent) {
186 if (!po.fMarkerOrPolyline) {
190 if (isPicking) glLoadName(po.fPickName);
191 if ((iPO == 0) || (c != fOldDisplayListColor)) {
192 fOldDisplayListColor = c;
193 if (transparency_enabled) {
199 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
200 if (fDepthTestEnable !=
false) {
201 glDisable (GL_DEPTH_TEST);
202 fDepthTestEnable =
false;
205 if (fDepthTestEnable !=
true) {
206 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
207 fDepthTestEnable =
true;
210 if (po.fpG4TextPlus) {
211 if (po.fpG4TextPlus->fProcessing2D) {
212 glMatrixMode (GL_PROJECTION);
215 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
216 glMatrixMode (GL_MODELVIEW);
219 G4OpenGLTransform3D oglt (po.fTransform);
220 glMultMatrixd (oglt.GetGLMatrix ());
221 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
222 (po.fpG4TextPlus->fG4Text);
225 G4OpenGLTransform3D oglt (po.fTransform);
226 glMultMatrixd (oglt.GetGLMatrix ());
227 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
228 (po.fpG4TextPlus->fG4Text);
232 if (po.fpG4TextPlus->fProcessing2D) {
233 glMatrixMode (GL_PROJECTION);
235 glMatrixMode (GL_MODELVIEW);
240 G4OpenGLTransform3D oglt (po.fTransform);
241 glMultMatrixd (oglt.GetGLMatrix ());
242 glCallList (po.fDisplayListId);
252 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
253 if (TOSelected(iTO)) {
254 G4OpenGLStoredSceneHandler::TO& to =
255 fG4OpenGLStoredSceneHandler.fTOList[iTO];
259 if (isTransparent && transparency_enabled) {
260 secondPassForTransparencyRequested =
true;
263 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
264 thirdPassForNonHiddenMarkersRequested =
true;
267 }
else if (iPass == 2) {
268 if (!isTransparent) {
272 if (!to.fMarkerOrPolyline) {
276 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
277 if (fDepthTestEnable !=
false) {
278 glDisable (GL_DEPTH_TEST);
279 fDepthTestEnable =
false;
282 if (fDepthTestEnable !=
true) {
283 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
284 fDepthTestEnable =
true;
287 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
288 if (fVP.IsPicking()) glLoadName(to.fPickName);
289 if (to.fpG4TextPlus) {
290 if (to.fpG4TextPlus->fProcessing2D) {
291 glMatrixMode (GL_PROJECTION);
294 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
295 glMatrixMode (GL_MODELVIEW);
299 G4OpenGLTransform3D oglt (to.fTransform);
300 glMultMatrixd (oglt.GetGLMatrix ());
301 if (transparency_enabled) {
306 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive
307 (to.fpG4TextPlus->fG4Text);
308 if (to.fpG4TextPlus->fProcessing2D) {
309 glMatrixMode (GL_PROJECTION);
311 glMatrixMode (GL_MODELVIEW);
315 if (to.fTransform != lastMatrixTransform) {
321 G4OpenGLTransform3D oglt (to.fTransform);
322 glMultMatrixd (oglt.GetGLMatrix ());
325 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
328 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
329 const G4Colour& bg = fVP.GetBackgroundColour();
330 if (transparency_enabled) {
332 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
333 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
334 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
335 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
338 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
339 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
340 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
343 if (transparency_enabled) {
349 glCallList (to.fDisplayListId);
351 if (to.fTransform != lastMatrixTransform) {
352 lastMatrixTransform = to.fTransform;
361 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
364 if (iPass == 2) secondPassForTransparencyRequested =
false;
365 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
367 if (secondPassForTransparencyRequested) iPass = 2;
368 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
374 if (fDisplayHeadTime && fEndTime <
DBL_MAX) {
375 glMatrixMode (GL_PROJECTION);
378 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
379 glMatrixMode (GL_MODELVIEW);
383 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
384 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
386 (fDisplayHeadTimeRed,
387 fDisplayHeadTimeGreen,
388 fDisplayHeadTimeBlue));
389 headTimeText.SetVisAttributes(&visAtts);
390 fOpenGLSceneHandler.G4OpenGLSceneHandler::AddPrimitive(headTimeText);
391 glMatrixMode (GL_PROJECTION);
393 glMatrixMode (GL_MODELVIEW);
398 if (fDisplayLightFront && fEndTime <
DBL_MAX) {
399 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) * c_light;
400 if (lightFrontRadius > 0.) {
401 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
402 G4Point3D circleCentre = lightFrontCentre;
403 G4double circleRadius = lightFrontRadius;
404 if (fVP.GetFieldHalfAngle() > 0.) {
406 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
407 fVP.GetCurrentTargetPoint();
408 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
409 if(sceneRadius <= 0.) sceneRadius = 1.;
410 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
411 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
412 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
413 G4double lightFrontCentreDistance = lightFrontToCameraDirection.mag();
422 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
424 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
425 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.unit();
426 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
437 if (circleRadius > 0.) {
439 lightFront.SetWorldRadius(circleRadius);
440 glColor3d(fDisplayLightFrontRed,
441 fDisplayLightFrontGreen,
442 fDisplayLightFrontBlue);
443 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