Points&Forces (survey)
Software tools facilitating the task of surveying architecture
pt2arch.cxx
Go to the documentation of this file.
1 /*
2  Copyright 2010-2016 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 #include "config.h"
27 
29 
30 //---------------------------------------------------------------------------
31 CSimpleOpt::SOption g_rgOptions[] =
32 {
33  {OPT_HELP,_T("-?"),SO_NONE},
34  {OPT_HELP,_T("-h"),SO_NONE},
35  {OPT_HELP,_T("--help"),SO_NONE},
36  {OPT_NAME,_T("-n"),SO_REQ_SEP},
37  {OPT_NAME,_T("--name"),SO_REQ_SEP},
38  {OPT_SIDE,_T("-s"),SO_REQ_SEP},
39  {OPT_SIDE,_T("--side"),SO_REQ_SEP},
40  SO_END_OF_OPTIONS
41 };
42 //---------------------------------------------------------------------------
43 int error(int val)
44 {
45  std::cerr << "pt2arch:" << std::endl;
46  std::cerr << "convert 'x y z' file to an input file to build the arch with calipous tcl module" << std::endl;
47  std::cerr << "syntax: pt2arch [-n string|--name string] [-s double|--side double] [-?|-h|--help] thickness depth < point_file > arch_file" << std::endl;
48  std::cerr << " thickness: in the plane of the arch" << std::endl;
49  std::cerr << " depth: perpendicularly to the plane of the arch" << std::endl;
50  std::cerr << " -n name: give the name to the arch" << std::endl;
51  std::cerr << " (default: arch)" << std::endl;
52  std::cerr << " -s code: position of the points on the arch" << std::endl;
53  std::cerr << " -1: intrados (default)" << std::endl;
54  std::cerr << " 1: extrados" << std::endl;
55  std::cerr << " 0: centre" << std::endl;
56  std::cerr << "author: P.Smars, 2010-16" << std::endl;
57  std::cerr << "version: 2016-10-28" << std::endl;
58  return val;
59 }
60 //---------------------------------------------------------------------------
61 int main( int argc, char *argv[] )
62 {
63  std::string name("arch");
64  double pos = -1;
65  CSimpleOpt args(argc, argv, g_rgOptions);
66  while (args.Next())
67  {
68  if (args.LastError() == SO_SUCCESS)
69  {
70  if (args.OptionId() == OPT_HELP)
71  return error(0);
72  else if (args.OptionId() == OPT_NAME)
73  name = args.OptionArg();
74  else if (args.OptionId() == OPT_SIDE)
75  {
76  std::istringstream i(args.OptionArg());
77  i >> pos;
78  }
79  else
80  return error(-1);
81  // handle option, using OptionId(), OptionText() and OptionArg()
82  } else {
83  std::cerr << "Invalid argument: " << args.OptionText() << std::endl;
84  return error(args.LastError());
85  // handle error, one of: SO_OPT_INVALID, SO_OPT_MULTIPLE,
86  // SO_ARG_INVALID, SO_ARG_INVALID_TYPE, SO_ARG_MISSING
87  }
88  }
89  if (args.FileCount() != 2) return error(-2);
90  std::ostringstream o;
91  for (int k= 0; k < 2; k++) o << args.File(k) << " ";
92  std::istringstream i(o.str().c_str());
93  double thickness, depth;
94  i >> thickness >> depth;
95  double ui = -(1+pos)/2.*thickness;
96  double us = (1-pos)/2.*thickness;
97  int npts;
98  std::cin >> npts;
99  if (npts<3)
100  error(-2);
101  std::vector<a_point *> intrados;
102  std::vector<a_point *> normals;
103  for (int i = 0; i < npts; i++)
104  {
105  a_point * p = new a_point;
106  std::cin >> *p;
107  intrados.push_back(p);
108  }
109  a_point * p1 = intrados[0];
110  a_point * p = intrados[intrados.size()/2];
111  a_point * p2 = intrados[intrados.size()-1];
112  a_point d1 = (*p-*p1).normalise();
113  a_point d2 = (*p2-*p).normalise();
114  a_point n = cross(d2,d1).normalise();
115  p = intrados[0];
116  p2 = intrados[1];
117  a_point d = (*p2-*p).normalise();
118  a_point * pn = new a_point(cross(n,d).normalise());
119  normals.push_back(pn);
120  for (int i=1; i<npts-1; i++)
121  {
122  a_point * p1 = intrados[i-1];
123  a_point * p = intrados[i];
124  a_point * p2 = intrados[i+1];
125  a_point d1 = (*p-*p1).normalise();
126  a_point d2 = (*p2-*p).normalise();
127  a_point d = (d1+d2)/2.;
128  a_point * pn = new a_point(cross(n,d).normalise());
129  normals.push_back(pn);
130  }
131  p1 = intrados[intrados.size()-2];
132  p = intrados[intrados.size()-1];
133  d = (*p-*p1).normalise();
134  pn = new a_point(cross(n,d).normalise());
135  normals.push_back(pn);
136  std::cout << "#created by pt2arch!" << std::endl;
137  std::cout << "#*********************************************" << std::endl;
138  std::cout << "#define structure" << std::endl;
139  std::cout << "a_structure " << name << std::endl;
140  for (int i = 0; i < npts-1; i++)
141  {
142  std::cout << "#define block: " << i << std::endl;
143  a_point p1 = *intrados[i];
144  a_point p2 = *intrados[i+1];
145  a_point d1 = *normals[i];
146  a_point d2 = *normals[i+1];
147  std::cout << "a_point p" << i << "_0 " << p1+d1*us << std::endl;
148  std::cout << "a_point p" << i << "_1 " << p1+d1*ui << std::endl;
149  std::cout << "a_point p" << i << "_2 " << p2+d2*ui << std::endl;
150  std::cout << "a_point p" << i << "_3 " << p2+d2*us << std::endl;
151  std::cout << "a_block_2d4 b" << i;
152  std::cout << " p" << i << "_0";
153  std::cout << " p" << i << "_1";
154  std::cout << " p" << i << "_2";
155  std::cout << " p" << i << "_3" << std::endl;
156  std::cout << "b" << i << " thickness " << depth << std::endl;
157  std::cout << name << " add_block b" << i << std::endl;
158  }
159  std::cout << "#link blocks" << std::endl;
160  for (int i = 0; i < npts-2; i++)
161  std::cout << name << " link_blocks " << i << " 2 " << i+1 << " 0" << std::endl;
162  std::cout << "#exit faces" << std::endl;
163  std::cout << "b0 exit 0" << std::endl;
164  std::cout << "b" << npts-2 << " exit 2" << std::endl;
165  std::cout << "#*********************************************" << std::endl;
166  std::cout << "#* edit the following lines to suit your needs" << std::endl;
167  std::cout << "#*********************************************" << std::endl;
168  std::cout << "set base_face 0" << std::endl;
169  std::cout << "a_material mat" << std::endl;
170  std::cout << " mat ref 1" << std::endl;
171  std::cout << " mat name edit_name" << std::endl;
172  std::cout << " mat density 1." << std::endl;
173  std::cout << "s material mat" << std::endl;
174  std::cout << "a_fcriteria_in c" << std::endl;
175  std::cout << " c max 1." << std::endl;
176  std::cout << "s criteria c" << std::endl;
177  std::cout << "#*********************************************" << std::endl;
178  for(std::vector<a_point *>::iterator it = intrados.begin(); it != intrados.end(); ++it) delete *it;
179  for(std::vector<a_point *>::iterator it = normals.begin(); it != normals.end(); ++it) delete *it;
180  intrados.clear();
181  normals.clear();
182  return 0;
183 }
@ OPT_SIDE
Definition: pt2arch.cxx:28
@ OPT_HELP
Definition: pt2arch.cxx:28
@ OPT_NAME
Definition: pt2arch.cxx:28
int main(int argc, char *argv[])
Definition: pt2arch.cxx:61
int error(int val)
Definition: pt2arch.cxx:43
CSimpleOpt::SOption g_rgOptions[]
Definition: pt2arch.cxx:31