59 for (
int j=0; j<
N; j++) {
71 const string &Name,
bool O) :
EGS_BaseGeometry(Name), N(G.size()), ortho(O) {
74 for (
int j=0; j<
N; j++) {
85 EGS_NDGeometry::~EGS_NDGeometry() {
86 for (
int j=0; j<
N; j++) {
96 void EGS_NDGeometry::setup() {
101 void EGS_NDGeometry::printInfo()
const {
104 for (
int j=0; j<
N; j++)
106 j+1,
g[j]->
getName().c_str(),
g[j]->getType().c_str());
108 "=======================================================\n");
116 int err = i->
getInput(
"set medium",inp);
119 if (inp.size() == 2) {
122 else if (inp.size() == 3) {
125 else if (inp.size() == 4)
setMedium(inp[0],inp[1],mind[inp[2]],
127 else if (inp.size() == 2*N+1) {
128 setM(0,0,inp,mind[inp[2*N]]);
130 else egsWarning(
"EGS_NDGeometry::setMedia(): found %dinputs\n"
131 "in a 'set medium' input. 2, 3, 4, or %d are allowed\n",2*N+1);
133 else egsWarning(
"EGS_NDGeometry::setMedia(): wrong 'set medium'"
138 void EGS_NDGeometry::setM(
int ibase,
int idim,
139 const vector<int> &ranges,
int medium) {
140 int istart = ranges[2*idim], iend = ranges[2*idim+1];
144 int ndim =
n[idim+1] /
n[idim];
148 if (idim < N-1)
for (
int j=istart; j<=iend; j++) {
149 setM(ibase+j*
n[idim],idim+1,ranges,medium);
151 else for (
int j=istart; j<=iend; j++) {
158 string EGS_XYZGeometry::type =
"EGS_XYZGeometry";
162 xp(Xp), yp(Yp), zp(Zp) {
171 xpos = xp->getPositions();
172 ypos = yp->getPositions();
173 zpos = zp->getPositions();
176 EGS_XYZGeometry::~EGS_XYZGeometry() {
188 void EGS_XYZGeometry::printInfo()
const {
194 "=======================================================\n");
197 void EGS_XYZGeometry::setMedia(
EGS_Input *input,
int nmed,
const int *mind) {
202 int err = i->
getInput(
"set medium",inp);
205 if (inp.size() == 2) {
208 else if (inp.size() == 3) {
211 else if (inp.size() == 4)
setMedium(inp[0],inp[1],mind[inp[2]],
213 else if (inp.size() == 7) {
214 int is = inp[0], ie = inp[1];
221 int js = inp[2], je = inp[3];
228 int ks = inp[4], ke = inp[5];
232 if (ke >
nreg/nxy-1) {
237 for (
int i=is; i<=ie; i++) {
238 for (
int j=js; j<=je; j++) {
239 for (
int k=ks; k<=ke; k++) {
240 int ireg = i + j*nx + k*nxy;
248 else if (inp.size() == 10) {
249 int is = inp[0], ie = inp[1], idelta = inp[2];
259 int js = inp[3], je = inp[4], jdelta = inp[5];
269 int ks = inp[6], ke = inp[7], kdelta = inp[8];
273 if (ke >
nreg/nxy-1) {
281 for (
int i=is; i<=ie; i+=idelta) {
282 for (
int j=js; j<=je; j+=jdelta) {
283 for (
int k=ks; k<=ke; k+=kdelta) {
284 int ireg = i + j*nx + k*nxy;
292 else egsWarning(
"EGS_XYZGeometry::setMedia(): found %dinputs\n"
293 "in a 'set medium' input. 2, 3, 4, 7, or 10 are allowed\n");
295 else egsWarning(
"EGS_XYZGeometry::setMedia(): wrong 'set medium'"
300 EGS_XYZGeometry *EGS_XYZGeometry::constructGeometry(
const char *dens_file,
301 const char *ramp_file,
int dens_or_egsphant_or_interfile) {
302 const static char *func =
"EGS_XYZGeometry::constructGeometry";
303 if (!dens_file || !ramp_file) {
306 ifstream ramp(ramp_file);
308 egsWarning(
"%s: failed to open CT ramp file %s\n",func,ramp_file);
311 vector<string> med_names;
312 vector<EGS_Float> rho_min,rho_max,rho_def;
314 if (dens_or_egsphant_or_interfile == 2) {
318 for (
int i=0; i < meds; i++) {
320 EGS_Float rmin,rmax,rdef;
321 ramp >> rmin >> rmax >> medname;
322 rdef=(rmin+rmax) / 2.0;
323 if (ramp.eof() || ramp.fail() || !ramp.good()) {
326 egsInformation(
"Using medium %s for rho=%g...%g\n",medname.c_str(),
328 med_names.push_back(medname);
329 rho_min.push_back(rmin);
330 rho_max.push_back(rmax+1);
331 rho_def.push_back(rdef);
335 for (EGS_I64 loopCount=0; loopCount<=
loopMax; ++loopCount) {
337 egsFatal(
"EGS_XYZGeometry::constructGeometry: Too many iterations were required! Input may be invalid, or consider increasing loopMax.");
342 EGS_Float rmin,rmax,rdef;
343 ramp >> medname >> rmin >> rmax >> rdef;
344 if (ramp.eof() || ramp.fail() || !ramp.good()) {
347 egsInformation(
"Using medium %s for rho=%g...%g\n",medname.c_str(),
349 med_names.push_back(medname);
350 rho_min.push_back(rmin);
351 rho_max.push_back(rmax);
352 rho_def.push_back(rdef);
355 if (med_names.size() < 1) {
356 egsWarning(
"%s: no media defined in the CT ramp "
357 "file %s!\n",func,ramp_file);
361 EGS_Float *xx, *yy, *zz;
363 if (dens_or_egsphant_or_interfile == 0) {
365 if (my_endian < 0)
egsFatal(
"%s: machine has an unknown"
366 " endianess!\n",func);
367 ifstream dens(dens_file,ios::binary);
369 egsWarning(
"%s: failed to open density matrix file "
370 "%s\n",func,dens_file);
374 dens.read(&their_endian,1);
375 if (their_endian != 0 && their_endian != 1)
376 egsFatal(
"%s: density data created on a machine with"
377 " unknown endianess!\n",func);
378 bool swap = my_endian != their_endian;
379 dens.read((
char *) &Nx,
sizeof(
int));
383 dens.read((
char *) &Ny,
sizeof(
int));
387 dens.read((
char *) &Nz,
sizeof(
int));
391 if (Nx < 1 || Ny < 1 || Nz < 1) {
392 egsWarning(
"%s: invalid density matrix file: "
393 " Nx=%d Ny=%d Nz=%d\n",func,Nx,Ny,Nz);
396 float *x =
new float [Nx+1];
397 float *y =
new float [Ny+1];
398 float *z =
new float [Nz+1];
399 dens.read((
char *)x, (Nx+1)*
sizeof(
float));
400 if (dens.eof() || dens.fail() || !dens.good()) {
401 egsWarning(
"%s: error while reading %d x-planes from"
402 " file %s\n",func,Nx+1,dens_file);
408 dens.read((
char *)y, (Ny+1)*
sizeof(
float));
409 if (dens.eof() || dens.fail() || !dens.good()) {
410 egsWarning(
"%s: error while reading %d y-planes from"
411 " file %s\n",func,Ny+1,dens_file);
417 dens.read((
char *)z, (Nz+1)*
sizeof(
float));
418 if (dens.eof() || dens.fail() || !dens.good()) {
419 egsWarning(
"%s: error while reading %d z-planes from"
420 " file %s\n",func,Nz+1,dens_file);
428 for (j=0; j<Nx; j++) {
431 for (j=0; j<Ny; j++) {
434 for (j=0; j<Nz; j++) {
440 xx =
new EGS_Float [Nx+1];
441 for (j=0; j<=Nx; j++) {
444 yy =
new EGS_Float [Ny+1];
445 for (j=0; j<=Ny; j++) {
448 zz =
new EGS_Float [Nz+1];
449 for (j=0; j<=Nz; j++) {
456 rho =
new float [Nx*Ny*Nz];
457 dens.read((
char *)rho, Nx*Ny*Nz*
sizeof(
float));
459 egsWarning(
"%s: failed reading mass densities from density matrux file\n",func);
467 for (
int j=0; j<Nx*Ny*Nz; j++) {
472 else if (dens_or_egsphant_or_interfile == 2) {
473 ifstream h_file(dens_file);
475 egsWarning(
"%s: failed to open the interfile header %s\n",func,dens_file);
478 string data_file(
"");
480 float scale_x=0.0, scale_y=0.0, scale_z=0.0;
481 for (EGS_I64 loopCount=0; loopCount<=
loopMax; ++loopCount) {
483 egsFatal(
"EGS_XYZGeometry::constructGeometry: Too many iterations were required! Input may be invalid, or consider increasing loopMax.");
486 string line, key, value;
488 getline(h_file, line);
489 if (h_file.eof() || h_file.fail() || !h_file.good()) {
493 pos = line.find(
":=");
494 if (pos == string::npos) {
497 key = line.substr(0,
int(pos));
498 value = line.substr(
int(pos)+2);
499 while ((key[0] ==
'!') || (key[0] ==
' ')) {
502 while (key[key.length()-1] ==
' ') {
503 key.erase(key.length()-1, 1);
505 while (value[0] ==
' ') {
508 while (value[value.length()-1] ==
' ') {
509 value.erase(value.length()-1, 1);
512 if (key ==
"matrix size [1]") {
513 sscanf(value.c_str(),
"%u", &Nx);
515 else if (key ==
"matrix size [2]") {
516 sscanf(value.c_str(),
"%u", &Ny);
518 else if ((key ==
"number of slices") || (key ==
"number of images")) {
519 sscanf(value.c_str(),
"%u", &Nz);
521 else if (key ==
"scaling factor (mm/pixel) [1]") {
522 sscanf(value.c_str(),
"%f", &scale_x);
524 else if (key ==
"scaling factor (mm/pixel) [2]") {
525 sscanf(value.c_str(),
"%f", &scale_y);
527 else if (key ==
"slice thickness (pixels)") {
528 sscanf(value.c_str(),
"%f", &scale_z);
530 else if (key ==
"name of data file") {
533 else if (key ==
"number format") {
534 if ((value ==
"float") || (value ==
"FLOAT")) {
537 else if ((value ==
"unsigned integer") || (value ==
"UNSIGNED INTEGER")) {
541 egsWarning(
"%s: unrecognised 'number format' type: %s \n",func,value.c_str());
545 if (Nx < 1 || Ny < 1 || Nz < 1 || scale_x <= 0.0 || scale_y <= 0.0 || scale_z <= 0.0 || data_file ==
"" || data_type == -1) {
546 egsWarning(
"%s: invalid interfile header information: "
547 "Nx=%d Ny=%d Nz=%d scale_x=%f scale_y=%f scale_z=%f "
548 "data_file='%s' number_format=%d\n",func,Nx,Ny,Nz,scale_x,scale_y,scale_z,data_file.c_str(),data_type);
551 ifstream i_file(data_file.c_str(),ios::binary);
553 egsWarning(
"%s: failed to open interfile data "
554 "%s\n",func,data_file.c_str());
562 xx =
new EGS_Float [Nx+1];
563 for (j=0; j<=Nx; j++) {
564 xx[j] = -(float)Nx*scale_x/2.0 + j*scale_x;
566 yy =
new EGS_Float [Ny+1];
567 for (j=0; j<=Ny; j++) {
568 yy[j] = -(float)Ny*scale_y/2.0 + j*scale_y;
570 zz =
new EGS_Float [Nz+1];
571 for (j=0; j<=Nz; j++) {
572 zz[j] = -(float)Nz*scale_z/2.0 + j*scale_z;
575 rho =
new float [Nx*Ny*Nz];
576 if (data_type == 0) {
577 i_file.read((
char *)rho, Nx*Ny*Nz*
sizeof(
float));
580 unsigned short int *rho_tmp =
new unsigned short int [Nx*Ny*Nz];
581 i_file.read((
char *)rho_tmp, (Nx*Ny*Nz)*
sizeof(
unsigned short int));
582 for (
int cc = 0; cc<Nx*Ny*Nz; cc++) {
583 rho[cc] = (float)(rho_tmp[cc]);
588 egsWarning(
"%s: failed reading interfile data\n",func);
598 ifstream tempf(dens_file, ios::binary);
606 egsWarning(
"%s: failed to open .egsphant file %s\n",func,dens_file);
610 bool is_gzip = (tempf.get() == 0x1f && tempf.get() == 0x8b);
615 binf.open(dens_file);
618 egsWarning(
"Tried to read gzipped egsphant but egs_ndgeometry was not compiled with gzip support\n");
623 textf.open(dens_file);
630 if ((*data).fail()) {
631 egsWarning(
"%s: failed reading number of media\n",func);
636 (*data).getline(buf,1023);
637 for (imed=0; imed<nmed; ++imed) {
638 (*data).getline(buf,1023);
639 if ((*data).fail()) {
640 egsWarning(
"%s: failed reading medium name for %d'th medium\n",func,imed+1);
646 for (imed=0; imed<nmed; ++imed) {
649 (*data) >> Nx >> Ny >> Nz;
650 if ((*data).fail()) {
651 egsWarning(
"%s: failed reading number of voxels\n",func);
654 xx =
new EGS_Float [Nx+1];
655 yy =
new EGS_Float [Ny+1];
656 zz =
new EGS_Float [Nz+1];
658 for (j=0; j<=Nx; ++j) {
661 if ((*data).fail()) {
662 egsWarning(
"%s: failed reading x-planes\n",func);
668 for (j=0; j<=Ny; ++j) {
671 if ((*data).fail()) {
672 egsWarning(
"%s: failed reading y-planes\n",func);
678 for (j=0; j<=Nz; ++j) {
681 if ((*data).fail()) {
682 egsWarning(
"%s: failed reading z-planes\n",func);
691 (*data).getline(buf,1023);
692 for (
int iz=0; iz<Nz; ++iz) {
693 for (
int iy=0; iy<Ny; ++iy) {
694 (*data).getline(buf,1023);
696 (*data).getline(buf,1023);
698 if ((*data).fail()) {
699 egsWarning(
"%s: failed reading media indeces matrix\n",func);
705 rho =
new float [nr];
706 for (j=0; j<nr; ++j) {
709 if ((*data).fail()) {
710 egsWarning(
"%s: failed reading mass density matrix\n",func);
722 EGS_Float rhomin=1e30,rhomax=0;
724 for (j=0; j<Nx*Ny*Nz; j++) {
725 if (rho[j] > rhomax) {
728 if (rho[j] < rhomin) {
734 int nmed = med_names.size();
735 int *imed =
new int [nmed];
736 for (j=0; j<nmed; j++) {
739 for (j=0; j<Nx*Ny*Nz; j++) {
741 for (i=0; i<nmed; i++) {
742 if (rho[j] >= rho_min[i] && rho[j] < rho_max[i]) {
747 egsWarning(
"%s: no material defined for density %g, leaving voxel %d"
748 " as vacuum\n",func,rho[j],j);
755 med_names[i].c_str(),imed[i]);
758 if (rho_def[i] > 0) {
759 EGS_Float rrho = rho[j]/rho_def[i];
771 string EGS_DeformedXYZ::def_type =
"EGS_DeformedXYZ";
773 char EGS_DeformedXYZ::tetrahedra[] = {0,2,3,6, 0,6,3,7, 0,4,6,7,
774 7,0,1,3, 7,1,0,4, 7,5,1,4
777 char EGS_DeformedXYZ::plane_order[] = {0,1,2, 0,2,3, 0,3,1, 1,3,2};
779 char EGS_DeformedXYZ::enter_tetra1[] = {0, 3, 4, 0, 0, 2};
780 char EGS_DeformedXYZ::enter_plane1[] = {1, 1, 1, 3, 0, 3};
781 char EGS_DeformedXYZ::enter_tetra2[] = {2, 5, 5, 1, 3, 5};
782 char EGS_DeformedXYZ::enter_plane2[] = {0, 0, 2, 3, 2, 2};
785 char EGS_DeformedXYZ::tetra_data[] = {
819 EGS_PlanesZ *Zp,
const char *defFile,
const string &Name) :
821 setDeformations(defFile);
829 ifstream data(defFile,ios::binary);
831 egsWarning(
"Failed to open deformations file %s\n",defFile);
835 data.read((
char *)&nvec,
sizeof(
int));
836 int nneed = (nx+1)*(ny+1)*(nz+1);
838 egsWarning(
"Inconsistent deformations file: %d instead of %d vectors\n",
847 for (j=0; j<nvec; ++j) {
848 data.read((
char *)tmp,3*
sizeof(
float));
850 egsWarning(
"Error while readinf vector %d from file\n",j+1);
853 vectors[j] =
EGS_Vector(tmp[0],tmp[1],tmp[2]);
857 for (k=0; k<=nz; ++k)
for (j=0; j<=ny; ++j)
for (i=0; i<=nx; ++i) {
858 int index = i + j*(nx+1) + k*(nx+1)*(ny+1);
859 vectors[index] +=
EGS_Vector(xpos[i],ypos[j],zpos[k]);
862 for (j=0; j<24; ++j) {
863 int i = tetrahedra[j];
878 tnodes[j] = (nx+1)*(ny+1);
881 tnodes[j] = (nx+1)*(ny+1)+1;
884 tnodes[j] = (nx+1)*(ny+1)+nx+1;
887 tnodes[j] = (nx+1)*(ny+1)+nx+2;
897 EGS_DeformedXYZ::~EGS_DeformedXYZ() {
903 string EGS_XYZRepeater::type =
"EGS_XYZRepeater";
905 EGS_XYZRepeater::EGS_XYZRepeater(EGS_Float xmin, EGS_Float xmax,
906 EGS_Float ymin, EGS_Float ymax,
907 EGS_Float zmin, EGS_Float zmax,
908 int Nx,
int Ny,
int Nz,
910 const string &Name) :
912 dx = (xmax - xmin)/nx;
915 dy = (ymax - ymin)/ny;
918 dz = (zmax - zmin)/nz;
935 for (
int ix=0; ix<nx; ix++)
936 for (
int iy=0; iy<ny; iy++)
937 for (
int iz=0; iz<nz; iz++)
938 translation[ix+iy*nx+iz*nxy] =
EGS_Vector(xmin + dx*(0.5+ix),
944 EGS_XYZRepeater::~EGS_XYZRepeater() {
951 delete [] translation;
954 void EGS_XYZRepeater::printInfo()
const {
957 nx,xyz->getXPositions()[0],xyz->getXPositions()[nx]);
959 ny,xyz->getYPositions()[0],xyz->getYPositions()[ny]);
961 nz,xyz->getZPositions()[0],xyz->getZPositions()[nz]);
973 void EGS_XYZGeometry::voxelizeGeometry(
EGS_Input *input) {
975 int err = input->
getInput(
"voxelize geometry",gname);
980 egsInformation(
" setting media from geometry %s\n",gname.c_str());
983 egsInformation(
" this geometry does not exist -> media will be not set.\n");
1000 bool hrs = geometry->hasRhoScaling();
1009 bool hbs = geometry->hasBScaling();
1018 EGS_Vector v1(xp->position(0),yp->position(0),zp->position(0));
1019 EGS_Vector v2(xp->position(nx),yp->position(ny),zp->position(nz));
1020 egsInformation(
" top/left/front corner : (%g,%g,%g)\n",v1.x,v1.y,v1.z);
1021 egsInformation(
" bottom/right/back corner: (%g,%g,%g)\n",v2.x,v2.y,v2.z);
1023 egsInformation(
" the above are transformed as follows before looking up media:\n");
1026 egsInformation(
" top/left/front corner : (%g,%g,%g)\n",v1.x,v1.y,v1.z);
1027 egsInformation(
" bottom/right/back corner: (%g,%g,%g)\n",v2.x,v2.y,v2.z);
1029 for (
int ix=0; ix<nx; ++ix)
for (
int iy=0; iy<ny; iy++)
for (
int iz=0; iz<nz; ++iz) {
1030 int ir = ix + iy*nx + iz*nxy;
1031 EGS_Vector v(0.5*(xp->position(ix)+xp->position(ix+1)),
1032 0.5*(yp->position(iy)+yp->position(iy+1)),
1033 0.5*(zp->position(iz)+zp->position(iz+1)));
1037 int ireg = geometry->isWhere(v);
1041 rhor[ir] = geometry->getRelativeRho(ir);
1044 bfactor[ir] = geometry->getBScaling(ir);
1057 vector<string> options;
1058 options.push_back(
"no");
1059 options.push_back(
"yes");
1060 bool delete_geometry = input->
getInput(
"delete geometry",options,0);
1061 if (delete_geometry) {
1062 if (geometry->deref() == -1) {
1063 egsInformation(
" deleting geometry %s as requested\n",geometry->getName().c_str());
1067 egsInformation(
" not deleting geometry %s as requested due to remaining references\n",
1068 geometry->getName().c_str());
1075 const char *err_msg1 =
"createGeometry(EGS_XYZRepeater)";
1085 const static char *func =
"createGeometry(XYZ)";
1087 int is_xyz = input->
getInput(
"type",type);
1088 if (!is_xyz && input->
compare(
"EGS_XYZRepeater",type)) {
1090 vector<EGS_Float> xr, yr, zr;
1091 int err1 = input->
getInput(
"repeated geometry",base);
1092 int err2 = input->
getInput(
"repeat x",xr);
1093 int err3 = input->
getInput(
"repeat y",yr);
1094 int err4 = input->
getInput(
"repeat z",zr);
1095 int err5 = input->
getInput(
"medium",medium);
1098 egsWarning(
"%s: missing 'repeated geometry' input\n",err_msg1);
1103 egsWarning(
"%s: no geometry named %s exists\n",err_msg1,
1108 if (err2 || xr.size() != 3) {
1110 egsWarning(
"%s: wrong/missing 'repeat x' input\n",err_msg1);
1112 if (err3 || yr.size() != 3) {
1114 egsWarning(
"%s: wrong/missing 'repeat y' input\n",err_msg1);
1116 if (err4 || zr.size() != 3) {
1118 egsWarning(
"%s: wrong/missing 'repeat z' input\n",err_msg1);
1123 EGS_Float xmin = xr[0], xmax = xr[1];
1124 int nx = (int)(xr[2]+0.1);
1125 if (xmin >= xmax || nx < 1) {
1126 egsWarning(
"%s: wrong 'repeat x' input xmin=%g xmax=%g nx=%d\n",
1130 EGS_Float ymin = yr[0], ymax = yr[1];
1131 int ny = (int)(yr[2]+0.1);
1132 if (ymin >= ymax || ny < 1) {
1133 egsWarning(
"%s: wrong 'repeat y' input ymin=%g ymax=%g ny=%d\n",
1137 EGS_Float zmin = zr[0], zmax = zr[1];
1138 int nz = (int)(zr[2]+0.1);
1139 if (zmin >= zmax || nz < 1) {
1140 egsWarning(
"%s: wrong 'repeat z' input zmin=%g zmax=%g nz=%d\n",
1155 result->setXYZLabels(input);
1159 else if (!is_xyz && input->
compare(
"EGS_XYZGeometry",type)) {
1160 string dens_file, ramp_file, egsphant_file, interfile_file;
1161 int ierr1 = input->
getInput(
"density matrix",dens_file);
1162 int ierr2 = input->
getInput(
"ct ramp",ramp_file);
1163 int ierr3 = input->
getInput(
"egsphant file",egsphant_file);
1164 int ierr4 = input->
getInput(
"interfile header",interfile_file);
1165 int dens_or_egsphant_or_interfile = -1;
1167 dens_or_egsphant_or_interfile = 0;
1170 dens_or_egsphant_or_interfile = 1;
1171 dens_file = egsphant_file;
1174 dens_or_egsphant_or_interfile = 2;
1175 dens_file = interfile_file;
1177 if (dens_or_egsphant_or_interfile >= 0 || !ierr2) {
1178 if (dens_or_egsphant_or_interfile < 0) {
1179 egsWarning(
"%s: no 'density matrix', 'egsphant file' or 'interfile header' input\n",func);
1187 EGS_XYZGeometry::constructGeometry(dens_file.c_str(),ramp_file.c_str(),dens_or_egsphant_or_interfile);
1197 vector<EGS_Float> xpos, ypos, zpos, xslab, yslab, zslab;
1198 int ix = input->
getInput(
"x-planes",xpos);
1199 int iy = input->
getInput(
"y-planes",ypos);
1200 int iz = input->
getInput(
"z-planes",zpos);
1201 int ix1 = input->
getInput(
"x-slabs",xslab);
1202 int iy1 = input->
getInput(
"y-slabs",yslab);
1203 int iz1 = input->
getInput(
"z-slabs",zslab);
1204 int nx=0, ny=0, nz=0;
1206 if (xslab.size() != 3) {
1207 egsWarning(
"createGeometry(XYZ): exactly 3 inputs are required"
1208 " when using 'x-slabs' input method\n");
1212 nx = (int)(xslab[2]+0.1);
1214 egsWarning(
"createGeometry(XYZ): number of slabs must be"
1218 if (xslab[1] <= 0) {
1219 egsWarning(
"createGeometry(XYZ): slab thickness must be"
1226 egsWarning(
"createGeometry(XYZ): wrong/missing 'x-planes' "
1227 "and 'x-slabs' input\n");
1231 if (yslab.size() != 3) {
1232 egsWarning(
"createGeometry(XYZ): exactly 3 inputs are required"
1233 " when using 'y-slabs' input method\n");
1237 ny = (int)(yslab[2]+0.1);
1239 egsWarning(
"createGeometry(XYZ): number of slabs must be"
1243 if (yslab[1] <= 0) {
1244 egsWarning(
"createGeometry(XYZ): slab thickness must be"
1251 egsWarning(
"createGeometry(XYZ): wrong/missing 'y-planes' "
1252 "and 'y-slabs' input\n");
1256 if (zslab.size() != 3) {
1257 egsWarning(
"createGeometry(XYZ): exactly 3 inputs are required"
1258 " when using 'z-slabs' input method\n");
1262 nz = (int)(zslab[2]+0.1);
1264 egsWarning(
"createGeometry(XYZ): number of slabs must be"
1268 if (zslab[1] <= 0) {
1269 egsWarning(
"createGeometry(XYZ): slab thickness must be"
1276 egsWarning(
"createGeometry(XYZ): wrong/missing 'z-planes' "
1277 "and 'z-slabs' input\n");
1292 egsWarning(
"**********************************************\n");
1297 result->voxelizeGeometry(input);
1300 result->setXYZLabels(input);
1306 vector<EGS_BaseGeometry *> dims;
1309 while ((ij = input->
takeInputItem(
"geometry",
false)) != 0) {
1320 vector<string> gnames;
1321 int err1 = input->
getInput(
"dimensions",gnames);
1323 for (
unsigned int j=0; j<gnames.size(); j++) {
1330 egsWarning(
"Geometry %s does not exist\n",gnames[j].c_str());
1336 egsWarning(
"createGeometry(ND_Geometry): %d errors while "
1337 "creating/geting geometries defining individual dimensions\n",error);
1340 if (dims.size() < 2) {
1341 egsWarning(
"createGeometry(ND_Geometry): why do you want to "
1342 "construct a ND geometry with a single dimension?\n");
1343 input->
print(0,cerr);
1344 for (
int j=0; j<gnames.size(); j++)
egsWarning(
"dimension %d: %s\n",
1345 j+1,gnames[j].c_str());
1348 for (
int j=0; j<dims.size(); j++)
if (!dims[j]->isConvex()) {
1353 egsWarning(
"createGeometry(ND_Geometry): a ND geometry can not have "
1354 " more than one non-convex dimension, yours has %d\n",n_concav);
1357 else if (n_concav == 1) {
1358 if (dims[dims.size()-1]->isConvex()) {
1359 egsWarning(
"createGeometry(ND_Geometry): the non-convex "
1360 "dimension must be the last dimension\n");
1365 for (
int j=0; j<dims.size(); j++)
1366 if (dims[j]->deref()) {
1372 err1 = input->
getInput(
"hownear method",hn_method);
1374 if (!err1 && hn_method == 1) {
1388 void EGS_XYZGeometry::setXYZLabels(
EGS_Input *input) {
1394 err = input->
getInput(
"set x label", inp);
1399 err = input->
getInput(
"set y label", inp);
1404 err = input->
getInput(
"set z label", inp);
1411 void EGS_NDGeometry::ndRegions(
int r,
int dim,
int dimk,
int k, vector<int> ®s) {
1420 ndRegions(r, dim+1, dimk, k, regs);
1425 else if (dim == N-1) {
1426 for (
int j=0; j<g[dim]->
regions(); j++) {
1427 regs.push_back(r+j*n[dim]);
1433 for (
int j=0; j<g[dim]->
regions(); j++) {
1434 ndRegions(r + j*n[dim], dim+1, dimk, k, regs);
1440 void EGS_NDGeometry::getLabelRegions(
const string &str, vector<int> ®s) {
1443 vector<int> local_regs;
1444 for (
int i=0; i<
N; i++) {
1449 if (local_regs.size() == 0) {
1454 for (
int j=0; j<local_regs.size(); j++) {
1455 ndRegions(0, 0, i, local_regs[j], regs);
1465 void EGS_XYZGeometry::getLabelRegions(
const string &str, vector<int> ®s) {
1467 vector<int> local_regs;
1472 for (
int i=0; i<local_regs.size(); i++) {
1473 for (
int j=0; j<ny; j++) {
1474 for (
int k=0; k<nz; k++) {
1475 regs.push_back(local_regs[i] + nx*j + nxy*k);
1483 for (
int j=0; j<local_regs.size(); j++) {
1484 for (
int i=0; i<nx; i++) {
1485 for (
int k=0; k<nz; k++) {
1486 regs.push_back(i + nx*local_regs[j] + nxy*k);
1494 for (
int k=0; k<local_regs.size(); k++) {
1495 for (
int i=0; i<nx; i++) {
1496 for (
int j=0; j<ny; j++) {
1497 regs.push_back(i + nx*j + nxy*local_regs[k]);
1508 void EGS_XYZRepeater::getLabelRegions(
const string &str, vector<int> ®s) {
1510 vector<int> local_regs;
1515 for (
int i=0; i<nx; i++) {
1516 for (
int j=0; j<ny; j++) {
1517 for (
int k=0; k<nz; k++) {
1518 for (
int r=0; r<local_regs.size(); r++) {
1519 regs.push_back(ng*(i + nx*j + nxy*k) + local_regs[r]);
1527 xyz->getXLabelRegions(str, local_regs);
1528 for (
int i=0; i<local_regs.size(); i++) {
1529 for (
int j=0; j<ny; j++) {
1530 for (
int k=0; k<nz; k++) {
1531 for (
int r=0; r<ng; r++) {
1532 regs.push_back(ng*(local_regs[i] + nx*j + nxy*k) + r);
1540 xyz->getYLabelRegions(str, local_regs);
1541 for (
int j=0; j<local_regs.size(); j++) {
1542 for (
int i=0; i<nx; i++) {
1543 for (
int k=0; k<nz; k++) {
1544 for (
int r=0; r<ng; r++) {
1545 regs.push_back(ng*(i + nx*local_regs[j] + nxy*k) + r);
1553 xyz->getZLabelRegions(str, local_regs);
1554 for (
int k=0; k<local_regs.size(); k++) {
1555 for (
int i=0; i<nx; i++) {
1556 for (
int j=0; j<ny; j++) {
1557 for (
int r=0; r<ng; r++) {
1558 regs.push_back(ng*(i + nx*j + nxy*local_regs[k]) + r);
const EGS_I64 loopMax
The maximum number of iterations for near-infinite loops.
int regions() const
Returns the number of local regions in this geometry.
int deref()
Decrease the reference count to this geometry.
virtual void printInfo() const
Print information about this geometry.
EGS_Float * bfactor
Array with B field scaling factors.
int N
Number of dimensions.
string name
Name of this geometry.
A class representing 3D vectors.
int setLabels(EGS_Input *input)
Set the labels from an input block.
Global egspp functions header file.
int * n
Used for calculating region indeces.
EGS_GLIB_EXPORT EGS_BaseGeometry * createGeometry(EGS_Input *input)
void egsSwapBytes(int *n)
Swap the bytes of 32 bit integers.
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual void setRelativeRho(int start, int end, EGS_Float rho)
Set the relative mass density in regions.
void setBoundaryTolerance(EGS_Input *inp)
Set the value of the boundary tolerance from the input inp.
bool isConvex() const
Is the geometry convex?
N-dimensional geometries: header.
virtual void setBScaling(int start, int end, EGS_Float bf)
Set the B field scaling factor in regions.
static EGS_BaseGeometry * getGeometry(const string &Name)
Get a pointer to the geometry named Name.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
virtual void getLabelRegions(const string &str, vector< int > ®s)
Get the list of all regions labeled with str.
void setMedia(EGS_Input *inp)
Set the media in the geometry from the input pointed to by inp.
static int addMedium(const string &medname)
Add a medium or get the index of an existing medium.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
A set of parallel planes.
bool is_convex
Is this geometry convex?
int egsGetEndian()
Get the endianess of the machine.
void setMedium(const string &Name)
Set all regions to a medium with name Name.
void setName(EGS_Input *inp)
Set the name of the geometry from the input inp.
void setMedia(EGS_Input *inp, int nmed, const int *med_ind)
Define media.
A geometry repeated on a regular XYZ grid.
A projector into the z-plane.
short * region_media
Array of media indeces.
A projector into the y-plane.
bool has_rho_scaling
Does this geometry have relative mass density scvaling?
int ref()
Increase the reference count to this geometry.
A projector into the x-plane.
static EGS_BaseGeometry * createSingleGeometry(EGS_Input *inp)
Create a single geometry from the input inp.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
A class modeling a N-dimensional geometry.
static const char * getMediumName(int ind)
Get the name of medium with index ind.
const string & getName() const
Get the name of this geometry.
EGS_BaseGeometry ** g
The dimensions.
int nreg
Number of local regions in this geometry.
EGS_NDGeometry(int ng, EGS_BaseGeometry **G, const string &Name="", bool O=true)
EGS_Float * rhor
Array with relative mass densities.
static string type
The geometry type.
bool has_B_scaling
Does this geometry has B field scaling factor?
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.