Points&Forces (survey)
Software tools facilitating the task of surveying architecture
pt2dat.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2008-2019 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 <fstream>
17 #include <sstream>
18 #include <iostream>
19 #include <string>
20 #include <vector>
21 #include <math.h>
22 
23 #include "a_point.h"
24 #include "SimpleOpt.h"
25 
26 enum { OPT_HELP, OPT_NAME };
27 
28 //---------------------------------------------------------------------------
29 CSimpleOpt::SOption g_rgOptions[] = {
30  { OPT_HELP, _T("-?"), SO_NONE },
31  { OPT_HELP, _T("-h"), SO_NONE },
32  { OPT_HELP, _T("--help"), SO_NONE },
33  { OPT_NAME, _T("-n"), SO_REQ_SEP },
34  { OPT_NAME, _T("--name"), SO_REQ_SEP },
35  SO_END_OF_OPTIONS
36 };
37 //---------------------------------------------------------------------------
38 int error(int val)
39 {
40  std::cerr << "pt2dat:" << std::endl;
41  std::cerr << "convert 'x y z' file to a calipous 'dat' file (arch modelling)" << std::endl;
42  std::cerr << "syntax: pt2dat [-n name|--name name] [-?|-h|--help] density thickness depth < point_file > dat_file" << std::endl;
43  std::cerr << " -n name: give the name to the arch" << std::endl;
44  std::cerr << " (default: arch)" << std::endl;
45  std::cerr << "author: P.Smars, 2002-2011" << std::endl;
46  std::cerr << "version: 2009-03-24" << std::endl;
47  return val;
48 }
49 //---------------------------------------------------------------------------
50 class calipous
51 {
52  public:
53  calipous(std::vector<a_point *> *);
54  std::string name() const {return name_;}
55  void name(const std::string name) {name_ = name;}
56  double n_blocks() const {return points_->size()-1;}
57  double n_points() const {return points_->size();}
58  double density() const {return density_;}
59  void density(double val) {density_ = val;}
60  double depth() const {return depth_;}
61  void depth(double val) {depth_ = val;}
62  double thickness() const {return thickness_;}
63  void thickness(double val) {thickness_ = val;}
64  a_point operator()(const unsigned int i) const {return *(*points_)[i];}
65  // output
66  friend std::ostream& operator<<(std::ostream& o, const calipous& l);
67  protected:
68  std::vector<a_point *> * points_;
69  std::string name_;
70  double density_;
71  double thickness_;
72  double depth_;
73  double length() const;
74 };
75 
76 //---------------------------------------------------------------------------
77 calipous::calipous(std::vector<a_point *> * points)
78 {
79  points_ = points;
80  name_ = "arch";
81  density_ = 2000;
82  thickness_ = 1;
83  depth_ = 1;
84 }
85 //---------------------------------------------------------------------------
86 double calipous::length() const
87 {
88  double val = 0;
89  a_point x0 = *(*points_)[0];
90  for (unsigned int i=0; i<this->n_points(); i++)
91  {
92  a_point x = *(*points_)[i];
93  val += (x-x0).norm();
94  x0 = x;
95  }
96  return val;
97 }
98 //---------------------------------------------------------------------------
99 std::ostream& operator<< (std::ostream& o, const calipous& c)
100 {
101  int n_blocks;
102  n_blocks = c.n_blocks();
103  o << c.name() << std::endl;
104  o << c.n_points() << std::endl;
105  o << c.density() << std::endl;
106  o << "3D" << std::endl;
107  a_point origin = c(0);
108  a_point end = c(c.n_points()-1);
109  a_point az(0,0,1);
110  std::cout << origin << std::endl;
111  a_point ay = cross(az,end-origin).normalise();
112  a_point ax = cross(ay,az).normalise();
113  o << ax << std::endl;
114  o << ay << std::endl;
115  o << "0 0" << std::endl;
116  o << c.thickness() << std::endl;
117  o << c.depth() << std::endl;
118  o << "AA" << std::endl;
119  for (unsigned int i=1;i<c.n_points();i++)
120  {
121  a_point p = c(i);
122  a_point d = p-origin;
123  double x = d*ax;
124  double z = d*az;
125  o << x << " " << z << std::endl;
126  o << c.thickness() << std::endl;
127  o << c.depth() << std::endl;
128  o << "AA" << std::endl;
129  }
130  return o;
131 }
132 //---------------------------------------------------------------------------
133 int main( int argc, char *argv[] )
134 {
135  std::string name("arch");
136  CSimpleOpt args(argc, argv, g_rgOptions);
137  while (args.Next())
138  {
139  if (args.LastError() == SO_SUCCESS)
140  {
141  if (args.OptionId() == OPT_HELP)
142  return error(0);
143  else if (args.OptionId() == OPT_NAME)
144  name = args.OptionArg();
145  else
146  return error(-1);
147  // handle option, using OptionId(), OptionText() and OptionArg()
148  } else {
149  std::cerr << "Invalid argument: " << args.OptionText() << std::endl;
150  return error(args.LastError());
151  // handle error, one of: SO_OPT_INVALID, SO_OPT_MULTIPLE,
152  // SO_ARG_INVALID, SO_ARG_INVALID_TYPE, SO_ARG_MISSING
153  }
154  }
155  if (args.FileCount() != 3) return error(-2);
156  std::ostringstream o;
157  for (short k= 0; k < 3; k++) o << args.File(k) << " ";
158  std::istringstream i(o.str().c_str());
159  double density, thickness, depth;
160  i >> density >> thickness >> depth;
161  int npts;
162  std::cin >> npts;
163  auto points = new std::vector<a_point *>;
164  for (unsigned int i = 0; i < npts; i++)
165  {
166  auto p = new a_point;
167  std::cin >> *p;
168  points->push_back(p);
169  }
170  calipous arc(points);
171  arc.name(name);
172  arc.density(density);
173  arc.thickness(thickness);
174  arc.depth(depth);
175  std::cout << arc;
176  delete points;
177  return 0;
178 }
double length() const
Definition: pt2dat.cxx:86
double density_
Definition: pt2dat.cxx:70
double n_points() const
Definition: pt2dat.cxx:57
double density() const
Definition: pt2dat.cxx:58
std::string name() const
Definition: pt2dat.cxx:54
void depth(double val)
Definition: pt2dat.cxx:61
void name(const std::string name)
Definition: pt2dat.cxx:55
double n_blocks() const
Definition: pt2dat.cxx:56
a_point operator()(const unsigned int i) const
Definition: pt2dat.cxx:64
double depth_
Definition: pt2dat.cxx:72
double depth() const
Definition: pt2dat.cxx:60
double thickness_
Definition: pt2dat.cxx:71
double thickness() const
Definition: pt2dat.cxx:62
calipous(std::vector< a_point * > *)
Definition: pt2dat.cxx:77
friend std::ostream & operator<<(std::ostream &o, const calipous &l)
Definition: pt2dat.cxx:99
void thickness(double val)
Definition: pt2dat.cxx:63
void density(double val)
Definition: pt2dat.cxx:59
std::string name_
Definition: pt2dat.cxx:69
std::vector< a_point * > * points_
Definition: pt2dat.cxx:68
e_point & normalise()
Definition: e_point.cxx:67
e_point cross(e_point &a, e_point &b)
Definition: e_point.cxx:105
std::string name
Definition: pixelpos.cxx:77
int main(int argc, char *argv[])
Definition: pt2dat.cxx:133
int error(int val)
Definition: pt2dat.cxx:38
CSimpleOpt::SOption g_rgOptions[]
Definition: pt2dat.cxx:29
std::ostream & operator<<(std::ostream &o, const calipous &c)
Definition: pt2dat.cxx:99
@ OPT_HELP
Definition: pt2dat.cxx:26
@ OPT_NAME
Definition: pt2dat.cxx:26