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

Last change on this file since 543 was 531, checked in by garnier, 18 years ago

r660@mac-90108: laurentgarnier | 2007-06-25 16:10:12 +0200
ajout de fichiers NON modifies

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