23 #include "a_segment.h"
24 #include "a_triangle.h"
28 #include "SimpleOpt.h"
33 {
OPT_P, _T(
"-p"), SO_NONE },
34 {
OPT_P, _T(
"--point"), SO_NONE },
35 {
OPT_L, _T(
"-l"), SO_NONE },
36 {
OPT_L, _T(
"--line"), SO_NONE },
37 {
OPT_T, _T(
"-t"), SO_NONE },
38 {
OPT_T, _T(
"--triangle"), SO_NONE },
40 {
OPT_BOX, _T(
"--box"), SO_NONE },
46 {
OPT_COV, _T(
"--covariance"), SO_NONE },
48 {
OPT_SCALAR, _T(
"--scalar-file"), SO_REQ_SEP },
57 #include "average.help"
61 double xmin[] = {1.e30,1.e30,1.e30};
62 double xmax[] = {-1.e30,-1.e30,-1.e30};
67 for (
short i=0;i<3;i++)
75 int main(
int argc,
char *argv[] )
82 bool with_scalars =
false;
83 bool with_mass =
false;
84 std::string scalar_file;
85 unsigned int n_scalars;
90 if (args.LastError() == SO_SUCCESS)
94 else if (args.OptionId() ==
OPT_P)
96 else if (args.OptionId() ==
OPT_L)
98 else if (args.OptionId() ==
OPT_T)
100 else if (args.OptionId() ==
OPT_BOX)
102 else if (args.OptionId() ==
OPT_COV)
107 scalar_file = args.OptionArg();
109 else if (args.OptionId() ==
OPT_MASS)
117 return error(args.LastError());
122 std::vector<double> scalars;
125 std::ifstream
in(scalar_file.c_str());
128 std::cerr <<
"Cannot open file '" << scalar_file <<
"'" << std::endl;
132 for (
unsigned int i=0; i<n_scalars; i++)
136 scalars.push_back(val);
146 if ((with_scalars)&&(n_pts!=n_scalars))
148 std::cerr <<
"Number of scalars does not correspond to number of points" << std::endl;
151 for (
unsigned int k = 0; k < n_pts; k++)
167 if (!with_scalars||(scalars[k]!=0))
173 x2 += p.inertia()*scalars[k];
184 if ((with_scalars)&&(n_lis!=n_scalars))
186 std::cerr <<
"Number of scalars does not correspond to number of lines" << std::endl;
189 for (
unsigned int k = 0; k < n_lis; k++)
193 double l = s.length();
197 a_point centre = s.c();
201 if (!with_scalars||(scalars[k]!=0))
210 x2 += s.inertia()*scalars[k];
221 std::vector<a_point> points(npts);
222 for (
unsigned int k = 0; k < npts; k++)
232 if ((with_scalars)&&(n_tris!=n_scalars))
234 std::cerr <<
"Number of scalars does not correspond to number of triangles" << std::endl;
237 for (
unsigned int k = 0; k < n_tris; k++)
240 for (
short l = 0; l < 3; l++)
242 a_triangle
tri(points[pr[0]],points[pr[1]],points[pr[2]]);
243 double surface =
tri.S();
245 surface *= scalars[k];
246 a_point centre =
tri.c();
248 pt += centre*surface;
252 x2 +=
tri.inertia()*scalars[k];
263 std::cout <<
"center_of_mass: ";
264 std::cout << average << std::endl;
268 std::cout <<
"mass: ";
269 std::cout << mass << std::endl;
274 std::cout <<
"inertia: " << std::endl;
276 m = average.inertia();
284 std::cout <<
"bounding_box: ";
285 std::cout << std::endl <<
"min: ";
287 std::cout <<
xmin[0] <<
" " <<
xmin[1] <<
" " <<
xmin[2] << std::endl;
289 std::cout <<
"max: ";
290 std::cout <<
xmax[0] <<
" " <<
xmax[1] <<
" " <<
xmax[2] << std::endl;
int main(int argc, char *argv[])
CSimpleOpt::SOption g_rgOptions[]
void extremes(const a_point &p)
void tri(const uint32_t i, const uint32_t j)