| 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4OpenGLSceneHandler.cc,v 1.56 2009/10/21 15:18:43 allison Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 29 | //
|
|---|
| 30 | //
|
|---|
| 31 | // Andrew Walkden 27th March 1996
|
|---|
| 32 | // OpenGL stored scene - creates OpenGL display lists.
|
|---|
| 33 | // OpenGL immediate scene - draws immediately to buffer
|
|---|
| 34 | // (saving space on server).
|
|---|
| 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 | {}
|
|---|
| 77 |
|
|---|
| 78 | G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
|
|---|
| 79 | {
|
|---|
| 80 | ClearStore ();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
|
|---|
| 84 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 85 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 86 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 87 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 88 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 89 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 90 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 91 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 92 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 93 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 94 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 95 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 96 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 97 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 98 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
|
|---|
| 99 | 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
|
|---|
| 100 | };
|
|---|
| 101 |
|
|---|
| 102 | void G4OpenGLSceneHandler::ClearAndDestroyAtts()
|
|---|
| 103 | {
|
|---|
| 104 | std::map<GLuint, G4AttHolder*>::iterator i;
|
|---|
| 105 | for (i = fPickMap.begin(); i != fPickMap.end(); ++i) delete i->second;
|
|---|
| 106 | fPickMap.clear();
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | void G4OpenGLSceneHandler::PreAddSolid
|
|---|
| 110 | (const G4Transform3D& objectTransformation,
|
|---|
| 111 | const G4VisAttributes& visAttribs)
|
|---|
| 112 | {
|
|---|
| 113 | G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | void G4OpenGLSceneHandler::BeginPrimitives
|
|---|
| 117 | (const G4Transform3D& objectTransformation)
|
|---|
| 118 | {
|
|---|
| 119 | G4VSceneHandler::BeginPrimitives (objectTransformation);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void G4OpenGLSceneHandler::EndPrimitives ()
|
|---|
| 123 | {
|
|---|
| 124 | G4VSceneHandler::EndPrimitives ();
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | void G4OpenGLSceneHandler::BeginPrimitives2D
|
|---|
| 128 | (const G4Transform3D& objectTransformation)
|
|---|
| 129 | {
|
|---|
| 130 | G4VSceneHandler::BeginPrimitives2D (objectTransformation);
|
|---|
| 131 | fProcessing2D = true;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | void G4OpenGLSceneHandler::EndPrimitives2D ()
|
|---|
| 135 | {
|
|---|
| 136 | fProcessing2D = false;
|
|---|
| 137 | G4VSceneHandler::EndPrimitives2D ();
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | const G4Polyhedron* G4OpenGLSceneHandler::CreateSectionPolyhedron ()
|
|---|
| 141 | {
|
|---|
| 142 | // Clipping done in G4OpenGLViewer::SetView.
|
|---|
| 143 | return 0;
|
|---|
| 144 |
|
|---|
| 145 | // But...OpenGL no longer seems to reconstruct clipped edges, so,
|
|---|
| 146 | // when the BooleanProcessor is up to it, abandon this and use
|
|---|
| 147 | // generic clipping in G4VSceneHandler::CreateSectionPolyhedron...
|
|---|
| 148 | // return G4VSceneHandler::CreateSectionPolyhedron();
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | const G4Polyhedron* G4OpenGLSceneHandler::CreateCutawayPolyhedron ()
|
|---|
| 152 | {
|
|---|
| 153 | // Cutaway done in G4OpenGLViewer::SetView.
|
|---|
| 154 | return 0;
|
|---|
| 155 |
|
|---|
| 156 | // But...if not, when the BooleanProcessor is up to it...
|
|---|
| 157 | // return G4VSceneHandler::CreateCutawayPolyhedron();
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
|
|---|
| 161 | {
|
|---|
| 162 | G4int nPoints = line.size ();
|
|---|
| 163 | if (nPoints <= 0) return;
|
|---|
| 164 |
|
|---|
| 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);}
|
|---|
| 177 |
|
|---|
| 178 | glDisable (GL_LIGHTING);
|
|---|
| 179 |
|
|---|
| 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 |
|
|---|
| 187 | glBegin (GL_LINE_STRIP);
|
|---|
| 188 | for (G4int iPoint = 0; iPoint < nPoints; iPoint++) {
|
|---|
| 189 | G4double x, y, z;
|
|---|
| 190 | x = line[iPoint].x();
|
|---|
| 191 | y = line[iPoint].y();
|
|---|
| 192 | z = line[iPoint].z();
|
|---|
| 193 | glVertex3d (x, y, z);
|
|---|
| 194 | }
|
|---|
| 195 | glEnd ();
|
|---|
| 196 | }
|
|---|
| 197 |
|
|---|
| 198 | void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
|
|---|
| 199 | {
|
|---|
| 200 | G4int nPoints = polymarker.size ();
|
|---|
| 201 | if (nPoints <= 0) return;
|
|---|
| 202 |
|
|---|
| 203 | fProcessingPolymarker = true;
|
|---|
| 204 |
|
|---|
| 205 | // Loads G4Atts for picking...
|
|---|
| 206 | if (fpViewer->GetViewParameters().IsPicking()) {
|
|---|
| 207 | G4AttHolder* holder = new G4AttHolder;
|
|---|
| 208 | LoadAtts(polymarker, holder);
|
|---|
| 209 | fPickMap[fPickName] = holder;
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | switch (polymarker.GetMarkerType()) {
|
|---|
| 213 | default:
|
|---|
| 214 | case G4Polymarker::dots:
|
|---|
| 215 | {
|
|---|
| 216 | for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
|---|
| 217 | G4Circle dot (polymarker);
|
|---|
| 218 | dot.SetPosition (polymarker[iPoint]);
|
|---|
| 219 | dot.SetWorldSize (0.);
|
|---|
| 220 | dot.SetScreenSize (0.1); // Very small circle.
|
|---|
| 221 | G4OpenGLSceneHandler::AddPrimitive (dot);
|
|---|
| 222 | }
|
|---|
| 223 | }
|
|---|
| 224 | break;
|
|---|
| 225 | case G4Polymarker::circles:
|
|---|
| 226 | {
|
|---|
| 227 | for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
|---|
| 228 | G4Circle circle (polymarker);
|
|---|
| 229 | circle.SetPosition (polymarker[iPoint]);
|
|---|
| 230 | G4OpenGLSceneHandler::AddPrimitive (circle);
|
|---|
| 231 | }
|
|---|
| 232 | }
|
|---|
| 233 | break;
|
|---|
| 234 | case G4Polymarker::squares:
|
|---|
| 235 | {
|
|---|
| 236 | for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
|
|---|
| 237 | G4Square square (polymarker);
|
|---|
| 238 | square.SetPosition (polymarker[iPoint]);
|
|---|
| 239 | G4OpenGLSceneHandler::AddPrimitive (square);
|
|---|
| 240 | }
|
|---|
| 241 | }
|
|---|
| 242 | break;
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | fProcessingPolymarker = false;
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) {
|
|---|
| 249 |
|
|---|
| 250 | // Loads G4Atts for picking...
|
|---|
| 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();
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) {
|
|---|
| 297 | glEnable (GL_POINT_SMOOTH);
|
|---|
| 298 | AddCircleSquare (circle, G4OpenGLBitMapStore::circle);
|
|---|
| 299 | }
|
|---|
| 300 |
|
|---|
| 301 | void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) {
|
|---|
| 302 | glDisable (GL_POINT_SMOOTH);
|
|---|
| 303 | AddCircleSquare (square, G4OpenGLBitMapStore::square);
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 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);
|
|---|
| 434 | }
|
|---|
| 435 |
|
|---|
| 436 | //Method for handling G4Polyhedron objects for drawing solids.
|
|---|
| 437 | void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
|
|---|
| 438 |
|
|---|
| 439 | // Assume all facets are planar convex quadrilaterals.
|
|---|
| 440 | // Draw each facet individually
|
|---|
| 441 |
|
|---|
| 442 | if (polyhedron.GetNoFacets() == 0) return;
|
|---|
| 443 |
|
|---|
| 444 | // Loads G4Atts for picking...
|
|---|
| 445 | if (fpViewer->GetViewParameters().IsPicking()) {
|
|---|
| 446 | G4AttHolder* holder = new G4AttHolder;
|
|---|
| 447 | LoadAtts(polyhedron, holder);
|
|---|
| 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 |
|
|---|
| 455 | // Get view parameters that the user can force through the vis
|
|---|
| 456 | // attributes, thereby over-riding the current view parameter.
|
|---|
| 457 | G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
|
|---|
| 458 |
|
|---|
| 459 | //Get colour, etc...
|
|---|
| 460 | G4bool transparency_enabled = true;
|
|---|
| 461 | G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
|---|
| 462 | if (pViewer) transparency_enabled = pViewer->transparency_enabled;
|
|---|
| 463 | const G4Colour& c = pVA->GetColour();
|
|---|
| 464 | GLfloat materialColour [4];
|
|---|
| 465 | materialColour [0] = c.GetRed ();
|
|---|
| 466 | materialColour [1] = c.GetGreen ();
|
|---|
| 467 | materialColour [2] = c.GetBlue ();
|
|---|
| 468 | if (transparency_enabled) {
|
|---|
| 469 | materialColour [3] = c.GetAlpha ();
|
|---|
| 470 | } else {
|
|---|
| 471 | materialColour [3] = 1.;
|
|---|
| 472 | }
|
|---|
| 473 |
|
|---|
| 474 | G4double lineWidth = GetLineWidth(pVA);
|
|---|
| 475 | glLineWidth(lineWidth);
|
|---|
| 476 |
|
|---|
| 477 | GLfloat clear_colour[4];
|
|---|
| 478 | glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
|
|---|
| 479 |
|
|---|
| 480 | G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
|
|---|
| 481 |
|
|---|
| 482 | G4bool clipping = pViewer->fVP.IsSection() || pViewer->fVP.IsCutaway();
|
|---|
| 483 |
|
|---|
| 484 | // Lighting disabled unless otherwise requested
|
|---|
| 485 | glDisable (GL_LIGHTING);
|
|---|
| 486 |
|
|---|
| 487 | switch (drawing_style) {
|
|---|
| 488 | case (G4ViewParameters::hlhsr):
|
|---|
| 489 | // Set up as for hidden line removal but paint polygon faces later...
|
|---|
| 490 | case (G4ViewParameters::hlr):
|
|---|
| 491 | glEnable (GL_STENCIL_TEST);
|
|---|
| 492 | // The stencil buffer is cleared in G4OpenGLViewer::ClearView.
|
|---|
| 493 | // The procedure below leaves it clear.
|
|---|
| 494 | glStencilFunc (GL_ALWAYS, 0, 1);
|
|---|
| 495 | glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
|
|---|
| 496 | glEnable (GL_DEPTH_TEST);
|
|---|
| 497 | glDepthFunc (GL_LEQUAL);
|
|---|
| 498 | if (materialColour[3] < 1.) {
|
|---|
| 499 | // Transparent...
|
|---|
| 500 | glDisable (GL_CULL_FACE);
|
|---|
| 501 | glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
|---|
| 502 | } else {
|
|---|
| 503 | // Opaque...
|
|---|
| 504 | if (clipping) {
|
|---|
| 505 | glDisable (GL_CULL_FACE);
|
|---|
| 506 | glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
|---|
| 507 | } else {
|
|---|
| 508 | glEnable (GL_CULL_FACE);
|
|---|
| 509 | glCullFace (GL_BACK);
|
|---|
| 510 | glPolygonMode (GL_FRONT, GL_LINE);
|
|---|
| 511 | }
|
|---|
| 512 | }
|
|---|
| 513 | glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
|---|
| 514 | break;
|
|---|
| 515 | case (G4ViewParameters::hsr):
|
|---|
| 516 | glEnable (GL_DEPTH_TEST);
|
|---|
| 517 | glDepthFunc (GL_LEQUAL);
|
|---|
| 518 | if (materialColour[3] < 1.) {
|
|---|
| 519 | // Transparent...
|
|---|
| 520 | glDepthMask (0); // Make depth buffer read-only.
|
|---|
| 521 | glDisable (GL_CULL_FACE);
|
|---|
| 522 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
|---|
| 523 | glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, materialColour);
|
|---|
| 524 | } else {
|
|---|
| 525 | // Opaque...
|
|---|
| 526 | glDepthMask (1); // Make depth buffer writable (default).
|
|---|
| 527 | if (clipping) {
|
|---|
| 528 | glDisable (GL_CULL_FACE);
|
|---|
| 529 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
|---|
| 530 | } else {
|
|---|
| 531 | glEnable (GL_CULL_FACE);
|
|---|
| 532 | glCullFace (GL_BACK);
|
|---|
| 533 | glPolygonMode (GL_FRONT, GL_FILL);
|
|---|
| 534 | }
|
|---|
| 535 | glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColour);
|
|---|
| 536 | }
|
|---|
| 537 | if (!fProcessing2D) glEnable (GL_LIGHTING);
|
|---|
| 538 | break;
|
|---|
| 539 | case (G4ViewParameters::wireframe):
|
|---|
| 540 | default:
|
|---|
| 541 | glEnable (GL_DEPTH_TEST);
|
|---|
| 542 | glDepthFunc (GL_LEQUAL); //??? was GL_ALWAYS
|
|---|
| 543 | glDisable (GL_CULL_FACE);
|
|---|
| 544 | glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
|---|
| 545 | glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
|---|
| 546 | break;
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | //Loop through all the facets...
|
|---|
| 550 | glBegin (GL_QUADS);
|
|---|
| 551 | G4bool notLastFace;
|
|---|
| 552 | do {
|
|---|
| 553 |
|
|---|
| 554 | //First, find vertices, edgeflags and normals and note "not last facet"...
|
|---|
| 555 | G4Point3D vertex[4];
|
|---|
| 556 | G4int edgeFlag[4];
|
|---|
| 557 | G4Normal3D normals[4];
|
|---|
| 558 | G4int n;
|
|---|
| 559 | notLastFace = polyhedron.GetNextFacet(n, vertex, edgeFlag, normals);
|
|---|
| 560 |
|
|---|
| 561 | //Loop through the four edges of each G4Facet...
|
|---|
| 562 | G4int edgeCount = 0;
|
|---|
| 563 | for(edgeCount = 0; edgeCount < n; ++edgeCount) {
|
|---|
| 564 | // Check to see if edge is visible or not...
|
|---|
| 565 | if (isAuxEdgeVisible) {
|
|---|
| 566 | edgeFlag[edgeCount] = 1;
|
|---|
| 567 | }
|
|---|
| 568 | if (edgeFlag[edgeCount] > 0) {
|
|---|
| 569 | glEdgeFlag (GL_TRUE);
|
|---|
| 570 | } else {
|
|---|
| 571 | glEdgeFlag (GL_FALSE);
|
|---|
| 572 | }
|
|---|
| 573 | glNormal3d (normals[edgeCount].x(),
|
|---|
| 574 | normals[edgeCount].y(),
|
|---|
| 575 | normals[edgeCount].z());
|
|---|
| 576 | glVertex3d (vertex[edgeCount].x(),
|
|---|
| 577 | vertex[edgeCount].y(),
|
|---|
| 578 | vertex[edgeCount].z());
|
|---|
| 579 | }
|
|---|
| 580 | // HepPolyhedron produces triangles too; in that case add an extra
|
|---|
| 581 | // vertex identical to first...
|
|---|
| 582 | if (n == 3) {
|
|---|
| 583 | edgeCount = 3;
|
|---|
| 584 | normals[edgeCount] = normals[0];
|
|---|
| 585 | vertex[edgeCount] = vertex[0];
|
|---|
| 586 | edgeFlag[edgeCount] = -1;
|
|---|
| 587 | glEdgeFlag (GL_FALSE);
|
|---|
| 588 | glNormal3d (normals[edgeCount].x(),
|
|---|
| 589 | normals[edgeCount].y(),
|
|---|
| 590 | normals[edgeCount].z());
|
|---|
| 591 | glVertex3d (vertex[edgeCount].x(),
|
|---|
| 592 | vertex[edgeCount].y(),
|
|---|
| 593 | vertex[edgeCount].z());
|
|---|
| 594 | }
|
|---|
| 595 | // Trap situation where number of edges is > 4...
|
|---|
| 596 | if (n > 4) {
|
|---|
| 597 | G4cerr <<
|
|---|
| 598 | "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING";
|
|---|
| 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;
|
|---|
| 611 | }
|
|---|
| 612 |
|
|---|
| 613 | // Do it all over again (twice) for hlr...
|
|---|
| 614 | if (drawing_style == G4ViewParameters::hlr ||
|
|---|
| 615 | drawing_style == G4ViewParameters::hlhsr) {
|
|---|
| 616 |
|
|---|
| 617 | glEnd (); // Placed here to balance glBegin above, allowing GL
|
|---|
| 618 | // state changes below, then glBegin again. Avoids
|
|---|
| 619 | // having glBegin/End pairs *inside* loop in the more
|
|---|
| 620 | // usual case of no hidden line removal.
|
|---|
| 621 |
|
|---|
| 622 | // Lighting disabled unless otherwise requested
|
|---|
| 623 | glDisable (GL_LIGHTING);
|
|---|
| 624 |
|
|---|
| 625 | // Draw through stencil...
|
|---|
| 626 | glStencilFunc (GL_EQUAL, 0, 1);
|
|---|
| 627 | glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
|
|---|
| 628 | if (drawing_style == G4ViewParameters::hlhsr) {
|
|---|
| 629 | if (!fProcessing2D) glEnable (GL_LIGHTING);
|
|---|
| 630 | }
|
|---|
| 631 | glEnable (GL_DEPTH_TEST);
|
|---|
| 632 | glDepthFunc (GL_LEQUAL);
|
|---|
| 633 | if (materialColour[3] < 1.) {
|
|---|
| 634 | // Transparent...
|
|---|
| 635 | glDepthMask (0); // Make depth buffer read-only.
|
|---|
| 636 | glDisable (GL_CULL_FACE);
|
|---|
| 637 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
|---|
| 638 | } else {
|
|---|
| 639 | // Opaque...
|
|---|
| 640 | glDepthMask (1); // Make depth buffer writable (default).
|
|---|
| 641 | if (clipping) {
|
|---|
| 642 | glDisable (GL_CULL_FACE);
|
|---|
| 643 | glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
|
|---|
| 644 | } else {
|
|---|
| 645 | glEnable (GL_CULL_FACE);
|
|---|
| 646 | glCullFace (GL_BACK);
|
|---|
| 647 | glPolygonMode (GL_FRONT, GL_FILL);
|
|---|
| 648 | }
|
|---|
| 649 | }
|
|---|
| 650 | GLfloat* painting_colour;
|
|---|
| 651 | if (drawing_style == G4ViewParameters::hlr) {
|
|---|
| 652 | if (materialColour[3] < 1.) {
|
|---|
| 653 | // Transparent - don't paint...
|
|---|
| 654 | goto end_of_drawing_through_stencil;
|
|---|
| 655 | }
|
|---|
| 656 | painting_colour = clear_colour;
|
|---|
| 657 | } else { // drawing_style == G4ViewParameters::hlhsr
|
|---|
| 658 | painting_colour = materialColour;
|
|---|
| 659 | }
|
|---|
| 660 | if (materialColour[3] < 1.) {
|
|---|
| 661 | // Transparent...
|
|---|
| 662 | glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
|
|---|
| 663 | } else {
|
|---|
| 664 | // Opaque...
|
|---|
| 665 | glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
|
|---|
| 666 | }
|
|---|
| 667 | glColor4fv (painting_colour);
|
|---|
| 668 | glBegin (GL_QUADS);
|
|---|
| 669 | for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
|
|---|
| 670 | if (edgeFlag[edgeCount] > 0) {
|
|---|
| 671 | glEdgeFlag (GL_TRUE);
|
|---|
| 672 | } else {
|
|---|
| 673 | glEdgeFlag (GL_FALSE);
|
|---|
| 674 | }
|
|---|
| 675 | glNormal3d (normals[edgeCount].x(),
|
|---|
| 676 | normals[edgeCount].y(),
|
|---|
| 677 | normals[edgeCount].z());
|
|---|
| 678 | glVertex3d (vertex[edgeCount].x(),
|
|---|
| 679 | vertex[edgeCount].y(),
|
|---|
| 680 | vertex[edgeCount].z());
|
|---|
| 681 | }
|
|---|
| 682 | glEnd ();
|
|---|
| 683 | end_of_drawing_through_stencil:
|
|---|
| 684 |
|
|---|
| 685 | // and once more to reset the stencil bits...
|
|---|
| 686 | glStencilFunc (GL_ALWAYS, 0, 1);
|
|---|
| 687 | glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
|
|---|
| 688 | glDepthFunc (GL_LEQUAL); // to make sure line gets drawn.
|
|---|
| 689 | if (materialColour[3] < 1.) {
|
|---|
| 690 | // Transparent...
|
|---|
| 691 | glDisable (GL_CULL_FACE);
|
|---|
| 692 | glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
|---|
| 693 | } else {
|
|---|
| 694 | // Opaque...
|
|---|
| 695 | if (clipping) {
|
|---|
| 696 | glDisable (GL_CULL_FACE);
|
|---|
| 697 | glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
|
|---|
| 698 | } else {
|
|---|
| 699 | glEnable (GL_CULL_FACE);
|
|---|
| 700 | glCullFace (GL_BACK);
|
|---|
| 701 | glPolygonMode (GL_FRONT, GL_LINE);
|
|---|
| 702 | }
|
|---|
| 703 | }
|
|---|
| 704 | glDisable (GL_LIGHTING);
|
|---|
| 705 | glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
|---|
| 706 | glBegin (GL_QUADS);
|
|---|
| 707 | for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
|
|---|
| 708 | if (edgeFlag[edgeCount] > 0) {
|
|---|
| 709 | glEdgeFlag (GL_TRUE);
|
|---|
| 710 | } else {
|
|---|
| 711 | glEdgeFlag (GL_FALSE);
|
|---|
| 712 | }
|
|---|
| 713 | glNormal3d (normals[edgeCount].x(),
|
|---|
| 714 | normals[edgeCount].y(),
|
|---|
| 715 | normals[edgeCount].z());
|
|---|
| 716 | glVertex3d (vertex[edgeCount].x(),
|
|---|
| 717 | vertex[edgeCount].y(),
|
|---|
| 718 | vertex[edgeCount].z());
|
|---|
| 719 | }
|
|---|
| 720 | glEnd ();
|
|---|
| 721 | glDepthFunc (GL_LEQUAL); // Revert for next facet.
|
|---|
| 722 | glBegin (GL_QUADS); // Ready for next facet. GL
|
|---|
| 723 | // says it ignores incomplete
|
|---|
| 724 | // quadrilaterals, so final empty
|
|---|
| 725 | // glBegin/End sequence should be OK.
|
|---|
| 726 | }
|
|---|
| 727 | } while (notLastFace);
|
|---|
| 728 |
|
|---|
| 729 | glEnd ();
|
|---|
| 730 | glDisable (GL_STENCIL_TEST); // Revert to default for next primitive.
|
|---|
| 731 | glDepthMask (1); // Revert to default for next primitive.
|
|---|
| 732 | glDisable (GL_LIGHTING); // Revert to default for next primitive.
|
|---|
| 733 | }
|
|---|
| 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 |
|
|---|
| 839 | void G4OpenGLSceneHandler::AddCompound(const G4VTrajectory& traj) {
|
|---|
| 840 | G4VSceneHandler::AddCompound(traj); // For now.
|
|---|
| 841 | }
|
|---|
| 842 |
|
|---|
| 843 | void G4OpenGLSceneHandler::AddCompound(const G4VHit& hit) {
|
|---|
| 844 | G4VSceneHandler::AddCompound(hit); // For now.
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | void G4OpenGLSceneHandler::AddCompound(const G4THitsMap<G4double>& hits) {
|
|---|
| 848 | G4VSceneHandler::AddCompound(hits); // For now.
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | #endif
|
|---|