Points&Forces (survey)
Software tools facilitating the task of surveying architecture
extract.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2002-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 <iomanip>
18 #include <vector>
19 #include <sstream>
20 #include <string>
21 #include <stdlib.h>
22 
23 //*****************************************************
24 class s_pt
25 {
26  public:
27  s_pt(std::string ax, std::string ay, std::string az): x(ax), y(ay), z(az) {}
28  std::string x,y,z;
29 };
30 //*****************************************************
31 int error(int code)
32 {
33  std::cerr << "extract:" << std::endl;
34  std::cerr << " extract .pt files (x,y,z) from other .pt files or numbered pt files (i,x,y,z)" << std::endl;
35  std::cerr << "syntax: extract (from to) < input_file > output_file" << std::endl;
36  std::cerr << " if 'from' and 'to' are omitted, all the points are extracted" << std::endl;
37  std::cerr << " 'from' and 'to' can also take the values 'first' or 'last'" << std::endl;
38  std::cerr << "author: P.Smars, 2002" << std::endl;
39  return code;
40 }
41 //*****************************************************
42 int is_pt()
43 {
44  char buf[256];
45  std::cin.getline(buf,256);
46  std::istringstream ff(buf);
47  std::string x0,x;
48  int i=0;
49  ff >> x0;
50  while (ff >> x)
51  {
52  i++;
53  }
54  if (i==0)
55  return atoi(x0.c_str());
56  else if (i==3)
57  return 0;
58  else
59  return error(-2);
60 }
61 //*****************************************************
62 int main(int argc, char ** argv)
63 {
64  if ((argc != 1)&&(argc != 3))
65  return error(-1);
66  bool code = false;
67  std::vector<s_pt *> points;
68  int nn = is_pt();
69  int n = 0;
70  if (argc == 1)
71  {
72  while (std::cin)
73  {
74  int i;
75  std::string x,y,z;
76  if (nn==0)
77  std::cin >> i >> x >> y >> z;
78  else
79  {
80  std::cin >> x >> y >> z;
81  n++;
82  }
83  if (std::cin)
84  {
85  auto pt = new s_pt(x,y,z);
86  points.push_back(pt);
87  }
88  if ((nn!=0)&&(n==nn)) break;
89  }
90  }
91  else
92  {
93  int imin,imax;
94  std::ostringstream o;
95  std::string a1(argv[1]);
96  std::string a2(argv[2]);
97  std::ostringstream aa;
98  aa << nn;
99  if (a1=="first")
100  a1 = "1";
101  if (a2=="first")
102  a2 = "1";
103  if (a1=="last")
104  {
105  if (nn !=0)
106  a1 = aa.str();
107  else
108  a1 = "1";
109  code = true;
110  }
111  if (a2=="last")
112  {
113  if (nn !=0)
114  a2 = aa.str();
115  else
116  a2 = "100000000";
117  }
118  o << a1 << " " << a2;
119  std::istringstream i(o.str().c_str());
120  i >> imin >> imax;
121  if (imax<imin)
122  return error(-3);
123  if ((nn!=0)&&((nn<imin)||(nn<imax)))
124  return error(-4);
125  while (std::cin)
126  {
127  static int i = 0;
128  std::string x,y,z;
129  if (nn==0)
130  std::cin >> i >> x >> y >> z;
131  else
132  {
133  i++;
134  std::cin >> x >> y >> z;
135  }
136  if ((std::cin)&&(i >= imin)&&(i <= imax))
137  {
138  auto pt = new s_pt(x,y,z);
139  points.push_back(pt);
140  }
141  }
142  }
143  int n_pts = points.size();
144  if (code)
145  {
146  std::cout << 1 << std::endl;
147  s_pt * pt = *(points.end()-1);
148  std::cout << pt->x << " " << pt->y << " " << pt->z << std::endl;
149  std::cerr << std::endl << "1 point extracted." << std::endl;
150  }
151  else if (n_pts != 0)
152  {
153  std::cout << n_pts << std::endl;
154  for (auto pt:points)
155  std::cout << pt->x << " " << pt->y << " " << pt->z << std::endl;
156  for (auto pt:points)
157  delete pt;
158  if (n_pts==1)
159  std::cerr << std::endl << "1 point extracted." << std::endl;
160  else
161  std::cerr << std::endl << n_pts << " points extracted." << std::endl;
162  }
163  else
164  std::cerr << std::endl << "no points extracted!" << std::endl;
165  points.clear();
166 
167  return 0;
168 }
Definition: extract.cxx:25
std::string z
Definition: extract.cxx:28
std::string y
Definition: extract.cxx:28
std::string x
Definition: extract.cxx:28
s_pt(std::string ax, std::string ay, std::string az)
Definition: extract.cxx:27
int is_pt()
Definition: extract.cxx:42
int main(int argc, char **argv)
Definition: extract.cxx:62
int error(int code)
Definition: extract.cxx:31
uint32_t n[]
Definition: generate.cxx:34
Definition: stlb2stla.cxx:21
float y
Definition: stlb2stla.cxx:23
float z
Definition: stlb2stla.cxx:24
float x
Definition: stlb2stla.cxx:22