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