35#ifdef G4VIS_BUILD_OPENGL_DRIVER
42#define CENTERLINE_CLPP
75fEventsDrawInterval(1),
76fEventsWaitingToBeFlushed(0),
77fThreePassCapable(false),
78fSecondPassForTransparencyRequested(false),
79fSecondPassForTransparency(false),
80fThirdPassForNonHiddenMarkersRequested(false),
81fThirdPassForNonHiddenMarkers(false)
84G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
89const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
90 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
91 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
92 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
93 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
94 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
95 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
96 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
97 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
98 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
99 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
100 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
101 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
102 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
103 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
104 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
105 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
108void G4OpenGLSceneHandler::ClearAndDestroyAtts()
110 std::map<GLuint, G4AttHolder*>::iterator i;
111 for (i = fPickMap.begin(); i != fPickMap.end(); ++i)
delete i->second;
115void G4OpenGLSceneHandler::ScaledFlush()
117 fEventsWaitingToBeFlushed++;
118 if (fEventsWaitingToBeFlushed < fEventsDrawInterval)
return;
120 fEventsWaitingToBeFlushed = 0;
123void G4OpenGLSceneHandler::ProcessScene()
125 fThreePassCapable =
true;
130 if (fSecondPassForTransparencyRequested) {
131 fSecondPassForTransparency =
true;
133 fSecondPassForTransparency =
false;
134 fSecondPassForTransparencyRequested =
false;
138 if (fThirdPassForNonHiddenMarkersRequested) {
139 fThirdPassForNonHiddenMarkers =
true;
141 fThirdPassForNonHiddenMarkers =
false;
142 fThirdPassForNonHiddenMarkersRequested =
false;
145 fThreePassCapable =
false;
148void G4OpenGLSceneHandler::PreAddSolid
155void G4OpenGLSceneHandler::BeginPrimitives
161void G4OpenGLSceneHandler::EndPrimitives ()
166void G4OpenGLSceneHandler::BeginPrimitives2D
172void G4OpenGLSceneHandler::EndPrimitives2D ()
177G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
188G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
197void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
199 G4int nPoints = line.size ();
200 if (nPoints <= 0)
return;
204 glDisable (GL_LIGHTING);
210 G4double lineWidth = GetLineWidth(pVA);
215 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
216 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
218 glBegin (GL_LINE_STRIP);
219 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
221 x = line[iPoint].x();
222 y = line[iPoint].y();
223 z = line[iPoint].z();
224 glVertex3d (x, y, z);
229void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
231 if (polymarker.size() == 0) {
237 glDisable (GL_LIGHTING);
243 G4double lineWidth = GetLineWidth(pVA);
248 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
249 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
254 static G4bool hashedWarned =
false;
258 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
263 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
264 <<
"\n Not implemented. Using G4VMarker::filled."
272 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
277 MarkerSizeType sizeType;
278 G4double size = GetMarkerSize(polymarker, sizeType);
281 if (sizeType == world) {
291 nSides = GetNoOfSides(pVA);
301 fpViewer -> GetViewParameters().GetViewpointDirection();
302 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
303 const G4double dPhi = twopi / nSides;
308 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
309 glBegin (GL_POLYGON);
310 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
313 glVertex3d (p.
x(), p.
y(), p.
z());
320 pGLViewer->ChangePointSize(size);
327 glEnable (GL_POINT_SMOOTH);
break;
329 glDisable (GL_POINT_SMOOTH);
break;
333 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
335 glVertex3d(centre.
x(),centre.
y(),centre.
z());
341void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
343 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
344 if (pGLViewer) pGLViewer->DrawText(text);
347void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
352 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
355void G4OpenGLSceneHandler::AddPrimitive (
const G4Square& square) {
360 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
363void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale& scale)
369void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
378 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
379 if (!pGLViewer)
return;
393 GLfloat current_colour [4];
394 glGetFloatv (GL_CURRENT_COLOR, current_colour);
396 G4bool isTransparent =
false;
397 if (current_colour[3] < 1.) {
398 isTransparent =
true;
402 GLfloat clear_colour[4];
403 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
405 G4double lineWidth = GetLineWidth(pVA);
406 pGLViewer->ChangeLineWidth(lineWidth);
408 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
410 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
413 glDisable (GL_LIGHTING);
415 switch (drawing_style) {
419 glEnable (GL_STENCIL_TEST);
422 glStencilFunc (GL_ALWAYS, 0, 1);
423 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
424 glEnable (GL_DEPTH_TEST);
425 glDepthFunc (GL_LEQUAL);
428 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
429 glEnable(GL_COLOR_MATERIAL);
430 glDisable (GL_CULL_FACE);
431 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
435 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
436 glEnable(GL_COLOR_MATERIAL);
437 glDisable (GL_CULL_FACE);
438 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
440 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
441 glEnable(GL_COLOR_MATERIAL);
442 glEnable (GL_CULL_FACE);
443 glCullFace (GL_BACK);
444 glPolygonMode (GL_FRONT, GL_LINE);
449 glEnable (GL_DEPTH_TEST);
450 glDepthFunc (GL_LEQUAL);
453 glDepthMask (GL_FALSE);
454 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
455 glEnable(GL_COLOR_MATERIAL);
456 glDisable (GL_CULL_FACE);
457 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
460 glDepthMask (GL_TRUE);
462 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
463 glEnable(GL_COLOR_MATERIAL);
464 glDisable (GL_CULL_FACE);
465 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
467 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
468 glEnable(GL_COLOR_MATERIAL);
469 glEnable (GL_CULL_FACE);
470 glCullFace (GL_BACK);
471 glPolygonMode (GL_FRONT, GL_FILL);
474 if (!fProcessing2D) glEnable (GL_LIGHTING);
478 glEnable (GL_DEPTH_TEST);
479 glDepthFunc (GL_LEQUAL);
480 glDisable (GL_CULL_FACE);
481 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
495 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normals);
498 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
500 if (isAuxEdgeVisible) {
501 edgeFlag[edgeCount] = 1;
503 if (edgeFlag[edgeCount] > 0) {
504 glEdgeFlag (GL_TRUE);
506 glEdgeFlag (GL_FALSE);
508 glNormal3d (normals[edgeCount].x(),
509 normals[edgeCount].y(),
510 normals[edgeCount].z());
511 glVertex3d (vertex[edgeCount].x(),
512 vertex[edgeCount].y(),
513 vertex[edgeCount].z());
519 normals[edgeCount] = normals[0];
520 vertex[edgeCount] = vertex[0];
521 edgeFlag[edgeCount] = -1;
522 glEdgeFlag (GL_FALSE);
523 glNormal3d (normals[edgeCount].x(),
524 normals[edgeCount].y(),
525 normals[edgeCount].z());
526 glVertex3d (vertex[edgeCount].x(),
527 vertex[edgeCount].y(),
528 vertex[edgeCount].z());
533 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
534 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
537 glDisable(GL_COLOR_MATERIAL);
549 glDisable (GL_LIGHTING);
552 glStencilFunc (GL_EQUAL, 0, 1);
553 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
555 if (!fProcessing2D) glEnable (GL_LIGHTING);
557 glEnable (GL_DEPTH_TEST);
558 glDepthFunc (GL_LEQUAL);
561 glDepthMask (GL_FALSE);
562 glDisable (GL_CULL_FACE);
563 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
566 glDepthMask (GL_TRUE);
568 glDisable (GL_CULL_FACE);
569 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
571 glEnable (GL_CULL_FACE);
572 glCullFace (GL_BACK);
573 glPolygonMode (GL_FRONT, GL_FILL);
576 GLfloat* painting_colour;
580 goto end_of_drawing_through_stencil;
582 painting_colour = clear_colour;
584 painting_colour = current_colour;
588 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
591 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
593 glColor4fv (painting_colour);
595 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
596 if (edgeFlag[edgeCount] > 0) {
597 glEdgeFlag (GL_TRUE);
599 glEdgeFlag (GL_FALSE);
601 glNormal3d (normals[edgeCount].x(),
602 normals[edgeCount].y(),
603 normals[edgeCount].z());
604 glVertex3d (vertex[edgeCount].x(),
605 vertex[edgeCount].y(),
606 vertex[edgeCount].z());
609 end_of_drawing_through_stencil:
612 glStencilFunc (GL_ALWAYS, 0, 1);
613 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
614 glDepthFunc (GL_LEQUAL);
617 glDisable (GL_CULL_FACE);
618 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
622 glDisable (GL_CULL_FACE);
623 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
625 glEnable (GL_CULL_FACE);
626 glCullFace (GL_BACK);
627 glPolygonMode (GL_FRONT, GL_LINE);
630 glDisable (GL_LIGHTING);
631 glColor4fv (current_colour);
633 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
634 if (edgeFlag[edgeCount] > 0) {
635 glEdgeFlag (GL_TRUE);
637 glEdgeFlag (GL_FALSE);
639 glNormal3d (normals[edgeCount].x(),
640 normals[edgeCount].y(),
641 normals[edgeCount].z());
642 glVertex3d (vertex[edgeCount].x(),
643 vertex[edgeCount].y(),
644 vertex[edgeCount].z());
647 glDepthFunc (GL_LEQUAL);
653 }
while (notLastFace);
656 glDisable (GL_STENCIL_TEST);
657 glDepthMask (GL_TRUE);
658 glDisable (GL_LIGHTING);
663void G4OpenGLSceneHandler::AddPrimitive (
const G4NURBS& nurb) {
665 GLUnurbsObj *gl_nurb;
666 gl_nurb = gluNewNurbsRenderer ();
668 GLfloat *u_knot_array, *u_knot_array_ptr;
671 while (u_iterator.pick (u_knot_array_ptr++)){}
673 GLfloat *v_knot_array, *v_knot_array_ptr;
676 while (v_iterator.pick (v_knot_array_ptr++)){}
678 GLfloat *ctrl_pnt_array, *ctrl_pnt_array_ptr;
679 ctrl_pnt_array = ctrl_pnt_array_ptr =
682 while (c_p_iterator.pick (ctrl_pnt_array_ptr++)){}
694 const G4Colour& c = pVA -> GetColour ();
696 switch (drawing_style) {
703 if (!fProcessing2D) glEnable (GL_LIGHTING);
704 glEnable (GL_DEPTH_TEST);
705 glEnable (GL_AUTO_NORMAL);
706 glEnable (GL_NORMALIZE);
707 gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_FILL);
708 gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
709 GLfloat materialColour [4];
710 materialColour [0] = c.
GetRed ();
712 materialColour [2] = c.
GetBlue ();
713 materialColour [3] = 1.0;
716 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
724 glDisable (GL_LIGHTING);
726 glEnable (GL_DEPTH_TEST);
727 glDisable (GL_AUTO_NORMAL);
728 glDisable (GL_NORMALIZE);
729 gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
730 gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
735 gluBeginSurface (gl_nurb);
739 gluNurbsSurface (gl_nurb,
749 gluEndSurface (gl_nurb);
751 delete [] u_knot_array;
752 delete [] v_knot_array;
753 delete [] ctrl_pnt_array;
755 gluDeleteNurbsRenderer (gl_nurb);
758void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
762void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
766void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
G4double GetAlpha() const
G4double GetGreen() const
G4int GetnbrKnots(t_direction in_dir) const
G4int GettotalnbrCtrlPts() const
G4int GetnbrCtrlPts(t_direction in_dir) const
MarkerType GetMarkerType() const
FillStyle GetFillStyle() const
G4Point3D GetPosition() const
virtual G4VSolid * CreateSectionSolid()
virtual void EndPrimitives()
virtual void ProcessScene()
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
virtual void EndPrimitives2D()
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
virtual G4VSolid * CreateCutawaySolid()
virtual void AddCompound(const G4VTrajectory &)
virtual void AddPrimitive(const G4Polyline &)=0
const G4VisAttributes * GetVisAttributes() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > & rotate(T a, const BasicVector3D< T > &v)
G4int GetNoFacets() const
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const