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