43 static bool EGS_SHAPE_COLLECTION_LOCAL inputSet =
false;
44 static shared_ptr<EGS_BlockInput> EGS_SHAPE_COLLECTION_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>(
"shape");
46 EGS_ShapeCollection::EGS_ShapeCollection(
const vector<EGS_BaseShape *> &Shapes,
49 int n1 = Shapes.size(), n2 = Probs.size();
50 if (n1 < 2 || n2 < 2 || n1 != n2) {
51 egsWarning(
"EGS_ShapeCollection::EGS_ShapeCollection: invalid input\n");
56 EGS_Float *p =
new EGS_Float [nshape];
57 for (
int j=0; j<nshape; j++) {
58 shapes[j] = Shapes[j];
68 static void setInputs() {
70 shapeBlockInput->addSingleInput(
"library",
true,
"The type of shape, loaded by shared library in egs++/dso.", {
"egs_shape_collection"});
71 shapeBlockInput->addSingleInput(
"probabilities",
true,
"A list of the relative sampling weight for each of the shapes: p1 p2 ... pn");
73 auto shapePtr = shapeBlockInput->addBlockInput(
"shape");
74 setShapeInputs(shapePtr);
77 EGS_SHAPE_COLLECTION_EXPORT
string getExample() {
81 # Example of egs_shape_collection
83 library = egs_shape_collection
85 definition of the first shape in the collection:
88 definition of the second shape in the collection
92 definition of the last shape in the collection
94 probablities = p1 p2 ... pn
100 EGS_SHAPE_COLLECTION_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
104 return shapeBlockInput;
110 egsWarning(
"createShape(shape collection): null input?\n");
113 vector<EGS_BaseShape *> shapes;
114 vector<EGS_Float> probs;
119 egsWarning(
"createShape(shape collection): got null shape\n");
122 shapes.push_back(shape);
126 vector<string> snames;
127 int err = input->
getInput(
"shape names",snames);
128 if (!err && snames.size() > 0) {
129 for (
unsigned int j=0; j<snames.size(); j++) {
131 if (!shape)
egsWarning(
"createShape(shape collection): no shape "
132 "named %s exists\n",snames[j].c_str());
134 shapes.push_back(shape);
138 err = input->
getInput(
"probabilities",probs);
141 egsWarning(
"createShape(shape collection): no 'probabilities' input\n");
144 if (shapes.size() < 2) {
145 egsWarning(
"createShape(shape collection): at least 2 shapes are "
146 "needed for a shape collection, you defined %d\n",shapes.size());
149 if (shapes.size() != probs.size()) {
150 egsWarning(
"createShape(shape collection): the number of shapes (%d)"
151 " is not the same as the number of input probabilities (%d)\n");
154 for (
unsigned int i=0; i<probs.size(); i++) {
156 egsWarning(
"createShape(shape collection): probabilities must not"
157 " be negative, but your input probability %d is %g\n",
163 for (
unsigned int j=0; j<shapes.size(); j++) {
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
static EGS_BaseShape * getShape(const string &Name)
Get a pointer to the shape named Name.
static EGS_BaseShape * createShape(EGS_Input *inp)
Create a shape from the information pointed to by inp.
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.
int ref()
Increase the reference count to this object.
static void deleteObject(EGS_Object *o)
Delete an object.
A class for sampling random bins from a given probability distribution using the alias table techniqu...
Global egspp functions header file.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.