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] [ 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 /geometry/navigation/src/G4DrawVoxels.cc (Version 11.3.0) and /geometry/navigation/src/G4DrawVoxels.cc (Version 9.4.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 // class G4DrawVoxels implementation           <<  26 //
                                                   >>  27 // $Id: G4DrawVoxels.cc,v 1.4 2006-06-29 18:36:34 gunter Exp $
                                                   >>  28 // GEANT4 tag $Name: geant4-09-04-patch-02 $
                                                   >>  29 //
                                                   >>  30 // 
                                                   >>  31 // class G4DrawVoxels
                                                   >>  32 //
                                                   >>  33 // Implementation
 27 //                                                 34 //
 28 // Define G4DrawVoxelsDebug for debugging info     35 // Define G4DrawVoxelsDebug for debugging information on G4cout
 29 //                                                 36 //
                                                   >>  37 // History:
                                                   >>  38 // 03/08/1999 The G4VisAttributes have been made member data for
                                                   >>  39 //            lifetime reasons / visualisation  L.G
 30 // 29/07/1999 first comitted version L.G.          40 // 29/07/1999 first comitted version L.G.
 31 // -------------------------------------------     41 // --------------------------------------------------------------------
 32                                                    42 
 33 #include "G4DrawVoxels.hh"                         43 #include "G4DrawVoxels.hh"
 34 #include "G4AffineTransform.hh"                    44 #include "G4AffineTransform.hh"
 35 #include "G4SmartVoxelHeader.hh"                   45 #include "G4SmartVoxelHeader.hh"
 36 #include "G4LogicalVolume.hh"                      46 #include "G4LogicalVolume.hh"
 37 #include "G4VSolid.hh"                             47 #include "G4VSolid.hh"
 38 #include "G4VVisManager.hh"                        48 #include "G4VVisManager.hh"
 39 #include "G4Colour.hh"                             49 #include "G4Colour.hh"
 40 #include "G4TransportationManager.hh"              50 #include "G4TransportationManager.hh"
 41 #include "G4TouchableHandle.hh"                <<  51 #include "G4TouchableHistoryHandle.hh"
 42                                                    52 
 43 #define voxel_width 0                              53 #define voxel_width 0
 44                                                    54 
 45 // Private Constructor                             55 // Private Constructor
 46 //                                                 56 //
 47 G4DrawVoxels::G4DrawVoxels()                       57 G4DrawVoxels::G4DrawVoxels()
 48 {                                                  58 {
 49   fVoxelsVisAttributes[0].SetColour(G4Colour(1     59   fVoxelsVisAttributes[0].SetColour(G4Colour(1.,0.,0.));
 50   fVoxelsVisAttributes[1].SetColour(G4Colour(0     60   fVoxelsVisAttributes[1].SetColour(G4Colour(0.,1.,0.));
 51   fVoxelsVisAttributes[2].SetColour(G4Colour(0     61   fVoxelsVisAttributes[2].SetColour(G4Colour(0.,0.,1.));
 52   fBoundingBoxVisAttributes.SetColour(G4Colour     62   fBoundingBoxVisAttributes.SetColour(G4Colour(.3,0.,.2));
 53 }                                                  63 }
 54                                                    64 
                                                   >>  65 // Destructor
                                                   >>  66 //
                                                   >>  67 G4DrawVoxels::~G4DrawVoxels()
                                                   >>  68 {
                                                   >>  69 }
                                                   >>  70 
 55 // Methods that allow changing colors of the d     71 // Methods that allow changing colors of the drawing
 56 //                                                 72 //
 57 void G4DrawVoxels::SetVoxelsVisAttributes(G4Vi     73 void G4DrawVoxels::SetVoxelsVisAttributes(G4VisAttributes& VA_voxelX,
 58                                           G4Vi     74                                           G4VisAttributes& VA_voxelY,
 59                                           G4Vi     75                                           G4VisAttributes& VA_voxelZ)
 60 {                                                  76 {
 61   fVoxelsVisAttributes[0] = VA_voxelX;         <<  77   fVoxelsVisAttributes[0]=VA_voxelX;
 62   fVoxelsVisAttributes[1] = VA_voxelY;         <<  78   fVoxelsVisAttributes[1]=VA_voxelY;
 63   fVoxelsVisAttributes[2] = VA_voxelZ;         <<  79   fVoxelsVisAttributes[2]=VA_voxelZ;
 64 }                                                  80 }
 65                                                    81 
 66 void G4DrawVoxels::SetBoundingBoxVisAttributes     82 void G4DrawVoxels::SetBoundingBoxVisAttributes(G4VisAttributes& VA_boundingbox)
 67 {                                                  83 {
 68   fBoundingBoxVisAttributes = VA_boundingbox;  <<  84   fBoundingBoxVisAttributes=VA_boundingbox;
 69 }                                                  85 }
 70                                                    86 
 71 // ------------------------------------------- <<  87 // ***************************************************************
 72                                                    88 
 73 void                                               89 void
 74 G4DrawVoxels::ComputeVoxelPolyhedra(const G4Lo     90 G4DrawVoxels::ComputeVoxelPolyhedra(const G4LogicalVolume* lv,
 75                                     const G4Sm     91                                     const G4SmartVoxelHeader* header,
 76                                           G4Vo     92                                           G4VoxelLimits& limit,
 77                                           G4Pl     93                                           G4PlacedPolyhedronList* ppl) const
 78 {                                                  94 {
 79   // Let's draw the selected voxelisation now      95   // Let's draw the selected voxelisation now !
 80                                                    96  
 81    G4VSolid* solid = lv->GetSolid();           <<  97    G4VSolid* solid=lv->GetSolid();
 82                                                    98   
 83    G4double dx=kInfinity, dy=kInfinity, dz=kIn <<  99    G4double dx=kInfinity,dy=kInfinity,dz=kInfinity;
 84    G4double xmax=0, xmin=0, ymax=0, ymin=0, zm << 100    G4double xmax=0,xmin=0,ymax=0,ymin=0,zmax=0,zmin=0;
 85                                                   101    
 86    if (lv->GetNoDaughters()<=0)                   102    if (lv->GetNoDaughters()<=0)
 87    {                                              103    {
 88      return;                                      104      return;
 89    }                                              105    }
 90                                                   106    
 91    // Let's get the data for the voxelisation     107    // Let's get the data for the voxelisation
 92                                                   108 
 93    solid->CalculateExtent(kXAxis,limit,G4Affin    109    solid->CalculateExtent(kXAxis,limit,G4AffineTransform(),xmin,xmax);
 94      // G4AffineTransform() is identity           110      // G4AffineTransform() is identity
 95    solid->CalculateExtent(kYAxis,limit,G4Affin    111    solid->CalculateExtent(kYAxis,limit,G4AffineTransform(),ymin,ymax);
 96      // extents according to the axis of the l    112      // extents according to the axis of the local frame
 97    solid->CalculateExtent(kZAxis,limit,G4Affin    113    solid->CalculateExtent(kZAxis,limit,G4AffineTransform(),zmin,zmax);
 98    dx = xmax-xmin;                             << 114    dx=xmax-xmin;
 99    dy = ymax-ymin;                             << 115    dy=ymax-ymin;
100    dz = zmax-zmin;                             << 116    dz=zmax-zmin;
101                                                   117 
102    // Preparing the colored bounding polyhedro    118    // Preparing the colored bounding polyhedronBox for the pVolume
103    //                                             119    //
104    G4PolyhedronBox bounding_polyhedronBox(dx*0    120    G4PolyhedronBox bounding_polyhedronBox(dx*0.5,dy*0.5,dz*0.5);
105    bounding_polyhedronBox.SetVisAttributes(&fB    121    bounding_polyhedronBox.SetVisAttributes(&fBoundingBoxVisAttributes);
106    G4ThreeVector t_centerofBoundingBox((xmin+x    122    G4ThreeVector t_centerofBoundingBox((xmin+xmax)*0.5,
107                                        (ymin+y    123                                        (ymin+ymax)*0.5,
108                                        (zmin+z    124                                        (zmin+zmax)*0.5);
109                                                   125    
110    ppl->push_back(G4PlacedPolyhedron(bounding_    126    ppl->push_back(G4PlacedPolyhedron(bounding_polyhedronBox,
111                                      G4Transla    127                                      G4Translate3D(t_centerofBoundingBox)));
112                                                   128    
113    G4ThreeVector t_FirstCenterofVoxelPlane;       129    G4ThreeVector t_FirstCenterofVoxelPlane;
114    const G4VisAttributes* voxelsVisAttributes  << 130    const G4VisAttributes* voxelsVisAttributes=0;
115                                                   131 
116    G4ThreeVector unit_translation_vector;         132    G4ThreeVector unit_translation_vector;
117    G4ThreeVector current_translation_vector;      133    G4ThreeVector current_translation_vector;
118                                                   134    
119    switch(header->GetAxis())                      135    switch(header->GetAxis())
120    {                                              136    {
121      case kXAxis:                                 137      case kXAxis:
122        dx=voxel_width;                            138        dx=voxel_width;
123        unit_translation_vector=G4ThreeVector(1    139        unit_translation_vector=G4ThreeVector(1,0,0);
124        t_FirstCenterofVoxelPlane=G4ThreeVector    140        t_FirstCenterofVoxelPlane=G4ThreeVector(xmin,(ymin+ymax)*0.5,
125                                                   141                                                     (zmin+zmax)*0.5);
126        voxelsVisAttributes=&fVoxelsVisAttribut    142        voxelsVisAttributes=&fVoxelsVisAttributes[0];
127        break;                                     143        break;
128      case kYAxis:                                 144      case kYAxis:
129        dy=voxel_width;                            145        dy=voxel_width;
130        t_FirstCenterofVoxelPlane=G4ThreeVector    146        t_FirstCenterofVoxelPlane=G4ThreeVector((xmin+xmax)*0.5,ymin,
131                                                   147                                                (zmin+zmax)*0.5);
132        unit_translation_vector=G4ThreeVector(0    148        unit_translation_vector=G4ThreeVector(0,1,0);
133        voxelsVisAttributes=&fVoxelsVisAttribut    149        voxelsVisAttributes=&fVoxelsVisAttributes[1];
134        break;                                     150        break;
135      case kZAxis:                                 151      case kZAxis:
136        dz=voxel_width;                            152        dz=voxel_width;
137        t_FirstCenterofVoxelPlane=G4ThreeVector    153        t_FirstCenterofVoxelPlane=G4ThreeVector((xmin+xmax)*0.5,
138                                                   154                                                (ymin+ymax)*0.5,zmin);
139        unit_translation_vector=G4ThreeVector(0    155        unit_translation_vector=G4ThreeVector(0,0,1);
140        voxelsVisAttributes=&fVoxelsVisAttribut    156        voxelsVisAttributes=&fVoxelsVisAttributes[2];
141        break;                                     157        break;
142      default:                                     158      default:
143        break;                                     159        break;
144    };                                             160    };
145                                                   161      
146    G4PolyhedronBox voxel_plane(dx*0.5,dy*0.5,d    162    G4PolyhedronBox voxel_plane(dx*0.5,dy*0.5,dz*0.5);
147    voxel_plane.SetVisAttributes(voxelsVisAttri    163    voxel_plane.SetVisAttributes(voxelsVisAttributes);
148                                                   164    
149    G4SmartVoxelProxy* slice = header->GetSlice << 165    G4SmartVoxelProxy* slice=header->GetSlice(0);
150    std::size_t slice_no = 0, no_slices = heade << 166    G4int slice_no=0,no_slices=header->GetNoSlices();
151    G4double beginning = header->GetMinExtent() << 167    G4double beginning=header->GetMinExtent(),
152             step = (header->GetMaxExtent()-beg << 168             step=(header->GetMaxExtent()-beginning)/no_slices;
153                                                   169 
154    while (slice_no<no_slices)                     170    while (slice_no<no_slices)
155    {                                              171    {    
156      if (slice->IsHeader())                       172      if (slice->IsHeader())
157      {                                            173      {
158        G4VoxelLimits newlimit(limit);             174        G4VoxelLimits newlimit(limit);
159        newlimit.AddLimit(header->GetAxis(), be << 175        newlimit.AddLimit(header->GetAxis(),beginning+step*slice_no,
160          beginning+step*(slice->GetHeader()->G << 176        beginning+step*(slice->GetHeader()->GetMaxEquivalentSliceNo()+1));
161        ComputeVoxelPolyhedra(lv,slice->GetHead << 177        ComputeVoxelPolyhedra(lv,slice->GetHeader(),newlimit,ppl);
162      }                                            178      }
163      current_translation_vector = unit_transla << 179      current_translation_vector=unit_translation_vector;
164      current_translation_vector *= step*slice_ << 180      current_translation_vector*=step*slice_no;
165                                                   181    
166      ppl->push_back(G4PlacedPolyhedron(voxel_p    182      ppl->push_back(G4PlacedPolyhedron(voxel_plane,
167                     G4Translate3D(current_tran    183                     G4Translate3D(current_translation_vector
168                                  + t_FirstCent << 184                                  +t_FirstCenterofVoxelPlane)));
169      slice_no = (slice->IsHeader()             << 185      slice_no=(slice->IsHeader()
170                ? slice->GetHeader()->GetMaxEqu    186                ? slice->GetHeader()->GetMaxEquivalentSliceNo()+1
171                : slice->GetNode()->GetMaxEquiv    187                : slice->GetNode()->GetMaxEquivalentSliceNo()+1);
172      if (slice_no<no_slices) { slice=header->G    188      if (slice_no<no_slices) { slice=header->GetSlice(slice_no); }
173    }                                              189    }
174 }                                                 190 }
175                                                   191 
176 // ------------------------------------------- << 192 // ########################################################################
177                                                   193 
178 G4PlacedPolyhedronList*                           194 G4PlacedPolyhedronList*
179 G4DrawVoxels::CreatePlacedPolyhedra(const G4Lo    195 G4DrawVoxels::CreatePlacedPolyhedra(const G4LogicalVolume* lv) const
180 {                                                 196 {
181   auto  pplist = new G4PlacedPolyhedronList;   << 197   G4PlacedPolyhedronList* pplist=new G4PlacedPolyhedronList;
182   G4VoxelLimits limits;  // Working object for    198   G4VoxelLimits limits;  // Working object for recursive call.
183   ComputeVoxelPolyhedra(lv,lv->GetVoxelHeader(    199   ComputeVoxelPolyhedra(lv,lv->GetVoxelHeader(),limits,pplist);
184   return pplist; //it s up to the calling prog    200   return pplist; //it s up to the calling program to destroy it then!
185 }                                                 201 }
186                                                   202 
187 // ------------------------------------------- << 
188                                                << 
189 void G4DrawVoxels::DrawVoxels(const G4LogicalV    203 void G4DrawVoxels::DrawVoxels(const G4LogicalVolume* lv) const
190 {                                                 204 {   
191    G4VVisManager* pVVisManager = G4VVisManager    205    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
192                                                   206 
193    if (lv->GetNoDaughters()<=0)                   207    if (lv->GetNoDaughters()<=0)
194    {                                              208    {
195      return;                                      209      return;
196    }                                              210    }
197                                                   211 
198    // Computing the transformation according t    212    // Computing the transformation according to the world volume 
199    // (the drawing is directly in the world vo    213    // (the drawing is directly in the world volume while the axis
200    // are relative to the mother volume of lv'    214    // are relative to the mother volume of lv's daughter.)
201                                                   215 
202    G4TouchableHandle aTouchable =              << 216    G4TouchableHistoryHandle aTouchable =
203      G4TransportationManager::GetTransportatio    217      G4TransportationManager::GetTransportationManager()->
204      GetNavigatorForTracking()->CreateTouchabl    218      GetNavigatorForTracking()->CreateTouchableHistoryHandle();
205    G4AffineTransform globTransform =              219    G4AffineTransform globTransform =
206      aTouchable->GetHistory()->GetTopTransform    220      aTouchable->GetHistory()->GetTopTransform().Inverse();
207    G4Transform3D transf3D(globTransform.NetRot    221    G4Transform3D transf3D(globTransform.NetRotation(),
208                           globTransform.NetTra    222                           globTransform.NetTranslation());
209                                                   223 
210    G4PlacedPolyhedronList* pplist = CreatePlac << 224    G4PlacedPolyhedronList* pplist=CreatePlacedPolyhedra(lv);
211    if(pVVisManager != nullptr)                 << 225    if(pVVisManager)
212    {                                              226    {
213      // Drawing the bounding and voxel polyhed    227      // Drawing the bounding and voxel polyhedra for the pVolume
214      //                                           228      //
215      for (const auto & i : *pplist)            << 229      for (size_t i=0;i<pplist->size();i++)
216      {                                            230      {
217        pVVisManager->Draw(i.GetPolyhedron(),   << 231        pVVisManager->Draw((*pplist)[i].GetPolyhedron(),
218                           i.GetTransform()*tra << 232                           (*pplist)[i].GetTransform()*transf3D);
219      }                                            233      }
220    }                                              234    }
221    else                                           235    else
222    {                                              236    {
                                                   >> 237      G4cerr << "ERROR - G4DrawVoxels::DrawVoxels()" << G4endl
                                                   >> 238             << "        Pointer to visualization manager is null!"
                                                   >> 239             << G4endl; 
223      G4Exception("G4DrawVoxels::DrawVoxels()",    240      G4Exception("G4DrawVoxels::DrawVoxels()",
224                  "GeomNav1002", JustWarning,   << 241                  "NotApplicable", JustWarning,
225                  "Pointer to visualization man    242                  "Pointer to visualization manager is null!");
226    }                                              243    }
227    delete pplist;                                 244    delete pplist;
228 }                                                 245 }
229                                                   246