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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 10.0.p4)


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