45 static bool EGS_POLYGON_SHAPE_LOCAL inputSet =
false;
46 static shared_ptr<EGS_BlockInput> EGS_POLYGON_SHAPE_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>(
"shape");
48 EGS_TriangleShape::EGS_TriangleShape(
const vector<EGS_Float> &points,
56 A = 0.5*fabs(ax*by-ay*bx);
59 EGS_TriangleShape::EGS_TriangleShape(
const EGS_Float *points,
67 A = 0.5*fabs(ax*by-ay*bx);
70 EGS_PolygonShape::EGS_PolygonShape(
const vector<EGS_Float> &points,
72 int np = points.size();
74 EGS_Float auxx = points[np-2] - points[0];
75 EGS_Float auxy = points[np-1] - points[1];
77 if (auxx*auxx + auxy*auxy >
epsilon) {
80 xc =
new EGS_Float [n];
81 yc =
new EGS_Float [n];
82 vector<EGS_2DVector> p1;
83 for (
int j=0; j<np/2; j++) {
85 yc[j] = points[2*j+1];
99 for (
int i=0; i<np-2; i++) {
100 EGS_2DVector aux(0.5*(xc[i+2]+xc[i]),0.5*(yc[i+2]+yc[i]));
101 if (pol.isInside(aux)) {
103 vector<EGS_2DVector> p2;
104 for (
int k=0; k<3; k++) {
105 p_tmp[2*k] = xc[i+k];
106 p_tmp[2*k+1] = yc[i+k];
110 for (
int j=0; j<np-1; j++) {
111 if (j < i || j > i+2) {
113 if (tri.isInside(tmp)) {
122 for (
int j=i+1; j<np-1; j++) {
131 for (
int k=0; k<3; k++) {
133 p_tmp[2*k+1] = yc[k];
137 for (
int i=0; i<ntr; i++) {
138 yc[i] = triangle[i]->area();
148 static void setInputs() {
151 setShapeInputs(shapeBlockInput);
152 shapeBlockInput->getSingleInput(
"library")->setValues({
"egs_polygon_shape"});
154 shapeBlockInput->addSingleInput(
"points",
true,
"A list of at least 3 2D points (at least 6 floating numbers). By default these are in the x-y plane at z=0; use a transformation to adjust.");
157 EGS_POLYGON_SHAPE_EXPORT
string getExample() {
161 # Example of egs_polygon_shape
163 library = egs_polygon_shape
164 points = list of 2D points
170 EGS_POLYGON_SHAPE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
174 return shapeBlockInput;
180 egsWarning(
"createShape(polygon): null input?\n");
183 vector<EGS_Float> points;
184 int err = input->
getInput(
"points",points);
186 egsWarning(
"createShape(polygon): no 'points' input\n");
189 int np = points.size();
191 egsWarning(
"createShape(polygon): you must input an even number of"
192 " floating numbers\n");
196 egsWarning(
"createShape(polygon): you must input at least 3 2D points"
197 " to form a polygon\n");
A class to represent a polygon in a plane (a 2D polygon).
A class representing 2D vectors.
A class for sampling random values from a given probability distribution using the alias table techni...
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
void setTransformation(EGS_Input *inp)
Set the transformation attached to this shape.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
Global egspp functions header file.
Attempts to fix broken math header files.
EGS_2DPolygon and EGS_PolygonT class header file.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.