62 for (
int j=0; j<
N; j++) {
74 const string &Name,
bool O) :
EGS_BaseGeometry(Name), N(G.size()), ortho(O) {
77 for (
int j=0; j<
N; j++) {
88 EGS_NDGeometry::~EGS_NDGeometry() {
89 for (
int j=0; j<
N; j++) {
99 void EGS_NDGeometry::setup() {
104 void EGS_NDGeometry::printInfo()
const {
107 for (
int j=0; j<
N; j++)
109 j+1,
g[j]->
getName().c_str(),
g[j]->getType().c_str());
111 "=======================================================\n");
119 int err = i->
getInput(
"set medium",inp);
122 if (inp.size() == 2) {
125 else if (inp.size() == 3) {
128 else if (inp.size() == 4)
setMedium(inp[0],inp[1],mind[inp[2]],
130 else if (inp.size() == 2*
N+1) {
131 setM(0,0,inp,mind[inp[2*
N]]);
133 else egsWarning(
"EGS_NDGeometry::setMedia(): found %dinputs\n"
134 "in a 'set medium' input. 2, 3, 4, or %d are allowed\n",2*
N+1);
136 else egsWarning(
"EGS_NDGeometry::setMedia(): wrong 'set medium'"
141 void EGS_NDGeometry::setM(
int ibase,
int idim,
142 const vector<int> &ranges,
int medium) {
143 int istart = ranges[2*idim], iend = ranges[2*idim+1];
147 int ndim =
n[idim+1] /
n[idim];
151 if (idim <
N-1)
for (
int j=istart; j<=iend; j++) {
152 setM(ibase+j*
n[idim],idim+1,ranges,
medium);
154 else for (
int j=istart; j<=iend; j++) {
161 string EGS_XYZGeometry::type =
"EGS_XYZGeometry";
165 xp(Xp), yp(Yp), zp(Zp) {
174 xpos = xp->getPositions();
175 ypos = yp->getPositions();
176 zpos = zp->getPositions();
179 EGS_XYZGeometry::~EGS_XYZGeometry() {
191 void EGS_XYZGeometry::printInfo()
const {
197 "=======================================================\n");
200 void EGS_XYZGeometry::setMedia(
EGS_Input *input,
int nmed,
const int *mind) {
205 int err = i->
getInput(
"set medium",inp);
208 if (inp.size() == 2) {
211 else if (inp.size() == 3) {
214 else if (inp.size() == 4)
setMedium(inp[0],inp[1],mind[inp[2]],
216 else if (inp.size() == 7) {
217 int is = inp[0], ie = inp[1];
224 int js = inp[2], je = inp[3];
231 int ks = inp[4], ke = inp[5];
235 if (ke >
nreg/nxy-1) {
240 for (
int i=is; i<=ie; i++) {
241 for (
int j=js; j<=je; j++) {
242 for (
int k=ks; k<=ke; k++) {
243 int ireg = i + j*nx + k*nxy;
251 else if (inp.size() == 10) {
252 int is = inp[0], ie = inp[1], idelta = inp[2];
262 int js = inp[3], je = inp[4], jdelta = inp[5];
272 int ks = inp[6], ke = inp[7], kdelta = inp[8];
276 if (ke >
nreg/nxy-1) {
284 for (
int i=is; i<=ie; i+=idelta) {
285 for (
int j=js; j<=je; j+=jdelta) {
286 for (
int k=ks; k<=ke; k+=kdelta) {
287 int ireg = i + j*nx + k*nxy;
295 else egsWarning(
"EGS_XYZGeometry::setMedia(): found %dinputs\n"
296 "in a 'set medium' input. 2, 3, 4, 7, or 10 are allowed\n");
298 else egsWarning(
"EGS_XYZGeometry::setMedia(): wrong 'set medium'"
303 EGS_XYZGeometry *EGS_XYZGeometry::constructGeometry(
const char *dens_file,
304 const char *ramp_file,
int dens_or_egsphant_or_interfile) {
305 const static char *func =
"EGS_XYZGeometry::constructGeometry";
306 if (!dens_file || !ramp_file) {
309 ifstream ramp(ramp_file);
311 egsWarning(
"%s: failed to open CT ramp file %s\n",func,ramp_file);
314 vector<string> med_names;
315 vector<EGS_Float> rho_min,rho_max,rho_def;
317 if (dens_or_egsphant_or_interfile == 2) {
321 for (
int i=0; i < meds; i++) {
323 EGS_Float rmin,rmax,rdef;
324 ramp >> rmin >> rmax >> medname;
325 rdef=(rmin+rmax) / 2.0;
326 if (ramp.eof() || ramp.fail() || !ramp.good()) {
329 egsInformation(
"Using medium %s for rho=%g...%g\n",medname.c_str(),
331 med_names.push_back(medname);
332 rho_min.push_back(rmin);
333 rho_max.push_back(rmax+1);
334 rho_def.push_back(rdef);
338 for (EGS_I64 loopCount=0; loopCount<=
loopMax; ++loopCount) {
340 egsFatal(
"EGS_XYZGeometry::constructGeometry: Too many iterations were required! Input may be invalid, or consider increasing loopMax.");
345 EGS_Float rmin,rmax,rdef;
346 ramp >> medname >> rmin >> rmax >> rdef;
347 if (ramp.eof() || ramp.fail() || !ramp.good()) {
350 egsInformation(
"Using medium %s for rho=%g...%g\n",medname.c_str(),
352 med_names.push_back(medname);
353 rho_min.push_back(rmin);
354 rho_max.push_back(rmax);
355 rho_def.push_back(rdef);
358 if (med_names.size() < 1) {
359 egsWarning(
"%s: no media defined in the CT ramp "
360 "file %s!\n",func,ramp_file);
364 EGS_Float *xx, *yy, *zz;
366 if (dens_or_egsphant_or_interfile == 0) {
368 if (my_endian < 0)
egsFatal(
"%s: machine has an unknown"
369 " endianess!\n",func);
370 ifstream dens(dens_file,ios::binary);
372 egsWarning(
"%s: failed to open density matrix file "
373 "%s\n",func,dens_file);
377 dens.read(&their_endian,1);
378 if (their_endian != 0 && their_endian != 1)
379 egsFatal(
"%s: density data created on a machine with"
380 " unknown endianess!\n",func);
381 bool swap = my_endian != their_endian;
382 dens.read((
char *) &Nx,
sizeof(
int));
386 dens.read((
char *) &Ny,
sizeof(
int));
390 dens.read((
char *) &Nz,
sizeof(
int));
394 if (Nx < 1 || Ny < 1 || Nz < 1) {
395 egsWarning(
"%s: invalid density matrix file: "
396 " Nx=%d Ny=%d Nz=%d\n",func,Nx,Ny,Nz);
399 float *x =
new float [Nx+1];
400 float *y =
new float [Ny+1];
401 float *z =
new float [Nz+1];
402 dens.read((
char *)x, (Nx+1)*
sizeof(
float));
403 if (dens.eof() || dens.fail() || !dens.good()) {
404 egsWarning(
"%s: error while reading %d x-planes from"
405 " file %s\n",func,Nx+1,dens_file);
411 dens.read((
char *)y, (Ny+1)*
sizeof(
float));
412 if (dens.eof() || dens.fail() || !dens.good()) {
413 egsWarning(
"%s: error while reading %d y-planes from"
414 " file %s\n",func,Ny+1,dens_file);
420 dens.read((
char *)z, (Nz+1)*
sizeof(
float));
421 if (dens.eof() || dens.fail() || !dens.good()) {
422 egsWarning(
"%s: error while reading %d z-planes from"
423 " file %s\n",func,Nz+1,dens_file);
431 for (j=0; j<Nx; j++) {
434 for (j=0; j<Ny; j++) {
437 for (j=0; j<Nz; j++) {
443 xx =
new EGS_Float [Nx+1];
444 for (j=0; j<=Nx; j++) {
447 yy =
new EGS_Float [Ny+1];
448 for (j=0; j<=Ny; j++) {
451 zz =
new EGS_Float [Nz+1];
452 for (j=0; j<=Nz; j++) {
459 rho =
new float [Nx*Ny*Nz];
460 dens.read((
char *)rho, Nx*Ny*Nz*
sizeof(
float));
462 egsWarning(
"%s: failed reading mass densities from density matrux file\n",func);
470 for (
int j=0; j<Nx*Ny*Nz; j++) {
475 else if (dens_or_egsphant_or_interfile == 2) {
476 ifstream h_file(dens_file);
478 egsWarning(
"%s: failed to open the interfile header %s\n",func,dens_file);
481 string data_file(
"");
483 float scale_x=0.0, scale_y=0.0, scale_z=0.0;
484 for (EGS_I64 loopCount=0; loopCount<=
loopMax; ++loopCount) {
486 egsFatal(
"EGS_XYZGeometry::constructGeometry: Too many iterations were required! Input may be invalid, or consider increasing loopMax.");
489 string line, key, value;
491 getline(h_file, line);
492 if (h_file.eof() || h_file.fail() || !h_file.good()) {
496 pos = line.find(
":=");
497 if (pos == string::npos) {
500 key = line.substr(0,
int(pos));
501 value = line.substr(
int(pos)+2);
502 while ((key[0] ==
'!') || (key[0] ==
' ')) {
505 while (key[key.length()-1] ==
' ') {
506 key.erase(key.length()-1, 1);
508 while (value[0] ==
' ') {
511 while (value[value.length()-1] ==
' ') {
512 value.erase(value.length()-1, 1);
515 if (key ==
"matrix size [1]") {
516 sscanf(value.c_str(),
"%u", &Nx);
518 else if (key ==
"matrix size [2]") {
519 sscanf(value.c_str(),
"%u", &Ny);
521 else if ((key ==
"number of slices") || (key ==
"number of images")) {
522 sscanf(value.c_str(),
"%u", &Nz);
524 else if (key ==
"scaling factor (mm/pixel) [1]") {
525 sscanf(value.c_str(),
"%f", &scale_x);
527 else if (key ==
"scaling factor (mm/pixel) [2]") {
528 sscanf(value.c_str(),
"%f", &scale_y);
530 else if (key ==
"slice thickness (pixels)") {
531 sscanf(value.c_str(),
"%f", &scale_z);
533 else if (key ==
"name of data file") {
536 else if (key ==
"number format") {
537 if ((value ==
"float") || (value ==
"FLOAT")) {
540 else if ((value ==
"unsigned integer") || (value ==
"UNSIGNED INTEGER")) {
544 egsWarning(
"%s: unrecognised 'number format' type: %s \n",func,value.c_str());
548 if (Nx < 1 || Ny < 1 || Nz < 1 || scale_x <= 0.0 || scale_y <= 0.0 || scale_z <= 0.0 || data_file ==
"" || data_type == -1) {
549 egsWarning(
"%s: invalid interfile header information: "
550 "Nx=%d Ny=%d Nz=%d scale_x=%f scale_y=%f scale_z=%f "
551 "data_file='%s' number_format=%d\n",func,Nx,Ny,Nz,scale_x,scale_y,scale_z,data_file.c_str(),data_type);
554 ifstream i_file(data_file.c_str(),ios::binary);
556 egsWarning(
"%s: failed to open interfile data "
557 "%s\n",func,data_file.c_str());
565 xx =
new EGS_Float [Nx+1];
566 for (j=0; j<=Nx; j++) {
567 xx[j] = -(float)Nx*scale_x/2.0 + j*scale_x;
569 yy =
new EGS_Float [Ny+1];
570 for (j=0; j<=Ny; j++) {
571 yy[j] = -(float)Ny*scale_y/2.0 + j*scale_y;
573 zz =
new EGS_Float [Nz+1];
574 for (j=0; j<=Nz; j++) {
575 zz[j] = -(float)Nz*scale_z/2.0 + j*scale_z;
578 rho =
new float [Nx*Ny*Nz];
579 if (data_type == 0) {
580 i_file.read((
char *)rho, Nx*Ny*Nz*
sizeof(float));
583 unsigned short int *rho_tmp =
new unsigned short int [Nx*Ny*Nz];
584 i_file.read((
char *)rho_tmp, (Nx*Ny*Nz)*
sizeof(
unsigned short int));
585 for (
int cc = 0; cc<Nx*Ny*Nz; cc++) {
586 rho[cc] = (float)(rho_tmp[cc]);
591 egsWarning(
"%s: failed reading interfile data\n",func);
601 ifstream tempf(dens_file, ios::binary);
609 egsWarning(
"%s: failed to open .egsphant file %s\n",func,dens_file);
613 bool is_gzip = (tempf.get() == 0x1f && tempf.get() == 0x8b);
618 binf.open(dens_file);
621 egsWarning(
"Tried to read gzipped egsphant but egs_ndgeometry was not compiled with gzip support\n");
626 textf.open(dens_file);
633 if ((*data).fail()) {
634 egsWarning(
"%s: failed reading number of media\n",func);
639 (*data).getline(buf,1023);
640 for (imed=0; imed<nmed; ++imed) {
641 (*data).getline(buf,1023);
642 if ((*data).fail()) {
643 egsWarning(
"%s: failed reading medium name for %d'th medium\n",func,imed+1);
649 for (imed=0; imed<nmed; ++imed) {
652 (*data) >> Nx >> Ny >> Nz;
653 if ((*data).fail()) {
654 egsWarning(
"%s: failed reading number of voxels\n",func);
657 xx =
new EGS_Float [Nx+1];
658 yy =
new EGS_Float [Ny+1];
659 zz =
new EGS_Float [Nz+1];
661 for (j=0; j<=Nx; ++j) {
664 if ((*data).fail()) {
665 egsWarning(
"%s: failed reading x-planes\n",func);
671 for (j=0; j<=Ny; ++j) {
674 if ((*data).fail()) {
675 egsWarning(
"%s: failed reading y-planes\n",func);
681 for (j=0; j<=Nz; ++j) {
684 if ((*data).fail()) {
685 egsWarning(
"%s: failed reading z-planes\n",func);
694 (*data).getline(buf,1023);
695 for (
int iz=0; iz<Nz; ++iz) {
696 for (
int iy=0; iy<Ny; ++iy) {
697 (*data).getline(buf,1023);
699 (*data).getline(buf,1023);
701 if ((*data).fail()) {
702 egsWarning(
"%s: failed reading media indeces matrix\n",func);
708 rho =
new float [nr];
709 for (j=0; j<nr; ++j) {
712 if ((*data).fail()) {
713 egsWarning(
"%s: failed reading mass density matrix\n",func);
725 EGS_Float rhomin=1e30,rhomax=0;
727 for (j=0; j<Nx*Ny*Nz; j++) {
728 if (rho[j] > rhomax) {
731 if (rho[j] < rhomin) {
737 int nmed = med_names.size();
738 int *imed =
new int [nmed];
739 for (j=0; j<nmed; j++) {
742 for (j=0; j<Nx*Ny*Nz; j++) {
744 for (i=0; i<nmed; i++) {
745 if (rho[j] >= rho_min[i] && rho[j] < rho_max[i]) {
750 egsWarning(
"%s: no material defined for density %g, leaving voxel %d"
751 " as vacuum\n",func,rho[j],j);
758 med_names[i].c_str(),imed[i]);
761 if (rho_def[i] > 0) {
762 EGS_Float rrho = rho[j]/rho_def[i];
774 string EGS_DeformedXYZ::def_type =
"EGS_DeformedXYZ";
776 char EGS_DeformedXYZ::tetrahedra[] = {0,2,3,6, 0,6,3,7, 0,4,6,7,
777 7,0,1,3, 7,1,0,4, 7,5,1,4
780 char EGS_DeformedXYZ::plane_order[] = {0,1,2, 0,2,3, 0,3,1, 1,3,2};
782 char EGS_DeformedXYZ::enter_tetra1[] = {0, 3, 4, 0, 0, 2};
783 char EGS_DeformedXYZ::enter_plane1[] = {1, 1, 1, 3, 0, 3};
784 char EGS_DeformedXYZ::enter_tetra2[] = {2, 5, 5, 1, 3, 5};
785 char EGS_DeformedXYZ::enter_plane2[] = {0, 0, 2, 3, 2, 2};
788 char EGS_DeformedXYZ::tetra_data[] = {
822 EGS_PlanesZ *Zp,
const char *defFile,
const string &Name) :
824 setDeformations(defFile);
832 ifstream data(defFile,ios::binary);
834 egsWarning(
"Failed to open deformations file %s\n",defFile);
838 data.read((
char *)&nvec,
sizeof(
int));
839 int nneed = (nx+1)*(ny+1)*(nz+1);
841 egsWarning(
"Inconsistent deformations file: %d instead of %d vectors\n",
850 for (j=0; j<nvec; ++j) {
851 data.read((
char *)tmp,3*
sizeof(
float));
853 egsWarning(
"Error while readinf vector %d from file\n",j+1);
856 vectors[j] =
EGS_Vector(tmp[0],tmp[1],tmp[2]);
860 for (k=0; k<=nz; ++k)
for (j=0; j<=ny; ++j)
for (i=0; i<=nx; ++i) {
861 int index = i + j*(nx+1) + k*(nx+1)*(ny+1);
862 vectors[index] +=
EGS_Vector(xpos[i],ypos[j],zpos[k]);
865 for (j=0; j<24; ++j) {
866 int i = tetrahedra[j];
881 tnodes[j] = (nx+1)*(ny+1);
884 tnodes[j] = (nx+1)*(ny+1)+1;
887 tnodes[j] = (nx+1)*(ny+1)+nx+1;
890 tnodes[j] = (nx+1)*(ny+1)+nx+2;
900 EGS_DeformedXYZ::~EGS_DeformedXYZ() {
906 string EGS_XYZRepeater::type =
"EGS_XYZRepeater";
908 EGS_XYZRepeater::EGS_XYZRepeater(EGS_Float xmin, EGS_Float xmax,
909 EGS_Float ymin, EGS_Float ymax,
910 EGS_Float zmin, EGS_Float zmax,
911 int Nx,
int Ny,
int Nz,
913 const string &Name) :
915 dx = (xmax - xmin)/nx;
918 dy = (ymax - ymin)/ny;
921 dz = (zmax - zmin)/nz;
938 for (
int ix=0; ix<nx; ix++)
939 for (
int iy=0; iy<ny; iy++)
940 for (
int iz=0; iz<nz; iz++)
941 translation[ix+iy*nx+iz*nxy] =
EGS_Vector(xmin + dx*(0.5+ix),
947 EGS_XYZRepeater::~EGS_XYZRepeater() {
954 delete [] translation;
957 void EGS_XYZRepeater::printInfo()
const {
960 nx,xyz->getXPositions()[0],xyz->getXPositions()[nx]);
962 ny,xyz->getYPositions()[0],xyz->getYPositions()[ny]);
964 nz,xyz->getZPositions()[0],xyz->getZPositions()[nz]);
976 void EGS_XYZGeometry::voxelizeGeometry(
EGS_Input *input) {
978 int err = input->
getInput(
"voxelize geometry",gname);
983 egsInformation(
" setting media from geometry %s\n",gname.c_str());
986 egsInformation(
" this geometry does not exist -> media will be not set.\n");
1021 EGS_Vector v1(xp->position(0),yp->position(0),zp->position(0));
1022 EGS_Vector v2(xp->position(nx),yp->position(ny),zp->position(nz));
1023 egsInformation(
" top/left/front corner : (%g,%g,%g)\n",v1.x,v1.y,v1.z);
1024 egsInformation(
" bottom/right/back corner: (%g,%g,%g)\n",v2.x,v2.y,v2.z);
1026 egsInformation(
" the above are transformed as follows before looking up media:\n");
1029 egsInformation(
" top/left/front corner : (%g,%g,%g)\n",v1.x,v1.y,v1.z);
1030 egsInformation(
" bottom/right/back corner: (%g,%g,%g)\n",v2.x,v2.y,v2.z);
1032 for (
int ix=0; ix<nx; ++ix)
for (
int iy=0; iy<ny; iy++)
for (
int iz=0; iz<nz; ++iz) {
1033 int ir = ix + iy*nx + iz*nxy;
1034 EGS_Vector v(0.5*(xp->position(ix)+xp->position(ix+1)),
1035 0.5*(yp->position(iy)+yp->position(iy+1)),
1036 0.5*(zp->position(iz)+zp->position(iz+1)));
1040 int ireg = geometry->
isWhere(v);
1060 vector<string> options;
1061 options.push_back(
"no");
1062 options.push_back(
"yes");
1063 bool delete_geometry = input->
getInput(
"delete geometry",options,0);
1064 if (delete_geometry) {
1065 if (geometry->
deref() == -1) {
1070 egsInformation(
" not deleting geometry %s as requested due to remaining references\n",
1078 const char *err_msg1 =
"createGeometry(EGS_XYZRepeater)";
1088 const static char *func =
"createGeometry(XYZ)";
1090 int is_xyz = input->
getInput(
"type",type);
1091 if (!is_xyz && input->
compare(
"EGS_XYZRepeater",type)) {
1093 vector<EGS_Float> xr, yr, zr;
1094 int err1 = input->
getInput(
"repeated geometry",base);
1095 int err2 = input->
getInput(
"repeat x",xr);
1096 int err3 = input->
getInput(
"repeat y",yr);
1097 int err4 = input->
getInput(
"repeat z",zr);
1098 int err5 = input->
getInput(
"medium",medium);
1101 egsWarning(
"%s: missing 'repeated geometry' input\n",err_msg1);
1106 egsWarning(
"%s: no geometry named %s exists\n",err_msg1,
1111 if (err2 || xr.size() != 3) {
1113 egsWarning(
"%s: wrong/missing 'repeat x' input\n",err_msg1);
1115 if (err3 || yr.size() != 3) {
1117 egsWarning(
"%s: wrong/missing 'repeat y' input\n",err_msg1);
1119 if (err4 || zr.size() != 3) {
1121 egsWarning(
"%s: wrong/missing 'repeat z' input\n",err_msg1);
1126 EGS_Float xmin = xr[0], xmax = xr[1];
1127 int nx = (int)(xr[2]+0.1);
1128 if (xmin >= xmax || nx < 1) {
1129 egsWarning(
"%s: wrong 'repeat x' input xmin=%g xmax=%g nx=%d\n",
1133 EGS_Float ymin = yr[0], ymax = yr[1];
1134 int ny = (int)(yr[2]+0.1);
1135 if (ymin >= ymax || ny < 1) {
1136 egsWarning(
"%s: wrong 'repeat y' input ymin=%g ymax=%g ny=%d\n",
1140 EGS_Float zmin = zr[0], zmax = zr[1];
1141 int nz = (int)(zr[2]+0.1);
1142 if (zmin >= zmax || nz < 1) {
1143 egsWarning(
"%s: wrong 'repeat z' input zmin=%g zmax=%g nz=%d\n",
1158 result->setXYZLabels(input);
1162 else if (!is_xyz && input->
compare(
"EGS_XYZGeometry",type)) {
1163 string dens_file, ramp_file, egsphant_file, interfile_file;
1164 int ierr1 = input->
getInput(
"density matrix",dens_file);
1165 int ierr2 = input->
getInput(
"ct ramp",ramp_file);
1166 int ierr3 = input->
getInput(
"egsphant file",egsphant_file);
1167 int ierr4 = input->
getInput(
"interfile header",interfile_file);
1168 int dens_or_egsphant_or_interfile = -1;
1170 dens_or_egsphant_or_interfile = 0;
1173 dens_or_egsphant_or_interfile = 1;
1174 dens_file = egsphant_file;
1177 dens_or_egsphant_or_interfile = 2;
1178 dens_file = interfile_file;
1180 if (dens_or_egsphant_or_interfile >= 0 || !ierr2) {
1181 if (dens_or_egsphant_or_interfile < 0) {
1182 egsWarning(
"%s: no 'density matrix', 'egsphant file' or 'interfile header' input\n",func);
1190 EGS_XYZGeometry::constructGeometry(dens_file.c_str(),ramp_file.c_str(),dens_or_egsphant_or_interfile);
1200 vector<EGS_Float> xpos, ypos, zpos, xslab, yslab, zslab;
1201 int ix = input->
getInput(
"x-planes",xpos);
1202 int iy = input->
getInput(
"y-planes",ypos);
1203 int iz = input->
getInput(
"z-planes",zpos);
1204 int ix1 = input->
getInput(
"x-slabs",xslab);
1205 int iy1 = input->
getInput(
"y-slabs",yslab);
1206 int iz1 = input->
getInput(
"z-slabs",zslab);
1207 int nx=0, ny=0, nz=0;
1209 if (xslab.size() != 3) {
1210 egsWarning(
"createGeometry(XYZ): exactly 3 inputs are required"
1211 " when using 'x-slabs' input method\n");
1215 nx = (int)(xslab[2]+0.1);
1217 egsWarning(
"createGeometry(XYZ): number of slabs must be"
1221 if (xslab[1] <= 0) {
1222 egsWarning(
"createGeometry(XYZ): slab thickness must be"
1229 egsWarning(
"createGeometry(XYZ): wrong/missing 'x-planes' "
1230 "and 'x-slabs' input\n");
1234 if (yslab.size() != 3) {
1235 egsWarning(
"createGeometry(XYZ): exactly 3 inputs are required"
1236 " when using 'y-slabs' input method\n");
1240 ny = (int)(yslab[2]+0.1);
1242 egsWarning(
"createGeometry(XYZ): number of slabs must be"
1246 if (yslab[1] <= 0) {
1247 egsWarning(
"createGeometry(XYZ): slab thickness must be"
1254 egsWarning(
"createGeometry(XYZ): wrong/missing 'y-planes' "
1255 "and 'y-slabs' input\n");
1259 if (zslab.size() != 3) {
1260 egsWarning(
"createGeometry(XYZ): exactly 3 inputs are required"
1261 " when using 'z-slabs' input method\n");
1265 nz = (int)(zslab[2]+0.1);
1267 egsWarning(
"createGeometry(XYZ): number of slabs must be"
1271 if (zslab[1] <= 0) {
1272 egsWarning(
"createGeometry(XYZ): slab thickness must be"
1279 egsWarning(
"createGeometry(XYZ): wrong/missing 'z-planes' "
1280 "and 'z-slabs' input\n");
1295 egsWarning(
"**********************************************\n");
1300 result->voxelizeGeometry(input);
1303 result->setXYZLabels(input);
1309 vector<EGS_BaseGeometry *> dims;
1312 while ((ij = input->
takeInputItem(
"geometry",
false)) != 0) {
1323 vector<string> gnames;
1324 int err1 = input->
getInput(
"dimensions",gnames);
1326 for (
unsigned int j=0; j<gnames.size(); j++) {
1333 egsWarning(
"Geometry %s does not exist\n",gnames[j].c_str());
1339 egsWarning(
"createGeometry(ND_Geometry): %d errors while "
1340 "creating/geting geometries defining individual dimensions\n",error);
1343 if (dims.size() < 2) {
1344 egsWarning(
"createGeometry(ND_Geometry): why do you want to "
1345 "construct a ND geometry with a single dimension?\n");
1346 input->
print(0,cerr);
1347 for (
int j=0; j<gnames.size(); j++)
egsWarning(
"dimension %d: %s\n",
1348 j+1,gnames[j].c_str());
1351 for (
int j=0; j<dims.size(); j++)
if (!dims[j]->isConvex()) {
1356 egsWarning(
"createGeometry(ND_Geometry): a ND geometry can not have "
1357 " more than one non-convex dimension, yours has %d\n",n_concav);
1360 else if (n_concav == 1) {
1361 if (dims[dims.size()-1]->isConvex()) {
1362 egsWarning(
"createGeometry(ND_Geometry): the non-convex "
1363 "dimension must be the last dimension\n");
1368 for (
int j=0; j<dims.size(); j++)
1369 if (dims[j]->deref()) {
1375 err1 = input->
getInput(
"hownear method",hn_method);
1377 if (!err1 && hn_method == 1) {
1391 void EGS_XYZGeometry::setXYZLabels(
EGS_Input *input) {
1397 err = input->
getInput(
"set x label", inp);
1402 err = input->
getInput(
"set y label", inp);
1407 err = input->
getInput(
"set z label", inp);
1414 void EGS_NDGeometry::ndRegions(
int r,
int dim,
int dimk,
int k, vector<int> ®s) {
1423 ndRegions(r, dim+1, dimk, k, regs);
1428 else if (dim ==
N-1) {
1429 for (
int j=0; j<
g[dim]->
regions(); j++) {
1430 regs.push_back(r+j*
n[dim]);
1436 for (
int j=0; j<
g[dim]->
regions(); j++) {
1437 ndRegions(r + j*
n[dim], dim+1, dimk, k, regs);
1443 void EGS_NDGeometry::getLabelRegions(
const string &str, vector<int> ®s) {
1446 vector<int> local_regs;
1447 for (
int i=0; i<
N; i++) {
1452 if (local_regs.size() == 0) {
1457 for (
int j=0; j<local_regs.size(); j++) {
1458 ndRegions(0, 0, i, local_regs[j], regs);
1468 void EGS_XYZGeometry::getLabelRegions(
const string &str, vector<int> ®s) {
1470 vector<int> local_regs;
1475 for (
int i=0; i<local_regs.size(); i++) {
1476 for (
int j=0; j<ny; j++) {
1477 for (
int k=0; k<nz; k++) {
1478 regs.push_back(local_regs[i] + nx*j + nxy*k);
1486 for (
int j=0; j<local_regs.size(); j++) {
1487 for (
int i=0; i<nx; i++) {
1488 for (
int k=0; k<nz; k++) {
1489 regs.push_back(i + nx*local_regs[j] + nxy*k);
1497 for (
int k=0; k<local_regs.size(); k++) {
1498 for (
int i=0; i<nx; i++) {
1499 for (
int j=0; j<ny; j++) {
1500 regs.push_back(i + nx*j + nxy*local_regs[k]);
1511 void EGS_XYZRepeater::getLabelRegions(
const string &str, vector<int> ®s) {
1513 vector<int> local_regs;
1518 for (
int i=0; i<nx; i++) {
1519 for (
int j=0; j<ny; j++) {
1520 for (
int k=0; k<nz; k++) {
1521 for (
int r=0; r<local_regs.size(); r++) {
1522 regs.push_back(ng*(i + nx*j + nxy*k) + local_regs[r]);
1530 xyz->getXLabelRegions(str, local_regs);
1531 for (
int i=0; i<local_regs.size(); i++) {
1532 for (
int j=0; j<ny; j++) {
1533 for (
int k=0; k<nz; k++) {
1534 for (
int r=0; r<ng; r++) {
1535 regs.push_back(ng*(local_regs[i] + nx*j + nxy*k) + r);
1543 xyz->getYLabelRegions(str, local_regs);
1544 for (
int j=0; j<local_regs.size(); j++) {
1545 for (
int i=0; i<nx; i++) {
1546 for (
int k=0; k<nz; k++) {
1547 for (
int r=0; r<ng; r++) {
1548 regs.push_back(ng*(i + nx*local_regs[j] + nxy*k) + r);
1556 xyz->getZLabelRegions(str, local_regs);
1557 for (
int k=0; k<local_regs.size(); k++) {
1558 for (
int i=0; i<nx; i++) {
1559 for (
int j=0; j<ny; j++) {
1560 for (
int r=0; r<ng; r++) {
1561 regs.push_back(ng*(i + nx*j + nxy*local_regs[k]) + r);
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
int deref()
Decrease the reference count to this geometry.
virtual EGS_Float getBScaling(int ireg) const
Get the B field scaling factor in region ireg.
virtual void setBScaling(int start, int end, EGS_Float bf)
Set the B field scaling factor in regions.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
static EGS_BaseGeometry * createSingleGeometry(EGS_Input *inp)
Create a single geometry from the input inp.
virtual void getLabelRegions(const string &str, vector< int > ®s)
Get the list of all regions labeled with str.
int nreg
Number of local regions in this geometry.
bool has_B_scaling
Does this geometry has B field scaling factor?
bool is_convex
Is this geometry convex?
bool has_rho_scaling
Does this geometry have relative mass density scvaling?
bool hasBScaling() const
Does this geometry object have a B field scaling feature?
short * region_media
Array of media indeces.
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
void setMedium(const string &Name)
Set all regions to a medium with name Name.
const string & getName() const
Get the name of this geometry.
EGS_Float * rhor
Array with relative mass densities.
virtual EGS_Float getRelativeRho(int ireg) const
Get the relative mass density in region ireg.
EGS_Float * bfactor
Array with B field scaling factors.
bool isConvex() const
Is the geometry convex?
bool hasRhoScaling() const
Does this geometry object have a mass density scaling feature?
virtual int medium(int ireg) const
Returns the medium index in region ireg.
string name
Name of this geometry.
int regions() const
Returns the number of local regions in this geometry.
int setLabels(EGS_Input *input)
Set the labels from an input block.
virtual void setRelativeRho(int start, int end, EGS_Float rho)
Set the relative mass density in regions.
virtual void printInfo() const
Print information about this geometry.
int ref()
Increase the reference count to this geometry.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
static int addMedium(const string &medname)
Add a medium or get the index of an existing medium.
static const char * getMediumName(int ind)
Get the name of medium with index ind.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
virtual int isWhere(const EGS_Vector &x)=0
In which region is poisition x?
A class modeling a N-dimensional geometry.
static string type
The geometry type.
EGS_NDGeometry(int ng, EGS_BaseGeometry **G, const string &Name="", bool O=true)
int * n
Used for calculating region indeces.
void setMedia(EGS_Input *inp, int nmed, const int *med_ind)
Define media.
EGS_BaseGeometry ** g
The dimensions.
int N
Number of dimensions.
A set of parallel planes.
A class representing 3D vectors.
A projector into the x-plane.
A geometry repeated on a regular XYZ grid.
A projector into the y-plane.
A projector into the z-plane.
Global egspp functions header file.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
N-dimensional geometries: header.
int egsGetEndian()
Get the endianess of the machine.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
const EGS_I64 loopMax
The maximum number of iterations for near-infinite loops.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
void egsSwapBytes(int *n)
Swap the bytes of 32 bit integers.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.