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