Geant4  10.02
PerspectiveVisAction.cc
Go to the documentation of this file.
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 //
28 //
29 //
30 // $Id: PerspectiveVisAction.cc 69587 2013-05-08 14:26:03Z gcosmo $
31 
32 #include "PerspectiveVisAction.hh"
33 
35 #include "G4VVisManager.hh"
36 #include "G4VisAttributes.hh"
37 #include "G4Box.hh"
38 #include "G4Polyline.hh"
39 #include "G4Polyhedron.hh"
40 #include "G4Vector3D.hh"
41 #include "G4Point3D.hh"
42 #include "G4SystemOfUnits.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
48  fpVisManager(0),
49  fOptionString("none"),
50  fScene("room-and-chair"),
51  fRoomX(2.5*m), // Half-lengths...
52  fRoomY(2.5*m),
53  fRoomZ(1.3*m),
54  fWindowX(10*cm),
55  fWindowY(75*cm),
56  fWindowZ(50*cm),
57  fWindowSillHeight(80*cm),
58  fWindowOffset(-50*cm),
59  fDoorFrameX(10*cm),
60  fDoorFrameY(50*cm),
61  fDoorFrameZ(1*m),
62  fDoorFrameOffset(1.5*m),
63  fDoorX(2*cm),
64  fDoorY(50*cm),
65  fDoorZ(1*m),
66  fChairX(20*cm), // Half overall width.
67  fChairY(20*cm), // Half overall depth.
68  fChairZ(45*cm), // Half overall height.
69  fChairSeat(20*cm), // Half height of top of seat.
70  fChairThickness(3.*cm) // Half thicknes of back, seat, legs.
71 {
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
78 {
80  if (fpVisManager) {
81 
82  // All scenes assume upvector z and origin on "floor"...
83 
84  if (fScene == "room-and-chair" )
85  {
86  RoomAndChair();
87  }
88  }
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94 {
95  // Simple box, size of a room, translated so origin is on xy "floor"...
96  G4VisAttributes room_visAtts(G4Colour::Red());
97  room_visAtts.SetForceWireframe(true);
99  (G4Box("box",fRoomX,fRoomY,fRoomZ), room_visAtts, G4TranslateZ3D(fRoomZ));
100 
101  // Windows...
102  G4Box ("window",fWindowX,fWindowY,fWindowZ);
104  (G4Box("window-x",fWindowX,fWindowY,fWindowZ),
105  room_visAtts,
108  (G4Box("window-y1",fWindowX,fWindowY,fWindowZ),
109  room_visAtts,
111  G4RotateZ3D(90.*deg));
113  (G4Box("window-y2",fWindowX,fWindowY,fWindowZ),
114  room_visAtts,
116  G4RotateZ3D(-90.*deg));
117 
118  // Door...
120  (G4Box("door-frame",fDoorFrameX,fDoorFrameY,fDoorFrameZ),
121  room_visAtts,
124  (G4Box("door",fDoorX,fDoorY,fDoorZ),
125  room_visAtts,
128  G4RotateZ3D(60.*deg) *
129  G4TranslateY3D(-fDoorY)); // Last transform operates first.
130 
131  // Chair...
132  G4VisAttributes chair_visAtts(G4Colour::Cyan());
133  G4Transform3D A = G4RotateZ3D(90.*deg); // Turn through 90 deg.
134  G4Transform3D B = G4RotateY3D(90.*deg); // Lie down.
135  G4Transform3D C = G4RotateZ3D(-20.*deg) ; // Rotate a little.
136  G4Transform3D D = G4TranslateZ3D(fChairY); // Place on floor.
137  G4Transform3D E = G4TranslateY3D(-0.5 * fRoomY); // Move over to the left...
138  G4Transform3D chair_transform = E*D*C*B*A;
139  Chair(chair_visAtts, chair_transform);
140 }
141 
142 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
143 
145 (const G4VisAttributes& visAtts,
146  const G4Transform3D& transform)
147 {
148  // Origin is on floor, z = 0, and in the xy centre...
149  ExtendedDraw
150  (G4Box("chair-back",fChairX, fChairThickness, fChairZ - fChairSeat),
151  visAtts, transform *
152  G4Translate3D(0.,-fChairY + fChairThickness, fChairZ + fChairSeat));
153  ExtendedDraw
154  (G4Box("chair-seat",fChairX, fChairY, fChairThickness),
155  visAtts, transform * G4TranslateZ3D(-fChairThickness + 2.* fChairSeat));
156  for (int i = -1; i < 2; i+=2) {
157  for (int j = -1; j < 2; j+=2) {
158  ExtendedDraw
159  (G4Box("chair-leg",fChairThickness,
160  fChairThickness,
161  fChairSeat - fChairThickness),
162  visAtts, transform *
163  G4Translate3D(i * (fChairX - fChairThickness),
164  j * (fChairY - fChairThickness),
165  fChairSeat - fChairThickness));
166  }
167  }
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
171 
173 (const G4VSolid& solid,
174  const G4VisAttributes& visAtts,
175  const G4Transform3D& transform)
176 {
177  static const G4double extender = 100.*m;
178  static const G4Vector3D x(1,0,0);
179  static const G4Vector3D y(0,1,0);
180  static const G4Vector3D z(0,0,1);
181 
182  // Draw extended edges as requested...
183  G4bool any = false, A = false, X = false, Y = false, Z = false;
184  if (fOptionString.contains("a")) {A = true; any = true;}
185  if (fOptionString.contains("x")) {X = true; any = true;}
186  if (fOptionString.contains("y")) {Y = true; any = true;}
187  if (fOptionString.contains("z")) {Z = true; any = true;}
188  if (any)
189  {
190  G4Polyhedron* polyhedron = solid.GetPolyhedron();
191  G4bool isAuxEdgeVisible = false; // How do I pick this up??? Can't.
192  G4bool notLastFace;
193  do {
194  G4int n;
195  G4Point3D nodes[4];
196  notLastFace = polyhedron->GetNextFacet(n, nodes);
197  G4bool notLastEdge;
198  do {
199  G4Point3D v1, v2;
200  G4int edgeFlag;
201  notLastEdge = polyhedron->GetNextEdge(v1, v2, edgeFlag);
202  if (isAuxEdgeVisible || edgeFlag > 0) {
203  G4Vector3D v21 = v2 - v1;
204  // Check for components of actual edge...
205  G4Vector3D v21a = v21;
206  v21a.transform(transform);
207  // G4cout << "v21a: " << v21a << G4endl;
208  using namespace std;
209  if (A ||
210  (Z && abs(v21a.z()) >
211  sqrt(v21a.x()*v21a.x()+v21a.y()*v21a.y())) ||
212  (X && abs(v21a.x()) >
213  sqrt(v21a.y()*v21a.y()+v21a.z()*v21a.z())) ||
214  (Y && abs(v21a.y()) >
215  sqrt(v21a.x()*v21a.x()+v21a.x()*v21a.z()))) {
216  G4Polyline edge;
217  edge.SetVisAttributes(G4Colour(.2,.2,.2));
218  edge.push_back(v1 - extender * v21.unit());
219  edge.push_back(v2 + extender * v21.unit());
220  fpVisManager->Draw(edge, transform);
221  }
222  }
223  } while (notLastEdge);
224  } while (notLastFace);
225  }
226 
227  // Draw actual object...
228  fpVisManager->Draw(solid, visAtts, transform);
229 }
230 
231 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual G4Polyhedron * GetPolyhedron() const
Definition: G4VSolid.cc:644
static const double cm
Definition: G4SIunits.hh:118
double Y(double density)
void SetForceWireframe(G4bool)
HepGeom::RotateY3D G4RotateY3D
static G4VVisManager * GetConcreteInstance()
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
double C(double temp)
double B(double temperature)
HepGeom::TranslateY3D G4TranslateY3D
int G4int
Definition: G4Types.hh:78
HepGeom::RotateZ3D G4RotateZ3D
Definition of the PerspectiveVisActionMessenger class.
double A(double temperature)
static const double deg
Definition: G4SIunits.hh:151
bool G4bool
Definition: G4Types.hh:79
void ExtendedDraw(const G4VSolid &, const G4VisAttributes &, const G4Transform3D &objectTransformation=G4Transform3D())
HepGeom::Transform3D G4Transform3D
const G4int n
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
G4VVisManager * fpVisManager
Definition of the PerspectiveVisAction class.
static G4Colour Cyan()
Definition: G4Colour.hh:151
const G4double x[NPOINTSGL]
void Chair(const G4VisAttributes &, const G4Transform3D &)
double D(double temp)
HepGeom::Translate3D G4Translate3D
static const double m
Definition: G4SIunits.hh:128
static G4Colour Red()
Definition: G4Colour.hh:148
double G4double
Definition: G4Types.hh:76
HepGeom::TranslateZ3D G4TranslateZ3D