42 static bool EGS_DYNAMIC_SHAPE_LOCAL inputSet =
false;
43 static shared_ptr<EGS_BlockInput> EGS_DYNAMIC_SHAPE_LOCAL shapeBlockInput = make_shared<EGS_BlockInput>(
"shape");
47 static void setInputs() {
50 setShapeInputs(shapeBlockInput);
51 shapeBlockInput->getSingleInput(
"library")->setValues({
"egs_dynamic_shape"});
53 auto shapePtr = shapeBlockInput->addBlockInput(
"shape");
54 setShapeInputs(shapePtr);
56 shared_ptr<EGS_BlockInput> motionBlock = shapeBlockInput->addBlockInput(
"motion",
true);
57 motionBlock->addSingleInput(
"control point",
true,
"Parameters to define motion: timeIndex xtrans ytrans ztrans xrot yrot zrot");
60 EGS_DYNAMIC_SHAPE_EXPORT
string getExample() {
64 # Example of egs_dynamic_shape
66 library = egs_dynamic_shape
68 definition of the shape to be 'dynamic'
70 :start motion: # units of cm and degrees
71 control point = timeIndex(1) xtrans(1) ytrans(1) ztrans(1) xrot(1) yrot(1) zrot(1)
72 control point = timeIndex(2) xtrans(2) ytrans(2) ztrans(2) xrot(2) yrot(2) zrot(2)
76 control point = timeIndex(N) xtrans(N) ytrans(N) ztrans(N) xrot(N) yrot(N) zrot(N)
83 EGS_DYNAMIC_SHAPE_EXPORT shared_ptr<EGS_BlockInput> getInputs() {
87 return shapeBlockInput;
93 egsWarning(
"createShape(dynamic shape): null input?\n");
104 int err = input->
getInput(
"shape name",shape_name);
106 egsWarning(
"createShape(dynamic shape): no inline shape definition"
107 " and no 'shape name' keyword\n");
112 egsWarning(
"createShape(dynamic shape): no shape named %s "
113 "exists\n",shape_name.c_str());
127 egsWarning(
"EGS_DynamicShape: no control points input.\n");
135 vector<EGS_Float> point;
136 EGS_ControlPoint cpt;
140 string inputTag =
"control point";
141 string inputTag_backCompat =
"control point " + itos.str();
148 if (!currentInput || currentInput->
getInput(inputTag, point)) {
150 if (!currentInput || currentInput->
getInput(inputTag_backCompat, point)) {
158 if (point.size()!=6 && point.size()!=7) {
159 egsFatal(
"EGS_DynamicShape: Control point %i must specify either 6 or 7 values.\n",icpts);
163 rotsize=point.size();
166 egsFatal(
"EGS_DynamicShape: Time index of control point %i < time index of control point %i\n",icpts,
ncpts);
168 else if (point[0] < 0.) {
169 egsFatal(
"EGS_DynamicShape: Time index of control point %i < 0.0\n",icpts);
171 else if (
ncpts> 0 && point.size() != rotsize) {
172 egsFatal(
"EGS_DynamicShape: Rotation definition inconsistent \n");
177 if (
ncpts ==1 && point[0] > 0.0) {
178 egsWarning(
"EGS_DynamicShape: Time index of control point 1 > 0.0. This will generate many warning messages.\n");
181 vector<EGS_Float> T_vect;
182 vector<EGS_Float> R_vect;
184 T_vect.push_back(point[1]);
185 T_vect.push_back(point[2]);
186 T_vect.push_back(point[3]);
189 if (point.size()==6) {
190 R_vect.push_back(point[6]);
191 R_vect.push_back(point[4]);
193 if (point.size()==7) {
194 R_vect.push_back(point[4]);
195 R_vect.push_back(point[5]);
196 R_vect.push_back(point[6]);
207 inputTag_backCompat =
"control point " + itos.str();
212 egsFatal(
"EGS_DynamicShape: not enough or missing control points.\n");
215 egsFatal(
"EGS_DynamicShape: time index of last control point = 0. Something's wrong.\n");
219 for (
int i=0; i<=
ncpts-1; i++) {
228 EGS_ControlPoint gipt;
254 shape->getNextShapePosition(rndm);
262 for (i=0; i<
ncpts; i++) {
270 egsWarning(
"EGS_DynamicShape: could not locate control point.\n");
275 vector<EGS_Float> translation_LB=
cpts[iindex-1].trnsl;
276 vector<EGS_Float> translation_UB=
cpts[iindex].trnsl;
277 vector<EGS_Float> translation_samp;
280 EGS_Float factor = (rand-
cpts[iindex-1].time)/(
cpts[iindex].time-
cpts[iindex-1].time);
283 translation_samp.push_back(translation_LB[0]+(translation_UB[0]-translation_LB[0])*factor);
284 translation_samp.push_back(translation_LB[1]+(translation_UB[1]-translation_LB[1])*factor);
285 translation_samp.push_back(translation_LB[2]+(translation_UB[2]-translation_LB[2])*factor);
287 gipt.trnsl=translation_samp;
290 vector<EGS_Float> rotation_LB=
cpts[iindex-1].rot;
291 vector<EGS_Float> rotation_UB=
cpts[iindex].rot;
292 vector<EGS_Float> rotation_samp;
296 if (
cpts[iindex].rot.size()==2) {
297 rotation_samp.push_back((rotation_LB[0]+(rotation_UB[0]-rotation_LB[0])*factor)*(M_PI/180));
298 rotation_samp.push_back((rotation_LB[1]+(rotation_UB[1]-rotation_LB[1])*factor)*(M_PI/180));
300 else if (
cpts[iindex].rot.size()==3) {
301 rotation_samp.push_back((rotation_LB[0]+(rotation_UB[0]-rotation_LB[0])*factor)*(M_PI/180));
302 rotation_samp.push_back((rotation_LB[1]+(rotation_UB[1]-rotation_LB[1])*factor)*(M_PI/180));
303 rotation_samp.push_back((rotation_LB[2]+(rotation_UB[2]-rotation_LB[2])*factor)*(M_PI/180));
306 egsWarning(
"EGS_DynamicShape: Invalid number of rotation parameters\n");
308 gipt.rot=rotation_samp;
Base class for advanced EGSnrc C++ applications.
static EGS_Application * activeApplication()
Get the active application.
EGS_Float getTimeIndex()
Returns the value of the time synchronization parameter.
void setTimeIndex(EGS_Float temp_time)
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.
virtual void updatePosition(EGS_Float time)
Update the position of the shape if it is in motion.
EGS_Float ptime
Time index corresponding to particle.
int getCoord(EGS_Float rand, EGS_ControlPoint &gipt)
Extract coordinates for the next dynamic shape position.
void getNextShapePosition(EGS_RandomGenerator *rndm)
Get the next state of the dynamic shape.
void buildDynamicShape(EGS_Input *dyninp)
Build the dynamic shape using input specifications.
vector< EGS_ControlPoint > cpts
Control points.
int ncpts
Number of control points.
EGS_BaseShape * shape
Base shape made dynamic.
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
Base random number generator class. All random number generators should be derived from this class.
EGS_Float getUniform()
Returns a random number uniformly distributed between zero (inclusive) and 1 (exclusive).
Global egspp functions header file.
EGS_InfoFunction EGS_EXPORT egsFatal
Always use this function for reporting fatal errors.
const EGS_Float epsilon
The epsilon constant for floating point comparisons.
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.