50 static bool EGS_SPHERICAL_SHELL_LOCAL inputSet =
false;
51 static shared_ptr<EGS_BlockInput> EGS_SPHERICAL_SHELL_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>(
"shape");
55 EGS_BaseShape(Name, f), r_inner(ri), r_outer(ro), hemisphere(hemisph), half_angle(halfangle), xo(Xo) {
56 otype =
"sphericalShell";
73 EGS_Float rad = r_inner + (r_outer - r_inner)*pow(rnd1, 1/3.);
75 EGS_Float cos_max, cos_min;
84 cos_th = cos_min + rnd2*(1 - cos_min);
88 EGS_Float sin_th = sqrt(1-cos_th*cos_th);
90 EGS_Float cos_phi, sin_phi;
93 EGS_Float x = rad*sin_th*cos_phi;
94 EGS_Float y = rad*sin_th*sin_phi;
95 EGS_Float z = rad*cos_th;
97 if (hemisphere != 0) {
98 z = hemisphere*fabs(z);
110 EGS_Float sint = 1-cost*cost;
113 EGS_Float cphi, sphi;
115 sint = r_outer*sqrt(sint);
123 u = (x + this->
xo) - xo;
124 EGS_Float di = 1/u.length();
126 wt = u*x*4*M_PI*r_outer*di*di;
130 return 4*M_PI*r_outer*r_outer;
135 static void setInputs() {
138 setShapeInputs(shapeBlockInput);
139 shapeBlockInput->getSingleInput(
"library")->setValues({
"egs_spherical_shell"});
141 shapeBlockInput->addSingleInput(
"midpoint",
false,
"The midpoint of the shape, (x y z). Defaults to '0 0 0'.");
142 shapeBlockInput->addSingleInput(
"inner radius",
true,
"The inner radius");
143 shapeBlockInput->addSingleInput(
"outer radius",
true,
"The outer radius");
144 auto hemiPtr = shapeBlockInput->addSingleInput(
"hemisphere",
false,
"Truncates the sphere to a hemisphere in positive or negative z, by setting to 1 or -1, respectively.", {
"1",
"-1"});
145 auto halfAngPtr = shapeBlockInput->addSingleInput(
"half angle",
false,
"The half angle, in degrees. The shell is truncated by a conical section with the half angle specified. If 'half angle' is negative, the points will sampled with negative z coordinates.");
147 hemiPtr->addDependency(halfAngPtr,
"",
true);
148 halfAngPtr->addDependency(hemiPtr,
"",
true);
151 EGS_SPHERICAL_SHELL_EXPORT
string getExample() {
155 # Example of egs_spherical_shell
157 library = egs_spherical_shell
168 EGS_SPHERICAL_SHELL_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
172 return shapeBlockInput;
178 egsWarning(
"createShape(sphericalShell): null input?\n");
183 int err = input->
getInput(
"inner radius", ri);
185 egsWarning(
"createShape(sphericalShell): no 'inner radius' input\n");
189 egsWarning(
"createShape(sphericalShell): 'inner radius' must be >= 0\n");
193 err = input->
getInput(
"outer radius", ro);
195 egsWarning(
"createShape(sphericalShell): no 'outer radius' input\n");
199 egsWarning(
"createShape(sphericalShell): 'outer radius' must be >= 0\n");
203 egsWarning(
"createShape(sphericalShell): 'inner radius' must be less than 'outer radius'\n");
208 err = input->
getInput(
"hemisphere", hemisphere);
212 else if ((hemisphere != 0) && (hemisphere != -1) && (hemisphere != 1)) {
213 egsWarning(
"createShape(sphericalShell): 'hemisphere' must be 1, -1, 0\n");
217 EGS_Float half_angle=0, half_angle_deg= 0;
218 err = input->
getInput(
"half angle", half_angle_deg);
223 half_angle = M_PI/180.*half_angle_deg;
226 if (half_angle && hemisphere) {
227 egsWarning(
"createShape(sphericalShell): Hemisphere and half angle specified! Remove one and try again.");
234 vector<EGS_Float> xo;
235 err = input->
getInput(
"midpoint",xo);
236 if (err || xo.size() != 3) {
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
EGS_AffineTransform * T
The affine transformation attached to the shape.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
string otype
The object type.
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).
EGS_Float area() const
Returns the sphere surface area.
EGS_SphericalShellShape(EGS_Float ri, EGS_Float ro, int hemisph=0, EGS_Float halfangle=0, 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.
void getPointSourceDirection(const EGS_Vector &Xo, EGS_RandomGenerator *rndm, EGS_Vector &u, EGS_Float &wt)
Sets the direction u by picking a random point uniformely on the sphere surface.
EGS_Vector xo
The sphere midpoint.
EGS_Vector getPoint(EGS_RandomGenerator *rndm)
Returns a random point within the spherical shell.
EGS_Float sgn
The sphere radius.
EGS_Float half_angle
Half angle of conical section.
A class representing 3D vectors.
Global egspp functions header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.