53 inline void setShapeInputs(shared_ptr<EGS_BlockInput> shapePtr) {
54 auto libPtr = shapePtr->addSingleInput(
"library",
false,
"The type of shape, loaded by shared library in egs++/dso.");
55 auto typePtr = shapePtr->addSingleInput(
"type",
false,
"The type of shape - this input includes only a small set of simple shapes. For more options, use the 'library' input instead.", {
"point",
"box",
"sphere",
"cylinder"});
58 libPtr->addDependency(typePtr,
"",
true);
59 typePtr->addDependency(libPtr,
"",
true);
62 shapePtr->addSingleInput(
"position",
true,
"The x, y, z position that the source will emit particles from.")->addDependency(typePtr,
"point");
65 shapePtr->addSingleInput(
"box size",
true,
"The side lengths of the box, in cm. Enter 1 number for a cube, or 3 numbers to denote the x, y, and z side lengths.")->addDependency(typePtr,
"box");
68 auto radiusPtr = shapePtr->addSingleInput(
"radius",
true,
"The radius of the sphere or cylinder, in cm.");
69 radiusPtr->addDependency(typePtr,
"sphere");
70 auto midPtr = shapePtr->addSingleInput(
"midpoint",
false,
"The x, y and z coordinates of the midpoint of the sphere or cylinder, in cm. Defaults to 0, 0, 0.");
71 midPtr->addDependency(typePtr,
"sphere");
74 radiusPtr->addDependency(typePtr,
"cylinder");
75 midPtr->addDependency(typePtr,
"cylinder");
76 shapePtr->addSingleInput(
"height",
true,
"The height of the cylinder, in cm.")->addDependency(typePtr,
"cylinder");
77 shapePtr->addSingleInput(
"phi range",
false,
"The minimum and maximum phi values, in degrees. This allows you restrict the cylinder to a shape like a slice of pie!")->addDependency(typePtr,
"cylinder");
78 shapePtr->addSingleInput(
"axis",
true,
"A unit vector that defines the axis of the cylinder.")->addDependency(typePtr,
"cylinder");
80 addTransformationBlock(shapePtr);
152 otype =
"base_shape";
169 return (*T)*getPoint(rndm);
172 return getPoint(rndm);
184 egsFatal(
"You need to implement the getPoint function in your "
270 egsFatal(
"getPointSourceDirection: you have to implement this "
271 "method for the %s shape if you want to use it\n",otype.c_str());
280 virtual EGS_Float
area()
const {
334 EGS_Float d2i = 1/u.length2(), di = sqrt(d2i);
336 wt = A*fabs(u.
z)*d2i;
414 EGS_Float ax, ay,
az;
485 else if (eta < 2*(ax*ay + ax*az)) {
488 if (eta < 2*ax*ay + ax*az) {
498 eta -= 2*(ax*ay + ax*az);
511 EGS_Float d2 = u.length2(), d = sqrt(d2);
513 wt *= (area()/(d2*d));
520 return 2*(ax*ay + ax*az + ay*az);
576 EGS_Float sint = sqrt(1-cost*cost);
578 EGS_Float cphi, sphi;
580 return xo +
EGS_Vector(r1*cphi,r1*sphi,R*r*cost);
603 EGS_Float sint = 1-cost*cost;
606 EGS_Float cphi, sphi;
616 u = (x + this->xo) - xo;
617 EGS_Float di = 1/u.length();
619 wt = u*x*4*M_PI*R*di*di;
670 while (x*x + y*y > 1);
677 EGS_Float phi = phi_min*(1-eta) + phi_max*eta;
691 phi_min(0), phi_max(2*M_PI), has_phi(false) {
701 phi_min(0), phi_max(2*M_PI), has_phi(false) {
703 if (xo.length2() >
epsilon || !rmat.isI()) {
714 phi_min(0), phi_max(2*M_PI), has_phi(false) {
725 if (Phi_min < Phi_max) {
733 if (phi_max - phi_min < 1.99999*M_PI) {
746 getPointInCircle(rndm,x,y);
783 getPointInCircle(rndm,x.
x,x.
y);
802 u = (x+this->xo) - xo;
803 EGS_Float d2 = u.length2(), d = sqrt(d2);
813 return 2*M_PI*R*(R+h);
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
void setTransformation(EGS_AffineTransform *t)
Set the transformation attached to this shape.
virtual void getPointSourceDirection(const EGS_Vector &xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
virtual EGS_Float area() const
EGS_AffineTransform * T
The affine transformation attached to the shape.
EGS_BaseShape(const string &Name="", EGS_ObjectFactory *f=0)
Construct a shape named Name.
virtual ~EGS_BaseShape()
Destructor. Deletes T if it is not null.
virtual EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Sample and return a random 3D vector.
virtual void updatePosition(EGS_Float time)
Update the position of the shape if it is in motion.
const EGS_AffineTransform * getTransform() const
Get a pointer to the affine transformation attached to this shape.
virtual EGS_Vector getRandomPoint(EGS_RandomGenerator *rndm)
Returns a random 3D vector.
virtual bool supportsDirectionMethod() const
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Sets the direction u by picking a random point uniformly the on the box surface.
EGS_Float az
The box size.
EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Returns a point uniformly distributed within the box.
EGS_BoxShape(const string &Name="", EGS_ObjectFactory *f=0)
Create a box shape with unit size.
EGS_BoxShape(EGS_Float A, const EGS_AffineTransform *t=0, const string &Name="", EGS_ObjectFactory *f=0)
Create a cube with size A.
EGS_BoxShape(EGS_Float Ax, EGS_Float Ay, EGS_Float Az, const EGS_AffineTransform *t=0, const string &Name="", EGS_ObjectFactory *f=0)
Create a box shape with size Ax,Ay,Az.
bool supportsDirectionMethod() const
Returns true. (It is easy to implement the getPointSourceDirection() method for a box....
EGS_Float area() const
Returns the box surface area.
~EGS_BoxShape()
Destructor. Does nothing.
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Sets the direction u by picking a random point uniformly on the cylinder surface.
bool supportsDirectionMethod() const
Returns true. (It is easy to implement the getPointSourceDirection() method for a cylinder....
EGS_Float getHeight() const
void getPointInCircle(EGS_RandomGenerator *rndm, EGS_Float &x, EGS_Float &y)
Get a point uniformly distributed within a circle.
void setPhiRange(EGS_Float Phi_min, EGS_Float Phi_max)
EGS_Float h
Cylinder height.
EGS_Float getRadius() const
EGS_CylinderShape(EGS_Float r, EGS_Float H, const EGS_AffineTransform *t, const string &Name="", EGS_ObjectFactory *f=0)
EGS_Vector a
Cylinder axis.
EGS_CylinderShape(const string &Name="", EGS_ObjectFactory *f=0)
bool has_phi
True, if azimuthal range restricted.
EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Samples and returns a point uniformly distributed within the cylinder.
EGS_Float R
Cylinder radius.
EGS_Float area() const
Returns the cylinder surface area.
virtual EGS_Object * createObject(EGS_Input *inp)
Create an object from the infromation pointed to by inp.
A point shape. This is the simplest shape possible: it simply always returns the same point.
EGS_Vector xo
The point position.
EGS_Vector getPoint(EGS_RandomGenerator *)
Returns a fixed point.
EGS_PointShape(const EGS_Vector &Xo=EGS_Vector(), const string &Name="", EGS_ObjectFactory *f=0)
Construct a point shape located at Xo.
Base random number generator class. All random number generators should be derived from this class.
void getAzimuth(EGS_Float &cphi, EGS_Float &sphi)
Sets cphi and sphi to the cosine and sine of a random angle uniformely distributed between 0 and .
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
A class for vector rotations.
EGS_SphereShape(const string &Name="", EGS_ObjectFactory *f=0)
Construct a sphere of unit radius about the origin.
EGS_SphereShape(EGS_Float r, const EGS_Vector &Xo=EGS_Vector(0, 0, 0), const string &Name="", EGS_ObjectFactory *f=0)
Construct a sphere of radius r with midpoint Xo.
bool supportsDirectionMethod() const
Returns true. (It is easy to implement the getPointSourceDirection() method for a sphere....
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Sets the direction u by picking a random point uniformly on the sphere surface.
EGS_Float area() const
Returns the sphere surface area.
EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Returns a random point within the sphere.
EGS_Float R
The sphere radius.
EGS_Vector xo
The sphere midpoint.
EGS_SurfaceShape(const string &Name="", EGS_ObjectFactory *f=0)
Construct a surface shape named Name.
~EGS_SurfaceShape()
Destructor. Does nothing.
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Get a random direction given a source position Xo.
EGS_Float area() const
Returns the area of this surface shape.
bool supportsDirectionMethod() const
Always returns true. Shapes derived from this class must implement the getPoint() method to return po...
A class representing 3D vectors.
#define EGS_EXPORT
Export symbols from the egspp library.
EGS_Object and EGS_ObjectFactory class header file.
EGS_RandomGenerator class header file.
EGS_Vector methods for the manipulation of 3D vectors in cartesian co-ordinates.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.