EGSnrc C++ class library
Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Coding Examples
File List
File Members
egs++
shapes
egs_line_shape
egs_line_shape.cpp
Go to the documentation of this file.
1
/*
2
###############################################################################
3
#
4
# EGSnrc egs++ line shape
5
# Copyright (C) 2015 National Research Council Canada
6
#
7
# This file is part of EGSnrc.
8
#
9
# EGSnrc is free software: you can redistribute it and/or modify it under
10
# the terms of the GNU Affero General Public License as published by the
11
# Free Software Foundation, either version 3 of the License, or (at your
12
# option) any later version.
13
#
14
# EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17
# more details.
18
#
19
# You should have received a copy of the GNU Affero General Public License
20
# along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21
#
22
###############################################################################
23
#
24
# Author: Iwan Kawrakow, 2005
25
#
26
# Contributors:
27
#
28
###############################################################################
29
*/
30
31
37
#include "
egs_line_shape.h
"
38
#include "
egs_input.h
"
39
#include "
egs_functions.h
"
40
41
EGS_LineShape::EGS_LineShape(
const
vector<EGS_Float> &points,
42
const
string
&Name,
EGS_ObjectFactory
*f) :
EGS_BaseShape
(Name,f) {
43
int
np = points.size();
44
n = np/2;
45
if
(n <= 1) {
46
n = 0;
47
return
;
48
}
49
x =
new
EGS_Float[n];
50
y =
new
EGS_Float[n];
51
EGS_Float *w =
new
EGS_Float [n-1];
52
for
(
int
j=0; j<n; j++) {
53
x[j] = points[2*j];
54
y[j] = points[2*j+1];
55
if
(j > 0) {
56
EGS_Float ax = x[j]-x[j-1], ay = y[j]-y[j-1];
57
w[j-1] = sqrt(ax*ax+ay*ay);
58
}
59
}
60
table =
new
EGS_AliasTable
(n-1,x,w,0);
61
otype
=
"line"
;
62
}
63
64
extern
"C"
{
65
66
EGS_LINE_SHAPE_EXPORT
EGS_BaseShape
*createShape(
EGS_Input
*input,
67
EGS_ObjectFactory
*f) {
68
if
(!input) {
69
egsWarning
(
"createShape(line): null input?\n"
);
70
return
0;
71
}
72
vector<EGS_Float> points;
73
int
err = input->
getInput
(
"points"
,points);
74
if
(err) {
75
egsWarning
(
"createShape(line): no 'points' input\n"
);
76
return
0;
77
}
78
int
np = points.size();
79
if
((np%2) != 0) {
80
egsWarning
(
"createShape(line): you must input an even number of"
81
" floating numbers\n"
);
82
return
0;
83
}
84
if
(np < 4) {
85
egsWarning
(
"createShape(line): you must input at least 2 2D points"
86
" to form a line\n"
);
87
return
0;
88
}
89
EGS_LineShape
*shape =
new
EGS_LineShape
(points,
""
,f);
90
shape->
setName
(input);
91
shape->
setTransformation
(input);
92
return
shape;
93
}
94
95
}
EGS_LineShape
A line shape.
Definition:
egs_line_shape.h:83
EGS_AliasTable
A class for sampling random values from a given probability distribution using the alias table techni...
Definition:
egs_alias_table.h:63
EGS_BaseShape::setTransformation
void setTransformation(EGS_Input *inp)
Set the transformation attached to this shape.
Definition:
egs_shapes.cpp:68
egs_input.h
EGS_Input class header file.
egs_functions.h
Global egspp functions header file.
EGS_BaseShape
Base shape class. All shapes in the EGSnrc C++ class library are derived from EGS_BaseShape.
Definition:
egs_shapes.h:112
egs_line_shape.h
A line shape.
EGS_ObjectFactory
An object factory.
Definition:
egs_object_factory.h:206
EGS_Object::setName
void setName(EGS_Input *inp)
Set the name of the object from the information provided by inp.
Definition:
egs_object_factory.cpp:93
EGS_Input
A class for storing information in a tree-like structure of key-value pairs. This class is used throu...
Definition:
egs_input.h:182
EGS_Object::otype
string otype
The object type.
Definition:
egs_object_factory.h:180
EGS_Input::getInput
int getInput(const string &key, vector< string > &values) const
Assign values to an array of strings from an input identified by key.
Definition:
egs_input.cpp:338
egsWarning
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
Definition:
egs_functions.cpp:135
Generated by
1.8.5