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[ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/visualization/perspective/src/PerspectiveVisAction.cc (Version 11.3.0) and /examples/extended/visualization/perspective/src/PerspectiveVisAction.cc (Version 10.6.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 /// \file visualization/perspective/src/Perspe     26 /// \file visualization/perspective/src/PerspectiveVisAction.cc
 27 /// \brief Implementation of the PerspectiveVi     27 /// \brief Implementation of the PerspectiveVisAction class
 28 //                                                 28 //
 29 //                                                 29 //
 30                                                    30 
 31 #include "PerspectiveVisAction.hh"                 31 #include "PerspectiveVisAction.hh"
 32                                                    32 
 33 #include "PerspectiveVisActionMessenger.hh"        33 #include "PerspectiveVisActionMessenger.hh"
 34                                                <<  34 #include "G4VVisManager.hh"
                                                   >>  35 #include "G4VisAttributes.hh"
 35 #include "G4Box.hh"                                36 #include "G4Box.hh"
 36 #include "G4Point3D.hh"                        << 
 37 #include "G4Polyhedron.hh"                     << 
 38 #include "G4Polyline.hh"                           37 #include "G4Polyline.hh"
 39 #include "G4SystemOfUnits.hh"                  <<  38 #include "G4Polyhedron.hh"
 40 #include "G4VVisManager.hh"                    << 
 41 #include "G4Vector3D.hh"                           39 #include "G4Vector3D.hh"
 42 #include "G4VisAttributes.hh"                  <<  40 #include "G4Point3D.hh"
                                                   >>  41 #include "G4SystemOfUnits.hh"
 43                                                    42 
 44 //....oooOO0OOooo........oooOO0OOooo........oo     43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 45                                                    44 
 46 PerspectiveVisAction::PerspectiveVisAction()   <<  45 PerspectiveVisAction::PerspectiveVisAction():
 47   : G4VUserVisAction(),                        <<  46   G4VUserVisAction(),
 48     fpVisManager(0),                           <<  47   fpVisManager(0),
 49     fOptionString("none"),                     <<  48   fOptionString("none"),
 50     fScene("room-and-chair"),                  <<  49   fScene("room-and-chair"),
 51     fRoomX(2.5 * m),  // Half-lengths...       <<  50   fRoomX(2.5*m),  // Half-lengths...
 52     fRoomY(2.5 * m),                           <<  51   fRoomY(2.5*m),
 53     fRoomZ(1.3 * m),                           <<  52   fRoomZ(1.3*m),
 54     fWindowX(10 * cm),                         <<  53   fWindowX(10*cm),
 55     fWindowY(75 * cm),                         <<  54   fWindowY(75*cm),
 56     fWindowZ(50 * cm),                         <<  55   fWindowZ(50*cm),
 57     fWindowSillHeight(80 * cm),                <<  56   fWindowSillHeight(80*cm),
 58     fWindowOffset(-50 * cm),                   <<  57   fWindowOffset(-50*cm),
 59     fDoorFrameX(10 * cm),                      <<  58   fDoorFrameX(10*cm),
 60     fDoorFrameY(50 * cm),                      <<  59   fDoorFrameY(50*cm),
 61     fDoorFrameZ(1 * m),                        <<  60   fDoorFrameZ(1*m),
 62     fDoorFrameOffset(1.5 * m),                 <<  61   fDoorFrameOffset(1.5*m),
 63     fDoorX(2 * cm),                            <<  62   fDoorX(2*cm),
 64     fDoorY(50 * cm),                           <<  63   fDoorY(50*cm),
 65     fDoorZ(1 * m),                             <<  64   fDoorZ(1*m),
 66     fChairX(20 * cm),  // Half overall width.  <<  65   fChairX(20*cm),          // Half overall width.
 67     fChairY(20 * cm),  // Half overall depth.  <<  66   fChairY(20*cm),          // Half overall depth.
 68     fChairZ(45 * cm),  // Half overall height. <<  67   fChairZ(45*cm),          // Half overall height.
 69     fChairSeat(20 * cm),  // Half height of to <<  68   fChairSeat(20*cm),       // Half height of top of seat.
 70     fChairThickness(3. * cm)  // Half thicknes <<  69   fChairThickness(3.*cm)   // Half thicknes of back, seat, legs.
 71 {                                                  70 {
 72   new PerspectiveVisActionMessenger(this);         71   new PerspectiveVisActionMessenger(this);
 73 }                                                  72 }
 74                                                    73 
 75 //....oooOO0OOooo........oooOO0OOooo........oo     74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 76                                                    75 
 77 void PerspectiveVisAction::Draw()                  76 void PerspectiveVisAction::Draw()
 78 {                                                  77 {
 79   fpVisManager = G4VVisManager::GetConcreteIns     78   fpVisManager = G4VVisManager::GetConcreteInstance();
 80   if (fpVisManager) {                              79   if (fpVisManager) {
                                                   >>  80 
 81     // All scenes assume upvector z and origin     81     // All scenes assume upvector z and origin on "floor"...
 82                                                    82 
 83     if (fScene == "room-and-chair") {          <<  83     if (fScene == "room-and-chair" )
 84       RoomAndChair();                          <<  84       {
 85     }                                          <<  85         RoomAndChair();
                                                   >>  86       }
 86   }                                                87   }
 87 }                                                  88 }
 88                                                    89 
 89 //....oooOO0OOooo........oooOO0OOooo........oo     90 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 90                                                    91 
 91 void PerspectiveVisAction::RoomAndChair()          92 void PerspectiveVisAction::RoomAndChair()
 92 {                                                  93 {
 93   // Simple box, size of a room, translated so     94   // Simple box, size of a room, translated so origin is on xy "floor"...
 94   G4VisAttributes room_visAtts(G4Colour::Red()     95   G4VisAttributes room_visAtts(G4Colour::Red());
 95   room_visAtts.SetForceWireframe(true);            96   room_visAtts.SetForceWireframe(true);
 96   ExtendedDraw(G4Box("box", fRoomX, fRoomY, fR <<  97   ExtendedDraw
                                                   >>  98     (G4Box("box",fRoomX,fRoomY,fRoomZ), room_visAtts, G4TranslateZ3D(fRoomZ));
 97                                                    99 
 98   // Windows...                                   100   // Windows...
 99   G4Box("window", fWindowX, fWindowY, fWindowZ << 101   G4Box ("window",fWindowX,fWindowY,fWindowZ);
100   ExtendedDraw(G4Box("window-x", fWindowX, fWi << 102   ExtendedDraw
101                G4Translate3D(-fRoomX - fWindow << 103     (G4Box("window-x",fWindowX,fWindowY,fWindowZ),
102   ExtendedDraw(G4Box("window-y1", fWindowX, fW << 104      room_visAtts,
103                G4Translate3D(0., -fRoomY - fWi << 105      G4Translate3D(-fRoomX - fWindowX, fWindowOffset, fWindowY + fWindowSillHeight));
104                  * G4RotateZ3D(90. * deg));    << 106   ExtendedDraw
105   ExtendedDraw(G4Box("window-y2", fWindowX, fW << 107     (G4Box("window-y1",fWindowX,fWindowY,fWindowZ),
106                G4Translate3D(0., fRoomY + fWin << 108      room_visAtts,
107                  * G4RotateZ3D(-90. * deg));   << 109      G4Translate3D(0., -fRoomY - fWindowX, fWindowY + fWindowSillHeight) *
                                                   >> 110      G4RotateZ3D(90.*deg));
                                                   >> 111   ExtendedDraw
                                                   >> 112     (G4Box("window-y2",fWindowX,fWindowY,fWindowZ),
                                                   >> 113      room_visAtts,
                                                   >> 114      G4Translate3D(0., fRoomY + fWindowX, fWindowY + fWindowSillHeight) *
                                                   >> 115      G4RotateZ3D(-90.*deg));
108                                                   116 
109   // Door...                                      117   // Door...
110   ExtendedDraw(G4Box("door-frame", fDoorFrameX << 118   ExtendedDraw
111                G4Translate3D(-fRoomX - fDoorFr << 119     (G4Box("door-frame",fDoorFrameX,fDoorFrameY,fDoorFrameZ),
112   ExtendedDraw(G4Box("door", fDoorX, fDoorY, f << 120      room_visAtts,
113                G4Translate3D(-fRoomX - fDoorX, << 121      G4Translate3D(-fRoomX - fDoorFrameX, fDoorFrameOffset, fDoorFrameZ));
114                  * G4RotateZ3D(60. * deg)      << 122   ExtendedDraw
115                  * G4TranslateY3D(-fDoorY));   << 123     (G4Box("door",fDoorX,fDoorY,fDoorZ),
                                                   >> 124      room_visAtts,
                                                   >> 125      G4Translate3D(-fRoomX - fDoorX, fDoorFrameOffset, fDoorZ) *
                                                   >> 126      G4TranslateY3D(fDoorY) *
                                                   >> 127      G4RotateZ3D(60.*deg) *
                                                   >> 128      G4TranslateY3D(-fDoorY));  // Last transform operates first.
116                                                   129 
117   // Chair...                                     130   // Chair...
118   G4VisAttributes chair_visAtts(G4Colour::Cyan    131   G4VisAttributes chair_visAtts(G4Colour::Cyan());
119   G4Transform3D A = G4RotateZ3D(90. * deg);  / << 132   G4Transform3D A = G4RotateZ3D(90.*deg);           // Turn through 90 deg.
120   G4Transform3D B = G4RotateY3D(90. * deg);  / << 133   G4Transform3D B = G4RotateY3D(90.*deg);           // Lie down.
121   G4Transform3D C = G4RotateZ3D(-20. * deg);   << 134   G4Transform3D C = G4RotateZ3D(-20.*deg) ;         // Rotate a little.
122   G4Transform3D D = G4TranslateZ3D(fChairY);   << 135   G4Transform3D D = G4TranslateZ3D(fChairY);        // Place on floor.
123   G4Transform3D E = G4TranslateY3D(-0.5 * fRoo    136   G4Transform3D E = G4TranslateY3D(-0.5 * fRoomY);  // Move over to the left...
124   G4Transform3D chair_transform = E * D * C *  << 137   G4Transform3D chair_transform = E*D*C*B*A;
125   Chair(chair_visAtts, chair_transform);          138   Chair(chair_visAtts, chair_transform);
126 }                                                 139 }
127                                                   140 
128 //....oooOO0OOooo........oooOO0OOooo........oo    141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
129                                                   142 
130 void PerspectiveVisAction::Chair(const G4VisAt << 143 void PerspectiveVisAction::Chair
                                                   >> 144 (const G4VisAttributes& visAtts,
                                                   >> 145  const G4Transform3D& transform)
131 {                                                 146 {
132   // Origin is on floor, z = 0, and in the xy     147   // Origin is on floor, z = 0, and in the xy centre...
133   ExtendedDraw(G4Box("chair-back", fChairX, fC << 148   ExtendedDraw
134                transform * G4Translate3D(0., - << 149     (G4Box("chair-back",fChairX, fChairThickness, fChairZ - fChairSeat),
135   ExtendedDraw(G4Box("chair-seat", fChairX, fC << 150      visAtts, transform *
136                transform * G4TranslateZ3D(-fCh << 151      G4Translate3D(0.,-fChairY + fChairThickness, fChairZ + fChairSeat));
137   for (int i = -1; i < 2; i += 2) {            << 152   ExtendedDraw
138     for (int j = -1; j < 2; j += 2) {          << 153     (G4Box("chair-seat",fChairX, fChairY, fChairThickness),
139       ExtendedDraw(                            << 154      visAtts, transform * G4TranslateZ3D(-fChairThickness + 2.* fChairSeat));
140         G4Box("chair-leg", fChairThickness, fC << 155   for (int i = -1; i < 2; i+=2) {
141         transform                              << 156     for (int j = -1; j < 2; j+=2) {
142           * G4Translate3D(i * (fChairX - fChai << 157       ExtendedDraw
143                           fChairSeat - fChairT << 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));
144     }                                             165     }
145   }                                               166   }
146 }                                                 167 }
147                                                   168 
148 //....oooOO0OOooo........oooOO0OOooo........oo    169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149                                                   170 
150 void PerspectiveVisAction::ExtendedDraw(const  << 171 void PerspectiveVisAction::ExtendedDraw
151                                         const  << 172 (const G4VSolid& solid,
                                                   >> 173  const G4VisAttributes& visAtts,
                                                   >> 174  const G4Transform3D& transform)
152 {                                                 175 {
153   static const G4double extender = 100. * m;   << 176   static const G4double extender = 100.*m;
154   static const G4Vector3D x(1, 0, 0);          << 177   static const G4Vector3D x(1,0,0);
155   static const G4Vector3D y(0, 1, 0);          << 178   static const G4Vector3D y(0,1,0);
156   static const G4Vector3D z(0, 0, 1);          << 179   static const G4Vector3D z(0,0,1);
157                                                   180 
158   // Draw extended edges as requested...          181   // Draw extended edges as requested...
159   G4bool any = false, A = false, X = false, Y     182   G4bool any = false, A = false, X = false, Y = false, Z = false;
160   if (G4StrUtil::contains(fOptionString, "a")) << 183   if (fOptionString.contains("a")) {A = true; any = true;}
161     A = true;                                  << 184   if (fOptionString.contains("x")) {X = true; any = true;}
162     any = true;                                << 185   if (fOptionString.contains("y")) {Y = true; any = true;}
163   }                                            << 186   if (fOptionString.contains("z")) {Z = true; any = true;}
164   if (G4StrUtil::contains(fOptionString, "x")) << 187   if (any)
165     X = true;                                  << 188     {
166     any = true;                                << 189       G4Polyhedron* polyhedron = solid.GetPolyhedron();
167   }                                            << 190       G4bool isAuxEdgeVisible = false;  // How do I pick this up???   Can't.
168   if (G4StrUtil::contains(fOptionString, "y")) << 191       G4bool notLastFace;
169     Y = true;                                  << 
170     any = true;                                << 
171   }                                            << 
172   if (G4StrUtil::contains(fOptionString, "z")) << 
173     Z = true;                                  << 
174     any = true;                                << 
175   }                                            << 
176   if (any) {                                   << 
177     G4Polyhedron* polyhedron = solid.GetPolyhe << 
178     G4bool isAuxEdgeVisible = false;  // How d << 
179     G4bool notLastFace;                        << 
180     do {                                       << 
181       G4int n;                                 << 
182       G4Point3D nodes[4];                      << 
183       notLastFace = polyhedron->GetNextFacet(n << 
184       G4bool notLastEdge;                      << 
185       do {                                        192       do {
186         G4Point3D v1, v2;                      << 193         G4int n;
187         G4int edgeFlag;                        << 194         G4Point3D nodes[4];
188         notLastEdge = polyhedron->GetNextEdge( << 195         notLastFace = polyhedron->GetNextFacet(n, nodes);
189         if (isAuxEdgeVisible || edgeFlag > 0)  << 196         G4bool notLastEdge;
190           G4Vector3D v21 = v2 - v1;            << 197         do {
191           // Check for components of actual ed << 198           G4Point3D v1, v2;
192           G4Vector3D v21a = v21;               << 199           G4int edgeFlag;
193           v21a.transform(transform);           << 200           notLastEdge = polyhedron->GetNextEdge(v1, v2, edgeFlag);
194           // G4cout << "v21a: " << v21a << G4e << 201           if (isAuxEdgeVisible || edgeFlag > 0) {
195           using namespace std;                 << 202             G4Vector3D v21 = v2 - v1;
196           if (A || (Z && abs(v21a.z()) > sqrt( << 203             // Check for components of actual edge...
197               || (X && abs(v21a.x()) > sqrt(v2 << 204             G4Vector3D v21a = v21;
198               || (Y && abs(v21a.y()) > sqrt(v2 << 205             v21a.transform(transform);
199           {                                    << 206             // G4cout << "v21a: " << v21a << G4endl;
200             G4Polyline edge;                   << 207             using namespace std;
201             edge.SetVisAttributes(G4Colour(.2, << 208             if (A ||
202             edge.push_back(v1 - extender * v21 << 209                 (Z && abs(v21a.z()) >
203             edge.push_back(v2 + extender * v21 << 210                  sqrt(v21a.x()*v21a.x()+v21a.y()*v21a.y())) ||
204             fpVisManager->Draw(edge, transform << 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             }
205           }                                       221           }
206         }                                      << 222         } while (notLastEdge);
207       } while (notLastEdge);                   << 223       } while (notLastFace);
208     } while (notLastFace);                     << 224     }
209   }                                            << 
210                                                   225 
211   // Draw actual object...                        226   // Draw actual object...
212   fpVisManager->Draw(solid, visAtts, transform    227   fpVisManager->Draw(solid, visAtts, transform);
213 }                                                 228 }
214                                                   229 
215 //....oooOO0OOooo........oooOO0OOooo........oo    230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
216                                                   231