Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DicomIntersectVolume Class Reference

Manages intersections of DICOM files with volumes. More...

#include <DicomIntersectVolume.hh>

Inheritance diagram for DicomIntersectVolume:
Collaboration diagram for DicomIntersectVolume:

Public Member Functions

 DicomIntersectVolume ()
 
 ~DicomIntersectVolume ()
 
virtual void SetNewValue (G4UIcommand *command, G4String newValues)
 
- Public Member Functions inherited from G4UImessenger
 G4UImessenger ()
 
 G4UImessenger (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
virtual ~G4UImessenger ()
 
virtual G4String GetCurrentValue (G4UIcommand *command)
 
G4bool operator== (const G4UImessenger &messenger) const
 
G4bool CommandsShouldBeInMaster () const
 

Additional Inherited Members

- Protected Member Functions inherited from G4UImessenger
G4String ItoS (G4int i)
 
G4String DtoS (G4double a)
 
G4String BtoS (G4bool b)
 
G4int StoI (G4String s)
 
G4double StoD (G4String s)
 
G4bool StoB (G4String s)
 
void AddUIcommand (G4UIcommand *newCommand)
 
void CreateDirectory (const G4String &path, const G4String &dsc, G4bool commandsToBeBroadcasted=true)
 
template<typename T >
T * CreateCommand (const G4String &cname, const G4String &dsc)
 
- Protected Attributes inherited from G4UImessenger
G4UIdirectorybaseDir
 
G4String baseDirName
 
G4bool commandsShouldBeInMaster
 

Detailed Description

Manages intersections of DICOM files with volumes.

Definition at line 50 of file DicomIntersectVolume.hh.

Constructor & Destructor Documentation

DicomIntersectVolume::DicomIntersectVolume ( )

Definition at line 49 of file DicomIntersectVolume.cc.

50  : G4UImessenger(),
51  fG4VolumeCmd(0),
52  fSolid(0),
53  fPhantomMinusCorner(),
54  fVoxelIsInside(0)
55 {
56  fUserVolumeCmd= new G4UIcmdWithAString("/dicom/intersectWithUserVolume",this);
57  fUserVolumeCmd->SetGuidance("Intersects a phantom with a user-defined volume "
58  "and outputs the voxels that are totally inside the intersection as"
59  " a new phantom file. It must have the parameters: POS_X POS_Y POS_Z "
60  "ANG_X ANG_Y ANG_Z SOLID_TYPE SOLID_PARAM_1 (SOLID_PARAM_2 ...)");
61  fUserVolumeCmd->SetParameterName("choice",true);
62  fUserVolumeCmd->AvailableForStates(G4State_Idle);
63 
64  fG4VolumeCmd = new G4UIcmdWithAString("/dicom/intersectWithUserVolume",this);
65  fG4VolumeCmd->SetGuidance("Intersects a phantom with a user-defined volume"
66  " and outputs the voxels that are totally inside the intersection as "
67  " a new phantom file. It must have the parameters: POS_X POS_Y POS_Z "
68  "ANG_X ANG_Y ANG_Z SOLID_TYPE SOLID_PARAM_1 (SOLID_PARAM_2 ...)");
69  fG4VolumeCmd->SetParameterName("choice",true);
70  fG4VolumeCmd->AvailableForStates(G4State_Idle);
71 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:240

Here is the call graph for this function:

DicomIntersectVolume::~DicomIntersectVolume ( )

Definition at line 74 of file DicomIntersectVolume.cc.

75 {
76  if (fUserVolumeCmd) delete fUserVolumeCmd;
77  if (fG4VolumeCmd) delete fG4VolumeCmd;
78 }

Member Function Documentation

void DicomIntersectVolume::SetNewValue ( G4UIcommand command,
G4String  newValues 
)
virtual

Reimplemented from G4UImessenger.

Definition at line 81 of file DicomIntersectVolume.cc.

83 {
84  G4AffineTransform theVolumeTransform;
85 
86  if (command == fUserVolumeCmd) {
87 
88  std::vector<G4String> params = GetWordsInString( newValues );
89  if( params.size() < 8 ) {
90  G4Exception("DicomIntersectVolume::SetNewValue",
91  " There must be at least 8 parameter: SOLID_TYPE POS_X POS_Y POS_Z "
92  "ANG_X ANG_Y ANG_Z SOLID_PARAM_1 (SOLID_PARAM_2 ...)",
94  G4String("Number of parameters given = " +
95  G4UIcommand::ConvertToString( G4int(params.size()) )).c_str());
96 
97  }
98 
99  //----- Build G4VSolid
100  BuildUserSolid(params);
101 
102  //----- Calculate volume inverse 3D transform
104  G4UIcommand::ConvertToDouble(params[1]),
105  G4UIcommand::ConvertToDouble(params[2]) );
106  G4RotationMatrix* rotmat = new G4RotationMatrix;
107  std::vector<double> angles;
108  rotmat->rotateX( G4UIcommand::ConvertToDouble(params[3]) );
109  rotmat->rotateY( G4UIcommand::ConvertToDouble(params[4]) );
110  rotmat->rotateY( G4UIcommand::ConvertToDouble(params[5]) );
111  theVolumeTransform = G4AffineTransform( rotmat, pos ).Invert();
112 
113  } else if (command == fG4VolumeCmd) {
114  std::vector<G4String> params = GetWordsInString( newValues );
115  if( params.size() !=1 )
116  G4Exception("DicomIntersectVolume::SetNewValue",
117  "",
119  G4String("Command: "+ command->GetCommandPath() +
120  "/" + command->GetCommandName() +
121  " " + newValues +
122  " needs 1 argument: VOLUME_NAME").c_str());
123 
124  //----- Build G4VSolid
125  BuildG4Solid(params);
126 
127  //----- Calculate volume inverse 3D transform
128  G4VPhysicalVolume* pv = GetPhysicalVolumes( params[0], 1, 1)[0];
129 
130  theVolumeTransform =
132  }
133 
134  //----- Calculate relative phantom - volume 3D transform
135  G4PhantomParameterisation* thePhantomParam = GetPhantomParam(true);
136 
137  G4RotationMatrix* rotph = new G4RotationMatrix();
138  // assumes the phantom mother is not rotated !!!
139  G4AffineTransform thePhantomTransform( rotph, G4ThreeVector() );
140  // assumes the phantom mother is not translated !!!
141 
142  G4AffineTransform theTransform = theVolumeTransform*thePhantomTransform;
143 
144  G4ThreeVector axisX( 1., 0., 0. );
145  G4ThreeVector axisY( 0., 1., 0. );
146  G4ThreeVector axisZ( 0., 0., 1. );
147  theTransform.ApplyAxisTransform(axisX);
148  theTransform.ApplyAxisTransform(axisY);
149  theTransform.ApplyAxisTransform(axisZ);
150 
151  //----- Write phantom header
152  G4String thePhantomFileName = "phantom.g4pdcm";
153  fout.open(thePhantomFileName);
154  std::vector<G4Material*> materials = thePhantomParam->GetMaterials();
155  fout << materials.size() << G4endl;
156  for( unsigned int ii = 0; ii < materials.size(); ii++ ) {
157  fout << ii << " " << materials[ii]->GetName() << G4endl;
158  }
159 
160  //----- Loop to pantom voxels
161  G4int nx = thePhantomParam->GetNoVoxelX();
162  G4int ny = thePhantomParam->GetNoVoxelY();
163  G4int nz = thePhantomParam->GetNoVoxelZ();
164  G4int nxy = nx*ny;
165  fVoxelIsInside = new G4bool[nx*ny*nz];
166  G4double voxelHalfWidthX = thePhantomParam->GetVoxelHalfX();
167  G4double voxelHalfWidthY = thePhantomParam->GetVoxelHalfY();
168  G4double voxelHalfWidthZ = thePhantomParam->GetVoxelHalfZ();
169 
170  //----- Write phantom dimensions and limits
171  fout << nx << " " << ny << " " << nz << G4endl;
172  fout << -voxelHalfWidthX*nx+thePhantomTransform.NetTranslation().x() << " "
173  << voxelHalfWidthX*nx+thePhantomTransform.NetTranslation().x() << G4endl;
174  fout << -voxelHalfWidthY*ny+thePhantomTransform.NetTranslation().y() << " "
175  << voxelHalfWidthY*ny+thePhantomTransform.NetTranslation().y() << G4endl;
176  fout << -voxelHalfWidthZ*nz+thePhantomTransform.NetTranslation().z() << " "
177  << voxelHalfWidthZ*nz+thePhantomTransform.NetTranslation().z() << G4endl;
178 
179  for( G4int iz = 0; iz < nz; iz++ ){
180  for( G4int iy = 0; iy < ny; iy++) {
181 
182  G4bool bPrevVoxelInside = true;
183  G4bool b1VoxelFoundInside = false;
184  G4int firstVoxel = -1;
185  G4int lastVoxel = -1;
186  for(G4int ix = 0; ix < nx; ix++ ){
187  G4ThreeVector voxelCentre( (-nx+ix*2+1)*voxelHalfWidthX,
188  (-ny+iy*2+1)*voxelHalfWidthY, (-nz+iz*2+1)*voxelHalfWidthZ);
189  theTransform.ApplyPointTransform(voxelCentre);
190  G4bool bVoxelIsInside = true;
191  for( G4int ivx = -1; ivx <= 1; ivx+=2 ) {
192  for( G4int ivy = -1; ivy <= 1; ivy+=2 ){
193  for( G4int ivz = -1; ivz <= 1; ivz+=2 ) {
194  G4ThreeVector voxelPoint = voxelCentre
195  + ivx*voxelHalfWidthX*axisX +
196  ivy*voxelHalfWidthY*axisY + ivz*voxelHalfWidthZ*axisZ;
197  if( fSolid->Inside( voxelPoint ) == kOutside ) {
198  bVoxelIsInside = false;
199  break;
200  } else {
201  }
202  }
203  if( !bVoxelIsInside ) break;
204  }
205  if( !bVoxelIsInside ) break;
206  }
207 
208  G4int copyNo = ix + nx*iy + nxy*iz;
209  if( bVoxelIsInside ) {
210  if( !bPrevVoxelInside ) {
211  G4Exception("DicomIntersectVolume::SetNewValue",
212  "",
214  "Volume cannot intersect phantom in discontiguous voxels, "
215  "please use other voxel");
216  }
217  if( !b1VoxelFoundInside ) {
218  firstVoxel = ix;
219  b1VoxelFoundInside = true;
220  }
221  lastVoxel = ix;
222  fVoxelIsInside[copyNo] = true;
223  } else {
224  fVoxelIsInside[copyNo] = false;
225  }
226 
227  }
228  fout << firstVoxel << " " << lastVoxel << G4endl;
229  }
230  }
231 
232  //----- Now write the materials
233  for( G4int iz = 0; iz < nz; iz++ ){
234  for( G4int iy = 0; iy < ny; iy++) {
235  G4bool b1xFound = false;
236  for(G4int ix = 0; ix < nx; ix++ ){
237  size_t copyNo = ix + ny*iy + nxy*iz;
238  // fout << " iz " << iz << " i " << iy << " ix " << ix << G4endl;
239  if( fVoxelIsInside[copyNo] ) {
240  fout << thePhantomParam->GetMaterialIndex(copyNo)<< " ";
241  b1xFound = true;
242  }
243  }
244  if(b1xFound ) fout << G4endl;
245  }
246  }
247 
248  // Now write densities
249  for( G4int iz = 0; iz < nz; iz++ ){
250  for( G4int iy = 0; iy < ny; iy++) {
251  G4bool b1xFound = false;
252  for(G4int ix = 0; ix < nx; ix++ ){
253  size_t copyNo = ix + ny*iy + nxy*iz;
254  if( fVoxelIsInside[copyNo] ) {
255  fout <<thePhantomParam->GetMaterial(copyNo)->GetDensity()/g*cm3<< " ";
256  b1xFound = true;
257  }
258  }
259  if(b1xFound ) fout << G4endl;
260  }
261  }
262 
263 }
G4ThreeVector GetFrameTranslation() const
CLHEP::Hep3Vector G4ThreeVector
HepRotation & rotateX(double delta)
Definition: Rotation.cc:66
CLHEP::HepRotation G4RotationMatrix
G4double GetDensity() const
Definition: G4Material.hh:180
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:372
HepRotation & rotateY(double delta)
Definition: Rotation.cc:79
void ApplyAxisTransform(G4ThreeVector &axis) const
size_t GetMaterialIndex(size_t nx, size_t ny, size_t nz) const
int G4int
Definition: G4Types.hh:78
size_t GetNoVoxelZ() const
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4AffineTransform & Invert()
virtual EInside Inside(const G4ThreeVector &p) const =0
bool G4bool
Definition: G4Types.hh:79
std::vector< G4Material * > GetMaterials() const
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:455
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
G4double GetVoxelHalfY() const
static constexpr double cm3
Definition: G4SIunits.hh:121
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4Material * GetMaterial(size_t nx, size_t ny, size_t nz) const
const G4RotationMatrix * GetFrameRotation() const
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:141
size_t GetNoVoxelY() const
G4double GetVoxelHalfX() const
#define G4endl
Definition: G4ios.hh:61
G4double GetVoxelHalfZ() const
size_t GetNoVoxelX() const
double G4double
Definition: G4Types.hh:76
static const G4double pos
void ApplyPointTransform(G4ThreeVector &vec) const

Here is the call graph for this function:


The documentation for this class was generated from the following files: