Points&Forces (survey)
Software tools facilitating the task of surveying architecture
a_block_2d4.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 "a_block_2d4.h"
17 #include "a_face_2d4.h"
18 #include "a_triangle.h"
19 #define DE(x) std::cerr << #x << ": " << x << std::endl;
20 //---------------------------------------------------------------------------
21 a_block_2d4 * cb_2d4(a_block * b) {return dynamic_cast<a_block_2d4*>(b); }
22 
23 //---------------------------------------------------------------------------
24 void a_block_2d4::create_faces()
25 {
26  //create the 4 faces
27  int r0 = 0;
28  for (int i=0; i<4; i++)
29  {
30  a_face_2d4 * f = new a_face_2d4(this,i);
31  this->ai(f);
32  f->av(r0++);
33  f->av(r0%4);
34  }
35 }
36 //---------------------------------------------------------------------------
38 {
39  thickness_ = new double;
40  *thickness_ = 1.;
41  this->create_faces();
42 }
43 //---------------------------------------------------------------------------
45 {
46  //faces and vertices are erased in parent
47  delete thickness_;
48 }
49 //---------------------------------------------------------------------------
51 a_block_2d4::a_block_2d4(a_point* p1, a_point* p2, a_point* p3, a_point* p4, double thickness) : a_block()
52 {
53  thickness_ = new double;
55  //assign the vertices
56  this->av(p1);
57  this->av(p2);
58  this->av(p3);
59  this->av(p4);
60  this->create_faces();
61 }
62 //---------------------------------------------------------------------------
63 const std::string a_block_2d4::help()
64 {
65  std::ostringstream o;
66  o << "*************" << std::endl;
67  o << "a_block_2d4:" << std::endl;
68  o << "*************" << std::endl;
69  o << "a_block_2d4 is a special type of a_block, a class used to model the blocks of a 'a_structure' (see a_structure_help for more information)" << std::endl;
70  o << "It is an quadrilateral prism (a polyhedron with 6 faces: 2 parallel quadrilateral faces and 4 rectangular faces joining them)." << std::endl;
71  o << "The geometry of a block is defined by the 4 points defining the quadrilateral middle surface and the thickness of the block." << std::endl;
72  o << "The points used to define the geometry of the block could be directly the coordinates of the corners of the block in a world (or global) coordinate system." << std::endl;
73  o << "In practice, it is more convenient to define the geometry of the block in a local coordinate system, possibly rotate it, and then to move it in its final position." << std::endl;
74  o << "Commands:" << std::endl;
75  o << "--------" << std::endl;
76  o << "a_block_2d4 B 'p1' 'p2' 'p3' 'p4' 't': create a block named B" << std::endl;
77  o << " 'pi' are points (a_point) defining the shape of the block" << std::endl;
78  o << " 't' is the thickness of the block (default: 1.0)" << std::endl;
79  o << "thickness 'val': set the constant thickness of the block" << std::endl;
80  o << "thickness: gets the thickness of the block" << std::endl;
81  o << "normal: normal to the definition plan of the block (world coordinates)" << std::endl;
82  o << "normall: gets normal to the definition plan of the block (local coordinates)" << std::endl;
83  o << a_block::help();
84  return o.str();
85 }
86 //---------------------------------------------------------------------------
88 {
89  a_block::copy(b);
90  //in a copy, the thickness pointers should be different
91  //but their values should be the same
92  *thickness_ = b.thickness();
93 }
94 //---------------------------------------------------------------------------
96 {
98  //in a deep copy, the thickness pointers should be the same
99  //and consquently, their values will be the same
100  //as the block has already a pointer
101  //this original pointer should first be deallocated
102  delete thickness_;
103  thickness_ = b.thickness_p();
104 }
105 //---------------------------------------------------------------------------
106 a_point a_block_2d4::v3d(const int i) const
107 {
108  a_point n = this->normal();
109  n *= this->thickness()/2.;
110  int r = i;
111  if (r<0) r = 0;
112  if (r>7) r = 7;
113  if (r<4)
114  return *pos_*(*v(r))-n;
115  return *pos_*(*v(r-4))+n;
116 }
117 //---------------------------------------------------------------------------
118 a_point a_block_2d4::cl() const
119 {
120  a_triangle t1(*v(0),*v(1),*v(2));
121  a_triangle t2(*v(0),*v(2),*v(3));
122  double s1 = t1.S();
123  double s2 = t2.S();
124  a_point c1 = t1.c();
125  a_point c2 = t2.c();
126  return (c1*s1+c2*s2)/(s1+s2);
127 }
128 //---------------------------------------------------------------------------
129 double a_block_2d4::V() const
130 {
131  a_triangle t1(*v(0),*v(1),*v(2));
132  a_triangle t2(*v(0),*v(2),*v(3));
133  double s1 = t1.S();
134  double s2 = t2.S();
135  return (s1+s2)*this->thickness();
136 }
137 //---------------------------------------------------------------------------
138 a_point a_block_2d4::normall() const
139 {
140  a_point d1 = *v(1)-*v(0);
141  a_point d2 = *v(3)-*v(0);
142  return cross(d1,d2).normalise();
143 }
144 //---------------------------------------------------------------------------
145 a_point a_block_2d4::normal() const
146 {
147  //attention passage to world coordinate also translate...
148  return (*pos_)*(this->normall())-pos_->p2();
149 }
150 /*
151 //---------------------------------------------------------------------------
152 void a_block_2d4::compute()
153 {}
154 */
155 //---------------------------------------------------------------------------
156 void a_block_2d4::read(std::istream &in)
157 {
158  a_block::read(in);
159  double thickness;
160  in >> thickness;
161  this->thickness(thickness);
162 }
163 //---------------------------------------------------------------------------
164 void a_block_2d4::write(std::ostream &o) const
165 {
166  a_block::write(o);
167  o << this->thickness() << std::endl;
168 }
169 //---------------------------------------------------------------------------
170 void a_block_2d4::writetri(std::ostream &o) const
171 {
172  a_trianglecloud tri;
173  this->trianglecloud(tri);
174  tri.write(o);
175  tri.clear();
176 }
177 //---------------------------------------------------------------------------
178 void a_block_2d4::writeb(std::ostream &o) const
179 {
180  a_point n = this->normal()*(this->thickness()/2.);
181  o << "a_block_2d4(";
182  for (int i=0; i<this->nv(); i++)
183  {
184  a_point p0 = (*pos_)*(*this->v(i));
185  for (int j=0; j<3; j++)
186  o << (p0+n)[j] << ",";
187  }
188  for (int i=0; i<this->nv(); i++)
189  {
190  a_point p0 = (*pos_)*(*this->v(i));
191  if (i!=this->nv()-1)
192  {
193  for (int j=0; j<3; j++)
194  o << (p0-n)[j] << ",";
195  }
196  else
197  o << (p0-n)[0] << "," << (p0-n)[1] << "," << (p0-n)[2] << ")";
198  }
199 }
200 //---------------------------------------------------------------------------
201 void a_block_2d4::writeg(std::ostream &o) const
202 {
203  a_point n = this->normal()*(this->thickness()/2.);
204  o << "arb8 ";
205  for (int i=0; i<this->nv(); i++)
206  {
207  a_point p0 = (*pos_)*(*this->v(i));
208  o << p0+n << " ";
209  }
210  for (int i=0; i<this->nv(); i++)
211  {
212  a_point p0 = (*pos_)*(*this->v(i));
213  o << p0-n << " ";
214  }
215 }
216 //---------------------------------------------------------------------------
217 void a_block_2d4::writefaces(std::ostream &o, const int base = 0) const
218 {
219  o << base+0 << " " << base+2 << " " << base+1 << std::endl;
220  o << base+0 << " " << base+3 << " " << base+2 << std::endl;
221  o << base+4 << " " << base+5 << " " << base+6 << std::endl;
222  o << base+4 << " " << base+6 << " " << base+7 << std::endl;
223  o << base+5 << " " << base+1 << " " << base+2 << std::endl;
224  o << base+5 << " " << base+2 << " " << base+6 << std::endl;
225  o << base+4 << " " << base+3 << " " << base+0 << std::endl;
226  o << base+4 << " " << base+7 << " " << base+3 << std::endl;
227  o << base+6 << " " << base+2 << " " << base+3 << std::endl;
228  o << base+6 << " " << base+3 << " " << base+7 << std::endl;
229  o << base+5 << " " << base+0 << " " << base+1 << std::endl;
230  o << base+5 << " " << base+4 << " " << base+0 << std::endl;
231 }
232 //---------------------------------------------------------------------------
233 void a_block_2d4::trianglecloud(a_trianglecloud& tri) const
234 {
235  tri.addtriangle(this->v3d(0),this->v3d(2),this->v3d(1));
236  tri.addtriangle(this->v3d(0),this->v3d(3),this->v3d(2));
237  tri.addtriangle(this->v3d(4),this->v3d(5),this->v3d(6));
238  tri.addtriangle(this->v3d(4),this->v3d(6),this->v3d(7));
239  tri.addtriangle(this->v3d(5),this->v3d(1),this->v3d(2));
240  tri.addtriangle(this->v3d(5),this->v3d(2),this->v3d(6));
241  tri.addtriangle(this->v3d(4),this->v3d(3),this->v3d(0));
242  tri.addtriangle(this->v3d(4),this->v3d(7),this->v3d(3));
243  tri.addtriangle(this->v3d(6),this->v3d(2),this->v3d(3));
244  tri.addtriangle(this->v3d(6),this->v3d(3),this->v3d(7));
245  tri.addtriangle(this->v3d(5),this->v3d(0),this->v3d(1));
246  tri.addtriangle(this->v3d(5),this->v3d(4),this->v3d(0));
247 }
a_block_2d4 * cb_2d4(a_block *b)
Definition: a_block_2d4.cxx:21
a_point v3d(const int i) const
get vertex (world coordinate, 3D: 8 points: order v0-n, v0+n, v1+n, v1-n
virtual void writeg(std::ostream &o) const
write a brlcad description of the block
double thickness() const
get block thickness
Definition: a_block_2d4.h:39
static const std::string help()
get information about the class
Definition: a_block_2d4.cxx:63
double V() const
volume of the block
virtual void writetri(std::ostream &o) const
write a triangle face representation of the block
a_point normall() const
normal to the definition plan of the block (local coordinates)
virtual void write(std::ostream &o) const
void thickness(const double thickness)
set block thickness
Definition: a_block_2d4.h:37
virtual a_point cl() const
centre of gravity of the face (local coordinate system)
virtual void writeb(std::ostream &o) const
write a blender description of the block
double * thickness_p() const
get block thickness pointer
Definition: a_block_2d4.h:41
void trianglecloud(a_trianglecloud &) const
virtual void deepcopy(const a_block_2d4 &)
copy the block. create new edges
Definition: a_block_2d4.cxx:95
void writefaces(std::ostream &o, const int base) const
write a triangle file description of the block
double * thickness_
Definition: a_block_2d4.h:67
virtual void read(std::istream &i)
input/output
virtual void copy(const a_block_2d4 &)
copy the block. do not create new edges
Definition: a_block_2d4.cxx:87
a_point normal() const
normal to the definition plan of the block (world coordinates)
static const std::string help()
get information about the class
Definition: a_block.cxx:46
virtual void copy(const a_block &)
Definition: a_block.cxx:99
virtual void write(std::ostream &o) const
Definition: a_block.cxx:473
void av(a_point *vertex)
add a vertex
Definition: a_block.h:87
std::vector< int > in() const
return inside faces
Definition: a_block.cxx:373
a_twist * pos_
Definition: a_block.h:146
a_face * i(const int i)
get pointer to face
Definition: a_block.cxx:148
void ai(a_face *face)
add a face
Definition: a_block.h:89
a_point * v(const int i)
get pointer to vertex
Definition: a_block.cxx:134
virtual void deepcopy(const a_block &)
Definition: a_block.cxx:110
virtual void read(std::istream &i)
input/output
Definition: a_block.cxx:449
int nv() const
get number of vertices
Definition: a_block.h:79
void av(int ref)
add a vertex reference
Definition: a_face.h:43
a_point p2() const
Definition: a_plucker.h:42