Points&Forces (survey)
Software tools facilitating the task of surveying architecture
fit_circle.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2009-2020 Pierre SMARS (smars@yuntech.edu.tw)
3  This program is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 #include <iostream>
17 #include <vector>
18 #include "a_point.h"
19 #include "a_shape_circle.h"
20 #include <time.h>
21 
22 #include "SimpleOpt.h"
23 
25 
26 CSimpleOpt::SOption g_rgOptions[] = {
27  { OPT_THRES, _T("-t"), SO_REQ_SEP },
28  { OPT_THRES, _T("--threshold"), SO_REQ_SEP },
29  { OPT_EXPORT, _T("-e"), SO_REQ_SEP },
30  { OPT_EXPORT, _T("--export"), SO_REQ_SEP },
31  { OPT_DIS, _T("-d"), SO_REQ_SEP },
32  { OPT_DIS, _T("--discretisation"), SO_REQ_SEP },
33  { OPT_VERBOSE, _T("-v"), SO_NONE },
34  { OPT_VERBOSE, _T("--verbose"), SO_NONE },
35  { OPT_HELP, _T("-?"), SO_NONE },
36  { OPT_HELP, _T("-h"), SO_NONE },
37  { OPT_HELP, _T("--help"), SO_NONE },
38  SO_END_OF_OPTIONS
39 };
40 
41 //*********************************************************
42 int error(int val)
43 {
44 #include "fit_circle.help"
45  return val;
46 }
47 //*********************************************************
48 int main(int argc, char ** argv)
49 {
50  double threshold = 1000000.;
51  unsigned int export_type = 0;
52  unsigned int discretisation = 100;
53  bool verbose = false;
54  CSimpleOpt args(argc, argv, g_rgOptions);
55  while (args.Next())
56  {
57  if (args.LastError() == SO_SUCCESS)
58  {
59  if (args.OptionId() == OPT_HELP)
60  return error(0);
61  else if (args.OptionId() == OPT_VERBOSE)
62  verbose=true;
63  else if (args.OptionId() == OPT_THRES)
64  {
65  std::ostringstream o;
66  o << args.OptionArg();
67  std::istringstream in(o.str().c_str());
68  in >> threshold;
69  }
70  else if (args.OptionId() == OPT_EXPORT)
71  {
72  std::ostringstream o;
73  o << args.OptionArg();
74  std::istringstream in(o.str().c_str());
75  in >> export_type;
76  }
77  else if (args.OptionId() == OPT_DIS)
78  {
79  std::ostringstream o;
80  o << args.OptionArg();
81  std::istringstream in(o.str().c_str());
82  in >> discretisation;
83  }
84  else
85  return error(-1);
86  // handle option, using OptionId(), OptionText() and OptionArg()
87  } else {
88  std::cerr << "Invalid argument: " << args.OptionText() << std::endl;
89  return error(args.LastError());
90  // handle error, one of: SO_OPT_INVALID, SO_OPT_MULTIPLE,
91  // SO_ARG_INVALID, SO_ARG_INVALID_TYPE, SO_ARG_MISSING
92  }
93  }
94  if (args.FileCount() != 0) return error(-2);
95  if (threshold<0.)
96  return error(-3);
97  int npts;
98  std::vector<a_point> cloud;
99  std::cin >> npts;
100  for (int k = 0; k < npts; k++)
101  {
102  double x,y,z;
103  std::cin >> x >> y >> z;
104  cloud.push_back(a_point(x,y,z));
105  }
106  a_shape_circle l;
107  l.small(threshold);
108  l.verbose(verbose);
109  l.fit_cloud(cloud);
110  if (export_type==0)
111  std::cout << l << std::endl;
112  else if (export_type==1)
113  l.export_points(discretisation,cloud);
114  else if (export_type==2)
115  l.export_lines(discretisation,cloud);
116  else if (export_type==3)
117  l.export_inliers(cloud);
118  else if (export_type==4)
119  l.export_outliers(cloud);
120  if (verbose)
121  std::cerr << "rms dist (original cloud): " << l.rms_dist_cloud(cloud) << std::endl;
122 }
circle shape
void export_points(const unsigned int nseg, const std::vector< a_point > &pts) const
void export_lines(const unsigned int nseg, const std::vector< a_point > &pts) const
void fit_cloud(std::vector< a_point > &pts, short nl=1)
double rms_dist_cloud(const std::vector< a_point > &pts)
Definition: a_shape.cxx:53
void export_outliers(const std::vector< a_point > &pts)
Definition: a_shape.cxx:165
void verbose(bool v)
Definition: a_shape.h:62
void export_inliers(const std::vector< a_point > &pts)
Definition: a_shape.cxx:143
int error(int val)
Definition: fit_circle.cxx:42
CSimpleOpt::SOption g_rgOptions[]
Definition: fit_circle.cxx:26
int main(int argc, char **argv)
Definition: fit_circle.cxx:48
@ OPT_VERBOSE
Definition: fit_circle.cxx:24
@ OPT_DIS
Definition: fit_circle.cxx:24
@ OPT_THRES
Definition: fit_circle.cxx:24
@ OPT_HELP
Definition: fit_circle.cxx:24
@ OPT_EXPORT
Definition: fit_circle.cxx:24
bool verbose
Definition: h_compute.cxx:40
std::istringstream in
Definition: ply2tri.cxx:32