00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include "G4DrawVoxels.hh"
00043 #include "G4AffineTransform.hh"
00044 #include "G4SmartVoxelHeader.hh"
00045 #include "G4LogicalVolume.hh"
00046 #include "G4VSolid.hh"
00047 #include "G4VVisManager.hh"
00048 #include "G4Colour.hh"
00049 #include "G4TransportationManager.hh"
00050 #include "G4TouchableHistoryHandle.hh"
00051
00052 #define voxel_width 0
00053
00054
00055
00056 G4DrawVoxels::G4DrawVoxels()
00057 {
00058 fVoxelsVisAttributes[0].SetColour(G4Colour(1.,0.,0.));
00059 fVoxelsVisAttributes[1].SetColour(G4Colour(0.,1.,0.));
00060 fVoxelsVisAttributes[2].SetColour(G4Colour(0.,0.,1.));
00061 fBoundingBoxVisAttributes.SetColour(G4Colour(.3,0.,.2));
00062 }
00063
00064
00065
00066 G4DrawVoxels::~G4DrawVoxels()
00067 {
00068 }
00069
00070
00071
00072 void G4DrawVoxels::SetVoxelsVisAttributes(G4VisAttributes& VA_voxelX,
00073 G4VisAttributes& VA_voxelY,
00074 G4VisAttributes& VA_voxelZ)
00075 {
00076 fVoxelsVisAttributes[0]=VA_voxelX;
00077 fVoxelsVisAttributes[1]=VA_voxelY;
00078 fVoxelsVisAttributes[2]=VA_voxelZ;
00079 }
00080
00081 void G4DrawVoxels::SetBoundingBoxVisAttributes(G4VisAttributes& VA_boundingbox)
00082 {
00083 fBoundingBoxVisAttributes=VA_boundingbox;
00084 }
00085
00086
00087
00088 void
00089 G4DrawVoxels::ComputeVoxelPolyhedra(const G4LogicalVolume* lv,
00090 const G4SmartVoxelHeader* header,
00091 G4VoxelLimits& limit,
00092 G4PlacedPolyhedronList* ppl) const
00093 {
00094
00095
00096 G4VSolid* solid=lv->GetSolid();
00097
00098 G4double dx=kInfinity,dy=kInfinity,dz=kInfinity;
00099 G4double xmax=0,xmin=0,ymax=0,ymin=0,zmax=0,zmin=0;
00100
00101 if (lv->GetNoDaughters()<=0)
00102 {
00103 return;
00104 }
00105
00106
00107
00108 solid->CalculateExtent(kXAxis,limit,G4AffineTransform(),xmin,xmax);
00109
00110 solid->CalculateExtent(kYAxis,limit,G4AffineTransform(),ymin,ymax);
00111
00112 solid->CalculateExtent(kZAxis,limit,G4AffineTransform(),zmin,zmax);
00113 dx=xmax-xmin;
00114 dy=ymax-ymin;
00115 dz=zmax-zmin;
00116
00117
00118
00119 G4PolyhedronBox bounding_polyhedronBox(dx*0.5,dy*0.5,dz*0.5);
00120 bounding_polyhedronBox.SetVisAttributes(&fBoundingBoxVisAttributes);
00121 G4ThreeVector t_centerofBoundingBox((xmin+xmax)*0.5,
00122 (ymin+ymax)*0.5,
00123 (zmin+zmax)*0.5);
00124
00125 ppl->push_back(G4PlacedPolyhedron(bounding_polyhedronBox,
00126 G4Translate3D(t_centerofBoundingBox)));
00127
00128 G4ThreeVector t_FirstCenterofVoxelPlane;
00129 const G4VisAttributes* voxelsVisAttributes=0;
00130
00131 G4ThreeVector unit_translation_vector;
00132 G4ThreeVector current_translation_vector;
00133
00134 switch(header->GetAxis())
00135 {
00136 case kXAxis:
00137 dx=voxel_width;
00138 unit_translation_vector=G4ThreeVector(1,0,0);
00139 t_FirstCenterofVoxelPlane=G4ThreeVector(xmin,(ymin+ymax)*0.5,
00140 (zmin+zmax)*0.5);
00141 voxelsVisAttributes=&fVoxelsVisAttributes[0];
00142 break;
00143 case kYAxis:
00144 dy=voxel_width;
00145 t_FirstCenterofVoxelPlane=G4ThreeVector((xmin+xmax)*0.5,ymin,
00146 (zmin+zmax)*0.5);
00147 unit_translation_vector=G4ThreeVector(0,1,0);
00148 voxelsVisAttributes=&fVoxelsVisAttributes[1];
00149 break;
00150 case kZAxis:
00151 dz=voxel_width;
00152 t_FirstCenterofVoxelPlane=G4ThreeVector((xmin+xmax)*0.5,
00153 (ymin+ymax)*0.5,zmin);
00154 unit_translation_vector=G4ThreeVector(0,0,1);
00155 voxelsVisAttributes=&fVoxelsVisAttributes[2];
00156 break;
00157 default:
00158 break;
00159 };
00160
00161 G4PolyhedronBox voxel_plane(dx*0.5,dy*0.5,dz*0.5);
00162 voxel_plane.SetVisAttributes(voxelsVisAttributes);
00163
00164 G4SmartVoxelProxy* slice=header->GetSlice(0);
00165 G4int slice_no=0,no_slices=header->GetNoSlices();
00166 G4double beginning=header->GetMinExtent(),
00167 step=(header->GetMaxExtent()-beginning)/no_slices;
00168
00169 while (slice_no<no_slices)
00170 {
00171 if (slice->IsHeader())
00172 {
00173 G4VoxelLimits newlimit(limit);
00174 newlimit.AddLimit(header->GetAxis(),beginning+step*slice_no,
00175 beginning+step*(slice->GetHeader()->GetMaxEquivalentSliceNo()+1));
00176 ComputeVoxelPolyhedra(lv,slice->GetHeader(),newlimit,ppl);
00177 }
00178 current_translation_vector=unit_translation_vector;
00179 current_translation_vector*=step*slice_no;
00180
00181 ppl->push_back(G4PlacedPolyhedron(voxel_plane,
00182 G4Translate3D(current_translation_vector
00183 +t_FirstCenterofVoxelPlane)));
00184 slice_no=(slice->IsHeader()
00185 ? slice->GetHeader()->GetMaxEquivalentSliceNo()+1
00186 : slice->GetNode()->GetMaxEquivalentSliceNo()+1);
00187 if (slice_no<no_slices) { slice=header->GetSlice(slice_no); }
00188 }
00189 }
00190
00191
00192
00193 G4PlacedPolyhedronList*
00194 G4DrawVoxels::CreatePlacedPolyhedra(const G4LogicalVolume* lv) const
00195 {
00196 G4PlacedPolyhedronList* pplist=new G4PlacedPolyhedronList;
00197 G4VoxelLimits limits;
00198 ComputeVoxelPolyhedra(lv,lv->GetVoxelHeader(),limits,pplist);
00199 return pplist;
00200 }
00201
00202 void G4DrawVoxels::DrawVoxels(const G4LogicalVolume* lv) const
00203 {
00204 G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
00205
00206 if (lv->GetNoDaughters()<=0)
00207 {
00208 return;
00209 }
00210
00211
00212
00213
00214
00215 G4TouchableHistoryHandle aTouchable =
00216 G4TransportationManager::GetTransportationManager()->
00217 GetNavigatorForTracking()->CreateTouchableHistoryHandle();
00218 G4AffineTransform globTransform =
00219 aTouchable->GetHistory()->GetTopTransform().Inverse();
00220 G4Transform3D transf3D(globTransform.NetRotation(),
00221 globTransform.NetTranslation());
00222
00223 G4PlacedPolyhedronList* pplist=CreatePlacedPolyhedra(lv);
00224 if(pVVisManager)
00225 {
00226
00227
00228 for (size_t i=0;i<pplist->size();i++)
00229 {
00230 pVVisManager->Draw((*pplist)[i].GetPolyhedron(),
00231 (*pplist)[i].GetTransform()*transf3D);
00232 }
00233 }
00234 else
00235 {
00236 G4Exception("G4DrawVoxels::DrawVoxels()",
00237 "GeomNav1002", JustWarning,
00238 "Pointer to visualization manager is null!");
00239 }
00240 delete pplist;
00241 }