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