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());
504 if (has_rho_scaling) {
508 bool hasRS = sub->hasRhoScaling();
510 has_rho_scaling = hasRS;
515 has_rho_scaling = hasRS;
520 void finishInitialization()
override {
521 sub->finishInitialization();
522 base->finishInitialization();
525 virtual void getLabelRegions(
const string &str, vector<int> ®s,
bool sanitize=
true);
551 EGS_Float i1,j1,k1,i2,j2,j3,k3,j4;
552 EGS_Float r3a = 2.0*gap;
554 i1 = a*(round(x.
x/a));
555 j1 = r3a*(round(x.
y/r3a));
556 k1 = r3a*(round(x.
z/r3a));
558 i2 = a*(0.5+round(x.
x/a-0.5));
559 j2 = r3a*(0.5+round(x.
y/r3a-0.5));
561 j3 = r3a*(0.25+round(x.
y/r3a-0.25));
562 k3 = r3a*(0.5+round(x.
z/r3a-0.5));
564 j4 = r3a*(-0.25+round(x.
y/r3a+0.25));
571 d[0] = (x-p1).length2();
572 d[1] = (x-p2).length2();
573 d[2] = (x-p3).length2();
574 d[3] = (x-p4).length2();
576 if (d[0] < d[1] && d[0] < d[2] && d[0] < d[3]) {
579 if (d[1] < d[2] && d[1] < d[3]) {
597 return sub->isRealRegion(ireg - base->
regions());
607 sub->setTransformation(closestPoint(x));
608 if (sub->isInside(x)) {
609 return sub->isWhere(x) + base->
regions();
619 int medium(
int ireg)
const {
621 return sub->medium(ireg-base->
regions());
623 return base->
medium(ireg);
639 EGS_Float &t,
int *newmed=0,
EGS_Vector *normal=0) {
647 sub->setTransformation(closestPoint(x));
651 int tempReg = sub->howfar(ireg-base->
regions(),x,u,tempT,newmed,normal);
658 newX = x + (newX * tempT);
660 if (base->
isWhere(newX) != ind) {
663 tempReg = base->
howfar(ind,x,u,t,0,normal);
664 if (newmed && tempReg >= 0) {
665 *newmed = base->
medium(tempReg);
677 *newmed = base->
medium(ind);
689 return tempReg+base->
regions();
691 else if (ireg == ind) {
694 base->
howfar(ireg,x,u,tempT);
695 EGS_Float max = tempT;
698 EGS_Float min = max, minX = max, minY = max, minZ = max;
701 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));
706 EGS_Float max2 = max*max;
709 while ((x-x0).length2() < max2) {
711 tempP = closestPoint(x0);
712 sub->setTransformation(tempP);
713 if (sub->howfar(-1,x,u,tempT)+1)
714 if (tempT < max && tempT > 0) {
723 while ((x-x0).length2() < max2) {
725 tempP = closestPoint(x0);
726 sub->setTransformation(tempP);
727 if (sub->howfar(-1,x,u,tempT)+1)
728 if (tempT < max && tempT > 0) {
737 while ((x-x0).length2() < max2) {
739 tempP = closestPoint(x0);
740 sub->setTransformation(tempP);
741 if (sub->howfar(-1,x,u,tempT)+1)
742 if (tempT < max && tempT > 0) {
763 sub->setTransformation(closestPoint(x+unit*tempT));
764 sub->howfar(-1,x,u,tempT);
765 if (tempT < min && tempT > 0) {
767 finalP = closestPoint(x+unit*tempT);
773 sub->setTransformation(finalP);
774 int tempReg = sub->howfar(-1,x,u,tempT,newmed,normal);
776 if (newmed && tempReg >= 0) {
777 *newmed = sub->medium(tempReg);
785 return tempReg+base->
regions();
790 int tempReg = base->
howfar(ireg,x,u,t,newmed,normal);
795 if (newmed && tempReg >= 0) {
796 *newmed = base->
medium(tempReg);
804 int tempReg = base->
howfar(ireg,x,u,t,newmed,normal);
807 if (tempReg == ind) {
811 newX = x + (newX * t);
813 sub->setTransformation(closestPoint(newX));
814 int newReg = sub->isWhere(newX);
816 if (newmed && newReg >= 0) {
817 *newmed = sub->medium(newReg);
823 return newReg + base->
regions();
827 if (newmed && tempReg >= 0) {
828 *newmed = base->
medium(tempReg);
839 EGS_Float temp, dist = base->
hownear(ireg>=base->
regions()?ind:ireg,x);
841 sub->setTransformation(closestPoint(x));
842 temp = sub->hownear(ireg-base->
regions(),x);
843 dist=(temp<dist)?temp:dist;
845 else if (ireg == ind) {
848 EGS_Float r3a = 2.0*gap, hgap = gap/2.0, ha = a/2.0;
852 i = a*(floor(x.
x/a));
853 j = r3a*(round(x.
y/r3a));
854 k = r3a*(round(x.
z/r3a));
858 if (x.
y<=j && x.
z<=k)
868 else if (x.
y>j && x.
z<=k)
878 else if (x.
y<j && x.
z>k)
898 for (
int i = 0; i < 8; i++) {
899 sub->setTransformation(x0[i]);
900 temp = sub->hownear(-1,x);
917 const string &
getType()
const {
928 return sub->hasBooleanProperty(ireg - base->
regions(), prop);
947 return sub->getRelativeRho(ireg - base->
regions());
952 void setBScaling(
int start,
int end, EGS_Float rho);
958 return sub->getBScaling(ireg - base->
regions());
961 virtual void getLabelRegions(
const string &str, vector<int> ®s,
bool sanitize=
true);
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 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.
bool has_rho_scaling
Does this geometry have relative mass density scvaling?
virtual bool hasRhoScaling()
Does this geometry object have a mass density scaling feature?
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 void getLabelRegions(const string &str, vector< int > ®s, bool sanitize=true)
Get the list of all regions labeled with str.
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.