00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <sstream>
00034
00035 #include "G4ViewParameters.hh"
00036
00037 #include "G4VisManager.hh"
00038 #include "G4UnitsTable.hh"
00039 #include "G4SystemOfUnits.hh"
00040 #include "G4ios.hh"
00041
00042 G4ViewParameters::G4ViewParameters ():
00043 fDrawingStyle (wireframe),
00044 fAuxEdgeVisible (false),
00045 fRepStyle (polyhedron),
00046 fCulling (true),
00047 fCullInvisible (true),
00048 fDensityCulling (false),
00049 fVisibleDensity (0.01 * g / cm3),
00050 fCullCovered (false),
00051 fSection (false),
00052 fSectionPlane (),
00053 fCutawayMode (cutawayUnion),
00054 fCutawayPlanes (),
00055 fExplodeFactor (1.),
00056 fNoOfSides (24),
00057 fViewpointDirection (G4Vector3D (0., 0., 1.)),
00058 fUpVector (G4Vector3D (0., 1., 0.)),
00059 fFieldHalfAngle (0.),
00060 fZoomFactor (1.),
00061 fScaleFactor (G4Vector3D (1., 1., 1.)),
00062 fCurrentTargetPoint (),
00063 fDolly (0.),
00064 fLightsMoveWithCamera (false),
00065 fRelativeLightpointDirection (G4Vector3D (1., 1., 1.)),
00066 fActualLightpointDirection (G4Vector3D (1., 1., 1.)),
00067 fDefaultVisAttributes (),
00068 fDefaultTextVisAttributes (G4Colour (0., 0., 1.)),
00069 fDefaultMarker (),
00070 fGlobalMarkerScale (1.),
00071 fGlobalLineWidthScale (1.),
00072 fMarkerNotHidden (true),
00073 fWindowSizeHintX (600),
00074 fWindowSizeHintY (600),
00075 fWindowLocationHintX(0),
00076 fWindowLocationHintY(0),
00077 fWindowLocationHintXNegative(true),
00078 fWindowLocationHintYNegative(false),
00079 fGeometryMask(0),
00080 fAutoRefresh (false),
00081 fBackgroundColour (G4Colour(0.,0.,0.)),
00082 fPicking (false),
00083 fRotationStyle (constrainUpDirection)
00084 {
00085 fDefaultMarker.SetScreenSize (5.);
00086
00087 }
00088
00089 G4ViewParameters::~G4ViewParameters () {}
00090
00091 void G4ViewParameters::MultiplyScaleFactor
00092 (const G4Vector3D& scaleFactorMultiplier) {
00093 fScaleFactor.setX(fScaleFactor.x() * scaleFactorMultiplier.x());
00094 fScaleFactor.setY(fScaleFactor.y() * scaleFactorMultiplier.y());
00095 fScaleFactor.setZ(fScaleFactor.z() * scaleFactorMultiplier.z());
00096 }
00097
00098 G4Vector3D& G4ViewParameters::GetActualLightpointDirection () {
00099 SetViewAndLights (fViewpointDirection);
00100 return fActualLightpointDirection;
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111 G4double G4ViewParameters::GetCameraDistance (G4double radius) const {
00112 G4double cameraDistance;
00113 if (fFieldHalfAngle == 0.) {
00114 cameraDistance = radius;
00115 }
00116 else {
00117 cameraDistance = radius / std::sin (fFieldHalfAngle) - fDolly;
00118 }
00119 return cameraDistance;
00120 }
00121
00122 G4double G4ViewParameters::GetNearDistance (G4double cameraDistance,
00123 G4double radius) const {
00124 const G4double small = 1.e-6 * radius;
00125 G4double nearDistance = cameraDistance - radius;
00126 if (nearDistance < small) nearDistance = small;
00127 return nearDistance;
00128 }
00129
00130 G4double G4ViewParameters::GetFarDistance (G4double cameraDistance,
00131 G4double nearDistance,
00132 G4double radius) const {
00133 G4double farDistance = cameraDistance + radius;
00134 if (farDistance < nearDistance) farDistance = nearDistance;
00135 return farDistance;
00136 }
00137
00138 G4double G4ViewParameters::GetFrontHalfHeight (G4double nearDistance,
00139 G4double radius) const {
00140 G4double frontHalfHeight;
00141 if (fFieldHalfAngle == 0.) {
00142 frontHalfHeight = radius / fZoomFactor;
00143 }
00144 else {
00145 frontHalfHeight = nearDistance * std::tan (fFieldHalfAngle) / fZoomFactor;
00146 }
00147 return frontHalfHeight;
00148 }
00149
00150
00151 void G4ViewParameters::AddCutawayPlane (const G4Plane3D& cutawayPlane) {
00152 if (fCutawayPlanes.size () < 3 ) {
00153 fCutawayPlanes.push_back (cutawayPlane);
00154 }
00155 else {
00156 G4cout <<
00157 "ERROR: G4ViewParameters::AddCutawayPlane:"
00158 "\n A maximum of 3 cutaway planes supported." << G4endl;
00159 }
00160 }
00161
00162 void G4ViewParameters::ChangeCutawayPlane
00163 (size_t index, const G4Plane3D& cutawayPlane) {
00164 if (index >= fCutawayPlanes.size()) {
00165 G4cout <<
00166 "ERROR: G4ViewParameters::ChangeCutawayPlane:"
00167 "\n Plane " << index << " does not exist." << G4endl;
00168 } else {
00169 fCutawayPlanes[index] = cutawayPlane;
00170 }
00171 }
00172
00173 void G4ViewParameters::SetVisibleDensity (G4double visibleDensity) {
00174 const G4double reasonableMaximum = 10.0 * g / cm3;
00175 if (visibleDensity < 0) {
00176 G4cout << "G4ViewParameters::SetVisibleDensity: attempt to set negative "
00177 "density - ignored." << G4endl;
00178 }
00179 else {
00180 if (visibleDensity > reasonableMaximum) {
00181 G4cout << "G4ViewParameters::SetVisibleDensity: density > "
00182 << G4BestUnit (reasonableMaximum, "Volumic Mass")
00183 << " - did you mean this?"
00184 << G4endl;
00185 }
00186 fVisibleDensity = visibleDensity;
00187 }
00188 }
00189
00190 G4int G4ViewParameters::SetNoOfSides (G4int nSides) {
00191 const G4int nSidesMin = 12;
00192 if (nSides < nSidesMin) {
00193 nSides = nSidesMin;
00194 G4cout << "G4ViewParameters::SetNoOfSides: attempt to set the"
00195 "\nnumber of sides per circle < " << nSidesMin
00196 << "; forced to " << nSides << G4endl;
00197 }
00198 fNoOfSides = nSides;
00199 return fNoOfSides;
00200 }
00201
00202 void G4ViewParameters::SetViewAndLights
00203 (const G4Vector3D& viewpointDirection) {
00204
00205 fViewpointDirection = viewpointDirection;
00206
00207
00208
00209 if (fViewpointDirection.unit() * fUpVector.unit() > .9999) {
00210 G4cout <<
00211 "WARNING: Viewpoint direction is very close to the up vector direction."
00212 "\n Consider setting the up vector to obtain definable behaviour."
00213 << G4endl;
00214 }
00215
00216
00217 if (fLightsMoveWithCamera) {
00218 G4Vector3D zprime = fViewpointDirection.unit ();
00219 G4Vector3D xprime = (fUpVector.cross (zprime)).unit ();
00220 G4Vector3D yprime = zprime.cross (xprime);
00221 fActualLightpointDirection =
00222 fRelativeLightpointDirection.x () * xprime +
00223 fRelativeLightpointDirection.y () * yprime +
00224 fRelativeLightpointDirection.x () * zprime;
00225 } else {
00226 fActualLightpointDirection = fRelativeLightpointDirection;
00227 }
00228 }
00229
00230 void G4ViewParameters::SetLightpointDirection
00231 (const G4Vector3D& lightpointDirection) {
00232 fRelativeLightpointDirection = lightpointDirection;
00233 SetViewAndLights (fViewpointDirection);
00234 }
00235
00236 void G4ViewParameters::SetPan (G4double right, G4double up) {
00237 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
00238 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
00239 fCurrentTargetPoint = right * unitRight + up * unitUp;
00240 }
00241
00242 void G4ViewParameters::IncrementPan (G4double right, G4double up) {
00243 IncrementPan (right,up, 0);
00244 }
00245
00246 void G4ViewParameters::IncrementPan (G4double right, G4double up, G4double distance) {
00247 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
00248 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
00249 fCurrentTargetPoint += right * unitRight + up * unitUp + distance * fViewpointDirection;
00250 }
00251
00252 G4String G4ViewParameters::CameraAndLightingCommands
00253 (const G4Point3D standardTargetPoint) const
00254 {
00255 std::ostringstream oss;
00256
00257 oss << "#\n# Camera and lights commands";
00258
00259 oss << "\n/vis/viewer/set/viewpointVector "
00260 << fViewpointDirection.x()
00261 << ' ' << fViewpointDirection.y()
00262 << ' ' << fViewpointDirection.z();
00263
00264 oss << "\n/vis/viewer/set/upVector "
00265 << fUpVector.x()
00266 << ' ' << fUpVector.y()
00267 << ' ' << fUpVector.z();
00268
00269 oss << "\n/vis/viewer/set/projection ";
00270 if (fFieldHalfAngle == 0.) {
00271 oss
00272 << "orthogonal";
00273 } else {
00274 oss
00275 << "perspective "
00276 << fFieldHalfAngle/deg
00277 << " deg";
00278 }
00279
00280 oss << "\n/vis/viewer/zoomTo "
00281 << fZoomFactor;
00282
00283 oss << "\n/vis/viewer/scaleTo "
00284 << fScaleFactor.x()
00285 << ' ' << fScaleFactor.y()
00286 << ' ' << fScaleFactor.z();
00287
00288 oss << "\n/vis/viewer/set/targetPoint "
00289 << G4BestUnit(standardTargetPoint+fCurrentTargetPoint,"Length")
00290 << "\n# Note that if you have not set a target point, the vis system sets"
00291 << "\n# a target point based on the scene - plus any panning and dollying -"
00292 << "\n# so don't be alarmed by strange coordinates here.";
00293
00294 oss << "\n/vis/viewer/dollyTo "
00295 << G4BestUnit(fDolly,"Length");
00296
00297 oss << "\n/vis/viewer/set/lightsMove ";
00298 if (fLightsMoveWithCamera) {
00299 oss << "camera";
00300 } else {
00301 oss << "object";
00302 }
00303
00304 oss << "\n/vis/viewer/set/lightsVector "
00305 << fRelativeLightpointDirection.x()
00306 << ' ' << fRelativeLightpointDirection.y()
00307 << ' ' << fRelativeLightpointDirection.z();
00308
00309 oss << "\n/vis/viewer/set/rotationStyle ";
00310 if (fRotationStyle == constrainUpDirection) {
00311 oss << "constrainUpDirection";
00312 } else {
00313 oss << "freeRotation";
00314 }
00315
00316 G4Colour c = fBackgroundColour;
00317 oss << "\n/vis/viewer/set/background "
00318 << c.GetRed()
00319 << ' ' << c.GetGreen()
00320 << ' ' << c.GetBlue()
00321 << ' ' << c.GetAlpha();
00322
00323 c = fDefaultVisAttributes.GetColour();
00324 oss << "\n/vis/viewer/set/defaultColour "
00325 << c.GetRed()
00326 << ' ' << c.GetGreen()
00327 << ' ' << c.GetBlue()
00328 << ' ' << c.GetAlpha();
00329
00330 c = fDefaultTextVisAttributes.GetColour();
00331 oss << "\n/vis/viewer/set/defaultTextColour "
00332 << c.GetRed()
00333 << ' ' << c.GetGreen()
00334 << ' ' << c.GetBlue()
00335 << ' ' << c.GetAlpha();
00336
00337 oss << std::endl;
00338
00339 return oss.str();
00340 }
00341
00342 G4String G4ViewParameters::DrawingStyleCommands() const
00343 {
00344 std::ostringstream oss;
00345
00346 oss << "#\n# Drawing style commands";
00347
00348 oss << "\n/vis/viewer/set/style ";
00349 if (fDrawingStyle == wireframe || fDrawingStyle == hlr) {
00350 oss << "wireframe";
00351 } else {
00352 oss << "surface";
00353 }
00354
00355 oss << "\n/vis/viewer/set/hiddenEdge ";
00356 if (fDrawingStyle == hlr || fDrawingStyle == hlhsr) {
00357 oss << "true";
00358 } else {
00359 oss << "false";
00360 }
00361
00362 oss << "\n/vis/viewer/set/auxiliaryEdge ";
00363 if (fAuxEdgeVisible) {
00364 oss << "true";
00365 } else {
00366 oss << "false";
00367 }
00368
00369 oss << "\n/vis/viewer/set/hiddenMarker ";
00370 if (fMarkerNotHidden) {
00371 oss << "false";
00372 } else {
00373 oss << "true";
00374 }
00375
00376 oss << "\n/vis/viewer/set/globalLineWidthScale "
00377 << fGlobalLineWidthScale;
00378
00379 oss << "\n/vis/viewer/set/globalMarkerScale "
00380 << fGlobalMarkerScale;
00381
00382 oss << std::endl;
00383
00384 return oss.str();
00385 }
00386
00387 G4String G4ViewParameters::SceneModifyingCommands() const
00388 {
00389 std::ostringstream oss;
00390
00391 oss << "#\n# Scene-modifying commands";
00392
00393 oss << "\n/vis/viewer/set/culling global ";
00394 if (fCulling) {
00395 oss << "true";
00396 } else {
00397 oss << "false";
00398 }
00399
00400 oss << "\n/vis/viewer/set/culling invisible ";
00401 if (fCullInvisible) {
00402 oss << "true";
00403 } else {
00404 oss << "false";
00405 }
00406
00407 oss << "\n/vis/viewer/set/culling density ";
00408 if (fDensityCulling) {
00409 oss << "true " << fVisibleDensity/(g/cm3) << " g/cm3";
00410 } else {
00411 oss << "false";
00412 }
00413
00414 oss << "\n/vis/viewer/set/culling coveredDaughters ";
00415 if (fCullCovered) {
00416 oss << "true";
00417 } else {
00418 oss << "false";
00419 }
00420
00421 oss << "\n/vis/viewer/set/sectionPlane ";
00422 if (fSection) {
00423 oss << "on "
00424 << G4BestUnit(fSectionPlane.point(),"Length")
00425 << fSectionPlane.normal().x()
00426 << ' ' << fSectionPlane.normal().y()
00427 << ' ' << fSectionPlane.normal().z();
00428 } else {
00429 oss << "off";
00430 }
00431
00432 oss << "\n/vis/viewer/set/cutawayMode ";
00433 if (fCutawayMode == cutawayUnion) {
00434 oss << "union";
00435 } else {
00436 oss << "intersection";
00437 }
00438
00439 oss << "\n/vis/viewer/clearCutawayPlanes";
00440 if (fCutawayPlanes.size()) {
00441 for (size_t i = 0; i < fCutawayPlanes.size(); i++) {
00442 oss << "\n/vis/viewer/addCutawayPlane "
00443 << G4BestUnit(fCutawayPlanes[i].point(),"Length")
00444 << fCutawayPlanes[i].normal().x()
00445 << ' ' << fCutawayPlanes[i].normal().y()
00446 << ' ' << fCutawayPlanes[i].normal().z();
00447 }
00448 } else {
00449 oss << "\n# No cutaway planes defined.";
00450 }
00451
00452 oss << "\n/vis/viewer/set/explodeFactor "
00453 << fExplodeFactor
00454 << ' ' << G4BestUnit(fExplodeCentre,"Length");
00455
00456 oss << "\n/vis/viewer/set/lineSegmentsPerCircle "
00457 << fNoOfSides;
00458
00459 oss << std::endl;
00460
00461 return oss.str();
00462 }
00463
00464 G4String G4ViewParameters::TouchableCommands() const
00465 {
00466 std::ostringstream oss;
00467
00468 oss << "#\n# Touchable commands";
00469
00470 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
00471 fVisAttributesModifiers;
00472
00473 if (vams.empty()) {
00474 oss << "\n# None";
00475 oss << std::endl;
00476 return oss.str();
00477 }
00478
00479 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
00480 iModifier;
00481 for (iModifier = vams.begin();
00482 iModifier != vams.end();
00483 ++iModifier) {
00484 oss << "\n/vis/set/touchable";
00485 const G4ModelingParameters::PVNameCopyNoPath& vamPath =
00486 iModifier->GetPVNameCopyNoPath();
00487 G4ModelingParameters::PVNameCopyNoPathConstIterator iVAM;
00488 for (iVAM = vamPath.begin();
00489 iVAM != vamPath.end();
00490 ++iVAM) {
00491 oss << ' ' << iVAM->GetName() << ' ' << iVAM->GetCopyNo();
00492 }
00493 const G4VisAttributes& vamVisAtts = iModifier->GetVisAttributes();
00494 const G4Colour& c = vamVisAtts.GetColour();
00495 switch (iModifier->GetVisAttributesSignifier()) {
00496 case G4ModelingParameters::VASVisibility:
00497 oss << "\n/vis/touchable/set/visibility ";
00498 if (vamVisAtts.IsVisible()) {
00499 oss << "true";
00500 } else {
00501 oss << "false";
00502 }
00503 break;
00504 case G4ModelingParameters::VASDaughtersInvisible:
00505 oss << "\n/vis/touchable/set/daughtersInvisible ";
00506 if (vamVisAtts.IsDaughtersInvisible()) {
00507 oss << "true";
00508 } else {
00509 oss << "false";
00510 }
00511 break;
00512 case G4ModelingParameters::VASColour:
00513 oss << "\n/vis/touchable/set/colour "
00514 << c.GetRed()
00515 << ' ' << c.GetGreen()
00516 << ' ' << c.GetBlue()
00517 << ' ' << c.GetAlpha();
00518 break;
00519 case G4ModelingParameters::VASLineStyle:
00520 oss << "\n/vis/touchable/set/lineStyle ";
00521 switch (vamVisAtts.GetLineStyle()) {
00522 case G4VisAttributes::unbroken:
00523 oss << "unbroken";
00524 break;
00525 case G4VisAttributes::dashed:
00526 oss << "dashed";
00527 break;
00528 case G4VisAttributes::dotted:
00529 oss << "dotted";
00530 }
00531 break;
00532 case G4ModelingParameters::VASLineWidth:
00533 oss << "\n/vis/touchable/set/lineWidth "
00534 << vamVisAtts.GetLineWidth();
00535 break;
00536 case G4ModelingParameters::VASForceWireframe:
00537 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::wireframe) {
00538 oss << "\n/vis/touchable/set/forceWireframe ";
00539 if (vamVisAtts.IsForceDrawingStyle()) {
00540 oss << "true";
00541 } else {
00542 oss << "false";
00543 }
00544 }
00545 break;
00546 case G4ModelingParameters::VASForceSolid:
00547 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::solid) {
00548 oss << "\n/vis/touchable/set/forceSolid ";
00549 if (vamVisAtts.IsForceDrawingStyle()) {
00550 oss << "true";
00551 } else {
00552 oss << "false";
00553 }
00554 }
00555 break;
00556 case G4ModelingParameters::VASForceAuxEdgeVisible:
00557 oss << "\n/vis/touchable/set/forceAuxEdgeVisible ";
00558 if (vamVisAtts.IsForceAuxEdgeVisible()) {
00559 oss << "true";
00560 } else {
00561 oss << "false";
00562 }
00563 break;
00564 case G4ModelingParameters::VASForceLineSegmentsPerCircle:
00565 oss << "\n/vis/touchable/set/lineSegmentsPerCircle "
00566 << vamVisAtts.GetForcedLineSegmentsPerCircle();
00567 break;
00568 }
00569 }
00570
00571 oss << std::endl;
00572
00573 return oss.str();
00574 }
00575
00576 void G4ViewParameters::PrintDifferences (const G4ViewParameters& v) const {
00577
00578
00579 if (
00580
00581 (fViewpointDirection != v.fViewpointDirection) ||
00582
00583
00584 (fDrawingStyle != v.fDrawingStyle) ||
00585 (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
00586 (fRepStyle != v.fRepStyle) ||
00587 (fCulling != v.fCulling) ||
00588 (fCullInvisible != v.fCullInvisible) ||
00589 (fDensityCulling != v.fDensityCulling) ||
00590 (fVisibleDensity != v.fVisibleDensity) ||
00591 (fCullCovered != v.fCullCovered) ||
00592 (fSection != v.fSection) ||
00593 (fNoOfSides != v.fNoOfSides) ||
00594 (fUpVector != v.fUpVector) ||
00595 (fFieldHalfAngle != v.fFieldHalfAngle) ||
00596 (fZoomFactor != v.fZoomFactor) ||
00597 (fScaleFactor != v.fScaleFactor) ||
00598 (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
00599 (fDolly != v.fDolly) ||
00600 (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
00601 (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
00602 (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
00603 (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
00604 (fDefaultMarker != v.fDefaultMarker) ||
00605 (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
00606 (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
00607 (fMarkerNotHidden != v.fMarkerNotHidden) ||
00608 (fWindowSizeHintX != v.fWindowSizeHintX) ||
00609 (fWindowSizeHintY != v.fWindowSizeHintY) ||
00610 (fXGeometryString != v.fXGeometryString) ||
00611 (fGeometryMask != v.fGeometryMask) ||
00612 (fAutoRefresh != v.fAutoRefresh) ||
00613 (fBackgroundColour != v.fBackgroundColour) ||
00614 (fPicking != v.fPicking) ||
00615 (fRotationStyle != v.fRotationStyle)
00616 )
00617 G4cout << "Difference in 1st batch." << G4endl;
00618
00619 if (fSection) {
00620 if (!(fSectionPlane == v.fSectionPlane))
00621 G4cout << "Difference in section planes batch." << G4endl;
00622 }
00623
00624 if (IsCutaway()) {
00625 if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) {
00626 G4cout << "Difference in no of cutaway planes." << G4endl;
00627 }
00628 else {
00629 for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
00630 if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i]))
00631 G4cout << "Difference in cutaway plane no. " << i << G4endl;
00632 }
00633 }
00634 }
00635
00636 if (IsExplode()) {
00637 if (fExplodeFactor != v.fExplodeFactor)
00638 G4cout << "Difference in explode factor." << G4endl;
00639 if (fExplodeCentre != v.fExplodeCentre)
00640 G4cout << "Difference in explode centre." << G4endl;
00641 }
00642 }
00643
00644 std::ostream& operator << (std::ostream& os,
00645 const G4ViewParameters::DrawingStyle& style) {
00646 switch (style) {
00647 case G4ViewParameters::wireframe:
00648 os << "wireframe"; break;
00649 case G4ViewParameters::hlr:
00650 os << "hlr - hidden lines removed"; break;
00651 case G4ViewParameters::hsr:
00652 os << "hsr - hidden surfaces removed"; break;
00653 case G4ViewParameters::hlhsr:
00654 os << "hlhsr - hidden line, hidden surface removed"; break;
00655 default: os << "unrecognised"; break;
00656 }
00657 return os;
00658 }
00659
00660 std::ostream& operator << (std::ostream& os, const G4ViewParameters& v) {
00661 os << "View parameters and options:";
00662
00663 os << "\n Drawing style: ";
00664 switch (v.fDrawingStyle) {
00665 case G4ViewParameters::wireframe:
00666 os << "edges, wireframe"; break;
00667 case G4ViewParameters::hlr:
00668 os << "edges, hidden line removal"; break;
00669 case G4ViewParameters::hsr:
00670 os << "surfaces, hidden surface removal"; break;
00671 case G4ViewParameters::hlhsr:
00672 os << "surfaces and edges, hidden line and surface removal"; break;
00673 default: os << "unrecognised"; break;
00674 }
00675
00676 os << "\n Auxiliary edges: ";
00677 if (!v.fAuxEdgeVisible) os << "in";
00678 os << "visible";
00679
00680 os << "\n Representation style: ";
00681 switch (v.fRepStyle) {
00682 case G4ViewParameters::polyhedron:
00683 os << "polyhedron"; break;
00684 case G4ViewParameters::nurbs:
00685 os << "nurbs"; break;
00686 default: os << "unrecognised"; break;
00687 }
00688
00689 os << "\n Culling: ";
00690 if (v.fCulling) os << "on";
00691 else os << "off";
00692
00693 os << "\n Culling invisible objects: ";
00694 if (v.fCullInvisible) os << "on";
00695 else os << "off";
00696
00697 os << "\n Density culling: ";
00698 if (v.fDensityCulling) {
00699 os << "on - invisible if density less than "
00700 << v.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
00701 }
00702 else os << "off";
00703
00704 os << "\n Culling daughters covered by opaque mothers: ";
00705 if (v.fCullCovered) os << "on";
00706 else os << "off";
00707
00708 os << "\n Section flag: ";
00709 if (v.fSection) os << "true, section/cut plane: " << v.fSectionPlane;
00710 else os << "false";
00711
00712 if (v.IsCutaway()) {
00713 os << "\n Cutaway planes: ";
00714 for (size_t i = 0; i < v.fCutawayPlanes.size (); i++) {
00715 os << ' ' << v.fCutawayPlanes[i];
00716 }
00717 }
00718 else {
00719 os << "\n No cutaway planes";
00720 }
00721
00722 os << "\n Explode factor: " << v.fExplodeFactor
00723 << " about centre: " << v.fExplodeCentre;
00724
00725 os << "\n No. of sides used in circle polygon approximation: "
00726 << v.fNoOfSides;
00727
00728 os << "\n Viewpoint direction: " << v.fViewpointDirection;
00729
00730 os << "\n Up vector: " << v.fUpVector;
00731
00732 os << "\n Field half angle: " << v.fFieldHalfAngle;
00733
00734 os << "\n Zoom factor: " << v.fZoomFactor;
00735
00736 os << "\n Scale factor: " << v.fScaleFactor;
00737
00738 os << "\n Current target point: " << v.fCurrentTargetPoint;
00739
00740 os << "\n Dolly distance: " << v.fDolly;
00741
00742 os << "\n Light ";
00743 if (v.fLightsMoveWithCamera) os << "moves";
00744 else os << "does not move";
00745 os << " with camera";
00746
00747 os << "\n Relative lightpoint direction: "
00748 << v.fRelativeLightpointDirection;
00749
00750 os << "\n Actual lightpoint direction: "
00751 << v.fActualLightpointDirection;
00752
00753 os << "\n Derived parameters for standard view of object of unit radius:";
00754 G4ViewParameters tempVP = v;
00755 tempVP.fDolly = 0.;
00756 tempVP.fZoomFactor = 1.;
00757 const G4double radius = 1.;
00758 const G4double cameraDistance = tempVP.GetCameraDistance (radius);
00759 const G4double nearDistance =
00760 tempVP.GetNearDistance (cameraDistance, radius);
00761 const G4double farDistance =
00762 tempVP.GetFarDistance (cameraDistance, nearDistance, radius);
00763 const G4double right = tempVP.GetFrontHalfHeight (nearDistance, radius);
00764 os << "\n Camera distance: " << cameraDistance;
00765 os << "\n Near distance: " << nearDistance;
00766 os << "\n Far distance: " << farDistance;
00767 os << "\n Front half height: " << right;
00768
00769 os << "\n Default VisAttributes:\n " << v.fDefaultVisAttributes;
00770
00771 os << "\n Default TextVisAttributes:\n " << v.fDefaultTextVisAttributes;
00772
00773 os << "\n Default marker: " << v.fDefaultMarker;
00774
00775 os << "\n Global marker scale: " << v.fGlobalMarkerScale;
00776
00777 os << "\n Global lineWidth scale: " << v.fGlobalLineWidthScale;
00778
00779 os << "\n Marker ";
00780 if (v.fMarkerNotHidden) os << "not ";
00781 os << "hidden by surfaces.";
00782
00783 os << "\n Window size hint: "
00784 << v.fWindowSizeHintX << 'x'<< v.fWindowSizeHintX;
00785
00786 os << "\n X geometry string: " << v.fXGeometryString;
00787 os << "\n X geometry mask: "
00788 << std::showbase << std::hex << v.fGeometryMask
00789 << std::noshowbase << std::dec;
00790
00791 os << "\n Auto refresh: ";
00792 if (v.fAutoRefresh) os << "true";
00793 else os << "false";
00794
00795 os << "\n Background colour: " << v.fBackgroundColour;
00796
00797 os << "\n Picking requested: ";
00798 if (v.fPicking) os << "true";
00799 else os << "false";
00800
00801 os << "\n Rotation style: ";
00802 switch (v.fRotationStyle) {
00803 case G4ViewParameters::constrainUpDirection:
00804 os << "constrainUpDirection (conventional HEP view)"; break;
00805 case G4ViewParameters::freeRotation:
00806 os << "freeRotation (Google-like rotation, using mouse-grab)"; break;
00807 default: os << "unrecognised"; break;
00808 }
00809
00810 os << "\n Vis attributes modifiers: ";
00811 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
00812 v.fVisAttributesModifiers;
00813 if (vams.empty()) {
00814 os << "None";
00815 } else {
00816 os << vams;
00817 }
00818
00819 return os;
00820 }
00821
00822 G4bool G4ViewParameters::operator != (const G4ViewParameters& v) const {
00823
00824
00825 if (
00826
00827 (fViewpointDirection != v.fViewpointDirection) ||
00828
00829
00830 (fDrawingStyle != v.fDrawingStyle) ||
00831 (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
00832 (fRepStyle != v.fRepStyle) ||
00833 (fCulling != v.fCulling) ||
00834 (fCullInvisible != v.fCullInvisible) ||
00835 (fDensityCulling != v.fDensityCulling) ||
00836 (fCullCovered != v.fCullCovered) ||
00837 (fSection != v.fSection) ||
00838 (IsCutaway() != v.IsCutaway()) ||
00839 (IsExplode() != v.IsExplode()) ||
00840 (fNoOfSides != v.fNoOfSides) ||
00841 (fUpVector != v.fUpVector) ||
00842 (fFieldHalfAngle != v.fFieldHalfAngle) ||
00843 (fZoomFactor != v.fZoomFactor) ||
00844 (fScaleFactor != v.fScaleFactor) ||
00845 (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
00846 (fDolly != v.fDolly) ||
00847 (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
00848 (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
00849 (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
00850 (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
00851 (fDefaultMarker != v.fDefaultMarker) ||
00852 (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
00853 (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
00854 (fMarkerNotHidden != v.fMarkerNotHidden) ||
00855 (fWindowSizeHintX != v.fWindowSizeHintX) ||
00856 (fWindowSizeHintY != v.fWindowSizeHintY) ||
00857 (fXGeometryString != v.fXGeometryString) ||
00858 (fGeometryMask != v.fGeometryMask) ||
00859 (fAutoRefresh != v.fAutoRefresh) ||
00860 (fBackgroundColour != v.fBackgroundColour) ||
00861 (fPicking != v.fPicking) ||
00862 (fRotationStyle != v.fRotationStyle)
00863 )
00864 return true;
00865
00866 if (fDensityCulling &&
00867 (fVisibleDensity != v.fVisibleDensity)) return true;
00868
00869 if (fSection &&
00870 (!(fSectionPlane == v.fSectionPlane))) return true;
00871
00872 if (IsCutaway()) {
00873 if (fCutawayPlanes.size () != v.fCutawayPlanes.size ())
00874 return true;
00875 else {
00876 for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
00877 if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) return true;
00878 }
00879 }
00880 }
00881
00882 if (IsExplode() &&
00883 ((fExplodeFactor != v.fExplodeFactor) ||
00884 (fExplodeCentre != v.fExplodeCentre))) return true;
00885
00886 if (G4ModelingParameters::VAMSNotEqual
00887 (fVisAttributesModifiers, v.fVisAttributesModifiers))
00888 return true;
00889
00890 return false;
00891 }
00892
00893
00894 void G4ViewParameters::SetXGeometryString (const G4String& geomStringArg) {
00895
00896
00897 G4int x,y = 0;
00898 unsigned int w,h = 0;
00899 G4String geomString = geomStringArg;
00900
00901 const G4String delimiters("xX+-");
00902 G4String::size_type i = geomString.find_first_of(delimiters);
00903 if (i == G4String::npos) {
00904 std::istringstream iss(geomString);
00905 G4int size;
00906 iss >> size;
00907 if (!iss) {
00908 size = 600;
00909 G4cout << "Unrecognised windowSizeHint string: \""
00910 << geomString
00911 << "\". Asuuming " << size << G4endl;
00912 }
00913 std::ostringstream oss;
00914 oss << size << 'x' << size;
00915 geomString = oss.str();
00916 }
00917
00918 fGeometryMask = ParseGeometry( geomString, &x, &y, &w, &h );
00919
00920
00921 if ((fGeometryMask & fYValue) == 0)
00922 {
00923 y = fWindowLocationHintY;
00924 }
00925 if ((fGeometryMask & fXValue) == 0)
00926 {
00927 x = fWindowLocationHintX;
00928 }
00929
00930
00931
00932 if ( ((fGeometryMask & fHeightValue) == 0 ) &&
00933 ((fGeometryMask & fWidthValue) == 0 )) {
00934 h = fWindowSizeHintY;
00935 w = fWindowSizeHintX;
00936 } else if ((fGeometryMask & fHeightValue) == 0 ) {
00937
00938
00939
00940
00941 G4cout << "Unrecognised geometry string \""
00942 << geomString
00943 << "\". No Height found. Using Width value instead"
00944 << G4endl;
00945 h = w;
00946 }
00947 if ( ((fGeometryMask & fXValue) == 0 ) ||
00948 ((fGeometryMask & fYValue) == 0 )) {
00949
00950 x = fWindowLocationHintX;
00951 y = fWindowLocationHintY;
00952 }
00953
00954 fXGeometryString = geomString;
00955
00956
00957 fWindowSizeHintX = w;
00958 fWindowSizeHintY = h;
00959 fWindowLocationHintX = x;
00960 fWindowLocationHintY = y;
00961
00962 if ( ((fGeometryMask & fXValue)) &&
00963 ((fGeometryMask & fYValue))) {
00964
00965 if ( (fGeometryMask & fXNegative) ) {
00966 fWindowLocationHintXNegative = true;
00967 } else {
00968 fWindowLocationHintXNegative = false;
00969 }
00970 if ( (fGeometryMask & fYNegative) ) {
00971 fWindowLocationHintYNegative = true;
00972 } else {
00973 fWindowLocationHintYNegative = false;
00974 }
00975 }
00976 }
00977
00978 G4int G4ViewParameters::GetWindowAbsoluteLocationHintX (G4int sizeX ) const {
00979 if ( fWindowLocationHintXNegative ) {
00980 return sizeX + fWindowLocationHintX - fWindowSizeHintX;
00981 }
00982 return fWindowLocationHintX;
00983 }
00984
00985 G4int G4ViewParameters::GetWindowAbsoluteLocationHintY (G4int sizeY ) const {
00986 if ( fWindowLocationHintYNegative ) {
00987 return sizeY + fWindowLocationHintY - fWindowSizeHintY;
00988 }
00989 return fWindowLocationHintY;
00990 }
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006 int G4ViewParameters::ParseGeometry (
01007 const char *string,
01008 G4int *x,
01009 G4int *y,
01010 unsigned int *width,
01011 unsigned int *height)
01012 {
01013
01014 G4int mask = fNoValue;
01015 register char *strind;
01016 unsigned int tempWidth = 0;
01017 unsigned int tempHeight = 0;
01018 G4int tempX = 0;
01019 G4int tempY = 0;
01020 char *nextCharacter;
01021 if ( (string == NULL) || (*string == '\0')) {
01022 return(mask);
01023 }
01024 if (*string == '=')
01025 string++;
01026 strind = (char *)string;
01027 if (*strind != '+' && *strind != '-' && *strind != 'x') {
01028 tempWidth = ReadInteger(strind, &nextCharacter);
01029 if (strind == nextCharacter)
01030 return (0);
01031 strind = nextCharacter;
01032 mask |= fWidthValue;
01033 }
01034 if (*strind == 'x' || *strind == 'X') {
01035 strind++;
01036 tempHeight = ReadInteger(strind, &nextCharacter);
01037 if (strind == nextCharacter)
01038 return (0);
01039 strind = nextCharacter;
01040 mask |= fHeightValue;
01041 }
01042
01043 if ((*strind == '+') || (*strind == '-')) {
01044 if (*strind == '-') {
01045 strind++;
01046 tempX = -ReadInteger(strind, &nextCharacter);
01047 if (strind == nextCharacter)
01048 return (0);
01049 strind = nextCharacter;
01050 mask |= fXNegative;
01051
01052 }
01053 else
01054 { strind++;
01055 tempX = ReadInteger(strind, &nextCharacter);
01056 if (strind == nextCharacter)
01057 return(0);
01058 strind = nextCharacter;
01059 }
01060 mask |= fXValue;
01061 if ((*strind == '+') || (*strind == '-')) {
01062 if (*strind == '-') {
01063 strind++;
01064 tempY = -ReadInteger(strind, &nextCharacter);
01065 if (strind == nextCharacter)
01066 return(0);
01067 strind = nextCharacter;
01068 mask |= fYNegative;
01069 }
01070 else
01071 {
01072 strind++;
01073 tempY = ReadInteger(strind, &nextCharacter);
01074 if (strind == nextCharacter)
01075 return(0);
01076 strind = nextCharacter;
01077 }
01078 mask |= fYValue;
01079 }
01080 }
01081
01082
01083 if (*strind != '\0') return (0);
01084 if (mask & fXValue)
01085 *x = tempX;
01086 if (mask & fYValue)
01087 *y = tempY;
01088 if (mask & fWidthValue)
01089 *width = tempWidth;
01090 if (mask & fHeightValue)
01091 *height = tempHeight;
01092 return (mask);
01093 }
01094
01095
01096
01097
01098
01099 G4int G4ViewParameters::ReadInteger(char *string, char **NextString)
01100 {
01101 register G4int Result = 0;
01102 G4int Sign = 1;
01103
01104 if (*string == '+')
01105 string++;
01106 else if (*string == '-')
01107 {
01108 string++;
01109 Sign = -1;
01110 }
01111 for (; (*string >= '0') && (*string <= '9'); string++)
01112 {
01113 Result = (Result * 10) + (*string - '0');
01114 }
01115 *NextString = string;
01116 if (Sign >= 0)
01117 return (Result);
01118 else
01119 return (-Result);
01120 }