46 #include "../egs_gtransformed/egs_gtransformed.h"
48 #ifndef EGS_LATTICE_GEOMETRY_
49 #define EGS_LATTICE_GEOMETRY_
53 #ifdef BUILD_LATTICE_DLL
54 #define EGS_LATTICE_EXPORT __declspec(dllexport)
56 #define EGS_LATTICE_EXPORT __declspec(dllimport)
58 #define EGS_LATTICE_LOCAL
62 #ifdef HAVE_VISIBILITY
63 #define EGS_LATTICE_EXPORT __attribute__ ((visibility ("default")))
64 #define EGS_LATTICE_LOCAL __attribute__ ((visibility ("hidden")))
66 #define EGS_LATTICE_EXPORT
67 #define EGS_LATTICE_LOCAL
159 EGS_Float y, EGS_Float z,
const string &Name =
"");
165 int(round(x.
z/c))*c);
177 return sub->isRealRegion(ireg - base->
regions());
187 sub->setTransformation(closestPoint(x));
188 if (sub->isInside(x)) {
189 return sub->isWhere(x) + base->
regions();
199 int medium(
int ireg)
const {
201 return sub->medium(ireg-base->
regions());
203 return base->
medium(ireg);
219 EGS_Float &t,
int *newmed=0,
EGS_Vector *normal=0) {
227 sub->setTransformation(closestPoint(x));
231 int tempReg = sub->howfar(ireg-base->
regions(),x,u,tempT,newmed,normal);
238 newX = x + (newX * tempT);
240 if (base->
isWhere(newX) != ind) {
243 tempReg = base->
howfar(ind,x,u,t,0,normal);
244 if (newmed && tempReg >= 0) {
245 *newmed = base->
medium(tempReg);
257 *newmed = base->
medium(ind);
269 return tempReg+base->
regions();
271 else if (ireg == ind) {
274 base->
howfar(ireg,x,u,tempT);
275 EGS_Float max = tempT;
278 EGS_Float min = max, minX = max, minY = max, minZ = max;
281 EGS_Vector xInt = unit*(a/4.0/fabs(unit.
x)), yInt = unit*(b/4.0/fabs(unit.
y)), zInt = unit*(c/4.0/fabs(unit.
z));
286 EGS_Float max2 = max*max;
289 while ((x-x0).length2() < max2) {
291 tempP = closestPoint(x0);
292 sub->setTransformation(tempP);
293 if (sub->howfar(-1,x,u,tempT)+1)
294 if (tempT < max && tempT > 0) {
303 while ((x-x0).length2() < max2) {
305 tempP = closestPoint(x0);
306 sub->setTransformation(tempP);
307 if (sub->howfar(-1,x,u,tempT)+1)
308 if (tempT < max && tempT > 0) {
317 while ((x-x0).length2() < max2) {
319 tempP = closestPoint(x0);
320 sub->setTransformation(tempP);
321 if (sub->howfar(-1,x,u,tempT)+1)
322 if (tempT < max && tempT > 0) {
343 sub->setTransformation(closestPoint(x+unit*tempT));
344 sub->howfar(-1,x,u,tempT);
345 if (tempT < min && tempT > 0) {
347 finalP = closestPoint(x+unit*tempT);
353 sub->setTransformation(finalP);
354 int tempReg = sub->howfar(-1,x,u,tempT,newmed,normal);
356 if (newmed && tempReg >= 0) {
357 *newmed = sub->medium(tempReg);
365 return tempReg+base->
regions();
370 int tempReg = base->
howfar(ireg,x,u,t,newmed,normal);
375 if (newmed && tempReg >= 0) {
376 *newmed = base->
medium(tempReg);
384 int tempReg = base->
howfar(ireg,x,u,t,newmed,normal);
387 if (tempReg == ind) {
391 newX = x + (newX * t);
393 sub->setTransformation(closestPoint(newX));
394 int newReg = sub->isWhere(newX);
396 if (newmed && newReg >= 0) {
397 *newmed = sub->medium(newReg);
403 return newReg + base->
regions();
407 if (newmed && tempReg >= 0) {
408 *newmed = base->
medium(tempReg);
419 EGS_Float temp, dist = base->
hownear(ind,x);
421 sub->setTransformation(closestPoint(x));
422 temp = sub->hownear(ireg-base->
regions(),x);
423 dist=(temp<dist)?temp:dist;
425 else if (ireg == ind) {
427 EGS_Float xa = floor(x.
x/a)*a, yb = floor(x.
y/b)*b, zc = floor(x.
z/c)*c;
437 for (
int i = 0; i < 8; i++) {
438 sub->setTransformation(x0[i]);
439 temp = sub->hownear(-1,x);
459 const string &
getType()
const {
470 return sub->hasBooleanProperty(ireg - base->
regions(), prop);
489 return sub->getRelativeRho(ireg - base->
regions());
494 void setBScaling(
int start,
int end, EGS_Float rho);
500 return sub->getBScaling(ireg - base->
regions());
529 EGS_Float i1,j1,k1,i2,j2,j3,k3,j4;
530 EGS_Float r3a = 2.0*gap;
532 i1 = a*(round(x.
x/a));
533 j1 = r3a*(round(x.
y/r3a));
534 k1 = r3a*(round(x.
z/r3a));
536 i2 = a*(0.5+round(x.
x/a-0.5));
537 j2 = r3a*(0.5+round(x.
y/r3a-0.5));
539 j3 = r3a*(0.25+round(x.
y/r3a-0.25));
540 k3 = r3a*(0.5+round(x.
z/r3a-0.5));
542 j4 = r3a*(-0.25+round(x.
y/r3a+0.25));
549 d[0] = (x-p1).length2();
550 d[1] = (x-p2).length2();
551 d[2] = (x-p3).length2();
552 d[3] = (x-p4).length2();
554 if (d[0] < d[1] && d[0] < d[2] && d[0] < d[3]) {
557 if (d[1] < d[2] && d[1] < d[3]) {
575 return sub->isRealRegion(ireg - base->
regions());
585 sub->setTransformation(closestPoint(x));
586 if (sub->isInside(x)) {
587 return sub->isWhere(x) + base->
regions();
597 int medium(
int ireg)
const {
599 return sub->medium(ireg-base->
regions());
601 return base->
medium(ireg);
617 EGS_Float &t,
int *newmed=0,
EGS_Vector *normal=0) {
625 sub->setTransformation(closestPoint(x));
629 int tempReg = sub->howfar(ireg-base->
regions(),x,u,tempT,newmed,normal);
636 newX = x + (newX * tempT);
638 if (base->
isWhere(newX) != ind) {
641 tempReg = base->
howfar(ind,x,u,t,0,normal);
642 if (newmed && tempReg >= 0) {
643 *newmed = base->
medium(tempReg);
655 *newmed = base->
medium(ind);
667 return tempReg+base->
regions();
669 else if (ireg == ind) {
672 base->
howfar(ireg,x,u,tempT);
673 EGS_Float max = tempT;
676 EGS_Float min = max, minX = max, minY = max, minZ = max;
679 EGS_Vector xInt = unit*(a/8.0/fabs(unit.
x)), yInt = unit*(gap/8.0/fabs(unit.
y)), zInt = unit*(gap/8.0/fabs(unit.
z));
684 EGS_Float max2 = max*max;
687 while ((x-x0).length2() < max2) {
689 tempP = closestPoint(x0);
690 sub->setTransformation(tempP);
691 if (sub->howfar(-1,x,u,tempT)+1)
692 if (tempT < max && tempT > 0) {
701 while ((x-x0).length2() < max2) {
703 tempP = closestPoint(x0);
704 sub->setTransformation(tempP);
705 if (sub->howfar(-1,x,u,tempT)+1)
706 if (tempT < max && tempT > 0) {
715 while ((x-x0).length2() < max2) {
717 tempP = closestPoint(x0);
718 sub->setTransformation(tempP);
719 if (sub->howfar(-1,x,u,tempT)+1)
720 if (tempT < max && tempT > 0) {
741 sub->setTransformation(closestPoint(x+unit*tempT));
742 sub->howfar(-1,x,u,tempT);
743 if (tempT < min && tempT > 0) {
745 finalP = closestPoint(x+unit*tempT);
751 sub->setTransformation(finalP);
752 int tempReg = sub->howfar(-1,x,u,tempT,newmed,normal);
754 if (newmed && tempReg >= 0) {
755 *newmed = sub->medium(tempReg);
763 return tempReg+base->
regions();
768 int tempReg = base->
howfar(ireg,x,u,t,newmed,normal);
773 if (newmed && tempReg >= 0) {
774 *newmed = base->
medium(tempReg);
782 int tempReg = base->
howfar(ireg,x,u,t,newmed,normal);
785 if (tempReg == ind) {
789 newX = x + (newX * t);
791 sub->setTransformation(closestPoint(newX));
792 int newReg = sub->isWhere(newX);
794 if (newmed && newReg >= 0) {
795 *newmed = sub->medium(newReg);
801 return newReg + base->
regions();
805 if (newmed && tempReg >= 0) {
806 *newmed = base->
medium(tempReg);
817 EGS_Float temp, dist = base->
hownear(ireg>=base->
regions()?ind:ireg,x);
819 sub->setTransformation(closestPoint(x));
820 temp = sub->hownear(ireg-base->
regions(),x);
821 dist=(temp<dist)?temp:dist;
823 else if (ireg == ind) {
826 EGS_Float r3a = 2.0*gap, hgap = gap/2.0, ha = a/2.0;
830 i = a*(floor(x.
x/a));
831 j = r3a*(round(x.
y/r3a));
832 k = r3a*(round(x.
z/r3a));
836 if (x.
y<=j && x.
z<=k)
846 else if (x.
y>j && x.
z<=k)
856 else if (x.
y<j && x.
z>k)
876 for (
int i = 0; i < 8; i++) {
877 sub->setTransformation(x0[i]);
878 temp = sub->hownear(-1,x);
895 const string &
getType()
const {
906 return sub->hasBooleanProperty(ireg - base->
regions(), prop);
925 return sub->getRelativeRho(ireg - base->
regions());
930 void setBScaling(
int start,
int end, EGS_Float rho);
936 return sub->getBScaling(ireg - base->
regions());
Base geometry class. Every geometry class must be derived from EGS_BaseGeometry.
virtual int computeIntersections(int ireg, int n, const EGS_Vector &x, const EGS_Vector &u, EGS_GeometryIntersections *isections)
Calculates intersection distances to region boundaries.
virtual EGS_Float hownear(int ireg, const EGS_Vector &x)=0
Calculate the distance to a boundary for position x in any direction.
virtual int inside(const EGS_Vector &x)=0
Returns the region index, if inside, or -1 if outside (obsolete)
virtual bool hasBooleanProperty(int ireg, EGS_BPType prop) const
Is the boolean property prop set for region ireg ?
virtual EGS_Float howfarToOutside(int ireg, const EGS_Vector &x, const EGS_Vector &u)
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.
virtual const string & getType() const =0
Get the geometry type.
virtual void getLabelRegions(const string &str, vector< int > ®s)
Get the list of all regions labeled with str.
virtual int howfar(int ireg, const EGS_Vector &x, const EGS_Vector &u, EGS_Float &t, int *newmed=0, EGS_Vector *normal=0)=0
Calculate the distance to a boundary from x along the direction u.
virtual bool isRealRegion(int ireg) const
Returnes true if ireg is a real region, false otherwise.
virtual bool isInside(const EGS_Vector &x)=0
Is the position x inside the geometry?
virtual EGS_Float getRelativeRho(int ireg) const
Get the relative mass density in region ireg.
virtual void setBooleanProperty(EGS_BPType prop)
Set the boolean properties of the entire geometry to prop.
virtual int getMaxStep() const
Returns the maximum number of steps through the geometry.
virtual int medium(int ireg) const
Returns the medium index in region ireg.
int regions() const
Returns the number of local regions in this geometry.
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.
virtual void addBooleanProperty(int bit)
Add a boolean property for the entire geometry by setting the bit'th bit.
virtual int isWhere(const EGS_Vector &x)=0
In which region is poisition x?
EGS_Float a
The center-to-center distance to the nearest 12 neighbours.
vector< EGS_Float > d
Don't redefine 4 dists in closestPoint each invocation.
EGS_BaseGeometry * base
The geometry within which the sub geometry appears.
EGS_Float gap
Translating the hexagonal lattice to xyz coordinate,.
EGS_TransformedGeometry * sub
The sub geometry that could appear within base.
int maxStep
The maximum number of steps.
int ind
The region in base geom where we could encounter sub geom.
string type
The geometry type.
A Bravais, cubic, and hexagonal lattice geometry.
EGS_TransformedGeometry * sub
The sub geometry that could appear within base.
string type
The geometry type.
EGS_BaseGeometry * base
The geometry within which the sub geometry appears.
EGS_Float c
The center-to-center distance along x, y, and z.
int maxStep
The maximum number of steps.
int ind
The region in base geom where we could encounter sub geom.
A class representing 3D vectors.
EGS_BaseGeometry class header file.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.