Import Geant4 9.6.0 source tree
This commit is contained in:
@@ -24,8 +24,7 @@
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// $Id: G4OpenGLSceneHandler.cc,v 1.60 2010-12-11 17:04:07 allison Exp $
|
||||
// GEANT4 tag $Name: not supported by cvs2svn $
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// Andrew Walkden 27th March 1996
|
||||
@@ -64,18 +63,22 @@
|
||||
#include "G4Scene.hh"
|
||||
#include "G4VisExtent.hh"
|
||||
#include "G4AttHolder.hh"
|
||||
#include "G4PhysicalConstants.hh"
|
||||
|
||||
G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4VGraphicsSystem& system,
|
||||
G4int id,
|
||||
const G4String& name):
|
||||
G4VSceneHandler (system, id, name),
|
||||
fPickName(0),
|
||||
fProcessing2D (false),
|
||||
// glFlush take about 90% time. Dividing glFlush number by 100 will
|
||||
// change the first vis time from 100% to 10+90/100 = 10,9%.
|
||||
fNbListsBeforeFlush(100),
|
||||
fNbListsToBeFlush(0),
|
||||
fProcessingPolymarker(false)
|
||||
G4int id,
|
||||
const G4String& name):
|
||||
G4VSceneHandler (system, id, name),
|
||||
fPickName(0),
|
||||
// glFlush take about 90% time. Dividing glFlush number by 100 will
|
||||
// change the first vis time from 100% to 10+90/100 = 10,9%.
|
||||
fEventsDrawInterval(1),
|
||||
fEventsWaitingToBeFlushed(0),
|
||||
fThreePassCapable(false),
|
||||
fSecondPassForTransparencyRequested(false),
|
||||
fSecondPassForTransparency(false),
|
||||
fThirdPassForNonHiddenMarkersRequested(false),
|
||||
fThirdPassForNonHiddenMarkers(false)
|
||||
{}
|
||||
|
||||
G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
|
||||
@@ -111,10 +114,35 @@ void G4OpenGLSceneHandler::ClearAndDestroyAtts()
|
||||
|
||||
void G4OpenGLSceneHandler::ScaledFlush()
|
||||
{
|
||||
fNbListsToBeFlush++;
|
||||
if (fNbListsToBeFlush < fNbListsBeforeFlush) return;
|
||||
fEventsWaitingToBeFlushed++;
|
||||
if (fEventsWaitingToBeFlushed < fEventsDrawInterval) return;
|
||||
glFlush();
|
||||
fNbListsToBeFlush = 0;
|
||||
fEventsWaitingToBeFlushed = 0;
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::ProcessScene()
|
||||
{
|
||||
fThreePassCapable = true;
|
||||
|
||||
G4VSceneHandler::ProcessScene();
|
||||
|
||||
// Repeat if required...
|
||||
if (fSecondPassForTransparencyRequested) {
|
||||
fSecondPassForTransparency = true;
|
||||
G4VSceneHandler::ProcessScene();
|
||||
fSecondPassForTransparency = false;
|
||||
fSecondPassForTransparencyRequested = false;
|
||||
}
|
||||
|
||||
// And again if required...
|
||||
if (fThirdPassForNonHiddenMarkersRequested) {
|
||||
fThirdPassForNonHiddenMarkers = true;
|
||||
G4VSceneHandler::ProcessScene();
|
||||
fThirdPassForNonHiddenMarkers = false;
|
||||
fThirdPassForNonHiddenMarkersRequested = false;
|
||||
}
|
||||
|
||||
fThreePassCapable = false;
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::PreAddSolid
|
||||
@@ -139,12 +167,10 @@ void G4OpenGLSceneHandler::BeginPrimitives2D
|
||||
(const G4Transform3D& objectTransformation)
|
||||
{
|
||||
G4VSceneHandler::BeginPrimitives2D (objectTransformation);
|
||||
fProcessing2D = true;
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::EndPrimitives2D ()
|
||||
{
|
||||
fProcessing2D = false;
|
||||
G4VSceneHandler::EndPrimitives2D ();
|
||||
}
|
||||
|
||||
@@ -173,18 +199,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
|
||||
G4int nPoints = line.size ();
|
||||
if (nPoints <= 0) return;
|
||||
|
||||
// Loads G4Atts for picking...
|
||||
if (fpViewer->GetViewParameters().IsPicking()) {
|
||||
G4AttHolder* holder = new G4AttHolder;
|
||||
LoadAtts(line, holder);
|
||||
fPickMap[fPickName] = holder;
|
||||
}
|
||||
|
||||
// Note: colour treated in sub-class.
|
||||
|
||||
if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ())
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);}
|
||||
// Note: colour and depth test treated in sub-class.
|
||||
|
||||
glDisable (GL_LIGHTING);
|
||||
|
||||
@@ -193,10 +208,12 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
|
||||
fpViewer -> GetApplicableVisAttributes (line.GetVisAttributes ());
|
||||
|
||||
G4double lineWidth = GetLineWidth(pVA);
|
||||
// Need access to method in G4OpenGLViewer. static_cast doesn't
|
||||
// work with a virtual base class, so use dynamic_cast. No need to
|
||||
// test the outcome since viewer is guaranteed to be a
|
||||
// G4OpenGLViewer, but test it anyway to keep Coverity happy.
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if ( pGLViewer ) {
|
||||
pGLViewer->ChangeLineWidth(lineWidth);
|
||||
}
|
||||
if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
|
||||
|
||||
glBegin (GL_LINE_STRIP);
|
||||
for (G4int iPoint = 0; iPoint < nPoints; iPoint++) {
|
||||
@@ -211,160 +228,27 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
|
||||
{
|
||||
G4int nPoints = polymarker.size ();
|
||||
if (nPoints <= 0) return;
|
||||
|
||||
fProcessingPolymarker = true;
|
||||
|
||||
// Loads G4Atts for picking...
|
||||
if (fpViewer->GetViewParameters().IsPicking()) {
|
||||
G4AttHolder* holder = new G4AttHolder;
|
||||
LoadAtts(polymarker, holder);
|
||||
fPickMap[fPickName] = holder;
|
||||
}
|
||||
|
||||
switch (polymarker.GetMarkerType()) {
|
||||
default:
|
||||
case G4Polymarker::dots:
|
||||
{
|
||||
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
||||
G4Circle dot (polymarker);
|
||||
dot.SetPosition (polymarker[iPoint]);
|
||||
dot.SetWorldSize (0.);
|
||||
dot.SetScreenSize (0.1); // Very small circle.
|
||||
G4OpenGLSceneHandler::AddPrimitive (dot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case G4Polymarker::circles:
|
||||
{
|
||||
std::vector <G4VMarker> circleV;
|
||||
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
||||
G4Circle circle (polymarker);
|
||||
// If not already drawn
|
||||
circle.SetPosition (polymarker[iPoint]);
|
||||
circleV.push_back(circle);
|
||||
// G4OpenGLSceneHandler::AddPrimitive (circle);
|
||||
}
|
||||
G4OpenGLSceneHandler::AddPrimitivesCircle (circleV);
|
||||
}
|
||||
break;
|
||||
case G4Polymarker::squares:
|
||||
{
|
||||
std::vector <G4VMarker> squareV;
|
||||
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
||||
G4Square square (polymarker);
|
||||
square.SetPosition (polymarker[iPoint]);
|
||||
squareV.push_back(square);
|
||||
// G4OpenGLSceneHandler::AddPrimitive (square);
|
||||
}
|
||||
G4OpenGLSceneHandler::AddPrimitivesSquare (squareV);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
fProcessingPolymarker = false;
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) {
|
||||
|
||||
// Loads G4Atts for picking...
|
||||
if (fpViewer->GetViewParameters().IsPicking()) {
|
||||
G4AttHolder* holder = new G4AttHolder;
|
||||
LoadAtts(text, holder);
|
||||
fPickMap[fPickName] = holder;
|
||||
}
|
||||
|
||||
const G4Colour& c = GetTextColour (text); // Picks up default if none.
|
||||
MarkerSizeType sizeType;
|
||||
G4double size = GetMarkerSize (text, sizeType);
|
||||
G4ThreeVector position (text.GetPosition ());
|
||||
G4String textString = text.GetText();
|
||||
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if ( pGLViewer ) {
|
||||
const char* textCString = textString.c_str();
|
||||
GLfloat color[4]; /* Ask OpenGL for the current color */
|
||||
glGetFloatv(GL_CURRENT_COLOR, color);
|
||||
|
||||
// Change to new color
|
||||
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
||||
|
||||
// set position
|
||||
glRasterPos3d( position.x(),position.y(),position.z() );
|
||||
|
||||
pGLViewer->DrawText(textCString,position.x(),position.y(),position.z(),size);
|
||||
glColor3d (color[0], color[1], color[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) {
|
||||
glEnable (GL_POINT_SMOOTH);
|
||||
AddCircleSquare (circle, G4OpenGLBitMapStore::circle);
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) {
|
||||
glDisable (GL_POINT_SMOOTH);
|
||||
AddCircleSquare (square, G4OpenGLBitMapStore::square);
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitivesCircle (const std::vector <G4VMarker>& marker) {
|
||||
glEnable (GL_POINT_SMOOTH);
|
||||
AddCircleSquareVector (marker, G4OpenGLBitMapStore::square);
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitivesSquare (const std::vector <G4VMarker>& marker) {
|
||||
glDisable (GL_POINT_SMOOTH);
|
||||
AddCircleSquareVector (marker, G4OpenGLBitMapStore::circle);
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddCircleSquare
|
||||
(const G4VMarker& marker,
|
||||
G4OpenGLBitMapStore::Shape shape) {
|
||||
|
||||
std::vector <G4VMarker> circleVector;
|
||||
circleVector.push_back(marker);
|
||||
AddCircleSquareVector(circleVector,shape);
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddCircleSquareVector
|
||||
(const std::vector <G4VMarker>& marker,
|
||||
G4OpenGLBitMapStore::Shape shape) {
|
||||
|
||||
if (marker.size() == 0) {
|
||||
if (polymarker.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fProcessingPolymarker) { // Polymarker has already loaded atts.
|
||||
// Loads G4Atts for picking...
|
||||
if (fpViewer->GetViewParameters().IsPicking()) {
|
||||
G4AttHolder* holder = new G4AttHolder;
|
||||
LoadAtts(marker[0], holder);
|
||||
fPickMap[fPickName] = holder;
|
||||
}
|
||||
}
|
||||
// Note: colour and depth test treated in sub-class.
|
||||
|
||||
// Note: colour treated in sub-class.
|
||||
|
||||
if (fpViewer -> GetViewParameters ().IsMarkerNotHidden ()) {
|
||||
glDisable (GL_DEPTH_TEST);
|
||||
} else {
|
||||
glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LESS);
|
||||
}
|
||||
|
||||
glDisable (GL_LIGHTING);
|
||||
|
||||
// Get vis attributes - pick up defaults if none.
|
||||
const G4VisAttributes* pVA =
|
||||
fpViewer -> GetApplicableVisAttributes (marker[0].GetVisAttributes ());
|
||||
fpViewer -> GetApplicableVisAttributes (polymarker.GetVisAttributes ());
|
||||
|
||||
G4double lineWidth = GetLineWidth(pVA);
|
||||
// Need access to method in G4OpenGLViewer. static_cast doesn't
|
||||
// work with a virtual base class, so use dynamic_cast. No need to
|
||||
// test the outcome since viewer is guaranteed to be a
|
||||
// G4OpenGLViewer, but test it anyway to keep Coverity happy.
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if ( pGLViewer ) {
|
||||
pGLViewer->ChangeLineWidth(lineWidth);
|
||||
}
|
||||
if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
|
||||
|
||||
G4VMarker::FillStyle style = marker[0].GetFillStyle();
|
||||
G4VMarker::FillStyle style = polymarker.GetFillStyle();
|
||||
|
||||
// G4bool filled = false; Not actually used - comment out to prevent compiler warnings (JA).
|
||||
static G4bool hashedWarned = false;
|
||||
@@ -374,7 +258,6 @@ void G4OpenGLSceneHandler::AddCircleSquareVector
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
//filled = false;
|
||||
break;
|
||||
|
||||
case G4VMarker::hashed:
|
||||
if (!hashedWarned) {
|
||||
G4cout << "Hashed fill style in G4OpenGLSceneHandler."
|
||||
@@ -384,90 +267,97 @@ void G4OpenGLSceneHandler::AddCircleSquareVector
|
||||
}
|
||||
// Maybe use
|
||||
//glPolygonStipple (fStippleMaskHashed);
|
||||
// Drop through to filled...
|
||||
|
||||
// Drop through to filled...
|
||||
case G4VMarker::filled:
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
//filled = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
MarkerSizeType sizeType;
|
||||
G4double size = GetMarkerSize(marker[0], sizeType);
|
||||
G4double size = GetMarkerSize(polymarker, sizeType);
|
||||
|
||||
// Draw...
|
||||
if (sizeType == world) { // Size specified in world coordinates.
|
||||
if (sizeType == world) { // Size specified in world coordinates.
|
||||
|
||||
for (unsigned int a=0;a<marker.size();a++) {
|
||||
G4Point3D centre = marker[a].GetPosition();
|
||||
// A few useful quantities...
|
||||
DrawXYPolygon (shape, size, centre, pVA);
|
||||
}
|
||||
} else { // Size specified in screen (window) coordinates.
|
||||
// A few useful quantities...
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if ( pGLViewer ) {
|
||||
pGLViewer->ChangePointSize(size);
|
||||
}
|
||||
//Antialiasing only for circles
|
||||
//Transparency
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glBegin (GL_POINTS);
|
||||
for (unsigned int a=0;a<marker.size();a++) {
|
||||
G4Point3D centre = marker[a].GetPosition();
|
||||
glVertex3f(centre.x(),centre.y(),centre.z());
|
||||
}
|
||||
glEnd();
|
||||
// L. GARNIER 1 March 2009
|
||||
// Old method, we draw a bitmap instead of a GL_POINT.
|
||||
// I remove it because it cost in term of computing performances
|
||||
// and gl2ps can't draw bitmaps
|
||||
G4int nSides;
|
||||
G4double startPhi;
|
||||
switch (polymarker.GetMarkerType()) {
|
||||
default:
|
||||
case G4Polymarker::dots:
|
||||
size = 1.;
|
||||
// Drop through to circles
|
||||
case G4Polymarker::circles:
|
||||
nSides = GetNoOfSides(pVA);
|
||||
startPhi = 0.;
|
||||
break;
|
||||
case G4Polymarker::squares:
|
||||
nSides = 4;
|
||||
startPhi = -pi / 4.;
|
||||
break;
|
||||
}
|
||||
|
||||
// glRasterPos3d(centre.x(),centre.y(),centre.z());
|
||||
// const GLubyte* marker =
|
||||
// G4OpenGLBitMapStore::GetBitMap(shape, size, filled);
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
// glBitmap(GLsizei(size), GLsizei(size), size/2., size/2., 0., 0., marker);
|
||||
}
|
||||
const G4Vector3D& viewpointDirection =
|
||||
fpViewer -> GetViewParameters().GetViewpointDirection();
|
||||
const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
|
||||
const G4double dPhi = twopi / nSides;
|
||||
const G4double radius = size / 2.;
|
||||
G4Vector3D start = radius * (up.cross(viewpointDirection)).unit();
|
||||
G4double phi;
|
||||
G4int i;
|
||||
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
||||
glBegin (GL_POLYGON);
|
||||
for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
|
||||
G4Vector3D r = start; r.rotate(phi, viewpointDirection);
|
||||
G4Vector3D p = polymarker[iPoint] + r;
|
||||
glVertex3d (p.x(), p.y(), p.z());
|
||||
}
|
||||
glEnd ();
|
||||
}
|
||||
|
||||
} else { // Size specified in screen (window) coordinates.
|
||||
|
||||
pGLViewer->ChangePointSize(size);
|
||||
|
||||
//Antialiasing only for circles
|
||||
switch (polymarker.GetMarkerType()) {
|
||||
default:
|
||||
case G4Polymarker::dots:
|
||||
case G4Polymarker::circles:
|
||||
glEnable (GL_POINT_SMOOTH); break;
|
||||
case G4Polymarker::squares:
|
||||
glDisable (GL_POINT_SMOOTH); break;
|
||||
}
|
||||
|
||||
glBegin (GL_POINTS);
|
||||
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
||||
G4Point3D centre = polymarker[iPoint];
|
||||
glVertex3d(centre.x(),centre.y(),centre.z());
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::DrawXYPolygon
|
||||
(G4OpenGLBitMapStore::Shape shape,
|
||||
G4double size,
|
||||
const G4Point3D& centre,
|
||||
const G4VisAttributes* pApplicableVisAtts)
|
||||
{
|
||||
G4int nSides;
|
||||
G4double startPhi;
|
||||
if (shape == G4OpenGLBitMapStore::circle) {
|
||||
nSides = GetNoOfSides(pApplicableVisAtts);
|
||||
startPhi = 0.;
|
||||
} else {
|
||||
nSides = 4;
|
||||
startPhi = -pi / 4.;
|
||||
}
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) {
|
||||
// Pass to specific viewer via virtual function DrawText.
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if (pGLViewer) pGLViewer->DrawText(text);
|
||||
}
|
||||
|
||||
const G4Vector3D& viewpointDirection =
|
||||
fpViewer -> GetViewParameters().GetViewpointDirection();
|
||||
const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
|
||||
const G4double dPhi = twopi / nSides;
|
||||
const G4double radius = size / 2.;
|
||||
G4Vector3D start = radius * (up.cross(viewpointDirection)).unit();
|
||||
G4double phi;
|
||||
G4int i;
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) {
|
||||
G4Polymarker oneCircle(circle);
|
||||
oneCircle.push_back(circle.GetPosition());
|
||||
oneCircle.SetMarkerType(G4Polymarker::circles);
|
||||
// Call this AddPrimitive to avoid re-doing sub-class code.
|
||||
G4OpenGLSceneHandler::AddPrimitive(oneCircle);
|
||||
}
|
||||
|
||||
glBegin (GL_POLYGON);
|
||||
for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
|
||||
G4Vector3D r = start; r.rotate(phi, viewpointDirection);
|
||||
G4Vector3D p = centre + r;
|
||||
glVertex3d (p.x(), p.y(), p.z());
|
||||
}
|
||||
glEnd ();
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) {
|
||||
G4Polymarker oneSquare(square);
|
||||
oneSquare.push_back(square.GetPosition());
|
||||
oneSquare.SetMarkerType(G4Polymarker::squares);
|
||||
// Call this AddPrimitive to avoid re-doing sub-class code.
|
||||
G4OpenGLSceneHandler::AddPrimitive(oneSquare);
|
||||
}
|
||||
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4Scale& scale)
|
||||
@@ -483,13 +373,11 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
|
||||
if (polyhedron.GetNoFacets() == 0) return;
|
||||
|
||||
// Loads G4Atts for picking...
|
||||
if (fpViewer->GetViewParameters().IsPicking()) {
|
||||
G4AttHolder* holder = new G4AttHolder;
|
||||
LoadAtts(polyhedron, holder);
|
||||
fPickMap[fPickName] = holder;
|
||||
}
|
||||
|
||||
// Need access to data in G4OpenGLViewer. static_cast doesn't work
|
||||
// with a virtual base class, so use dynamic_cast.
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if (!pGLViewer) return;
|
||||
|
||||
// Get vis attributes - pick up defaults if none.
|
||||
const G4VisAttributes* pVA =
|
||||
fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
|
||||
@@ -498,35 +386,28 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
// attributes, thereby over-riding the current view parameter.
|
||||
G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
|
||||
|
||||
// Get colour, etc...
|
||||
// Need access to data in G4OpenGLViewer. static_cast doesn't work
|
||||
// with a virtual base class, so use dynamic_cast. No need to test
|
||||
// the outcome since viewer is guaranteed to be a G4OpenGLViewer.
|
||||
G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
const G4bool& transparency_enabled = pViewer->transparency_enabled;
|
||||
const G4Colour& c = pVA->GetColour();
|
||||
GLfloat materialColour [4];
|
||||
materialColour [0] = c.GetRed ();
|
||||
materialColour [1] = c.GetGreen ();
|
||||
materialColour [2] = c.GetBlue ();
|
||||
if (transparency_enabled) {
|
||||
materialColour [3] = c.GetAlpha ();
|
||||
} else {
|
||||
materialColour [3] = 1.;
|
||||
}
|
||||
|
||||
G4double lineWidth = GetLineWidth(pVA);
|
||||
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
||||
if ( pGLViewer ) {
|
||||
pGLViewer->ChangeLineWidth(lineWidth);
|
||||
// Note that in stored mode, because this call gets embedded in a display
|
||||
// list, it is the colour _at the time of_ creation of the display list, so
|
||||
// even if the colour is changed, for example, by interaction with a Qt
|
||||
// window, current_colour does not change.
|
||||
GLfloat current_colour [4];
|
||||
glGetFloatv (GL_CURRENT_COLOR, current_colour);
|
||||
|
||||
G4bool isTransparent = false;
|
||||
if (current_colour[3] < 1.) { // This object is transparent
|
||||
isTransparent = true;
|
||||
}
|
||||
|
||||
// This is the colour used to paint surfaces in hlr mode.
|
||||
GLfloat clear_colour[4];
|
||||
glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
|
||||
|
||||
G4double lineWidth = GetLineWidth(pVA);
|
||||
pGLViewer->ChangeLineWidth(lineWidth);
|
||||
|
||||
G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
|
||||
|
||||
G4bool clipping = pViewer->fVP.IsSection() || pViewer->fVP.IsCutaway();
|
||||
G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
|
||||
|
||||
// Lighting disabled unless otherwise requested
|
||||
glDisable (GL_LIGHTING);
|
||||
@@ -542,44 +423,53 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
if (materialColour[3] < 1.) {
|
||||
if (isTransparent) {
|
||||
// Transparent...
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
} else {
|
||||
// Opaque...
|
||||
if (clipping) {
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
} else {
|
||||
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable (GL_CULL_FACE);
|
||||
glCullFace (GL_BACK);
|
||||
glPolygonMode (GL_FRONT, GL_LINE);
|
||||
}
|
||||
}
|
||||
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
||||
break;
|
||||
case (G4ViewParameters::hsr):
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
if (materialColour[3] < 1.) {
|
||||
if (isTransparent) {
|
||||
// Transparent...
|
||||
glDepthMask (0); // Make depth buffer read-only.
|
||||
glDepthMask (GL_FALSE); // Make depth buffer read-only.
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColour);
|
||||
} else {
|
||||
// Opaque...
|
||||
glDepthMask (1); // Make depth buffer writable (default).
|
||||
glDepthMask (GL_TRUE); // Make depth buffer writable (default).
|
||||
if (clipping) {
|
||||
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
} else {
|
||||
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glEnable (GL_CULL_FACE);
|
||||
glCullFace (GL_BACK);
|
||||
glPolygonMode (GL_FRONT, GL_FILL);
|
||||
}
|
||||
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
|
||||
}
|
||||
if (!fProcessing2D) glEnable (GL_LIGHTING);
|
||||
break;
|
||||
@@ -589,7 +479,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
glDepthFunc (GL_LEQUAL); //??? was GL_ALWAYS
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -602,12 +491,11 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
G4Point3D vertex[4];
|
||||
G4int edgeFlag[4];
|
||||
G4Normal3D normals[4];
|
||||
G4int n;
|
||||
notLastFace = polyhedron.GetNextFacet(n, vertex, edgeFlag, normals);
|
||||
G4int nEdges;
|
||||
notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normals);
|
||||
|
||||
//Loop through the four edges of each G4Facet...
|
||||
G4int edgeCount = 0;
|
||||
for(edgeCount = 0; edgeCount < n; ++edgeCount) {
|
||||
for(G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
|
||||
// Check to see if edge is visible or not...
|
||||
if (isAuxEdgeVisible) {
|
||||
edgeFlag[edgeCount] = 1;
|
||||
@@ -626,8 +514,8 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
}
|
||||
// HepPolyhedron produces triangles too; in that case add an extra
|
||||
// vertex identical to first...
|
||||
if (n == 3) {
|
||||
edgeCount = 3;
|
||||
if (nEdges == 3) {
|
||||
G4int edgeCount = 3;
|
||||
normals[edgeCount] = normals[0];
|
||||
vertex[edgeCount] = vertex[0];
|
||||
edgeFlag[edgeCount] = -1;
|
||||
@@ -640,23 +528,14 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
vertex[edgeCount].z());
|
||||
}
|
||||
// Trap situation where number of edges is > 4...
|
||||
if (n > 4) {
|
||||
if (nEdges > 4) {
|
||||
G4cerr <<
|
||||
"G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING";
|
||||
G4PhysicalVolumeModel* pPVModel =
|
||||
dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
|
||||
if (pPVModel) {
|
||||
G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
|
||||
G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
|
||||
G4cerr <<
|
||||
"\n Volume " << pCurrentPV->GetName() <<
|
||||
", Solid " << pCurrentLV->GetSolid()->GetName() <<
|
||||
" (" << pCurrentLV->GetSolid()->GetEntityType();
|
||||
}
|
||||
G4cerr<<
|
||||
"\n G4Polyhedron facet with " << n << " edges" << G4endl;
|
||||
"G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
|
||||
"\n G4Polyhedron facet with " << nEdges << " edges" << G4endl;
|
||||
}
|
||||
|
||||
glDisable(GL_COLOR_MATERIAL); // Revert to glMaterial for hlr/sr.
|
||||
|
||||
// Do it all over again (twice) for hlr...
|
||||
if (drawing_style == G4ViewParameters::hlr ||
|
||||
drawing_style == G4ViewParameters::hlhsr) {
|
||||
@@ -677,14 +556,14 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
}
|
||||
glEnable (GL_DEPTH_TEST);
|
||||
glDepthFunc (GL_LEQUAL);
|
||||
if (materialColour[3] < 1.) {
|
||||
if (isTransparent) {
|
||||
// Transparent...
|
||||
glDepthMask (0); // Make depth buffer read-only.
|
||||
glDepthMask (GL_FALSE); // Make depth buffer read-only.
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
} else {
|
||||
// Opaque...
|
||||
glDepthMask (1); // Make depth buffer writable (default).
|
||||
glDepthMask (GL_TRUE); // Make depth buffer writable (default).
|
||||
if (clipping) {
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
||||
@@ -696,15 +575,15 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
}
|
||||
GLfloat* painting_colour;
|
||||
if (drawing_style == G4ViewParameters::hlr) {
|
||||
if (materialColour[3] < 1.) {
|
||||
if (isTransparent) {
|
||||
// Transparent - don't paint...
|
||||
goto end_of_drawing_through_stencil;
|
||||
}
|
||||
painting_colour = clear_colour;
|
||||
} else { // drawing_style == G4ViewParameters::hlhsr
|
||||
painting_colour = materialColour;
|
||||
painting_colour = current_colour;
|
||||
}
|
||||
if (materialColour[3] < 1.) {
|
||||
if (isTransparent) {
|
||||
// Transparent...
|
||||
glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
|
||||
} else {
|
||||
@@ -733,7 +612,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
glStencilFunc (GL_ALWAYS, 0, 1);
|
||||
glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
|
||||
glDepthFunc (GL_LEQUAL); // to make sure line gets drawn.
|
||||
if (materialColour[3] < 1.) {
|
||||
if (isTransparent) {
|
||||
// Transparent...
|
||||
glDisable (GL_CULL_FACE);
|
||||
glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
||||
@@ -749,7 +628,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
}
|
||||
}
|
||||
glDisable (GL_LIGHTING);
|
||||
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
||||
glColor4fv (current_colour);
|
||||
glBegin (GL_QUADS);
|
||||
for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
|
||||
if (edgeFlag[edgeCount] > 0) {
|
||||
@@ -775,7 +654,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
|
||||
glEnd ();
|
||||
glDisable (GL_STENCIL_TEST); // Revert to default for next primitive.
|
||||
glDepthMask (1); // Revert to default for next primitive.
|
||||
glDepthMask (GL_TRUE); // Revert to default for next primitive.
|
||||
glDisable (GL_LIGHTING); // Revert to default for next primitive.
|
||||
}
|
||||
|
||||
@@ -783,13 +662,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
||||
//Knots and Ctrl Pnts MUST be arrays of GLfloats.
|
||||
void G4OpenGLSceneHandler::AddPrimitive (const G4NURBS& nurb) {
|
||||
|
||||
// Loads G4Atts for picking...
|
||||
if (fpViewer->GetViewParameters().IsPicking()) {
|
||||
G4AttHolder* holder = new G4AttHolder;
|
||||
LoadAtts(nurb, holder);
|
||||
fPickMap[fPickName] = holder;
|
||||
}
|
||||
|
||||
GLUnurbsObj *gl_nurb;
|
||||
gl_nurb = gluNewNurbsRenderer ();
|
||||
|
||||
@@ -856,7 +728,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4NURBS& nurb) {
|
||||
glDisable (GL_NORMALIZE);
|
||||
gluNurbsProperty (gl_nurb, GLU_DISPLAY_MODE, GLU_OUTLINE_POLYGON);
|
||||
gluNurbsProperty (gl_nurb, GLU_SAMPLING_TOLERANCE, 50.0);
|
||||
glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
||||
glColor4d(c.GetRed(), c.GetGreen(), c.GetBlue(),c.GetAlpha());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user