Points&Forces (survey)
Software tools facilitating the task of surveying architecture
generate.cxx
Go to the documentation of this file.
1 /*
2  Copyright 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 <sstream>
18 
19 #include "SimpleOpt.h"
20 
21 enum { OPT_HELP, OPT_TOPO};
22 
23 CSimpleOpt::SOption g_rgOptions[] = {
24  { OPT_TOPO, _T("-t"), SO_NONE },
25  { OPT_TOPO, _T("--topology"), SO_NONE },
26  { OPT_HELP, _T("-?"), SO_NONE },
27  { OPT_HELP, _T("-h"), SO_NONE },
28  { OPT_HELP, _T("--help"), SO_NONE },
29  SO_END_OF_OPTIONS
30 };
31 
32 //*********************************************************
33 //global variable
34 uint32_t n[] = {1,1,1};
35 //*********************************************************
36 int error(int val)
37 {
38 #include "generate.help"
39  return val;
40 }
41 //*********************************************************
42 double v(const uint32_t step, const uint32_t n)
43 {
44  if (n==1)
45  return 0.;
46  double s = step;
47  return s/(n-1);
48 }
49 //*********************************************************
50 void tri(const uint32_t i, const uint32_t j)
51 {
52  std::cout << i+j*n[0] << " " << i+1+j*n[0] << " " << i+(j+1)*n[0] << "\n";
53  std::cout << i+1+j*n[0] << " " << i+1+(j+1)*n[0] << " " << i+(j+1)*n[0] << "\n";
54 }
55 //*********************************************************
56 void tetra(const uint32_t a, const uint32_t b, const uint32_t c, const uint32_t d)
57 {
58  std::cout << a << " " << b << " " << c << " " << d << "\n";
59 }
60 //*********************************************************
61 void quad(const uint32_t i, const uint32_t j, const uint32_t k)
62 {
63  uint32_t a = n[0];
64  uint32_t b = n[0]*n[1];
65  tetra(i+j*a+k*b,i+1+j*a+k*b,i+(j+1)*a+k*b,i+j*a+(k+1)*b);
66  tetra(i+1+j*a+k*b,i+1+(j+1)*a+k*b,i+(j+1)*a+k*b,i+1+(j+1)*a+(k+1)*b);
67  tetra(i+1+j*a+k*b,i+(j+1)*a+k*b,i+j*a+(k+1)*b,i+1+j*a+(k+1)*b);
68  tetra(i+(j+1)*a+k*b,i+(j+1)*a+(k+1)*b,i+j*a+(k+1)*b,i+1+j*a+(k+1)*b);
69  tetra(i+1+j*a+k*b,i+1+(j+1)*a+(k+1)*b,i+(j+1)*a+k*b,i+1+j*a+(k+1)*b);
70  tetra(i+(j+1)*a+k*b,i+1+(j+1)*a+(k+1)*b,i+(j+1)*a+(k+1)*b,i+1+j*a+(k+1)*b);
71 }
72 //*********************************************************
73 int main(int argc, char ** argv)
74 {
75  bool topo = false;
76  CSimpleOpt args(argc, argv, g_rgOptions);
77  while (args.Next())
78  {
79  if (args.LastError() == SO_SUCCESS)
80  {
81  if (args.OptionId() == OPT_HELP)
82  return error(0);
83  else if (args.OptionId() == OPT_TOPO)
84  topo = true;
85  } else {
86  std::cerr << "Invalid argument: " << args.OptionText() << "\n";
87  return error(args.LastError());
88  // handle error, one of: SO_OPT_INVALID, SO_OPT_MULTIPLE,
89  // SO_ARG_INVALID, SO_ARG_INVALID_TYPE, SO_ARG_MISSING
90  }
91  }
92  uint8_t dim = args.FileCount();
93  if ((dim<1)||(dim>3)) return error(-2);
94  std::ostringstream o;
95  for (uint8_t i=0; i<dim;i++)
96  o << args.File(i) << " ";
97  std::istringstream in(o.str().c_str());
98  for (uint8_t i=0; i<dim;i++)
99  {
100  uint32_t val;
101  in >> val;
102  if (val<2) return error(-3);
103  n[i] = val;
104  }
105  uint32_t npts = 1;
106  for (uint8_t i=0; i<dim;i++)
107  npts *= n[i];
108  std::cout << npts << "\n";
109  for (uint32_t k=0; k<n[2];k++)
110  {
111  for (uint32_t j=0; j<n[1];j++)
112  {
113  for (uint32_t i=0; i<n[0];i++)
114  std:: cout << v(i,n[0]) << " " << v(j,n[1]) << " " << v(k,n[2]) << "\n";
115  }
116  }
117  if (topo)
118  {
119  switch (dim)
120  {
121  case 1:
122  std::cout << n[0]-1 << "\n";
123  for (uint32_t u=0; u<n[0]-1;u++)
124  std::cout << u << " " << u+1 << "\n";
125  break;
126  case 2:
127  std::cout << (n[0]-1)*(n[1]-1)*2 << "\n";
128  for (uint32_t v=0; v<n[1]-1;v++)
129  {
130  for (uint32_t u=0; u<n[0]-1;u++)
131  tri(u,v);
132  }
133  break;
134  case 3:
135  std::cout << (n[0]-1)*(n[1]-1)*(n[2]-1)*6 << "\n";
136  for (uint32_t w=0; w<n[2]-1;w++)
137  {
138  for (uint32_t v=0; v<n[1]-1;v++)
139  {
140  for (uint32_t u=0; u<n[0]-1;u++)
141  quad(u,v,w);
142  }
143  }
144  }
145  }
146  return 0;
147 }
@ OPT_HELP
Definition: generate.cxx:21
@ OPT_TOPO
Definition: generate.cxx:21
void quad(const uint32_t i, const uint32_t j, const uint32_t k)
Definition: generate.cxx:61
double v(const uint32_t step, const uint32_t n)
Definition: generate.cxx:42
int error(int val)
Definition: generate.cxx:36
CSimpleOpt::SOption g_rgOptions[]
Definition: generate.cxx:23
int main(int argc, char **argv)
Definition: generate.cxx:73
void tri(const uint32_t i, const uint32_t j)
Definition: generate.cxx:50
void tetra(const uint32_t a, const uint32_t b, const uint32_t c, const uint32_t d)
Definition: generate.cxx:56
uint32_t n[]
Definition: generate.cxx:34
std::istringstream in
Definition: ply2tri.cxx:32