[531] | 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 | // |
---|
[1346] | 27 | // $Id: G4ViewParameters.cc,v 1.38 2010/11/05 16:00:11 allison Exp $ |
---|
[954] | 28 | // GEANT4 tag $Name: $ |
---|
[531] | 29 | // |
---|
| 30 | // |
---|
| 31 | // John Allison 19th July 1996 |
---|
| 32 | // View parameters and options. |
---|
| 33 | |
---|
[1337] | 34 | #include <sstream> |
---|
| 35 | |
---|
[531] | 36 | #include "G4ViewParameters.hh" |
---|
| 37 | |
---|
| 38 | #include "G4VisManager.hh" |
---|
| 39 | #include "G4UnitsTable.hh" |
---|
| 40 | #include "G4ios.hh" |
---|
| 41 | |
---|
| 42 | G4ViewParameters::G4ViewParameters (): |
---|
[896] | 43 | fNoValue(0x0000), |
---|
| 44 | fXValue(0x0001), |
---|
| 45 | fYValue(0x0002), |
---|
| 46 | fWidthValue(0x0004), |
---|
| 47 | fHeightValue(0x0008), |
---|
| 48 | fAllValues(0x000F), |
---|
| 49 | fXNegative(0x0010), |
---|
| 50 | fYNegative(0x0020), |
---|
[1340] | 51 | fGeometryMask(0), |
---|
[531] | 52 | fDrawingStyle (wireframe), |
---|
| 53 | fAuxEdgeVisible (false), |
---|
| 54 | fRepStyle (polyhedron), |
---|
| 55 | fCulling (true), |
---|
| 56 | fCullInvisible (true), |
---|
| 57 | fDensityCulling (false), |
---|
| 58 | fVisibleDensity (0.01 * g / cm3), |
---|
| 59 | fCullCovered (false), |
---|
| 60 | fSection (false), |
---|
| 61 | fSectionPlane (), |
---|
| 62 | fCutawayMode (cutawayUnion), |
---|
| 63 | fCutawayPlanes (), |
---|
| 64 | fExplodeFactor (1.), |
---|
| 65 | fNoOfSides (24), |
---|
| 66 | fViewpointDirection (G4Vector3D (0., 0., 1.)), // On z-axis. |
---|
| 67 | fUpVector (G4Vector3D (0., 1., 0.)), // y-axis up. |
---|
| 68 | fFieldHalfAngle (0.), // Orthogonal projection. |
---|
| 69 | fZoomFactor (1.), |
---|
| 70 | fScaleFactor (G4Vector3D (1., 1., 1.)), |
---|
| 71 | fCurrentTargetPoint (), |
---|
| 72 | fDolly (0.), |
---|
| 73 | fLightsMoveWithCamera (false), |
---|
| 74 | fRelativeLightpointDirection (G4Vector3D (1., 1., 1.)), |
---|
| 75 | fActualLightpointDirection (G4Vector3D (1., 1., 1.)), |
---|
| 76 | fDefaultVisAttributes (), |
---|
| 77 | fDefaultTextVisAttributes (G4Colour (0., 0., 1.)), |
---|
| 78 | fDefaultMarker (), |
---|
| 79 | fGlobalMarkerScale (1.), |
---|
| 80 | fGlobalLineWidthScale (1.), |
---|
| 81 | fMarkerNotHidden (true), |
---|
| 82 | fWindowSizeHintX (600), |
---|
| 83 | fWindowSizeHintY (600), |
---|
[896] | 84 | fWindowLocationHintX(0), |
---|
| 85 | fWindowLocationHintY(0), |
---|
| 86 | fWindowLocationHintXNegative(true), |
---|
| 87 | fWindowLocationHintYNegative(false), |
---|
[531] | 88 | fAutoRefresh (false), |
---|
[593] | 89 | fBackgroundColour (G4Colour(0.,0.,0.)), // Black |
---|
| 90 | fPicking (false) |
---|
[531] | 91 | { |
---|
| 92 | fDefaultMarker.SetScreenSize (5.); |
---|
| 93 | // Markers are 5 pixels "overall" size, i.e., diameter. |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | G4ViewParameters::~G4ViewParameters () {} |
---|
| 97 | |
---|
| 98 | void G4ViewParameters::MultiplyScaleFactor |
---|
| 99 | (const G4Vector3D& scaleFactorMultiplier) { |
---|
| 100 | fScaleFactor.setX(fScaleFactor.x() * scaleFactorMultiplier.x()); |
---|
| 101 | fScaleFactor.setY(fScaleFactor.y() * scaleFactorMultiplier.y()); |
---|
| 102 | fScaleFactor.setZ(fScaleFactor.z() * scaleFactorMultiplier.z()); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | G4Vector3D& G4ViewParameters::GetActualLightpointDirection () { |
---|
| 106 | SetViewAndLights (fViewpointDirection); |
---|
| 107 | return fActualLightpointDirection; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | // Useful quantities - begin snippet. |
---|
| 111 | // Here Follow functions to evaluate the above algorithms as a |
---|
| 112 | // function of the radius of the Bounding Sphere of the object being |
---|
| 113 | // viewed. Call them in the order given - for efficiency, later |
---|
| 114 | // functions depend on the results of earlier ones (Store the |
---|
| 115 | // results of earlier functions in your own temporary variables - |
---|
| 116 | // see, for example, G4OpenGLView::SetView ().) |
---|
| 117 | |
---|
| 118 | G4double G4ViewParameters::GetCameraDistance (G4double radius) const { |
---|
| 119 | G4double cameraDistance; |
---|
| 120 | if (fFieldHalfAngle == 0.) { |
---|
| 121 | cameraDistance = radius; |
---|
| 122 | } |
---|
| 123 | else { |
---|
| 124 | cameraDistance = radius / std::sin (fFieldHalfAngle) - fDolly; |
---|
| 125 | } |
---|
| 126 | return cameraDistance; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | G4double G4ViewParameters::GetNearDistance (G4double cameraDistance, |
---|
| 130 | G4double radius) const { |
---|
| 131 | const G4double small = 1.e-6 * radius; |
---|
| 132 | G4double nearDistance = cameraDistance - radius; |
---|
| 133 | if (nearDistance < small) nearDistance = small; |
---|
| 134 | return nearDistance; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | G4double G4ViewParameters::GetFarDistance (G4double cameraDistance, |
---|
| 138 | G4double nearDistance, |
---|
| 139 | G4double radius) const { |
---|
| 140 | G4double farDistance = cameraDistance + radius; |
---|
| 141 | if (farDistance < nearDistance) farDistance = nearDistance; |
---|
| 142 | return farDistance; |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | G4double G4ViewParameters::GetFrontHalfHeight (G4double nearDistance, |
---|
| 146 | G4double radius) const { |
---|
| 147 | G4double frontHalfHeight; |
---|
| 148 | if (fFieldHalfAngle == 0.) { |
---|
| 149 | frontHalfHeight = radius / fZoomFactor; |
---|
| 150 | } |
---|
| 151 | else { |
---|
| 152 | frontHalfHeight = nearDistance * std::tan (fFieldHalfAngle) / fZoomFactor; |
---|
| 153 | } |
---|
| 154 | return frontHalfHeight; |
---|
| 155 | } |
---|
| 156 | // Useful quantities - end snippet. |
---|
| 157 | |
---|
| 158 | void G4ViewParameters::AddCutawayPlane (const G4Plane3D& cutawayPlane) { |
---|
| 159 | if (fCutawayPlanes.size () < 3 ) { |
---|
| 160 | fCutawayPlanes.push_back (cutawayPlane); |
---|
| 161 | } |
---|
| 162 | else { |
---|
| 163 | G4cout << |
---|
| 164 | "ERROR: G4ViewParameters::AddCutawayPlane:" |
---|
| 165 | "\n A maximum of 3 cutaway planes supported." << G4endl; |
---|
| 166 | } |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | void G4ViewParameters::ChangeCutawayPlane |
---|
| 170 | (size_t index, const G4Plane3D& cutawayPlane) { |
---|
| 171 | if (index >= fCutawayPlanes.size()) { |
---|
| 172 | G4cout << |
---|
| 173 | "ERROR: G4ViewParameters::ChangeCutawayPlane:" |
---|
| 174 | "\n Plane " << index << " does not exist." << G4endl; |
---|
| 175 | } else { |
---|
| 176 | fCutawayPlanes[index] = cutawayPlane; |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | void G4ViewParameters::SetVisibleDensity (G4double visibleDensity) { |
---|
| 181 | const G4double reasonableMaximum = 10.0 * g / cm3; |
---|
| 182 | if (visibleDensity < 0) { |
---|
| 183 | G4cout << "G4ViewParameters::SetVisibleDensity: attempt to set negative " |
---|
| 184 | "density - ignored." << G4endl; |
---|
| 185 | } |
---|
| 186 | else { |
---|
| 187 | if (visibleDensity > reasonableMaximum) { |
---|
| 188 | G4cout << "G4ViewParameters::SetVisibleDensity: density > " |
---|
| 189 | << G4BestUnit (reasonableMaximum, "Volumic Mass") |
---|
| 190 | << " - did you mean this?" |
---|
| 191 | << G4endl; |
---|
| 192 | } |
---|
| 193 | fVisibleDensity = visibleDensity; |
---|
| 194 | } |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | G4int G4ViewParameters::SetNoOfSides (G4int nSides) { |
---|
| 198 | const G4int nSidesMin = 12; |
---|
| 199 | if (nSides < nSidesMin) { |
---|
| 200 | nSides = nSidesMin; |
---|
| 201 | G4cout << "G4ViewParameters::SetNoOfSides: attempt to set the" |
---|
| 202 | "\nnumber of sides per circle < " << nSidesMin |
---|
| 203 | << "; forced to " << nSides << G4endl; |
---|
| 204 | } |
---|
| 205 | fNoOfSides = nSides; |
---|
| 206 | return fNoOfSides; |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | void G4ViewParameters::SetViewAndLights |
---|
| 210 | (const G4Vector3D& viewpointDirection) { |
---|
| 211 | |
---|
| 212 | fViewpointDirection = viewpointDirection; |
---|
| 213 | |
---|
| 214 | // If the requested viewpoint direction is parallel to the up |
---|
| 215 | // vector, the orientation of the view is undefined... |
---|
| 216 | if (fViewpointDirection.unit() * fUpVector.unit() > .9999) { |
---|
| 217 | G4cout << |
---|
| 218 | "WARNING: Viewpoint direction is very close to the up vector direction." |
---|
| 219 | "\n Consider setting the up vector to obtain definable behaviour." |
---|
| 220 | << G4endl; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | // Move the lights too if requested... |
---|
| 224 | if (fLightsMoveWithCamera) { |
---|
| 225 | G4Vector3D zprime = fViewpointDirection.unit (); |
---|
| 226 | G4Vector3D xprime = (fUpVector.cross (zprime)).unit (); |
---|
| 227 | G4Vector3D yprime = zprime.cross (xprime); |
---|
| 228 | fActualLightpointDirection = |
---|
| 229 | fRelativeLightpointDirection.x () * xprime + |
---|
| 230 | fRelativeLightpointDirection.y () * yprime + |
---|
| 231 | fRelativeLightpointDirection.x () * zprime; |
---|
| 232 | } else { |
---|
| 233 | fActualLightpointDirection = fRelativeLightpointDirection; |
---|
| 234 | } |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | void G4ViewParameters::SetLightpointDirection |
---|
| 238 | (const G4Vector3D& lightpointDirection) { |
---|
| 239 | fRelativeLightpointDirection = lightpointDirection; |
---|
| 240 | SetViewAndLights (fViewpointDirection); |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | void G4ViewParameters::SetPan (G4double right, G4double up) { |
---|
| 244 | G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit(); |
---|
| 245 | G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit(); |
---|
| 246 | fCurrentTargetPoint = right * unitRight + up * unitUp; |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | void G4ViewParameters::IncrementPan (G4double right, G4double up) { |
---|
[712] | 250 | IncrementPan (right,up, 0); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | void G4ViewParameters::IncrementPan (G4double right, G4double up, G4double distance) { |
---|
[531] | 254 | G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit(); |
---|
| 255 | G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit(); |
---|
[712] | 256 | fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection; |
---|
[531] | 257 | } |
---|
| 258 | |
---|
| 259 | void G4ViewParameters::PrintDifferences (const G4ViewParameters& v) const { |
---|
| 260 | |
---|
| 261 | // Put performance-sensitive parameters first. |
---|
| 262 | if ( |
---|
| 263 | // This first to optimise spin, etc. |
---|
| 264 | (fViewpointDirection != v.fViewpointDirection) || |
---|
| 265 | |
---|
| 266 | // No particular order from here on. |
---|
| 267 | (fDrawingStyle != v.fDrawingStyle) || |
---|
| 268 | (fAuxEdgeVisible != v.fAuxEdgeVisible) || |
---|
| 269 | (fRepStyle != v.fRepStyle) || |
---|
| 270 | (fCulling != v.fCulling) || |
---|
| 271 | (fCullInvisible != v.fCullInvisible) || |
---|
| 272 | (fDensityCulling != v.fDensityCulling) || |
---|
| 273 | (fVisibleDensity != v.fVisibleDensity) || |
---|
| 274 | (fCullCovered != v.fCullCovered) || |
---|
| 275 | (fSection != v.fSection) || |
---|
| 276 | (fNoOfSides != v.fNoOfSides) || |
---|
| 277 | (fUpVector != v.fUpVector) || |
---|
| 278 | (fFieldHalfAngle != v.fFieldHalfAngle) || |
---|
| 279 | (fZoomFactor != v.fZoomFactor) || |
---|
| 280 | (fScaleFactor != v.fScaleFactor) || |
---|
| 281 | (fCurrentTargetPoint != v.fCurrentTargetPoint) || |
---|
| 282 | (fDolly != v.fDolly) || |
---|
| 283 | (fRelativeLightpointDirection != v.fRelativeLightpointDirection) || |
---|
| 284 | (fLightsMoveWithCamera != v.fLightsMoveWithCamera) || |
---|
| 285 | (fDefaultVisAttributes != v.fDefaultVisAttributes) || |
---|
| 286 | (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) || |
---|
| 287 | (fDefaultMarker != v.fDefaultMarker) || |
---|
| 288 | (fGlobalMarkerScale != v.fGlobalMarkerScale) || |
---|
| 289 | (fGlobalLineWidthScale != v.fGlobalLineWidthScale) || |
---|
| 290 | (fMarkerNotHidden != v.fMarkerNotHidden) || |
---|
| 291 | (fWindowSizeHintX != v.fWindowSizeHintX) || |
---|
| 292 | (fWindowSizeHintY != v.fWindowSizeHintY) || |
---|
| 293 | (fXGeometryString != v.fXGeometryString) || |
---|
| 294 | (fAutoRefresh != v.fAutoRefresh) || |
---|
[593] | 295 | (fBackgroundColour != v.fBackgroundColour) || |
---|
| 296 | (fPicking != v.fPicking) |
---|
| 297 | ) |
---|
[531] | 298 | G4cout << "Difference in 1st batch." << G4endl; |
---|
| 299 | |
---|
| 300 | if (fSection) { |
---|
| 301 | if (!(fSectionPlane == v.fSectionPlane)) |
---|
| 302 | G4cout << "Difference in section planes batch." << G4endl; |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | if (IsCutaway()) { |
---|
| 306 | if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) { |
---|
| 307 | G4cout << "Difference in no of cutaway planes." << G4endl; |
---|
| 308 | } |
---|
| 309 | else { |
---|
| 310 | for (size_t i = 0; i < fCutawayPlanes.size (); i++) { |
---|
| 311 | if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) |
---|
| 312 | G4cout << "Difference in cutaway plane no. " << i << G4endl; |
---|
| 313 | } |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | if (IsExplode()) { |
---|
| 318 | if (fExplodeFactor != v.fExplodeFactor) |
---|
| 319 | G4cout << "Difference in explode factor." << G4endl; |
---|
| 320 | if (fExplodeCentre != v.fExplodeCentre) |
---|
| 321 | G4cout << "Difference in explode centre." << G4endl; |
---|
| 322 | } |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | std::ostream& operator << (std::ostream& os, |
---|
| 326 | const G4ViewParameters::DrawingStyle& style) { |
---|
| 327 | switch (style) { |
---|
| 328 | case G4ViewParameters::wireframe: |
---|
| 329 | os << "wireframe"; break; |
---|
| 330 | case G4ViewParameters::hlr: |
---|
| 331 | os << "hlr - hidden lines removed"; break; |
---|
| 332 | case G4ViewParameters::hsr: |
---|
| 333 | os << "hsr - hidden surfaces removed"; break; |
---|
| 334 | case G4ViewParameters::hlhsr: |
---|
| 335 | os << "hlhsr - hidden line, hidden surface removed"; break; |
---|
| 336 | default: os << "unrecognised"; break; |
---|
| 337 | } |
---|
| 338 | return os; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | std::ostream& operator << (std::ostream& os, const G4ViewParameters& v) { |
---|
| 342 | os << "View parameters and options:"; |
---|
| 343 | |
---|
| 344 | os << "\n Drawing style: " << v.fDrawingStyle; |
---|
| 345 | |
---|
| 346 | os << "\n Auxiliary edges: "; |
---|
| 347 | if (!v.fAuxEdgeVisible) os << "in"; |
---|
| 348 | os << "visible"; |
---|
| 349 | |
---|
| 350 | os << "\n Representation style: "; |
---|
| 351 | switch (v.fRepStyle) { |
---|
| 352 | case G4ViewParameters::polyhedron: |
---|
| 353 | os << "polyhedron"; break; |
---|
| 354 | case G4ViewParameters::nurbs: |
---|
| 355 | os << "nurbs"; break; |
---|
| 356 | default: os << "unrecognised"; break; |
---|
| 357 | } |
---|
| 358 | |
---|
| 359 | os << "\n Culling: "; |
---|
| 360 | if (v.fCulling) os << "on"; |
---|
| 361 | else os << "off"; |
---|
| 362 | |
---|
| 363 | os << "\n Culling invisible objects: "; |
---|
| 364 | if (v.fCullInvisible) os << "on"; |
---|
| 365 | else os << "off"; |
---|
| 366 | |
---|
| 367 | os << "\n Density culling: "; |
---|
| 368 | if (v.fDensityCulling) { |
---|
| 369 | os << "on - invisible if density less than " |
---|
| 370 | << v.fVisibleDensity / (1. * g / cm3) << " g cm^-3"; |
---|
| 371 | } |
---|
| 372 | else os << "off"; |
---|
| 373 | |
---|
| 374 | os << "\n Culling daughters covered by opaque mothers: "; |
---|
| 375 | if (v.fCullCovered) os << "on"; |
---|
| 376 | else os << "off"; |
---|
| 377 | |
---|
| 378 | os << "\n Section flag: "; |
---|
| 379 | if (v.fSection) os << "true, section/cut plane: " << v.fSectionPlane; |
---|
| 380 | else os << "false"; |
---|
| 381 | |
---|
| 382 | if (v.IsCutaway()) { |
---|
| 383 | os << "\n Cutaway planes: "; |
---|
| 384 | for (size_t i = 0; i < v.fCutawayPlanes.size (); i++) { |
---|
| 385 | os << ' ' << v.fCutawayPlanes[i]; |
---|
| 386 | } |
---|
| 387 | } |
---|
| 388 | else { |
---|
| 389 | os << "\n No cutaway planes"; |
---|
| 390 | } |
---|
| 391 | |
---|
| 392 | os << "\n Explode factor: " << v.fExplodeFactor |
---|
| 393 | << " about centre: " << v.fExplodeCentre; |
---|
| 394 | |
---|
| 395 | os << "\n No. of sides used in circle polygon approximation: " |
---|
| 396 | << v.fNoOfSides; |
---|
| 397 | |
---|
| 398 | os << "\n Viewpoint direction: " << v.fViewpointDirection; |
---|
| 399 | |
---|
| 400 | os << "\n Up vector: " << v.fUpVector; |
---|
| 401 | |
---|
| 402 | os << "\n Field half angle: " << v.fFieldHalfAngle; |
---|
| 403 | |
---|
| 404 | os << "\n Zoom factor: " << v.fZoomFactor; |
---|
| 405 | |
---|
| 406 | os << "\n Scale factor: " << v.fScaleFactor; |
---|
| 407 | |
---|
| 408 | os << "\n Current target point: " << v.fCurrentTargetPoint; |
---|
| 409 | |
---|
| 410 | os << "\n Dolly distance: " << v.fDolly; |
---|
| 411 | |
---|
| 412 | os << "\n Light "; |
---|
| 413 | if (v.fLightsMoveWithCamera) os << "moves"; |
---|
| 414 | else os << "does not move"; |
---|
| 415 | os << " with camera"; |
---|
| 416 | |
---|
| 417 | os << "\n Relative lightpoint direction: " |
---|
| 418 | << v.fRelativeLightpointDirection; |
---|
| 419 | |
---|
| 420 | os << "\n Actual lightpoint direction: " |
---|
| 421 | << v.fActualLightpointDirection; |
---|
| 422 | |
---|
| 423 | os << "\n Derived parameters for standard view of object of unit radius:"; |
---|
| 424 | G4ViewParameters tempVP = v; |
---|
| 425 | tempVP.fDolly = 0.; |
---|
| 426 | tempVP.fZoomFactor = 1.; |
---|
| 427 | const G4double radius = 1.; |
---|
| 428 | const G4double cameraDistance = tempVP.GetCameraDistance (radius); |
---|
| 429 | const G4double nearDistance = |
---|
| 430 | tempVP.GetNearDistance (cameraDistance, radius); |
---|
| 431 | const G4double farDistance = |
---|
| 432 | tempVP.GetFarDistance (cameraDistance, nearDistance, radius); |
---|
| 433 | const G4double right = tempVP.GetFrontHalfHeight (nearDistance, radius); |
---|
| 434 | os << "\n Camera distance: " << cameraDistance; |
---|
| 435 | os << "\n Near distance: " << nearDistance; |
---|
| 436 | os << "\n Far distance: " << farDistance; |
---|
| 437 | os << "\n Front half height: " << right; |
---|
| 438 | |
---|
| 439 | os << "\n Default VisAttributes:\n " << v.fDefaultVisAttributes; |
---|
| 440 | |
---|
| 441 | os << "\n Default TextVisAttributes:\n " << v.fDefaultTextVisAttributes; |
---|
| 442 | |
---|
| 443 | os << "\n Default marker: " << v.fDefaultMarker; |
---|
| 444 | |
---|
| 445 | os << "\n Global marker scale: " << v.fGlobalMarkerScale; |
---|
| 446 | |
---|
| 447 | os << "\n Global lineWidth scale: " << v.fGlobalLineWidthScale; |
---|
| 448 | |
---|
| 449 | os << "\n Marker "; |
---|
| 450 | if (v.fMarkerNotHidden) os << "not "; |
---|
| 451 | os << "hidden by surfaces."; |
---|
| 452 | |
---|
| 453 | os << "\n Window size hint: " |
---|
| 454 | << v.fWindowSizeHintX << 'x'<< v.fWindowSizeHintX; |
---|
| 455 | |
---|
| 456 | os << "\n X geometry string: " << v.fXGeometryString; |
---|
| 457 | |
---|
| 458 | os << "\n Auto refresh: "; |
---|
| 459 | if (v.fAutoRefresh) os << "true"; |
---|
| 460 | else os << "false"; |
---|
| 461 | |
---|
| 462 | os << "\n Background colour: " << v.fBackgroundColour; |
---|
| 463 | |
---|
[593] | 464 | os << "\n Picking requested: "; |
---|
| 465 | if (v.fPicking) os << "true"; |
---|
| 466 | else os << "false"; |
---|
| 467 | |
---|
[531] | 468 | return os; |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | G4bool G4ViewParameters::operator != (const G4ViewParameters& v) const { |
---|
| 472 | |
---|
| 473 | // Put performance-sensitive parameters first. |
---|
| 474 | if ( |
---|
| 475 | // This first to optimise spin, etc. |
---|
| 476 | (fViewpointDirection != v.fViewpointDirection) || |
---|
| 477 | |
---|
| 478 | // No particular order from here on. |
---|
| 479 | (fDrawingStyle != v.fDrawingStyle) || |
---|
| 480 | (fAuxEdgeVisible != v.fAuxEdgeVisible) || |
---|
| 481 | (fRepStyle != v.fRepStyle) || |
---|
| 482 | (fCulling != v.fCulling) || |
---|
| 483 | (fCullInvisible != v.fCullInvisible) || |
---|
| 484 | (fDensityCulling != v.fDensityCulling) || |
---|
| 485 | (fCullCovered != v.fCullCovered) || |
---|
| 486 | (fSection != v.fSection) || |
---|
| 487 | (IsCutaway() != v.IsCutaway()) || |
---|
| 488 | (IsExplode() != v.IsExplode()) || |
---|
| 489 | (fNoOfSides != v.fNoOfSides) || |
---|
| 490 | (fUpVector != v.fUpVector) || |
---|
| 491 | (fFieldHalfAngle != v.fFieldHalfAngle) || |
---|
| 492 | (fZoomFactor != v.fZoomFactor) || |
---|
| 493 | (fScaleFactor != v.fScaleFactor) || |
---|
| 494 | (fCurrentTargetPoint != v.fCurrentTargetPoint) || |
---|
| 495 | (fDolly != v.fDolly) || |
---|
| 496 | (fRelativeLightpointDirection != v.fRelativeLightpointDirection) || |
---|
| 497 | (fLightsMoveWithCamera != v.fLightsMoveWithCamera) || |
---|
| 498 | (fDefaultVisAttributes != v.fDefaultVisAttributes) || |
---|
| 499 | (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) || |
---|
| 500 | (fDefaultMarker != v.fDefaultMarker) || |
---|
| 501 | (fGlobalMarkerScale != v.fGlobalMarkerScale) || |
---|
| 502 | (fGlobalLineWidthScale != v.fGlobalLineWidthScale) || |
---|
| 503 | (fMarkerNotHidden != v.fMarkerNotHidden) || |
---|
| 504 | (fWindowSizeHintX != v.fWindowSizeHintX) || |
---|
| 505 | (fWindowSizeHintY != v.fWindowSizeHintY) || |
---|
| 506 | (fXGeometryString != v.fXGeometryString) || |
---|
| 507 | (fAutoRefresh != v.fAutoRefresh) || |
---|
[593] | 508 | (fBackgroundColour != v.fBackgroundColour) || |
---|
| 509 | (fPicking != v.fPicking) |
---|
| 510 | ) |
---|
[531] | 511 | return true; |
---|
| 512 | |
---|
| 513 | if (fDensityCulling && |
---|
| 514 | (fVisibleDensity != v.fVisibleDensity)) return true; |
---|
| 515 | |
---|
| 516 | if (fSection && |
---|
| 517 | (!(fSectionPlane == v.fSectionPlane))) return true; |
---|
| 518 | |
---|
| 519 | if (IsCutaway()) { |
---|
| 520 | if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) |
---|
| 521 | return true; |
---|
| 522 | else { |
---|
| 523 | for (size_t i = 0; i < fCutawayPlanes.size (); i++) { |
---|
| 524 | if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) return true; |
---|
| 525 | } |
---|
| 526 | } |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | if (IsExplode() && |
---|
[846] | 530 | ((fExplodeFactor != v.fExplodeFactor) || |
---|
| 531 | (fExplodeCentre != v.fExplodeCentre))) return true; |
---|
[531] | 532 | |
---|
| 533 | return false; |
---|
| 534 | } |
---|
[896] | 535 | |
---|
| 536 | |
---|
[910] | 537 | void G4ViewParameters::SetXGeometryString (const G4String& geomStringArg) { |
---|
[896] | 538 | |
---|
| 539 | |
---|
| 540 | G4int x,y = 0; |
---|
| 541 | unsigned int w,h = 0; |
---|
[910] | 542 | G4String geomString = geomStringArg; |
---|
| 543 | // Parse windowSizeHintString for backwards compatibility... |
---|
| 544 | const G4String delimiters("xX+-"); |
---|
| 545 | G4String::size_type i = geomString.find_first_of(delimiters); |
---|
| 546 | if (i == G4String::npos) { // Does not contain "xX+-". Assume single number |
---|
| 547 | std::istringstream iss(geomString); |
---|
| 548 | G4int size; |
---|
| 549 | iss >> size; |
---|
| 550 | if (!iss) { |
---|
| 551 | size = 600; |
---|
| 552 | G4cout << "Unrecognised windowSizeHint string: \"" |
---|
| 553 | << geomString |
---|
| 554 | << "\". Asuuming " << size << G4endl; |
---|
| 555 | } |
---|
| 556 | std::ostringstream oss; |
---|
| 557 | oss << size << 'x' << size; |
---|
| 558 | geomString = oss.str(); |
---|
| 559 | } |
---|
| 560 | |
---|
[913] | 561 | fGeometryMask = ParseGeometry( geomString, &x, &y, &w, &h ); |
---|
[896] | 562 | |
---|
[910] | 563 | // Handle special case : |
---|
[913] | 564 | if ((fGeometryMask & fYValue) == 0) |
---|
[910] | 565 | { // Using default |
---|
[913] | 566 | y = fWindowLocationHintY; |
---|
[910] | 567 | } |
---|
[913] | 568 | if ((fGeometryMask & fXValue) == 0) |
---|
[910] | 569 | { // Using default |
---|
[913] | 570 | x = fWindowLocationHintX; |
---|
[910] | 571 | } |
---|
| 572 | |
---|
[896] | 573 | // Check errors |
---|
[913] | 574 | // if there is no Width and Height |
---|
| 575 | if ( ((fGeometryMask & fHeightValue) == 0 ) && |
---|
| 576 | ((fGeometryMask & fWidthValue) == 0 )) { |
---|
| 577 | h = fWindowSizeHintY; |
---|
| 578 | w = fWindowSizeHintX; |
---|
| 579 | } else if ((fGeometryMask & fHeightValue) == 0 ) { |
---|
| 580 | |
---|
| 581 | // if there is only Width. Special case to be backward compatible |
---|
| 582 | // We set Width and Height the same to obtain a square windows. |
---|
| 583 | |
---|
| 584 | G4cout << "Unrecognised geometry string \"" |
---|
[896] | 585 | << geomString |
---|
[913] | 586 | << "\". No Height found. Using Width value instead" |
---|
[896] | 587 | << G4endl; |
---|
[913] | 588 | h = w; |
---|
| 589 | } |
---|
| 590 | if ( ((fGeometryMask & fXValue) == 0 ) || |
---|
| 591 | ((fGeometryMask & fYValue) == 0 )) { |
---|
| 592 | //Using defaults |
---|
| 593 | x = fWindowLocationHintX; |
---|
| 594 | y = fWindowLocationHintY; |
---|
| 595 | } |
---|
| 596 | // Set the string |
---|
| 597 | fXGeometryString = geomString; |
---|
| 598 | |
---|
| 599 | // Set values |
---|
| 600 | fWindowSizeHintX = w; |
---|
| 601 | fWindowSizeHintY = h; |
---|
| 602 | fWindowLocationHintX = x; |
---|
| 603 | fWindowLocationHintY = y; |
---|
[896] | 604 | |
---|
[913] | 605 | if ( ((fGeometryMask & fXValue)) && |
---|
| 606 | ((fGeometryMask & fYValue))) { |
---|
| 607 | |
---|
| 608 | if ( (fGeometryMask & fXNegative) ) { |
---|
[896] | 609 | fWindowLocationHintXNegative = true; |
---|
| 610 | } else { |
---|
| 611 | fWindowLocationHintXNegative = false; |
---|
| 612 | } |
---|
[913] | 613 | if ( (fGeometryMask & fYNegative) ) { |
---|
| 614 | fWindowLocationHintYNegative = true; |
---|
[896] | 615 | } else { |
---|
| 616 | fWindowLocationHintYNegative = false; |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | } |
---|
| 620 | |
---|
| 621 | G4int G4ViewParameters::GetWindowAbsoluteLocationHintX (G4int sizeX ) const { |
---|
| 622 | if ( fWindowLocationHintXNegative ) { |
---|
| 623 | return sizeX + fWindowLocationHintX - fWindowSizeHintX; |
---|
| 624 | } |
---|
| 625 | return fWindowLocationHintX; |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | G4int G4ViewParameters::GetWindowAbsoluteLocationHintY (G4int sizeY ) const { |
---|
| 629 | if ( fWindowLocationHintYNegative ) { |
---|
| 630 | return sizeY + fWindowLocationHintY - fWindowSizeHintY; |
---|
| 631 | } |
---|
| 632 | return fWindowLocationHintY; |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | /* Keep from : |
---|
| 636 | * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp |
---|
| 637 | * |
---|
| 638 | * ParseGeometry parses strings of the form |
---|
| 639 | * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where |
---|
| 640 | * width, height, xoffset, and yoffset are unsigned integers. |
---|
| 641 | * Example: "=80x24+300-49" |
---|
| 642 | * The equal sign is optional. |
---|
| 643 | * It returns a bitmask that indicates which of the four values |
---|
| 644 | * were actually found in the string. For each value found, |
---|
| 645 | * the corresponding argument is updated; for each value |
---|
| 646 | * not found, the corresponding argument is left unchanged. |
---|
| 647 | */ |
---|
| 648 | |
---|
| 649 | int G4ViewParameters::ParseGeometry ( |
---|
| 650 | const char *string, |
---|
| 651 | G4int *x, |
---|
| 652 | G4int *y, |
---|
| 653 | unsigned int *width, |
---|
| 654 | unsigned int *height) |
---|
| 655 | { |
---|
| 656 | |
---|
| 657 | G4int mask = fNoValue; |
---|
| 658 | register char *strind; |
---|
[907] | 659 | unsigned int tempWidth = 0; |
---|
| 660 | unsigned int tempHeight = 0; |
---|
| 661 | G4int tempX = 0; |
---|
| 662 | G4int tempY = 0; |
---|
[896] | 663 | char *nextCharacter; |
---|
| 664 | if ( (string == NULL) || (*string == '\0')) { |
---|
| 665 | return(mask); |
---|
| 666 | } |
---|
| 667 | if (*string == '=') |
---|
| 668 | string++; /* ignore possible '=' at beg of geometry spec */ |
---|
| 669 | strind = (char *)string; |
---|
| 670 | if (*strind != '+' && *strind != '-' && *strind != 'x') { |
---|
| 671 | tempWidth = ReadInteger(strind, &nextCharacter); |
---|
| 672 | if (strind == nextCharacter) |
---|
| 673 | return (0); |
---|
| 674 | strind = nextCharacter; |
---|
| 675 | mask |= fWidthValue; |
---|
| 676 | } |
---|
| 677 | if (*strind == 'x' || *strind == 'X') { |
---|
| 678 | strind++; |
---|
| 679 | tempHeight = ReadInteger(strind, &nextCharacter); |
---|
| 680 | if (strind == nextCharacter) |
---|
| 681 | return (0); |
---|
| 682 | strind = nextCharacter; |
---|
| 683 | mask |= fHeightValue; |
---|
| 684 | } |
---|
| 685 | |
---|
| 686 | if ((*strind == '+') || (*strind == '-')) { |
---|
| 687 | if (*strind == '-') { |
---|
| 688 | strind++; |
---|
| 689 | tempX = -ReadInteger(strind, &nextCharacter); |
---|
| 690 | if (strind == nextCharacter) |
---|
| 691 | return (0); |
---|
| 692 | strind = nextCharacter; |
---|
| 693 | mask |= fXNegative; |
---|
| 694 | |
---|
| 695 | } |
---|
| 696 | else |
---|
| 697 | { strind++; |
---|
| 698 | tempX = ReadInteger(strind, &nextCharacter); |
---|
| 699 | if (strind == nextCharacter) |
---|
| 700 | return(0); |
---|
| 701 | strind = nextCharacter; |
---|
| 702 | } |
---|
| 703 | mask |= fXValue; |
---|
| 704 | if ((*strind == '+') || (*strind == '-')) { |
---|
| 705 | if (*strind == '-') { |
---|
| 706 | strind++; |
---|
| 707 | tempY = -ReadInteger(strind, &nextCharacter); |
---|
| 708 | if (strind == nextCharacter) |
---|
| 709 | return(0); |
---|
| 710 | strind = nextCharacter; |
---|
| 711 | mask |= fYNegative; |
---|
| 712 | } |
---|
| 713 | else |
---|
| 714 | { |
---|
| 715 | strind++; |
---|
| 716 | tempY = ReadInteger(strind, &nextCharacter); |
---|
| 717 | if (strind == nextCharacter) |
---|
| 718 | return(0); |
---|
| 719 | strind = nextCharacter; |
---|
| 720 | } |
---|
| 721 | mask |= fYValue; |
---|
| 722 | } |
---|
| 723 | } |
---|
| 724 | /* If strind isn't at the end of the string the it's an invalid |
---|
| 725 | geometry specification. */ |
---|
| 726 | if (*strind != '\0') return (0); |
---|
| 727 | if (mask & fXValue) |
---|
| 728 | *x = tempX; |
---|
| 729 | if (mask & fYValue) |
---|
| 730 | *y = tempY; |
---|
| 731 | if (mask & fWidthValue) |
---|
| 732 | *width = tempWidth; |
---|
| 733 | if (mask & fHeightValue) |
---|
| 734 | *height = tempHeight; |
---|
| 735 | return (mask); |
---|
| 736 | } |
---|
| 737 | |
---|
| 738 | /* Keep from : |
---|
| 739 | * ftp://ftp.trolltech.com/qt/source/qt-embedded-free-3.0.6.tar.gz/qt-embedded-free-3.0.6/src/kernel/qapplication_qws.cpp |
---|
| 740 | * |
---|
| 741 | */ |
---|
| 742 | G4int G4ViewParameters::ReadInteger(char *string, char **NextString) |
---|
| 743 | { |
---|
| 744 | register G4int Result = 0; |
---|
| 745 | G4int Sign = 1; |
---|
| 746 | |
---|
| 747 | if (*string == '+') |
---|
| 748 | string++; |
---|
| 749 | else if (*string == '-') |
---|
| 750 | { |
---|
| 751 | string++; |
---|
| 752 | Sign = -1; |
---|
| 753 | } |
---|
| 754 | for (; (*string >= '0') && (*string <= '9'); string++) |
---|
| 755 | { |
---|
| 756 | Result = (Result * 10) + (*string - '0'); |
---|
| 757 | } |
---|
| 758 | *NextString = string; |
---|
| 759 | if (Sign >= 0) |
---|
| 760 | return (Result); |
---|
| 761 | else |
---|
| 762 | return (-Result); |
---|
| 763 | } |
---|
| 764 | |
---|