82{
84
86 {
88 if( params.size() < 8 ) {
89 G4Exception("DicomIntersectVolume::SetNewValue",
90 " There must be at least 8 parameter: SOLID_TYPE POS_X POS_Y POS_Z "
91 "ANG_X ANG_Y ANG_Z SOLID_PARAM_1 (SOLID_PARAM_2 ...)",
92 FatalErrorInArgument,
93 G4String(
"Number of parameters given = " +
94 G4UIcommand::ConvertToString( G4int(params.size()) )).c_str());
95
96 }
97
98
100
101
102 G4ThreeVector pos = G4ThreeVector( G4UIcommand::ConvertToDouble(params[0]),
103 G4UIcommand::ConvertToDouble(params[1]),
104 G4UIcommand::ConvertToDouble(params[2]) );
105 G4RotationMatrix* rotmat = new G4RotationMatrix;
106 std::vector<G4double> angles;
107 rotmat->rotateX( G4UIcommand::ConvertToDouble(params[3]) );
108 rotmat->rotateY( G4UIcommand::ConvertToDouble(params[4]) );
109 rotmat->rotateY( G4UIcommand::ConvertToDouble(params[5]) );
111
112 }
114 {
116 if( params.size() !=1 )
117 G4Exception("DicomIntersectVolume::SetNewValue",
118 "",
119 FatalErrorInArgument,
120 G4String(
"Command: "+ command->GetCommandPath() +
121 "/" + command->GetCommandName() +
122 " " + newValues +
123 " needs 1 argument: VOLUME_NAME").c_str());
124
125
127
128
130
131 theVolumeTransform =
133 }
134
135
137
138 G4RotationMatrix* rotph = new G4RotationMatrix();
139
141
142
144
145 G4ThreeVector axisX( 1., 0., 0. );
146 G4ThreeVector axisY( 0., 1., 0. );
147 G4ThreeVector axisZ( 0., 0., 1. );
148 theTransform.ApplyAxisTransform(axisX);
149 theTransform.ApplyAxisTransform(axisY);
150 theTransform.ApplyAxisTransform(axisZ);
151
152
153 G4String thePhantomFileName =
"phantom.g4pdcm";
154 fout.open(thePhantomFileName);
155 std::vector<G4Material*> materials = thePhantomParam->GetMaterials();
156 fout << materials.size() << G4endl;
157 for( unsigned int ii = 0; ii < materials.size(); ++ii )
158 {
159 fout << ii <<
" " << materials[ii]->GetName() << G4endl;
160 }
161
162
163 G4int nx = G4int(thePhantomParam->GetNoVoxelsX());
164 G4int ny = G4int(thePhantomParam->GetNoVoxelsY());
165 G4int nz = G4int(thePhantomParam->GetNoVoxelsZ());
166 G4int nxy = nx*ny;
168 G4double voxelHalfWidthX = thePhantomParam->GetVoxelHalfX();
169 G4double voxelHalfWidthY = thePhantomParam->GetVoxelHalfY();
170 G4double voxelHalfWidthZ = thePhantomParam->GetVoxelHalfZ();
171
172
173 fout << nx <<
" " << ny <<
" " << nz << G4endl;
174 fout << -voxelHalfWidthX*nx+thePhantomTransform.NetTranslation().x() <<
" "
175 << voxelHalfWidthX*nx+thePhantomTransform.NetTranslation().x() << G4endl;
176 fout << -voxelHalfWidthY*ny+thePhantomTransform.NetTranslation().y() <<
" "
177 << voxelHalfWidthY*ny+thePhantomTransform.NetTranslation().y() << G4endl;
178 fout << -voxelHalfWidthZ*nz+thePhantomTransform.NetTranslation().z() <<
" "
179 << voxelHalfWidthZ*nz+thePhantomTransform.NetTranslation().z() << G4endl;
180
181 for( G4int iz = 0; iz < nz; ++iz ){
182 for( G4int iy = 0; iy < ny; ++iy) {
183
184 G4bool bPrevVoxelInside = true;
185 G4bool b1VoxelFoundInside = false;
186 G4int firstVoxel = -1;
187 G4int lastVoxel = -1;
188 for(G4int ix = 0; ix < nx; ++ix ){
189 G4ThreeVector voxelCentre( (-nx+ix*2+1)*voxelHalfWidthX,
190 (-ny+iy*2+1)*voxelHalfWidthY, (-nz+iz*2+1)*voxelHalfWidthZ);
191 theTransform.ApplyPointTransform(voxelCentre);
192 G4bool bVoxelIsInside = true;
193 for( G4int ivx = -1; ivx <= 1; ivx+=2 ) {
194 for( G4int ivy = -1; ivy <= 1; ivy+=2 ){
195 for( G4int ivz = -1; ivz <= 1; ivz+=2 ) {
196 G4ThreeVector voxelPoint = voxelCentre
197 + ivx*voxelHalfWidthX*axisX +
198 ivy*voxelHalfWidthY*axisY + ivz*voxelHalfWidthZ*axisZ;
199 if(
fSolid->Inside( voxelPoint ) == kOutside ) {
200 bVoxelIsInside = false;
201 break;
202 } else {
203 }
204 }
205 if( !bVoxelIsInside ) break;
206 }
207 if( !bVoxelIsInside ) break;
208 }
209
210 G4int copyNo = ix + nx*iy + nxy*iz;
211 if( bVoxelIsInside ) {
212 if( !bPrevVoxelInside ) {
213 G4Exception("DicomIntersectVolume::SetNewValue",
214 "",
215 FatalException,
216 "Volume cannot intersect phantom in discontiguous voxels, "
217 "please use other voxel");
218 }
219 if( !b1VoxelFoundInside ) {
220 firstVoxel = ix;
221 b1VoxelFoundInside = true;
222 }
223 lastVoxel = ix;
225 } else {
227 }
228
229 }
230 fout << firstVoxel <<
" " << lastVoxel << G4endl;
231 }
232 }
233
234
235 for( G4int iz = 0; iz < nz; ++iz ){
236 for( G4int iy = 0; iy < ny; ++iy) {
237 G4bool b1xFound = false;
238 for(G4int ix = 0; ix < nx; ++ix ){
239 size_t copyNo = ix + ny*iy + nxy*iz;
241 fout << thePhantomParam->GetMaterialIndex(copyNo)<<
" ";
242 b1xFound = true;
243 }
244 }
245 if(b1xFound )
fout << G4endl;
246 }
247 }
248
249
250 for( G4int iz = 0; iz < nz; ++iz ){
251 for( G4int iy = 0; iy < ny; ++iy) {
252 G4bool b1xFound = false;
253 for(G4int ix = 0; ix < nx; ++ix ){
254 size_t copyNo = ix + ny*iy + nxy*iz;
256 fout <<thePhantomParam->GetMaterial(copyNo)->GetDensity()/g*cm3<<
" ";
257 b1xFound = true;
258 }
259 }
260 if(b1xFound )
fout << G4endl;
261 }
262 }
263
264}
void BuildG4Solid(std::vector< G4String > params)
G4PhantomParameterisation * GetPhantomParam(G4bool bMustExist)
void BuildUserSolid(std::vector< G4String > params)
std::vector< G4String > GetWordsInString(const G4String &stemp)
std::vector< G4VPhysicalVolume * > GetPhysicalVolumes(const G4String &name, G4bool exists, G4int nVols)