source: trunk/geant4/visualization/management/src/G4ViewParameters.cc@ 597

Last change on this file since 597 was 593, checked in by garnier, 18 years ago

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

  • Property svn:mime-type set to text/cpp
File size: 18.1 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4ViewParameters.cc,v 1.29 2007/04/03 13:33:16 allison Exp $
28// GEANT4 tag $Name: geant4-09-00-ref-01 $
29//
30//
31// John Allison 19th July 1996
32// View parameters and options.
33
34#include "G4ViewParameters.hh"
35
36#include "G4VisManager.hh"
37#include "G4UnitsTable.hh"
38#include "G4ios.hh"
39
40G4ViewParameters::G4ViewParameters ():
41 fDrawingStyle (wireframe),
42 fAuxEdgeVisible (false),
43 fRepStyle (polyhedron),
44 fCulling (true),
45 fCullInvisible (true),
46 fDensityCulling (false),
47 fVisibleDensity (0.01 * g / cm3),
48 fCullCovered (false),
49 fSection (false),
50 fSectionPlane (),
51 fCutawayMode (cutawayUnion),
52 fCutawayPlanes (),
53 fExplodeFactor (1.),
54 fNoOfSides (24),
55 fViewpointDirection (G4Vector3D (0., 0., 1.)), // On z-axis.
56 fUpVector (G4Vector3D (0., 1., 0.)), // y-axis up.
57 fFieldHalfAngle (0.), // Orthogonal projection.
58 fZoomFactor (1.),
59 fScaleFactor (G4Vector3D (1., 1., 1.)),
60 fCurrentTargetPoint (),
61 fDolly (0.),
62 fLightsMoveWithCamera (false),
63 fRelativeLightpointDirection (G4Vector3D (1., 1., 1.)),
64 fActualLightpointDirection (G4Vector3D (1., 1., 1.)),
65 fDefaultVisAttributes (),
66 fDefaultTextVisAttributes (G4Colour (0., 0., 1.)),
67 fDefaultMarker (),
68 fGlobalMarkerScale (1.),
69 fGlobalLineWidthScale (1.),
70 fMarkerNotHidden (true),
71 fWindowSizeHintX (600),
72 fWindowSizeHintY (600),
73 fAutoRefresh (false),
74 fBackgroundColour (G4Colour(0.,0.,0.)), // Black
75 fPicking (false)
76{
77 fDefaultMarker.SetScreenSize (5.);
78 // Markers are 5 pixels "overall" size, i.e., diameter.
79}
80
81G4ViewParameters::~G4ViewParameters () {}
82
83void G4ViewParameters::MultiplyScaleFactor
84(const G4Vector3D& scaleFactorMultiplier) {
85 fScaleFactor.setX(fScaleFactor.x() * scaleFactorMultiplier.x());
86 fScaleFactor.setY(fScaleFactor.y() * scaleFactorMultiplier.y());
87 fScaleFactor.setZ(fScaleFactor.z() * scaleFactorMultiplier.z());
88}
89
90G4Vector3D& G4ViewParameters::GetActualLightpointDirection () {
91 SetViewAndLights (fViewpointDirection);
92 return fActualLightpointDirection;
93}
94
95// Useful quantities - begin snippet.
96// Here Follow functions to evaluate the above algorithms as a
97// function of the radius of the Bounding Sphere of the object being
98// viewed. Call them in the order given - for efficiency, later
99// functions depend on the results of earlier ones (Store the
100// results of earlier functions in your own temporary variables -
101// see, for example, G4OpenGLView::SetView ().)
102
103G4double G4ViewParameters::GetCameraDistance (G4double radius) const {
104 G4double cameraDistance;
105 if (fFieldHalfAngle == 0.) {
106 cameraDistance = radius;
107 }
108 else {
109 cameraDistance = radius / std::sin (fFieldHalfAngle) - fDolly;
110 }
111 return cameraDistance;
112}
113
114G4double G4ViewParameters::GetNearDistance (G4double cameraDistance,
115 G4double radius) const {
116 const G4double small = 1.e-6 * radius;
117 G4double nearDistance = cameraDistance - radius;
118 if (nearDistance < small) nearDistance = small;
119 return nearDistance;
120}
121
122G4double G4ViewParameters::GetFarDistance (G4double cameraDistance,
123 G4double nearDistance,
124 G4double radius) const {
125 G4double farDistance = cameraDistance + radius;
126 if (farDistance < nearDistance) farDistance = nearDistance;
127 return farDistance;
128}
129
130G4double G4ViewParameters::GetFrontHalfHeight (G4double nearDistance,
131 G4double radius) const {
132 G4double frontHalfHeight;
133 if (fFieldHalfAngle == 0.) {
134 frontHalfHeight = radius / fZoomFactor;
135 }
136 else {
137 frontHalfHeight = nearDistance * std::tan (fFieldHalfAngle) / fZoomFactor;
138 }
139 return frontHalfHeight;
140}
141// Useful quantities - end snippet.
142
143void G4ViewParameters::AddCutawayPlane (const G4Plane3D& cutawayPlane) {
144 if (fCutawayPlanes.size () < 3 ) {
145 fCutawayPlanes.push_back (cutawayPlane);
146 }
147 else {
148 G4cout <<
149 "ERROR: G4ViewParameters::AddCutawayPlane:"
150 "\n A maximum of 3 cutaway planes supported." << G4endl;
151 }
152}
153
154void G4ViewParameters::ChangeCutawayPlane
155(size_t index, const G4Plane3D& cutawayPlane) {
156 if (index >= fCutawayPlanes.size()) {
157 G4cout <<
158 "ERROR: G4ViewParameters::ChangeCutawayPlane:"
159 "\n Plane " << index << " does not exist." << G4endl;
160 } else {
161 fCutawayPlanes[index] = cutawayPlane;
162 }
163}
164
165void G4ViewParameters::SetVisibleDensity (G4double visibleDensity) {
166 const G4double reasonableMaximum = 10.0 * g / cm3;
167 if (visibleDensity < 0) {
168 G4cout << "G4ViewParameters::SetVisibleDensity: attempt to set negative "
169 "density - ignored." << G4endl;
170 }
171 else {
172 if (visibleDensity > reasonableMaximum) {
173 G4cout << "G4ViewParameters::SetVisibleDensity: density > "
174 << G4BestUnit (reasonableMaximum, "Volumic Mass")
175 << " - did you mean this?"
176 << G4endl;
177 }
178 fVisibleDensity = visibleDensity;
179 }
180}
181
182G4int G4ViewParameters::SetNoOfSides (G4int nSides) {
183 const G4int nSidesMin = 12;
184 if (nSides < nSidesMin) {
185 nSides = nSidesMin;
186 G4cout << "G4ViewParameters::SetNoOfSides: attempt to set the"
187 "\nnumber of sides per circle < " << nSidesMin
188 << "; forced to " << nSides << G4endl;
189 }
190 fNoOfSides = nSides;
191 return fNoOfSides;
192}
193
194void G4ViewParameters::SetViewAndLights
195(const G4Vector3D& viewpointDirection) {
196
197 fViewpointDirection = viewpointDirection;
198
199 // If the requested viewpoint direction is parallel to the up
200 // vector, the orientation of the view is undefined...
201 if (fViewpointDirection.unit() * fUpVector.unit() > .9999) {
202 G4cout <<
203 "WARNING: Viewpoint direction is very close to the up vector direction."
204 "\n Consider setting the up vector to obtain definable behaviour."
205 << G4endl;
206 }
207
208 // Move the lights too if requested...
209 if (fLightsMoveWithCamera) {
210 G4Vector3D zprime = fViewpointDirection.unit ();
211 G4Vector3D xprime = (fUpVector.cross (zprime)).unit ();
212 G4Vector3D yprime = zprime.cross (xprime);
213 fActualLightpointDirection =
214 fRelativeLightpointDirection.x () * xprime +
215 fRelativeLightpointDirection.y () * yprime +
216 fRelativeLightpointDirection.x () * zprime;
217 } else {
218 fActualLightpointDirection = fRelativeLightpointDirection;
219 }
220}
221
222void G4ViewParameters::SetLightpointDirection
223(const G4Vector3D& lightpointDirection) {
224 fRelativeLightpointDirection = lightpointDirection;
225 SetViewAndLights (fViewpointDirection);
226}
227
228void G4ViewParameters::SetPan (G4double right, G4double up) {
229 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
230 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
231 fCurrentTargetPoint = right * unitRight + up * unitUp;
232}
233
234void G4ViewParameters::IncrementPan (G4double right, G4double up) {
235 G4Vector3D unitRight = (fUpVector.cross (fViewpointDirection)).unit();
236 G4Vector3D unitUp = (fViewpointDirection.cross (unitRight)).unit();
237 fCurrentTargetPoint += right * unitRight + up * unitUp;
238}
239
240void G4ViewParameters::PrintDifferences (const G4ViewParameters& v) const {
241
242 // Put performance-sensitive parameters first.
243 if (
244 // This first to optimise spin, etc.
245 (fViewpointDirection != v.fViewpointDirection) ||
246
247 // No particular order from here on.
248 (fDrawingStyle != v.fDrawingStyle) ||
249 (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
250 (fRepStyle != v.fRepStyle) ||
251 (fCulling != v.fCulling) ||
252 (fCullInvisible != v.fCullInvisible) ||
253 (fDensityCulling != v.fDensityCulling) ||
254 (fVisibleDensity != v.fVisibleDensity) ||
255 (fCullCovered != v.fCullCovered) ||
256 (fSection != v.fSection) ||
257 (fNoOfSides != v.fNoOfSides) ||
258 (fUpVector != v.fUpVector) ||
259 (fFieldHalfAngle != v.fFieldHalfAngle) ||
260 (fZoomFactor != v.fZoomFactor) ||
261 (fScaleFactor != v.fScaleFactor) ||
262 (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
263 (fDolly != v.fDolly) ||
264 (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
265 (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
266 (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
267 (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
268 (fDefaultMarker != v.fDefaultMarker) ||
269 (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
270 (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
271 (fMarkerNotHidden != v.fMarkerNotHidden) ||
272 (fWindowSizeHintX != v.fWindowSizeHintX) ||
273 (fWindowSizeHintY != v.fWindowSizeHintY) ||
274 (fXGeometryString != v.fXGeometryString) ||
275 (fAutoRefresh != v.fAutoRefresh) ||
276 (fBackgroundColour != v.fBackgroundColour) ||
277 (fPicking != v.fPicking)
278 )
279 G4cout << "Difference in 1st batch." << G4endl;
280
281 if (fSection) {
282 if (!(fSectionPlane == v.fSectionPlane))
283 G4cout << "Difference in section planes batch." << G4endl;
284 }
285
286 if (IsCutaway()) {
287 if (fCutawayPlanes.size () != v.fCutawayPlanes.size ()) {
288 G4cout << "Difference in no of cutaway planes." << G4endl;
289 }
290 else {
291 for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
292 if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i]))
293 G4cout << "Difference in cutaway plane no. " << i << G4endl;
294 }
295 }
296 }
297
298 if (IsExplode()) {
299 if (fExplodeFactor != v.fExplodeFactor)
300 G4cout << "Difference in explode factor." << G4endl;
301 if (fExplodeCentre != v.fExplodeCentre)
302 G4cout << "Difference in explode centre." << G4endl;
303 }
304}
305
306std::ostream& operator << (std::ostream& os,
307 const G4ViewParameters::DrawingStyle& style) {
308 switch (style) {
309 case G4ViewParameters::wireframe:
310 os << "wireframe"; break;
311 case G4ViewParameters::hlr:
312 os << "hlr - hidden lines removed"; break;
313 case G4ViewParameters::hsr:
314 os << "hsr - hidden surfaces removed"; break;
315 case G4ViewParameters::hlhsr:
316 os << "hlhsr - hidden line, hidden surface removed"; break;
317 default: os << "unrecognised"; break;
318 }
319 return os;
320}
321
322std::ostream& operator << (std::ostream& os, const G4ViewParameters& v) {
323 os << "View parameters and options:";
324
325 os << "\n Drawing style: " << v.fDrawingStyle;
326
327 os << "\n Auxiliary edges: ";
328 if (!v.fAuxEdgeVisible) os << "in";
329 os << "visible";
330
331 os << "\n Representation style: ";
332 switch (v.fRepStyle) {
333 case G4ViewParameters::polyhedron:
334 os << "polyhedron"; break;
335 case G4ViewParameters::nurbs:
336 os << "nurbs"; break;
337 default: os << "unrecognised"; break;
338 }
339
340 os << "\n Culling: ";
341 if (v.fCulling) os << "on";
342 else os << "off";
343
344 os << "\n Culling invisible objects: ";
345 if (v.fCullInvisible) os << "on";
346 else os << "off";
347
348 os << "\n Density culling: ";
349 if (v.fDensityCulling) {
350 os << "on - invisible if density less than "
351 << v.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
352 }
353 else os << "off";
354
355 os << "\n Culling daughters covered by opaque mothers: ";
356 if (v.fCullCovered) os << "on";
357 else os << "off";
358
359 os << "\n Section flag: ";
360 if (v.fSection) os << "true, section/cut plane: " << v.fSectionPlane;
361 else os << "false";
362
363 if (v.IsCutaway()) {
364 os << "\n Cutaway planes: ";
365 for (size_t i = 0; i < v.fCutawayPlanes.size (); i++) {
366 os << ' ' << v.fCutawayPlanes[i];
367 }
368 }
369 else {
370 os << "\n No cutaway planes";
371 }
372
373 os << "\n Explode factor: " << v.fExplodeFactor
374 << " about centre: " << v.fExplodeCentre;
375
376 os << "\n No. of sides used in circle polygon approximation: "
377 << v.fNoOfSides;
378
379 os << "\n Viewpoint direction: " << v.fViewpointDirection;
380
381 os << "\n Up vector: " << v.fUpVector;
382
383 os << "\n Field half angle: " << v.fFieldHalfAngle;
384
385 os << "\n Zoom factor: " << v.fZoomFactor;
386
387 os << "\n Scale factor: " << v.fScaleFactor;
388
389 os << "\n Current target point: " << v.fCurrentTargetPoint;
390
391 os << "\n Dolly distance: " << v.fDolly;
392
393 os << "\n Light ";
394 if (v.fLightsMoveWithCamera) os << "moves";
395 else os << "does not move";
396 os << " with camera";
397
398 os << "\n Relative lightpoint direction: "
399 << v.fRelativeLightpointDirection;
400
401 os << "\n Actual lightpoint direction: "
402 << v.fActualLightpointDirection;
403
404 os << "\n Derived parameters for standard view of object of unit radius:";
405 G4ViewParameters tempVP = v;
406 tempVP.fDolly = 0.;
407 tempVP.fZoomFactor = 1.;
408 const G4double radius = 1.;
409 const G4double cameraDistance = tempVP.GetCameraDistance (radius);
410 const G4double nearDistance =
411 tempVP.GetNearDistance (cameraDistance, radius);
412 const G4double farDistance =
413 tempVP.GetFarDistance (cameraDistance, nearDistance, radius);
414 const G4double right = tempVP.GetFrontHalfHeight (nearDistance, radius);
415 os << "\n Camera distance: " << cameraDistance;
416 os << "\n Near distance: " << nearDistance;
417 os << "\n Far distance: " << farDistance;
418 os << "\n Front half height: " << right;
419
420 os << "\n Default VisAttributes:\n " << v.fDefaultVisAttributes;
421
422 os << "\n Default TextVisAttributes:\n " << v.fDefaultTextVisAttributes;
423
424 os << "\n Default marker: " << v.fDefaultMarker;
425
426 os << "\n Global marker scale: " << v.fGlobalMarkerScale;
427
428 os << "\n Global lineWidth scale: " << v.fGlobalLineWidthScale;
429
430 os << "\n Marker ";
431 if (v.fMarkerNotHidden) os << "not ";
432 os << "hidden by surfaces.";
433
434 os << "\n Window size hint: "
435 << v.fWindowSizeHintX << 'x'<< v.fWindowSizeHintX;
436
437 os << "\n X geometry string: " << v.fXGeometryString;
438
439 os << "\n Auto refresh: ";
440 if (v.fAutoRefresh) os << "true";
441 else os << "false";
442
443 os << "\n Background colour: " << v.fBackgroundColour;
444
445 os << "\n Picking requested: ";
446 if (v.fPicking) os << "true";
447 else os << "false";
448
449 return os;
450}
451
452G4bool G4ViewParameters::operator != (const G4ViewParameters& v) const {
453
454 // Put performance-sensitive parameters first.
455 if (
456 // This first to optimise spin, etc.
457 (fViewpointDirection != v.fViewpointDirection) ||
458
459 // No particular order from here on.
460 (fDrawingStyle != v.fDrawingStyle) ||
461 (fAuxEdgeVisible != v.fAuxEdgeVisible) ||
462 (fRepStyle != v.fRepStyle) ||
463 (fCulling != v.fCulling) ||
464 (fCullInvisible != v.fCullInvisible) ||
465 (fDensityCulling != v.fDensityCulling) ||
466 (fCullCovered != v.fCullCovered) ||
467 (fSection != v.fSection) ||
468 (IsCutaway() != v.IsCutaway()) ||
469 (IsExplode() != v.IsExplode()) ||
470 (fNoOfSides != v.fNoOfSides) ||
471 (fUpVector != v.fUpVector) ||
472 (fFieldHalfAngle != v.fFieldHalfAngle) ||
473 (fZoomFactor != v.fZoomFactor) ||
474 (fScaleFactor != v.fScaleFactor) ||
475 (fCurrentTargetPoint != v.fCurrentTargetPoint) ||
476 (fDolly != v.fDolly) ||
477 (fRelativeLightpointDirection != v.fRelativeLightpointDirection) ||
478 (fLightsMoveWithCamera != v.fLightsMoveWithCamera) ||
479 (fDefaultVisAttributes != v.fDefaultVisAttributes) ||
480 (fDefaultTextVisAttributes != v.fDefaultTextVisAttributes) ||
481 (fDefaultMarker != v.fDefaultMarker) ||
482 (fGlobalMarkerScale != v.fGlobalMarkerScale) ||
483 (fGlobalLineWidthScale != v.fGlobalLineWidthScale) ||
484 (fMarkerNotHidden != v.fMarkerNotHidden) ||
485 (fWindowSizeHintX != v.fWindowSizeHintX) ||
486 (fWindowSizeHintY != v.fWindowSizeHintY) ||
487 (fXGeometryString != v.fXGeometryString) ||
488 (fAutoRefresh != v.fAutoRefresh) ||
489 (fBackgroundColour != v.fBackgroundColour) ||
490 (fPicking != v.fPicking)
491 )
492 return true;
493
494 if (fDensityCulling &&
495 (fVisibleDensity != v.fVisibleDensity)) return true;
496
497 if (fSection &&
498 (!(fSectionPlane == v.fSectionPlane))) return true;
499
500 if (IsCutaway()) {
501 if (fCutawayPlanes.size () != v.fCutawayPlanes.size ())
502 return true;
503 else {
504 for (size_t i = 0; i < fCutawayPlanes.size (); i++) {
505 if (!(fCutawayPlanes[i] == v.fCutawayPlanes[i])) return true;
506 }
507 }
508 }
509
510 if (IsExplode() &&
511 (fExplodeFactor != v.fExplodeFactor) ||
512 (fExplodeCentre != v.fExplodeCentre)) return true;
513
514 return false;
515}
Note: See TracBrowser for help on using the repository browser.