Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 // 28 // 29 // Andrew Walkden 10th February 1997 30 // OpenGL immediate scene - draws immediately 31 // (saving space on 32 33 #include "G4OpenGLImmediateSceneHandler.hh" 34 35 #include "G4OpenGLViewer.hh" 36 #include "G4OpenGLTransform3D.hh" 37 #include "G4Polyline.hh" 38 #include "G4Polymarker.hh" 39 #include "G4Text.hh" 40 #include "G4Circle.hh" 41 #include "G4Square.hh" 42 #include "G4Polyhedron.hh" 43 #include "G4AttHolder.hh" 44 45 #include <typeinfo> 46 47 G4OpenGLImmediateSceneHandler::G4OpenGLImmedia 48 (G4VGraphicsSystem& system,const G4String& nam 49 G4OpenGLSceneHandler (system, fSceneIdCount+ 50 {} 51 52 G4OpenGLImmediateSceneHandler::~G4OpenGLImmedi 53 {} 54 55 #include <iomanip> 56 57 G4bool G4OpenGLImmediateSceneHandler::AddPrimi 58 { 59 return AddPrimitivePreambleInternal(visibl 60 } 61 G4bool G4OpenGLImmediateSceneHandler::AddPrimi 62 { 63 return AddPrimitivePreambleInternal(visible, 64 } 65 G4bool G4OpenGLImmediateSceneHandler::AddPrimi 66 { 67 return AddPrimitivePreambleInternal(visible, 68 } 69 70 G4bool G4OpenGLImmediateSceneHandler::AddPrimi 71 { 72 // Get applicable vis attributes for all pri 73 fpVisAttribs = fpViewer->GetApplicableVisAtt 74 const G4Colour& c = GetColour (); 75 G4double opacity = c.GetAlpha (); 76 77 G4bool transparency_enabled = true; 78 G4bool isMarkerNotHidden = true; 79 G4OpenGLViewer* pViewer = dynamic_cast<G4Ope 80 if (pViewer) { 81 transparency_enabled = pViewer->transparen 82 isMarkerNotHidden = pViewer->fVP.IsMarkerN 83 } 84 85 G4bool isMarkerOrPolyline = isMarker || isPo 86 G4bool treatAsTransparent = transparency_ena 87 G4bool treatAsNotHidden = isMarkerNotHidden 88 89 if (fProcessing2D) glDisable (GL_DEPTH_TEST) 90 else { 91 if (isMarkerOrPolyline && isMarkerNotHidde 92 glDisable (GL_DEPTH_TEST); 93 else {glEnable (GL_DEPTH_TEST); glDepthFun 94 } 95 96 if (fThreePassCapable) { 97 98 // Ensure transparent objects are drawn op 99 // non-hidden markers. The problem of ble 100 // is quite a tricky one - see History of 101 if (!(fSecondPassForTransparency || fThird 102 // First pass... 103 if (treatAsTransparent) { // Request pa 104 fSecondPassForTransparencyRequested = 105 } 106 if (treatAsNotHidden) { // Request pa 107 fThirdPassForNonHiddenMarkersRequested 108 } 109 // On first pass, transparent objects an 110 if (treatAsTransparent || treatAsNotHidd 111 return false; 112 } 113 } 114 115 // On second pass, only transparent object 116 if (fSecondPassForTransparency) { 117 if (!treatAsTransparent) { 118 return false; 119 } 120 } 121 122 // On third pass, only non-hidden markers 123 if (fThirdPassForNonHiddenMarkers) { 124 if (!treatAsNotHidden) { 125 return false; 126 } 127 } 128 } // fThreePassCapable 129 130 // Loads G4Atts for picking... 131 if (fpViewer->GetViewParameters().IsPicking( 132 glLoadName(++fPickName); 133 G4AttHolder* holder = new G4AttHolder; 134 LoadAtts(visible, holder); 135 fPickMap[fPickName] = holder; 136 } 137 138 if (transparency_enabled) { 139 glColor4d(c.GetRed(),c.GetGreen(),c.GetBlu 140 } else { 141 glColor3d(c.GetRed(),c.GetGreen(),c.GetBlu 142 } 143 144 return true; 145 } 146 147 void G4OpenGLImmediateSceneHandler::AddPrimiti 148 { 149 G4bool furtherprocessing = AddPrimitivePream 150 if (furtherprocessing) { 151 G4OpenGLSceneHandler::AddPrimitive(polylin 152 } 153 } 154 155 void G4OpenGLImmediateSceneHandler::AddPrimiti 156 { 157 G4bool furtherprocessing = AddPrimitivePream 158 if (furtherprocessing) { 159 G4OpenGLSceneHandler::AddPrimitive(polymar 160 } 161 } 162 163 void G4OpenGLImmediateSceneHandler::AddPrimiti 164 { 165 // Note: colour is still handled in 166 // G4OpenGLSceneHandler::AddPrimitive(const 167 G4bool furtherprocessing = AddPrimitivePream 168 if (furtherprocessing) { 169 G4OpenGLSceneHandler::AddPrimitive(text); 170 } 171 } 172 173 void G4OpenGLImmediateSceneHandler::AddPrimiti 174 { 175 G4bool furtherprocessing = AddPrimitivePream 176 if (furtherprocessing) { 177 G4OpenGLSceneHandler::AddPrimitive(circle) 178 } 179 } 180 181 void G4OpenGLImmediateSceneHandler::AddPrimiti 182 { 183 G4bool furtherprocessing = AddPrimitivePream 184 if (furtherprocessing) { 185 G4OpenGLSceneHandler::AddPrimitive(square) 186 } 187 } 188 189 void G4OpenGLImmediateSceneHandler::AddPrimiti 190 { 191 // Note: colour is still handled in 192 // G4OpenGLSceneHandler::AddPrimitive(const 193 G4bool furtherprocessing = AddPrimitivePream 194 if (furtherprocessing) { 195 G4OpenGLSceneHandler::AddPrimitive(polyhed 196 } 197 } 198 199 void G4OpenGLImmediateSceneHandler::BeginPrimi 200 (const G4Transform3D& objectTransformation) 201 { 202 G4OpenGLSceneHandler::BeginPrimitives (objec 203 204 G4OpenGLTransform3D oglt (objectTransformati 205 206 glPushMatrix(); 207 208 /*************************** Check matrix. 209 const GLdouble* m = oglt.GetGLMatrix (); 210 G4cout << "G4OpenGLTransform3D matrix:"; 211 for (int i = 0; i < 16; i++) { 212 if ((i % 4) == 0) G4cout << '\n'; 213 G4cout << std::setw (15) << m[i]; 214 } 215 G4cout << G4endl; 216 *****************************************/ 217 218 glMultMatrixd (oglt.GetGLMatrix ()); 219 } 220 221 void G4OpenGLImmediateSceneHandler::EndPrimiti 222 { 223 glPopMatrix(); 224 225 // See all primitives immediately... At lea 226 ScaledFlush(); 227 228 G4OpenGLSceneHandler::EndPrimitives (); 229 } 230 231 void G4OpenGLImmediateSceneHandler::BeginPrimi 232 (const G4Transform3D& objectTransformation) 233 { 234 G4OpenGLSceneHandler::BeginPrimitives2D(obje 235 236 // Push current 3D world matrices and load i 237 // coordinates... 238 glMatrixMode (GL_PROJECTION); 239 glPushMatrix(); 240 glLoadIdentity(); 241 G4OpenGLViewer* pViewer = dynamic_cast<G4Ope 242 if (pViewer) { 243 pViewer->g4GlOrtho (-1., 1., -1., 1., -G4O 244 } 245 glMatrixMode (GL_MODELVIEW); 246 glPushMatrix(); 247 glLoadIdentity(); 248 G4OpenGLTransform3D oglt (objectTransformati 249 glMultMatrixd (oglt.GetGLMatrix ()); 250 glDisable(GL_DEPTH_TEST); // But see parent 251 glDisable (GL_LIGHTING); // some cases, we 252 } 253 254 void G4OpenGLImmediateSceneHandler::EndPrimiti 255 { 256 // Pop current 3D world matrices back again. 257 glMatrixMode (GL_PROJECTION); 258 glPopMatrix(); 259 glMatrixMode (GL_MODELVIEW); 260 glPopMatrix(); 261 262 // See all primitives immediately... At lea 263 ScaledFlush(); 264 265 G4OpenGLSceneHandler::EndPrimitives2D (); 266 } 267 268 void G4OpenGLImmediateSceneHandler::BeginModel 269 G4VSceneHandler::BeginModeling(); 270 } 271 272 void G4OpenGLImmediateSceneHandler::EndModelin 273 G4VSceneHandler::EndModeling (); 274 } 275 276 void G4OpenGLImmediateSceneHandler::ClearTrans 277 { 278 // Nothing to do except redraw the scene rea 279 if (fpViewer) { 280 fpViewer -> SetView (); 281 fpViewer -> ClearView (); 282 fpViewer -> DrawView (); 283 } 284 } 285 286 G4int G4OpenGLImmediateSceneHandler::fSceneIdC 287