Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id$ 27 // 28 // 28 // << 29 // 29 // Andrew Walkden 27th March 1996 30 // Andrew Walkden 27th March 1996 30 // OpenGL stored scene - creates OpenGL displa 31 // OpenGL stored scene - creates OpenGL display lists. 31 // OpenGL immediate scene - draws immediately 32 // OpenGL immediate scene - draws immediately to buffer 32 // (saving space on 33 // (saving space on server). 33 34 >> 35 #ifdef G4VIS_BUILD_OPENGL_DRIVER >> 36 >> 37 // Included here - problems with HP compiler if not before other includes? >> 38 #include "G4NURBS.hh" 34 39 35 # include "G4OpenGLSceneHandler.hh" << 40 // Here follows a special for Mesa, the OpenGL emulator. Does not affect 36 # include "G4OpenGLViewer.hh" << 41 // other OpenGL's, as far as I'm aware. John Allison 18/9/96. 37 # include "G4OpenGLTransform3D.hh" << 42 #define CENTERLINE_CLPP /* CenterLine C++ workaround: */ 38 # include "G4Point3D.hh" << 43 // Also seems to be required for HP's CC and AIX xlC, at least. 39 # include "G4Normal3D.hh" << 44 40 # include "G4Transform3D.hh" << 45 #include "G4OpenGLSceneHandler.hh" 41 # include "G4Polyline.hh" << 46 #include "G4OpenGLViewer.hh" 42 # include "G4Polymarker.hh" << 47 #include "G4OpenGLTransform3D.hh" 43 # include "G4Text.hh" << 48 #include "G4Point3D.hh" 44 # include "G4Circle.hh" << 49 #include "G4Normal3D.hh" 45 # include "G4Square.hh" << 50 #include "G4Transform3D.hh" 46 # include "G4VMarker.hh" << 51 #include "G4Polyline.hh" 47 # include "G4Polyhedron.hh" << 52 #include "G4Polymarker.hh" 48 # include "G4VisAttributes.hh" << 53 #include "G4Text.hh" 49 # include "G4PhysicalVolumeModel.hh" << 54 #include "G4Circle.hh" 50 # include "G4VPhysicalVolume.hh" << 55 #include "G4Square.hh" 51 # include "G4LogicalVolume.hh" << 56 #include "G4VMarker.hh" 52 # include "G4VSolid.hh" << 57 #include "G4Polyhedron.hh" 53 # include "G4Scene.hh" << 58 #include "G4VisAttributes.hh" 54 # include "G4VisExtent.hh" << 59 #include "G4PhysicalVolumeModel.hh" 55 # include "G4AttHolder.hh" << 60 #include "G4VPhysicalVolume.hh" 56 # include "G4PhysicalConstants.hh" << 61 #include "G4LogicalVolume.hh" 57 # include "G4RunManager.hh" << 62 #include "G4VSolid.hh" 58 # include "G4Run.hh" << 63 #include "G4Scene.hh" 59 # include "G4RunManagerFactory.hh" << 64 #include "G4VisExtent.hh" 60 # include "G4Mesh.hh" << 65 #include "G4AttHolder.hh" 61 # include "G4PseudoScene.hh" << 66 #include "G4PhysicalConstants.hh" 62 # include "G4VisManager.hh" << 67 >> 68 G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4VGraphicsSystem& system, >> 69 G4int id, >> 70 const G4String& name): >> 71 G4VSceneHandler (system, id, name), >> 72 fPickName(0), >> 73 // glFlush take about 90% time. Dividing glFlush number by 100 will >> 74 // change the first vis time from 100% to 10+90/100 = 10,9%. >> 75 fEventsDrawInterval(1), >> 76 fEventsWaitingToBeFlushed(0), >> 77 fThreePassCapable(false), >> 78 fSecondPassForTransparencyRequested(false), >> 79 fSecondPassForTransparency(false), >> 80 fThirdPassForNonHiddenMarkersRequested(false), >> 81 fThirdPassForNonHiddenMarkers(false) >> 82 {} >> 83 >> 84 G4OpenGLSceneHandler::~G4OpenGLSceneHandler () >> 85 { >> 86 ClearStore (); >> 87 } 63 88 64 const GLubyte G4OpenGLSceneHandler::fStippleMa 89 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = { 65 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 90 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 66 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 91 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 67 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 92 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 68 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 93 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 69 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 94 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 70 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 95 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 71 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 96 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 72 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 97 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 73 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 98 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 74 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 99 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 75 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 100 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 76 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 101 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 77 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 102 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 78 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 103 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 79 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 104 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, 80 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 105 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 81 }; 106 }; 82 107 83 G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4 << 84 G4 << 85 co << 86 G4VSceneHandler (system, id, name), << 87 fPickName(0), << 88 fThreePassCapable(false), << 89 fSecondPassForTransparencyRequested(false), << 90 fSecondPassForTransparency(false), << 91 fThirdPassForNonHiddenMarkersRequested(false), << 92 fThirdPassForNonHiddenMarkers(false), << 93 fEdgeFlag(true) << 94 { << 95 } << 96 << 97 G4OpenGLSceneHandler::~G4OpenGLSceneHandler () << 98 { << 99 ClearStore (); << 100 } << 101 << 102 void G4OpenGLSceneHandler::ClearAndDestroyAtts 108 void G4OpenGLSceneHandler::ClearAndDestroyAtts() 103 { 109 { 104 std::map<GLuint, G4AttHolder*>::iterator i; 110 std::map<GLuint, G4AttHolder*>::iterator i; 105 for (i = fPickMap.begin(); i != fPickMap.end 111 for (i = fPickMap.begin(); i != fPickMap.end(); ++i) delete i->second; 106 fPickMap.clear(); 112 fPickMap.clear(); 107 } 113 } 108 114 109 G4int G4OpenGLSceneHandler::fEntitiesFlushInte << 110 G4OpenGLSceneHandler::FlushAction << 111 G4OpenGLSceneHandler::fFlushAction = G4OpenGLS << 112 << 113 void G4OpenGLSceneHandler::ScaledFlush() 115 void G4OpenGLSceneHandler::ScaledFlush() 114 { 116 { 115 if (fReadyForTransients) { << 117 fEventsWaitingToBeFlushed++; 116 << 118 if (fEventsWaitingToBeFlushed < fEventsDrawInterval) return; 117 // Drawing transients, e.g., trajectories. << 119 glFlush(); 118 << 120 fEventsWaitingToBeFlushed = 0; 119 if (!fpScene) { << 120 // No scene - shouldn't happen << 121 glFlush(); << 122 return; << 123 } << 124 // Get event from modeling parameters << 125 if (!fpModel) { << 126 // No model - shouldn't happen << 127 glFlush(); << 128 return; << 129 } << 130 const G4ModelingParameters* modelingParame << 131 fpModel->GetModelingParameters(); << 132 if (!modelingParameters) { << 133 // No modeling parameters - shouldn't ha << 134 glFlush(); << 135 return; << 136 } << 137 const G4Event* thisEvent = modelingParamet << 138 if (!thisEvent) { << 139 // No event, so not in event loop. << 140 if (fFlushAction == endOfEvent) { << 141 fFlushAction = endOfRun; << 142 } else if (fFlushAction == NthEvent) { << 143 fFlushAction = NthPrimitive; << 144 } << 145 } << 146 G4RunManager* runMan = G4RunManagerFactory << 147 if (!runMan) { << 148 // No run manager - shouldn't happen << 149 glFlush(); << 150 return; << 151 } << 152 const G4Run* thisRun = runMan->GetCurrentR << 153 if (!thisRun) { << 154 // No run, so not in event loop. << 155 if (fFlushAction == endOfRun) { << 156 fFlushAction = NthPrimitive; << 157 } else if (fFlushAction == NthEvent) { << 158 fFlushAction = NthPrimitive; << 159 } << 160 } << 161 << 162 switch (fFlushAction) { << 163 case endOfEvent: << 164 // If "/vis/scene/endOfEventAction ref << 165 // end of run anyway, so only scale if << 166 if (!fpScene->GetRefreshAtEndOfEvent() << 167 // But if "/vis/scene/endOfEventActi << 168 // called until end of run, so we ha << 169 // Get event from modeling parameter << 170 G4int thisEventID = thisEvent->GetEv << 171 static G4int lastEventID = 0; << 172 if (thisEventID != lastEventID) { << 173 glFlush(); << 174 lastEventID = thisEventID; << 175 } << 176 } << 177 break; << 178 case endOfRun: << 179 // If "/vis/scene/endOfRunAction refre << 180 // end of run anyway, so only scale if << 181 if (!fpScene->GetRefreshAtEndOfRun()) << 182 // If "/vis/scene/endOfRunAction acc << 183 // so we have to watch for a new run << 184 G4int thisRunID = thisRun->GetRunID( << 185 static G4int lastRunID = 0; << 186 if (thisRunID != lastRunID) { << 187 glFlush(); << 188 lastRunID = thisRunID; << 189 } << 190 } << 191 break; << 192 case eachPrimitive: << 193 // This is equivalent to numeric with << 194 fEntitiesFlushInterval = 1; << 195 [[fallthrough]]; // Fall through to NthPrim << 196 case NthPrimitive: << 197 { // Encapsulate in scope {} brackets to << 198 static G4int primitivesWaitingToBeFlus << 199 primitivesWaitingToBeFlushed++; << 200 if (primitivesWaitingToBeFlushed < fEn << 201 glFlush(); << 202 primitivesWaitingToBeFlushed = 0; << 203 break; << 204 } << 205 case NthEvent: << 206 // If "/vis/scene/endOfEventAction ref << 207 // end of event anyway, so only scale << 208 if (!fpScene->GetRefreshAtEndOfEvent() << 209 G4int thisEventID = thisEvent->GetEv << 210 static G4int lastEventID = 0; << 211 if (thisEventID != lastEventID) { << 212 static G4int eventsWaitingToBeFlus << 213 eventsWaitingToBeFlushed++; << 214 if (eventsWaitingToBeFlushed < fEn << 215 glFlush(); << 216 eventsWaitingToBeFlushed = 0; << 217 lastEventID = thisEventID; << 218 } << 219 } << 220 break; << 221 case never: << 222 break; << 223 default: << 224 break; << 225 } << 226 << 227 } << 228 << 229 else << 230 << 231 { << 232 << 233 // For run duration model drawing (detecto << 234 // Immediate mode: a huge speed up is obta << 235 // Stored mode: no discernable difference << 236 // back buffer and then swapped. << 237 // So eachPrimitive and NthPrimitive make << 238 // endOfRun are treated as "no action", i. << 239 // as happens anyway, when drawing is comp << 240 << 241 switch (fFlushAction) { << 242 case endOfEvent: << 243 break; << 244 case endOfRun: << 245 break; << 246 case eachPrimitive: << 247 // This is equivalent to NthPrimitive << 248 fEntitiesFlushInterval = 1; << 249 [[fallthrough]]; // Fall through to NthPrim << 250 case NthPrimitive: << 251 { // Encapsulate in scope {} brackets to << 252 static G4int primitivesWaitingToBeFlus << 253 primitivesWaitingToBeFlushed++; << 254 if (primitivesWaitingToBeFlushed < fEn << 255 glFlush(); << 256 primitivesWaitingToBeFlushed = 0; << 257 break; << 258 } << 259 case NthEvent: << 260 break; << 261 case never: << 262 break; << 263 default: << 264 break; << 265 } << 266 << 267 } << 268 } 121 } 269 122 270 void G4OpenGLSceneHandler::ProcessScene() 123 void G4OpenGLSceneHandler::ProcessScene() 271 { 124 { 272 fThreePassCapable = true; 125 fThreePassCapable = true; 273 126 274 G4VSceneHandler::ProcessScene(); 127 G4VSceneHandler::ProcessScene(); 275 128 276 // Repeat if required... 129 // Repeat if required... 277 if (fSecondPassForTransparencyRequested) { 130 if (fSecondPassForTransparencyRequested) { 278 fSecondPassForTransparency = true; 131 fSecondPassForTransparency = true; 279 G4VSceneHandler::ProcessScene(); 132 G4VSceneHandler::ProcessScene(); 280 fSecondPassForTransparency = false; 133 fSecondPassForTransparency = false; 281 fSecondPassForTransparencyRequested = fals 134 fSecondPassForTransparencyRequested = false; 282 } 135 } 283 136 284 // And again if required... 137 // And again if required... 285 if (fThirdPassForNonHiddenMarkersRequested) 138 if (fThirdPassForNonHiddenMarkersRequested) { 286 fThirdPassForNonHiddenMarkers = true; 139 fThirdPassForNonHiddenMarkers = true; 287 G4VSceneHandler::ProcessScene(); 140 G4VSceneHandler::ProcessScene(); 288 fThirdPassForNonHiddenMarkers = false; 141 fThirdPassForNonHiddenMarkers = false; 289 fThirdPassForNonHiddenMarkersRequested = f 142 fThirdPassForNonHiddenMarkersRequested = false; 290 } 143 } 291 144 292 fThreePassCapable = false; 145 fThreePassCapable = false; 293 } 146 } 294 147 295 void G4OpenGLSceneHandler::PreAddSolid 148 void G4OpenGLSceneHandler::PreAddSolid 296 (const G4Transform3D& objectTransformation, 149 (const G4Transform3D& objectTransformation, 297 const G4VisAttributes& visAttribs) 150 const G4VisAttributes& visAttribs) 298 { 151 { 299 G4VSceneHandler::PreAddSolid (objectTransfor 152 G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs); 300 } 153 } 301 154 302 void G4OpenGLSceneHandler::BeginPrimitives 155 void G4OpenGLSceneHandler::BeginPrimitives 303 (const G4Transform3D& objectTransformation) 156 (const G4Transform3D& objectTransformation) 304 { 157 { 305 G4VSceneHandler::BeginPrimitives (objectTran 158 G4VSceneHandler::BeginPrimitives (objectTransformation); 306 } 159 } 307 160 308 void G4OpenGLSceneHandler::EndPrimitives () 161 void G4OpenGLSceneHandler::EndPrimitives () 309 { 162 { 310 G4VSceneHandler::EndPrimitives (); 163 G4VSceneHandler::EndPrimitives (); 311 } 164 } 312 165 313 void G4OpenGLSceneHandler::BeginPrimitives2D 166 void G4OpenGLSceneHandler::BeginPrimitives2D 314 (const G4Transform3D& objectTransformation) 167 (const G4Transform3D& objectTransformation) 315 { 168 { 316 G4VSceneHandler::BeginPrimitives2D (objectTr 169 G4VSceneHandler::BeginPrimitives2D (objectTransformation); 317 } 170 } 318 171 319 void G4OpenGLSceneHandler::EndPrimitives2D () 172 void G4OpenGLSceneHandler::EndPrimitives2D () 320 { 173 { 321 G4VSceneHandler::EndPrimitives2D (); 174 G4VSceneHandler::EndPrimitives2D (); 322 } 175 } 323 176 324 G4DisplacedSolid* G4OpenGLSceneHandler::Create << 177 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid () 325 { 178 { 326 return G4VSceneHandler::CreateSectionSolid() << 179 // Clipping done in G4OpenGLViewer::SetView. 327 // If clipping done in G4OpenGLViewer::SetVi << 328 // return 0; 180 // return 0; 329 // Note: if you change this, you must also c << 181 330 // G4OpenGLStoredViewer::CompareForKernelVis << 182 // But...OpenGL no longer seems to reconstruct clipped edges, so, >> 183 // when the BooleanProcessor is up to it, abandon this and use >> 184 // generic clipping in G4VSceneHandler::CreateSectionSolid... >> 185 return G4VSceneHandler::CreateSectionSolid(); 331 } 186 } 332 187 333 G4DisplacedSolid* G4OpenGLSceneHandler::Create << 188 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid () 334 { 189 { 335 // return G4VSceneHandler::CreateCutawaySoli << 190 // Cutaway done in G4OpenGLViewer::SetView. 336 // If cutaway done in G4OpenGLViewer::SetVie << 191 // return 0; 337 return 0; << 192 338 // Note: if you change this, you must also c << 193 // But...if not, when the BooleanProcessor is up to it... 339 // G4OpenGLStoredViewer::CompareForKernelVis << 194 return G4VSceneHandler::CreateCutawaySolid(); 340 } 195 } 341 196 342 void G4OpenGLSceneHandler::AddPrimitive (const 197 void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line) 343 { 198 { 344 std::size_t nPoints = line.size (); << 199 G4int nPoints = line.size (); 345 if (nPoints <= 0) return; 200 if (nPoints <= 0) return; 346 201 347 // Note: colour and depth test treated in su 202 // Note: colour and depth test treated in sub-class. 348 203 349 glDisable (GL_LIGHTING); 204 glDisable (GL_LIGHTING); 350 << 205 351 G4double lineWidth = GetLineWidth(fpVisAttri << 206 // Get vis attributes - pick up defaults if none. >> 207 const G4VisAttributes* pVA = >> 208 fpViewer -> GetApplicableVisAttributes (line.GetVisAttributes ()); >> 209 >> 210 G4double lineWidth = GetLineWidth(pVA); 352 // Need access to method in G4OpenGLViewer. 211 // Need access to method in G4OpenGLViewer. static_cast doesn't 353 // work with a virtual base class, so use dy 212 // work with a virtual base class, so use dynamic_cast. No need to 354 // test the outcome since viewer is guarante 213 // test the outcome since viewer is guaranteed to be a 355 // G4OpenGLViewer, but test it anyway to kee 214 // G4OpenGLViewer, but test it anyway to keep Coverity happy. 356 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 215 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 357 if (pGLViewer) pGLViewer->ChangeLineWidth(li 216 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth); 358 217 359 fEdgeFlag = true; << 360 glBegin (GL_LINE_STRIP); 218 glBegin (GL_LINE_STRIP); 361 // No ned glEdgeFlag for lines : << 219 for (G4int iPoint = 0; iPoint < nPoints; iPoint++) { 362 // Boundary and nonboundary edge flags on ve << 363 << 364 // glEdgeFlag (GL_TRUE); << 365 for (std::size_t iPoint = 0; iPoint < nPoint << 366 G4double x, y, z; 220 G4double x, y, z; 367 x = line[iPoint].x(); 221 x = line[iPoint].x(); 368 y = line[iPoint].y(); 222 y = line[iPoint].y(); 369 z = line[iPoint].z(); 223 z = line[iPoint].z(); 370 glVertex3d (x, y, z); 224 glVertex3d (x, y, z); 371 } 225 } 372 glEnd (); 226 glEnd (); 373 } 227 } 374 228 375 void G4OpenGLSceneHandler::AddPrimitive (const 229 void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 376 { 230 { 377 if (polymarker.size() == 0) { 231 if (polymarker.size() == 0) { 378 return; 232 return; 379 } 233 } 380 234 381 // Note: colour and depth test treated in su 235 // Note: colour and depth test treated in sub-class. 382 236 383 glDisable (GL_LIGHTING); 237 glDisable (GL_LIGHTING); 384 238 385 MarkerSizeType sizeType; << 239 // Get vis attributes - pick up defaults if none. 386 G4double size = GetMarkerSize(polymarker, si << 240 const G4VisAttributes* pVA = >> 241 fpViewer -> GetApplicableVisAttributes (polymarker.GetVisAttributes ()); 387 242 >> 243 G4double lineWidth = GetLineWidth(pVA); 388 // Need access to method in G4OpenGLViewer. 244 // Need access to method in G4OpenGLViewer. static_cast doesn't 389 // work with a virtual base class, so use dy 245 // work with a virtual base class, so use dynamic_cast. No need to 390 // test the outcome since viewer is guarante 246 // test the outcome since viewer is guaranteed to be a 391 // G4OpenGLViewer, but test it anyway to kee 247 // G4OpenGLViewer, but test it anyway to keep Coverity happy. 392 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 248 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 393 if (!pGLViewer) return; << 249 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth); 394 250 395 if (sizeType == world) { // Size specified << 251 G4VMarker::FillStyle style = polymarker.GetFillStyle(); 396 G4double lineWidth = GetLineWidth(fpVisAtt << 252 397 pGLViewer->ChangeLineWidth(lineWidth); << 253 // G4bool filled = false; Not actually used - comment out to prevent compiler warnings (JA). >> 254 static G4bool hashedWarned = false; 398 255 399 G4VMarker::FillStyle style = polymarker.Ge << 256 switch (style) { 400 << 257 case G4VMarker::noFill: 401 // G4bool filled = false; Not actually us << 258 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 402 static G4bool hashedWarned = false; << 259 //filled = false; 403 << 260 break; 404 switch (style) { << 261 case G4VMarker::hashed: 405 case G4VMarker::noFill: << 262 if (!hashedWarned) { 406 glPolygonMode (GL_FRONT_AND_BACK, GL_L << 263 G4cout << "Hashed fill style in G4OpenGLSceneHandler." 407 glEdgeFlag (GL_TRUE); << 264 << "\n Not implemented. Using G4VMarker::filled." 408 //filled = false; << 265 << G4endl; 409 break; << 266 hashedWarned = true; 410 case G4VMarker::hashed: << 267 } 411 if (!hashedWarned) { << 268 // Maybe use 412 G4cout << "Hashed fill style in G4Op << 269 //glPolygonStipple (fStippleMaskHashed); 413 << "\n Not implemented. Using G4VM << 270 // Drop through to filled... 414 << G4endl; << 271 case G4VMarker::filled: 415 hashedWarned = true; << 272 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 416 } << 273 //filled = true; 417 // Maybe use << 274 break; 418 //glPolygonStipple (fStippleMaskHashed << 419 [[fallthrough]]; // Drop through to filled << 420 case G4VMarker::filled: << 421 glPolygonMode (GL_FRONT_AND_BACK, GL_F << 422 //filled = true; << 423 break; << 424 } << 425 } 275 } 426 << 276 >> 277 MarkerSizeType sizeType; >> 278 G4double size = GetMarkerSize(polymarker, sizeType); >> 279 427 // Draw... 280 // Draw... 428 if (sizeType == world) { // Size specified 281 if (sizeType == world) { // Size specified in world coordinates. 429 282 430 G4int nSides; 283 G4int nSides; 431 G4double startPhi; 284 G4double startPhi; 432 switch (polymarker.GetMarkerType()) { 285 switch (polymarker.GetMarkerType()) { 433 default: 286 default: 434 case G4Polymarker::dots: 287 case G4Polymarker::dots: 435 size = 1.; << 288 size = 1.; 436 [[fallthrough]]; // Fall through to circles << 289 // Drop through to circles 437 case G4Polymarker::circles: 290 case G4Polymarker::circles: 438 nSides = GetNoOfSides(fpVisAttribs); << 291 nSides = GetNoOfSides(pVA); 439 startPhi = 0.; 292 startPhi = 0.; 440 break; 293 break; 441 case G4Polymarker::squares: 294 case G4Polymarker::squares: 442 nSides = 4; 295 nSides = 4; 443 startPhi = -pi / 4.; 296 startPhi = -pi / 4.; 444 break; 297 break; 445 } 298 } 446 299 447 const G4Vector3D& viewpointDirection = 300 const G4Vector3D& viewpointDirection = 448 fpViewer -> GetViewParameters().GetViewp 301 fpViewer -> GetViewParameters().GetViewpointDirection(); 449 const G4Vector3D& up = fpViewer->GetViewPa 302 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector(); 450 const G4double dPhi = twopi / nSides; 303 const G4double dPhi = twopi / nSides; 451 const G4double radius = size / 2.; 304 const G4double radius = size / 2.; 452 G4Vector3D start = radius * (up.cross(view 305 G4Vector3D start = radius * (up.cross(viewpointDirection)).unit(); 453 G4double phi; 306 G4double phi; 454 G4int i; 307 G4int i; 455 for (size_t iPoint = 0; iPoint < polymarke 308 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) { 456 fEdgeFlag = true; << 457 glBegin (GL_POLYGON); 309 glBegin (GL_POLYGON); 458 for (i = 0, phi = startPhi; i < nSides; 310 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) { 459 G4Vector3D r = start; r.rotate(phi, viewpoin 311 G4Vector3D r = start; r.rotate(phi, viewpointDirection); 460 G4Vector3D p = polymarker[iPoint] + r; 312 G4Vector3D p = polymarker[iPoint] + r; 461 glVertex3d (p.x(), p.y(), p.z()); 313 glVertex3d (p.x(), p.y(), p.z()); 462 } 314 } 463 glEnd (); 315 glEnd (); 464 } 316 } 465 317 466 } else { // Size specified in screen (window 318 } else { // Size specified in screen (window) coordinates. 467 319 468 pGLViewer->ChangePointSize(size); 320 pGLViewer->ChangePointSize(size); 469 321 470 //Antialiasing only for circles 322 //Antialiasing only for circles 471 switch (polymarker.GetMarkerType()) { 323 switch (polymarker.GetMarkerType()) { 472 default: 324 default: 473 case G4Polymarker::dots: 325 case G4Polymarker::dots: 474 case G4Polymarker::circles: 326 case G4Polymarker::circles: 475 glEnable (GL_POINT_SMOOTH); break; 327 glEnable (GL_POINT_SMOOTH); break; 476 case G4Polymarker::squares: 328 case G4Polymarker::squares: 477 glDisable (GL_POINT_SMOOTH); break; 329 glDisable (GL_POINT_SMOOTH); break; 478 } 330 } >> 331 479 glBegin (GL_POINTS); 332 glBegin (GL_POINTS); 480 for (size_t iPoint = 0; iPoint < polymarke 333 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) { 481 G4Point3D centre = polymarker[iPoint]; 334 G4Point3D centre = polymarker[iPoint]; 482 glVertex3d(centre.x(),centre.y(),centre. 335 glVertex3d(centre.x(),centre.y(),centre.z()); 483 } 336 } 484 glEnd(); 337 glEnd(); 485 } 338 } 486 } 339 } 487 340 488 void G4OpenGLSceneHandler::AddPrimitive (const 341 void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) { 489 // Pass to specific viewer via virtual funct 342 // Pass to specific viewer via virtual function DrawText. 490 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 343 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 491 if (pGLViewer) pGLViewer->DrawText(text); 344 if (pGLViewer) pGLViewer->DrawText(text); 492 } 345 } 493 346 494 void G4OpenGLSceneHandler::AddPrimitive (const 347 void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) { 495 G4Polymarker oneCircle(circle); 348 G4Polymarker oneCircle(circle); 496 oneCircle.push_back(circle.GetPosition()); 349 oneCircle.push_back(circle.GetPosition()); 497 oneCircle.SetMarkerType(G4Polymarker::circle 350 oneCircle.SetMarkerType(G4Polymarker::circles); 498 // Call this AddPrimitive to avoid re-doing 351 // Call this AddPrimitive to avoid re-doing sub-class code. 499 G4OpenGLSceneHandler::AddPrimitive(oneCircle 352 G4OpenGLSceneHandler::AddPrimitive(oneCircle); 500 } 353 } 501 354 502 void G4OpenGLSceneHandler::AddPrimitive (const 355 void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) { 503 G4Polymarker oneSquare(square); 356 G4Polymarker oneSquare(square); 504 oneSquare.push_back(square.GetPosition()); 357 oneSquare.push_back(square.GetPosition()); 505 oneSquare.SetMarkerType(G4Polymarker::square 358 oneSquare.SetMarkerType(G4Polymarker::squares); 506 // Call this AddPrimitive to avoid re-doing 359 // Call this AddPrimitive to avoid re-doing sub-class code. 507 G4OpenGLSceneHandler::AddPrimitive(oneSquare 360 G4OpenGLSceneHandler::AddPrimitive(oneSquare); 508 } 361 } 509 362 >> 363 void G4OpenGLSceneHandler::AddPrimitive (const G4Scale& scale) >> 364 { >> 365 G4VSceneHandler::AddPrimitive(scale); >> 366 } >> 367 510 //Method for handling G4Polyhedron objects for 368 //Method for handling G4Polyhedron objects for drawing solids. 511 void G4OpenGLSceneHandler::AddPrimitive (const 369 void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) { 512 370 513 // Assume all facets are planar convex quadr 371 // Assume all facets are planar convex quadrilaterals. 514 // Draw each facet individually 372 // Draw each facet individually 515 373 516 if (polyhedron.GetNoFacets() == 0) return; 374 if (polyhedron.GetNoFacets() == 0) return; 517 375 518 // Need access to data in G4OpenGLViewer. s 376 // Need access to data in G4OpenGLViewer. static_cast doesn't work 519 // with a virtual base class, so use dynamic 377 // with a virtual base class, so use dynamic_cast. 520 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 378 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 521 if (!pGLViewer) return; 379 if (!pGLViewer) return; 522 380 >> 381 // Get vis attributes - pick up defaults if none. >> 382 const G4VisAttributes* pVA = >> 383 fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ()); >> 384 523 // Get view parameters that the user can for 385 // Get view parameters that the user can force through the vis 524 // attributes, thereby over-riding the curre 386 // attributes, thereby over-riding the current view parameter. 525 G4ViewParameters::DrawingStyle drawing_style << 387 G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA); 526 388 527 // Note that in stored mode, because this ca 389 // Note that in stored mode, because this call gets embedded in a display 528 // list, it is the colour _at the time of_ 390 // list, it is the colour _at the time of_ creation of the display list, so 529 // even if the colour is changed, for examp 391 // even if the colour is changed, for example, by interaction with a Qt 530 // window, current_colour does not change. 392 // window, current_colour does not change. 531 GLfloat* painting_colour; << 393 GLfloat current_colour [4]; 532 GLfloat clear_colour[4]; << 533 GLfloat current_colour[4]; << 534 glGetFloatv (GL_CURRENT_COLOR, current_colou 394 glGetFloatv (GL_CURRENT_COLOR, current_colour); 535 395 536 G4bool isTransparent = false; 396 G4bool isTransparent = false; 537 if (current_colour[3] < 1.) { // This objec 397 if (current_colour[3] < 1.) { // This object is transparent 538 isTransparent = true; 398 isTransparent = true; 539 } 399 } 540 400 541 if (drawing_style == G4ViewParameters::hlr) << 401 // This is the colour used to paint surfaces in hlr mode. 542 // This is the colour used to paint surfac << 402 GLfloat clear_colour[4]; 543 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_c << 403 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour); 544 painting_colour = clear_colour; << 404 545 } else { // drawing_style == G4ViewParamete << 405 G4double lineWidth = GetLineWidth(pVA); 546 painting_colour = current_colour; << 547 } << 548 << 549 G4double lineWidth = GetLineWidth(fpVisAttri << 550 pGLViewer->ChangeLineWidth(lineWidth); 406 pGLViewer->ChangeLineWidth(lineWidth); 551 407 552 G4bool isAuxEdgeVisible = GetAuxEdgeVisible << 408 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA); 553 409 554 G4bool clipping = pGLViewer->fVP.IsSection() 410 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway(); 555 411 556 // Lighting disabled unless otherwise reques 412 // Lighting disabled unless otherwise requested 557 glDisable (GL_LIGHTING); 413 glDisable (GL_LIGHTING); 558 414 559 switch (drawing_style) { 415 switch (drawing_style) { 560 case (G4ViewParameters::hlhsr): 416 case (G4ViewParameters::hlhsr): 561 // Set up as for hidden line removal but p 417 // Set up as for hidden line removal but paint polygon faces later... 562 case (G4ViewParameters::hlr): 418 case (G4ViewParameters::hlr): 563 glEnable (GL_STENCIL_TEST); 419 glEnable (GL_STENCIL_TEST); 564 // The stencil buffer is cleared in G4Open 420 // The stencil buffer is cleared in G4OpenGLViewer::ClearView. 565 // The procedure below leaves it clear. 421 // The procedure below leaves it clear. 566 glStencilFunc (GL_ALWAYS, 0, 1); 422 glStencilFunc (GL_ALWAYS, 0, 1); 567 glStencilOp (GL_INVERT, GL_INVERT, GL_INVE 423 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT); 568 glEnable (GL_DEPTH_TEST); 424 glEnable (GL_DEPTH_TEST); 569 glDepthFunc (GL_LEQUAL); 425 glDepthFunc (GL_LEQUAL); 570 if (isTransparent) { 426 if (isTransparent) { 571 // Transparent... 427 // Transparent... 572 glColorMaterial(GL_FRONT_AND_BACK, GL_AM 428 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 573 glEnable(GL_COLOR_MATERIAL); 429 glEnable(GL_COLOR_MATERIAL); 574 //glDisable (GL_CULL_FACE); << 430 glDisable (GL_CULL_FACE); 575 glPolygonMode (GL_FRONT_AND_BACK, GL_LIN 431 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 576 } else { 432 } else { 577 // Opaque... 433 // Opaque... 578 if (clipping) { 434 if (clipping) { 579 glColorMaterial(GL_FRONT_AND_BACK, GL_ 435 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 580 glEnable(GL_COLOR_MATERIAL); 436 glEnable(GL_COLOR_MATERIAL); 581 //glDisable (GL_CULL_FACE); << 437 glDisable (GL_CULL_FACE); 582 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 438 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 583 } else { 439 } else { 584 glColorMaterial(GL_FRONT, GL_AMBIENT_A 440 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 585 glEnable(GL_COLOR_MATERIAL); 441 glEnable(GL_COLOR_MATERIAL); 586 //glEnable (GL_CULL_FACE); << 442 glEnable (GL_CULL_FACE); 587 //glCullFace (GL_BACK); << 443 glCullFace (GL_BACK); 588 glPolygonMode (GL_FRONT, GL_LINE); 444 glPolygonMode (GL_FRONT, GL_LINE); 589 } 445 } 590 } 446 } 591 break; 447 break; 592 case (G4ViewParameters::hsr): 448 case (G4ViewParameters::hsr): 593 glEnable (GL_DEPTH_TEST); 449 glEnable (GL_DEPTH_TEST); 594 glDepthFunc (GL_LEQUAL); 450 glDepthFunc (GL_LEQUAL); 595 if (isTransparent) { 451 if (isTransparent) { 596 // Transparent... 452 // Transparent... 597 glDepthMask (GL_FALSE); // Make depth b 453 glDepthMask (GL_FALSE); // Make depth buffer read-only. 598 glColorMaterial(GL_FRONT_AND_BACK, GL_AM 454 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 599 glEnable(GL_COLOR_MATERIAL); 455 glEnable(GL_COLOR_MATERIAL); 600 //glDisable (GL_CULL_FACE); << 456 glDisable (GL_CULL_FACE); 601 glPolygonMode (GL_FRONT_AND_BACK, GL_FIL 457 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 602 } else { 458 } else { 603 // Opaque... 459 // Opaque... 604 glDepthMask (GL_TRUE); // Make depth bu 460 glDepthMask (GL_TRUE); // Make depth buffer writable (default). 605 if (clipping) { 461 if (clipping) { 606 glColorMaterial(GL_FRONT_AND_BACK, GL_ 462 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 607 glEnable(GL_COLOR_MATERIAL); 463 glEnable(GL_COLOR_MATERIAL); 608 //glDisable (GL_CULL_FACE); << 464 glDisable (GL_CULL_FACE); 609 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 465 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 610 } else { 466 } else { 611 glColorMaterial(GL_FRONT, GL_AMBIENT_A 467 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 612 glEnable(GL_COLOR_MATERIAL); 468 glEnable(GL_COLOR_MATERIAL); 613 //glEnable (GL_CULL_FACE); << 469 glEnable (GL_CULL_FACE); 614 //glCullFace (GL_BACK); << 470 glCullFace (GL_BACK); 615 glPolygonMode (GL_FRONT, GL_FILL); 471 glPolygonMode (GL_FRONT, GL_FILL); 616 } 472 } 617 } 473 } 618 if (!fProcessing2D) glEnable (GL_LIGHTING) 474 if (!fProcessing2D) glEnable (GL_LIGHTING); 619 break; << 475 break; 620 case (G4ViewParameters::wireframe): 476 case (G4ViewParameters::wireframe): 621 default: 477 default: 622 glEnable (GL_DEPTH_TEST); 478 glEnable (GL_DEPTH_TEST); 623 glDepthFunc (GL_LEQUAL); //??? was GL_A 479 glDepthFunc (GL_LEQUAL); //??? was GL_ALWAYS 624 //glDisable (GL_CULL_FACE); << 480 glDisable (GL_CULL_FACE); 625 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) 481 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 626 break; 482 break; 627 } 483 } 628 484 629 //Loop through all the facets... 485 //Loop through all the facets... 630 fEdgeFlag = true; << 631 glBegin (GL_QUADS); 486 glBegin (GL_QUADS); 632 glEdgeFlag (GL_TRUE); << 633 G4bool notLastFace; 487 G4bool notLastFace; 634 do { 488 do { 635 489 636 //First, find vertices, edgeflags and norm 490 //First, find vertices, edgeflags and normals and note "not last facet"... 637 G4Point3D vertex[4]; 491 G4Point3D vertex[4]; 638 G4int edgeFlag[4]; 492 G4int edgeFlag[4]; 639 G4Normal3D normals[4]; 493 G4Normal3D normals[4]; 640 G4int nEdges; 494 G4int nEdges; 641 notLastFace = polyhedron.GetNextFacet(nEdg 495 notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normals); 642 496 643 //Loop through the four edges of each G4Fa 497 //Loop through the four edges of each G4Facet... 644 for(G4int edgeCount = 0; edgeCount < nEdge 498 for(G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) { 645 // Check to see if edge is visible or no 499 // Check to see if edge is visible or not... 646 if (isAuxEdgeVisible) { 500 if (isAuxEdgeVisible) { 647 edgeFlag[edgeCount] = 1; 501 edgeFlag[edgeCount] = 1; 648 } 502 } 649 if (edgeFlag[edgeCount] > 0) { 503 if (edgeFlag[edgeCount] > 0) { 650 if (fEdgeFlag != true) { << 504 glEdgeFlag (GL_TRUE); 651 glEdgeFlag (GL_TRUE); << 652 fEdgeFlag = true; << 653 } << 654 } else { 505 } else { 655 if (fEdgeFlag != false) { << 506 glEdgeFlag (GL_FALSE); 656 glEdgeFlag (GL_FALSE); << 657 fEdgeFlag = false; << 658 } << 659 } 507 } 660 glNormal3d (normals[edgeCount].x(), << 508 glNormal3d (normals[edgeCount].x(), 661 normals[edgeCount].y(), 509 normals[edgeCount].y(), 662 normals[edgeCount].z()); 510 normals[edgeCount].z()); 663 glVertex3d (vertex[edgeCount].x(), 511 glVertex3d (vertex[edgeCount].x(), 664 vertex[edgeCount].y(), 512 vertex[edgeCount].y(), 665 vertex[edgeCount].z()); 513 vertex[edgeCount].z()); 666 } 514 } 667 << 668 // HepPolyhedron produces triangles too; i 515 // HepPolyhedron produces triangles too; in that case add an extra 669 // vertex identical to first... 516 // vertex identical to first... 670 if (nEdges == 3) { 517 if (nEdges == 3) { 671 G4int edgeCount = 3; 518 G4int edgeCount = 3; 672 normals[edgeCount] = normals[0]; 519 normals[edgeCount] = normals[0]; 673 vertex[edgeCount] = vertex[0]; 520 vertex[edgeCount] = vertex[0]; 674 edgeFlag[edgeCount] = -1; 521 edgeFlag[edgeCount] = -1; 675 if (fEdgeFlag != false) { << 522 glEdgeFlag (GL_FALSE); 676 glEdgeFlag (GL_FALSE); << 677 fEdgeFlag = false; << 678 } << 679 << 680 glNormal3d (normals[edgeCount].x(), 523 glNormal3d (normals[edgeCount].x(), 681 normals[edgeCount].y(), 524 normals[edgeCount].y(), 682 normals[edgeCount].z()); 525 normals[edgeCount].z()); 683 glVertex3d (vertex[edgeCount].x(), 526 glVertex3d (vertex[edgeCount].x(), 684 vertex[edgeCount].y(), 527 vertex[edgeCount].y(), 685 vertex[edgeCount].z()); 528 vertex[edgeCount].z()); 686 } 529 } 687 // Trap situation where number of edges is 530 // Trap situation where number of edges is > 4... 688 if (nEdges > 4) { 531 if (nEdges > 4) { 689 G4cerr << 532 G4cerr << 690 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhe 533 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING" 691 "\n G4Polyhedron facet with " << nEdges << 534 "\n G4Polyhedron facet with " << nEdges << " edges" << G4endl; 692 } 535 } 693 536 694 << 537 glDisable(GL_COLOR_MATERIAL); // Revert to glMaterial for hlr/sr. >> 538 695 // Do it all over again (twice) for hlr... 539 // Do it all over again (twice) for hlr... 696 if (drawing_style == G4ViewParameters::hl 540 if (drawing_style == G4ViewParameters::hlr || 697 drawing_style == G4ViewParameters::hlhsr) { 541 drawing_style == G4ViewParameters::hlhsr) { 698 542 699 glDisable(GL_COLOR_MATERIAL); // Revert << 700 glEnd (); // Placed here to balance glB 543 glEnd (); // Placed here to balance glBegin above, allowing GL 701 << 544 // state changes below, then glBegin again. Avoids 702 // state changes below, then glBegin aga << 703 // having glBegin/End pairs *inside* loop 545 // having glBegin/End pairs *inside* loop in the more 704 // usual case of no hidden line removal. 546 // usual case of no hidden line removal. 705 547 706 // Lighting disabled unless otherwise re 548 // Lighting disabled unless otherwise requested 707 glDisable (GL_LIGHTING); 549 glDisable (GL_LIGHTING); 708 550 709 // Draw through stencil... 551 // Draw through stencil... 710 glStencilFunc (GL_EQUAL, 0, 1); 552 glStencilFunc (GL_EQUAL, 0, 1); 711 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 553 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 712 if (drawing_style == G4ViewParameters::h 554 if (drawing_style == G4ViewParameters::hlhsr) { 713 if (!fProcessing2D) glEnable (GL_LIGHTING); 555 if (!fProcessing2D) glEnable (GL_LIGHTING); 714 } 556 } 715 glEnable (GL_DEPTH_TEST); 557 glEnable (GL_DEPTH_TEST); 716 glDepthFunc (GL_LEQUAL); 558 glDepthFunc (GL_LEQUAL); 717 if (isTransparent) { 559 if (isTransparent) { 718 // Transparent... 560 // Transparent... 719 glDepthMask (GL_FALSE); // Make depth buffe 561 glDepthMask (GL_FALSE); // Make depth buffer read-only. 720 //glDisable (GL_CULL_FACE); << 562 glDisable (GL_CULL_FACE); 721 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 563 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 722 } else { 564 } else { 723 // Opaque... 565 // Opaque... 724 glDepthMask (GL_TRUE); // Make depth buffer 566 glDepthMask (GL_TRUE); // Make depth buffer writable (default). 725 if (clipping) { 567 if (clipping) { 726 //glDisable (GL_CULL_FACE); << 568 glDisable (GL_CULL_FACE); 727 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL) 569 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 728 } else { 570 } else { 729 //glEnable (GL_CULL_FACE); << 571 glEnable (GL_CULL_FACE); 730 //glCullFace (GL_BACK); << 572 glCullFace (GL_BACK); 731 glPolygonMode (GL_FRONT, GL_FILL); 573 glPolygonMode (GL_FRONT, GL_FILL); 732 } 574 } 733 } 575 } >> 576 GLfloat* painting_colour; 734 if (drawing_style == G4ViewParameters:: 577 if (drawing_style == G4ViewParameters::hlr) { 735 if (isTransparent) { 578 if (isTransparent) { 736 // Transparent - don't paint... 579 // Transparent - don't paint... 737 goto end_of_drawing_through_stencil; 580 goto end_of_drawing_through_stencil; 738 } 581 } >> 582 painting_colour = clear_colour; >> 583 } else { // drawing_style == G4ViewParameters::hlhsr >> 584 painting_colour = current_colour; 739 } 585 } 740 if (isTransparent) { 586 if (isTransparent) { 741 // Transparent... 587 // Transparent... 742 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_ 588 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour); 743 } else { 589 } else { 744 // Opaque... 590 // Opaque... 745 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFU 591 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour); 746 } 592 } 747 glColor4fv (painting_colour); 593 glColor4fv (painting_colour); 748 glBegin (GL_QUADS); 594 glBegin (GL_QUADS); 749 glEdgeFlag (GL_TRUE); << 750 fEdgeFlag = true; << 751 << 752 for (int edgeCount = 0; edgeCount < 4; + 595 for (int edgeCount = 0; edgeCount < 4; ++edgeCount) { 753 if (edgeFlag[edgeCount] > 0) { << 596 if (edgeFlag[edgeCount] > 0) { 754 if (fEdgeFlag != true) { << 597 glEdgeFlag (GL_TRUE); 755 glEdgeFlag (GL_TRUE); << 598 } else { 756 fEdgeFlag = true; << 599 glEdgeFlag (GL_FALSE); 757 } << 600 } 758 } else { << 601 glNormal3d (normals[edgeCount].x(), 759 if (fEdgeFlag != false) { << 602 normals[edgeCount].y(), 760 glEdgeFlag (GL_FALSE); << 603 normals[edgeCount].z()); 761 fEdgeFlag = false; << 604 glVertex3d (vertex[edgeCount].x(), 762 } << 605 vertex[edgeCount].y(), 763 } << 606 vertex[edgeCount].z()); 764 glNormal3d (normals[edgeCount].x(), << 765 normals[edgeCount].y(), << 766 normals[edgeCount].z()); << 767 glVertex3d (vertex[edgeCount].x(), << 768 vertex[edgeCount].y(), << 769 vertex[edgeCount].z()); << 770 } 607 } 771 glEnd (); 608 glEnd (); 772 end_of_drawing_through_stencil: 609 end_of_drawing_through_stencil: 773 610 774 // and once more to reset the stencil bi 611 // and once more to reset the stencil bits... 775 glStencilFunc (GL_ALWAYS, 0, 1); 612 glStencilFunc (GL_ALWAYS, 0, 1); 776 glStencilOp (GL_INVERT, GL_INVERT, GL_IN 613 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT); 777 glDepthFunc (GL_LEQUAL); // to make sur 614 glDepthFunc (GL_LEQUAL); // to make sure line gets drawn. 778 if (isTransparent) { 615 if (isTransparent) { 779 // Transparent... 616 // Transparent... 780 //glDisable (GL_CULL_FACE); << 617 glDisable (GL_CULL_FACE); 781 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 618 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 782 } else { 619 } else { 783 // Opaque... 620 // Opaque... 784 if (clipping) { 621 if (clipping) { 785 //glDisable (GL_CULL_FACE); << 622 glDisable (GL_CULL_FACE); 786 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) 623 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 787 } else { 624 } else { 788 //glEnable (GL_CULL_FACE); << 625 glEnable (GL_CULL_FACE); 789 //glCullFace (GL_BACK); << 626 glCullFace (GL_BACK); 790 glPolygonMode (GL_FRONT, GL_LINE); 627 glPolygonMode (GL_FRONT, GL_LINE); 791 } 628 } 792 } 629 } 793 glDisable (GL_LIGHTING); 630 glDisable (GL_LIGHTING); 794 glColor4fv (current_colour); 631 glColor4fv (current_colour); 795 fEdgeFlag = true; << 796 glBegin (GL_QUADS); 632 glBegin (GL_QUADS); 797 glEdgeFlag (GL_TRUE); << 798 fEdgeFlag = true; << 799 for (int edgeCount = 0; edgeCount < 4; + 633 for (int edgeCount = 0; edgeCount < 4; ++edgeCount) { 800 if (edgeFlag[edgeCount] > 0) { << 634 if (edgeFlag[edgeCount] > 0) { 801 if (fEdgeFlag != true) { << 635 glEdgeFlag (GL_TRUE); 802 glEdgeFlag (GL_TRUE); << 636 } else { 803 fEdgeFlag = true; << 637 glEdgeFlag (GL_FALSE); 804 } << 638 } 805 } else { << 639 glNormal3d (normals[edgeCount].x(), 806 if (fEdgeFlag != false) { << 640 normals[edgeCount].y(), 807 glEdgeFlag (GL_FALSE); << 641 normals[edgeCount].z()); 808 fEdgeFlag = false; << 642 glVertex3d (vertex[edgeCount].x(), 809 } << 643 vertex[edgeCount].y(), 810 } << 644 vertex[edgeCount].z()); 811 glNormal3d (normals[edgeCount].x(), << 812 normals[edgeCount].y(), << 813 normals[edgeCount].z()); << 814 glVertex3d (vertex[edgeCount].x(), << 815 vertex[edgeCount].y(), << 816 vertex[edgeCount].z()); << 817 } 645 } 818 glEnd (); 646 glEnd (); 819 << 820 glDepthFunc (GL_LEQUAL); // Revert for 647 glDepthFunc (GL_LEQUAL); // Revert for next facet. 821 fEdgeFlag = true; << 822 glBegin (GL_QUADS); // Ready for ne 648 glBegin (GL_QUADS); // Ready for next facet. GL 823 glEdgeFlag (GL_TRUE); << 649 // says it ignores incomplete 824 fEdgeFlag = true; << 650 // quadrilaterals, so final empty 825 // says it ignores incomplete << 651 // glBegin/End sequence should be OK. 826 // quadrilaterals, so final empty << 827 // glBegin/End sequence should be OK. << 828 } 652 } 829 } while (notLastFace); 653 } while (notLastFace); 830 654 831 glEnd (); 655 glEnd (); 832 glDisable (GL_STENCIL_TEST); // Revert to d 656 glDisable (GL_STENCIL_TEST); // Revert to default for next primitive. 833 glDepthMask (GL_TRUE); // Revert to d 657 glDepthMask (GL_TRUE); // Revert to default for next primitive. 834 glDisable (GL_LIGHTING); // Revert to d 658 glDisable (GL_LIGHTING); // Revert to default for next primitive. 835 } 659 } 836 660 >> 661 //Method for handling G4NURBS objects for drawing solids. >> 662 //Knots and Ctrl Pnts MUST be arrays of GLfloats. >> 663 void G4OpenGLSceneHandler::AddPrimitive (const G4NURBS& nurb) { >> 664 >> 665 GLUnurbsObj *gl_nurb; >> 666 gl_nurb = gluNewNurbsRenderer (); >> 667 >> 668 GLfloat *u_knot_array, *u_knot_array_ptr; >> 669 u_knot_array = u_knot_array_ptr = new GLfloat [nurb.GetnbrKnots(G4NURBS::U)]; >> 670 G4NURBS::KnotsIterator u_iterator (nurb, G4NURBS::U); >> 671 while (u_iterator.pick (u_knot_array_ptr++)){} >> 672 >> 673 GLfloat *v_knot_array, *v_knot_array_ptr; >> 674 v_knot_array = v_knot_array_ptr = new GLfloat [nurb.GetnbrKnots(G4NURBS::V)]; >> 675 G4NURBS::KnotsIterator v_iterator (nurb, G4NURBS::V); >> 676 while (v_iterator.pick (v_knot_array_ptr++)){} >> 677 >> 678 GLfloat *ctrl_pnt_array, *ctrl_pnt_array_ptr; >> 679 ctrl_pnt_array = ctrl_pnt_array_ptr = >> 680 new GLfloat [nurb.GettotalnbrCtrlPts () * G4NURBS::NofC]; >> 681 G4NURBS::CtrlPtsCoordsIterator c_p_iterator (nurb); >> 682 while (c_p_iterator.pick (ctrl_pnt_array_ptr++)){} >> 683 >> 684 // Get vis attributes - pick up defaults if none. >> 685 const G4VisAttributes* pVA = >> 686 fpViewer -> GetApplicableVisAttributes (nurb.GetVisAttributes ()); >> 687 >> 688 // Get view parameters that the user can force through the vis >> 689 // attributes, thereby over-riding the current view parameter. >> 690 G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA); >> 691 //G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA); >> 692 >> 693 //Get colour, etc.. >> 694 const G4Colour& c = pVA -> GetColour (); >> 695 >> 696 switch (drawing_style) { >> 697 >> 698 case (G4ViewParameters::hlhsr): >> 699 // G4cout << "Hidden line removal not implememented in G4OpenGL.\n" >> 700 // << "Using hidden surface removal." << G4endl; >> 701 case (G4ViewParameters::hsr): >> 702 { >> 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 (); >> 711 materialColour [1] = c.GetGreen (); >> 712 materialColour [2] = c.GetBlue (); >> 713 materialColour [3] = 1.0; // = c.GetAlpha () for transparency - >> 714 // but see complication in >> 715 // AddPrimitive(const G4Polyhedron&). >> 716 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour); >> 717 break; >> 718 } >> 719 case (G4ViewParameters::hlr): >> 720 // G4cout << "Hidden line removal not implememented in G4OpenGL.\n" >> 721 // << "Using wireframe." << G4endl; >> 722 case (G4ViewParameters::wireframe): >> 723 default: >> 724 glDisable (GL_LIGHTING); >> 725 // glDisable (GL_DEPTH_TEST); >> 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); >> 731 glColor4d(c.GetRed(), c.GetGreen(), c.GetBlue(),c.GetAlpha()); >> 732 break; >> 733 } >> 734 >> 735 gluBeginSurface (gl_nurb); >> 736 G4int u_stride = 4; >> 737 G4int v_stride = nurb.GetnbrCtrlPts(G4NURBS::U) * 4; >> 738 >> 739 gluNurbsSurface (gl_nurb, >> 740 nurb.GetnbrKnots (G4NURBS::U), (GLfloat*)u_knot_array, >> 741 nurb.GetnbrKnots (G4NURBS::V), (GLfloat*)v_knot_array, >> 742 u_stride, >> 743 v_stride, >> 744 ctrl_pnt_array, >> 745 nurb.GetUorder (), >> 746 nurb.GetVorder (), >> 747 GL_MAP2_VERTEX_4); >> 748 >> 749 gluEndSurface (gl_nurb); >> 750 >> 751 delete [] u_knot_array; // These should be allocated with smart allocators >> 752 delete [] v_knot_array; // to avoid memory explosion. >> 753 delete [] ctrl_pnt_array; >> 754 >> 755 gluDeleteNurbsRenderer (gl_nurb); >> 756 } >> 757 837 void G4OpenGLSceneHandler::AddCompound(const G 758 void G4OpenGLSceneHandler::AddCompound(const G4VTrajectory& traj) { 838 G4VSceneHandler::AddCompound(traj); // For 759 G4VSceneHandler::AddCompound(traj); // For now. 839 } 760 } 840 761 841 void G4OpenGLSceneHandler::AddCompound(const G 762 void G4OpenGLSceneHandler::AddCompound(const G4VHit& hit) { 842 G4VSceneHandler::AddCompound(hit); // For n 763 G4VSceneHandler::AddCompound(hit); // For now. 843 } 764 } 844 765 845 void G4OpenGLSceneHandler::AddCompound(const G 766 void G4OpenGLSceneHandler::AddCompound(const G4VDigi& digi) { 846 G4VSceneHandler::AddCompound(digi); // For 767 G4VSceneHandler::AddCompound(digi); // For now. 847 } 768 } 848 769 849 void G4OpenGLSceneHandler::AddCompound(const G 770 void G4OpenGLSceneHandler::AddCompound(const G4THitsMap<G4double>& hits) { 850 G4VSceneHandler::AddCompound(hits); // For 771 G4VSceneHandler::AddCompound(hits); // For now. 851 } 772 } 852 773 853 void G4OpenGLSceneHandler::AddCompound(const G << 774 #endif 854 G4VSceneHandler::AddCompound(hits); // For << 855 } << 856 << 857 void G4OpenGLSceneHandler::AddCompound(const G << 858 StandardSpecialMeshRendering(mesh); << 859 } << 860 775