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