WireFrame.h
Go to the documentation of this file.
1 /*
2 * ==========================================================================
3 * This file is part of the implementation of
4 *
5 * <FrameFab: Robotic Fabrication of Frame Shapes>
6 * Yijiang Huang, Juyong Zhang, Xin Hu, Guoxian Song, Zhongyuan Liu, Lei Yu, Ligang Liu
7 * In ACM Transactions on Graphics (Proc. SIGGRAPH Asia 2016)
8 ----------------------------------------------------------------------------
9 * class: WireFrame
10 *
11 * Description: WireFrame is the basic data structure to store original frame shape in
12 * FrameFab.
13 *
14 * Version: 2.0
15 * Created: Oct/10/2015
16 * Updated: Aug/24/2016
17 *
18 * Author: Xin Hu, Yijiang Huang, Guoxian Song
19 * Company: GCL@USTC
20 ----------------------------------------------------------------------------
21 * Copyright (C) 2016 Yijiang Huang, Xin Hu, Guoxian Song, Juyong Zhang
22 * and Ligang Liu.
23 *
24 * FrameFab is free software: you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation, either version 3 of the License, or
27 * (at your option) any later version.
28 *
29 * FrameFab is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with FrameFab. If not, see <http://www.gnu.org/licenses/>.
36 * ==========================================================================
37 */
38 
39 #pragma once
40 
41 #include <assert.h>
42 #include <cmath>
43 #include <string.h>
44 
46 
47 using namespace std;
48 using trimesh::vec;
49 using trimesh::point;
50 
54 
55 class WF_vert;
56 class WF_edge;
57 
58 class WF_vert
59 {
60  public:
62  : pedge_(NULL), id_(0), degree_(0),
63  b_fixed_(false), b_base_(false), b_subg_(false)
64  {}
66  : pedge_(NULL), position_(p), render_pos_(p),
67  id_(0), degree_(0),
68  b_fixed_(false), b_base_(false), b_subg_(false)
69  {}
70  WF_vert(double x, double y, double z)
71  : pedge_(NULL), position_(point(x, y, z)), render_pos_(point(x, y, z)),
72  id_(0), degree_(0),
73  b_fixed_(false), b_base_(false), b_subg_(false)
74  {}
76 
77  public:
78  point Position() const { return position_; }
79  point RenderPos() const { return render_pos_; }
80  int ID() const { return id_; }
81  int Degree() const { return degree_; }
82 
83  bool isFixed() const { return b_fixed_; }
84  bool isBase() const { return b_base_; }
85  bool isSubgraph() const { return b_subg_; }
86 
87  void SetPosition(point p) { position_ = p; }
88  void SetPosition(double x, double y, double z) { position_ = point(x, y, z); }
89  void SetRenderPos(point p) { render_pos_ = p; }
90  void SetRenderPos(double x, double y, double z) { render_pos_ = point(x, y, z); }
91  void SetID(int id) { id_ = id; }
92  void IncreaseDegree() { degree_++; }
93 
94  void SetFixed(bool b_fixed) { b_fixed_ = b_fixed; }
95  void SetBase(bool b_base) { b_base_ = b_base; }
96  void SetSubgraph(bool b_subg) { b_subg_ = b_subg; }
97 
98  public:
100 
101  private:
104 
105  int id_;
106  int degree_;
107 
108  bool b_base_;
109  bool b_fixed_;
110  bool b_subg_;
111 };
112 
113 class WF_edge
114 {
115  public:
117  :pvert_(NULL), pnext_(NULL), ppair_(NULL),
118  id_(0), layer_(-1), b_pillar_(false), b_ceiling_(false), b_subg_(false)
119  {}
121 
122  public:
123  int ID() const { return id_; }
124  int Layer() const { return layer_; }
125  bool isPillar() const { return b_pillar_; }
126  bool isCeiling() const { return b_ceiling_; }
127  bool isSubgraph() const { return b_subg_; }
128 
129  void SetID(int id) { id_ = id; }
130  void SetLayer(int layer) { layer_ = layer; }
131  void SetPillar(bool b_pillar) { b_pillar_ = b_pillar; }
132  void SetCeiling(bool b_ceiling) { b_ceiling_ = b_ceiling; }
133  void SetSubgraph(bool b_subg) { b_subg_ = b_subg; }
134 
135  point CenterPos() const
136  {
137  point u = pvert_->Position();
138  point v = ppair_->pvert_->Position();
139  return point((u.x() + v.x()) / 2, (u.y() + v.y()) / 2, (u.z() + v.z()) / 2);
140  }
141 
142  double Length() const
143  {
144  point u = pvert_->Position();
145  point v = ppair_->pvert_->Position();
146  double dx = u.x() - v.x();
147  double dy = u.y() - v.y();
148  double dz = u.z() - v.z();
149  return sqrt(dx*dx + dy*dy + dz*dz);
150  }
151 
152  double CenterDistanceTo(WF_edge* ej) const
153  {
154  point this_c = this->CenterPos();
155  point ej_c = ej->CenterPos();
156 
157  double dx = this_c.x() - ej_c.x();
158  double dy = this_c.y() - ej_c.y();
159  double dz = this_c.z() - ej_c.z();
160  return sqrt(dx*dx + dy*dy + dz*dz);
161  }
162 
163  public:
167 
168  private:
169  int id_;
170  int layer_;
171  bool b_pillar_;
173  bool b_subg_;
174 };
175 
176 
177 class WF_face
178 {
179  public:
180  WF_face() { bound_points_ = new vector<WF_vert*>; }
181  ~WF_face() { delete bound_points_; }
182 
183  public:
184  vector<WF_vert*>* bound_points_;
185 };
186 
187 
189 {
190  public:
191  WireFrame();
192  ~WireFrame();
193 
194  public:
195  void LoadFromOBJ(const char *path);
196  void LoadFromPWF(const char *path);
197  void WriteToOBJ(const char *path);
198  void WriteToPWF(
199  bool bVert, bool bLine,
200  bool bPillar, bool bCeiling,
201  bool bCut, int min_layer, int max_layer,
202  const char *path
203  );
204 
205  void ImportFrom3DD(const char *path);
206 
207  void ExportSubgraph(const char *path);
208  void ExportPoints(int min_layer, int max_layer, const char *path);
209  void ExportLines(int min_layer, int max_layer, const char *path);
210 
211  WF_vert* InsertVertex(const Vec3f p);
212  WF_edge* InsertEdge(WF_vert *u, WF_vert *v);
213  WF_edge* InsertOneWayEdge(WF_vert *u, WF_vert *v);
214 
215  void Unify();
216  point Unify(Vec3f p);
217 
218  void SimplifyFrame();
219  void ProjectBound(double len);
220  void ModifyProjection(double len);
221  void MakeBase(vector<WF_vert*> &base_v);
222  void MakeCeiling(vector<WF_edge*> &bound_e);
223  void MakeSubGraph(vector<WF_edge*> &subg_e);
224 
225  void SetUnitScale(double unit_scale) { unit_scale_ = unit_scale; }
226 
227  inline int SizeOfVertList() const { return pvert_list_->size(); }
228  inline int SizeOfEdgeList() const { return pedge_list_->size(); }
229  inline int SizeOfFixedVert() const { return fixed_vert_; }
230  inline int SizeOfBaseVert() const { return base_vert_; }
231  inline int SizeOfPillar() const { return pillar_size_; }
232  inline int SizeOfCeiling() const { return ceiling_size_; }
233  inline int SizeOfLayer() const { return layer_size_; }
234 
235  inline vector<WF_vert*> *GetVertList() { return pvert_list_; }
236  inline vector<WF_edge*> *GetEdgeList() { return pedge_list_; }
237  inline WF_vert *GetVert(int u) { return (u >= SizeOfVertList() || u < 0) ? NULL : (*pvert_list_)[u]; }
238  inline WF_edge *GetEdge(int i) { return (i >= SizeOfEdgeList() || i < 0) ? NULL : (*pedge_list_)[i]; }
239  inline WF_edge *GetNeighborEdge(int u) { return (u >= SizeOfVertList() || u < 0) ? NULL : (*pvert_list_)[u]->pedge_; }
240 
241  inline point GetPosition(int u) const { assert(u < SizeOfVertList() && u >= 0); return((*pvert_list_)[u]->Position()); }
242  inline int GetDegree(int u) const { assert(u < SizeOfVertList() && u >= 0); return((*pvert_list_)[u]->Degree()); }
243 
244  inline int GetEndu(int i) const { assert(i < SizeOfEdgeList() && i >= 0); return((*pedge_list_)[i]->ppair_->pvert_->ID()); }
245  inline int GetEndv(int i) const { assert(i < SizeOfEdgeList() && i >= 0); return((*pedge_list_)[i]->pvert_->ID()); }
246 
247  inline point GetCenterPos(int i) const { assert(i < SizeOfEdgeList() && i >= 0); return((*pedge_list_)[i]->CenterPos()); }
248  inline Vec3f GetCenterPos() const { return center_pos_; }
249  inline Vec3f GetBaseCenterPos() const { return base_center_pos_; }
250 
251  inline double GetUnitScale() const { return unit_scale_; }
252 
253  inline bool isFixed(int u) const { assert(u < SizeOfVertList() && u >= 0); return((*pvert_list_)[u]->isFixed()); }
254  inline bool isPillar(int i) const { assert(i < SizeOfEdgeList() && i >= 0); return((*pedge_list_)[i]->isPillar()); }
255 
256  inline double maxX() const { return maxx_; }
257  inline double minX() const { return minx_; }
258  inline double maxY() const { return maxy_; }
259  inline double minY() const { return miny_; }
260  inline double maxZ() const { return maxz_; }
261  inline double minZ() const { return minz_; }
262 
263  inline double Norm(point u) const
264  {
265  return sqrt(u.x()*u.x() + u.y()*u.y() + u.z()*u.z());
266  }
267 
268  inline double Dist(point u, point v) const
269  {
270  double dx = u.x() - v.x();
271  double dy = u.y() - v.y();
272  double dz = u.z() - v.z();
273  return sqrt(dx*dx + dy*dy + dz*dz);
274  }
275 
276  inline point CrossProduct(point u, point v) const
277  {
278  return point(u.y() * v.z() - u.z() * v.y(), u.z() * v.x() - u.x() * v.z(),
279  u.x() * v.y() - u.y() * v.x());
280  }
281 
282  inline double ArcHeight(point u, point v1, point v2) const
283  {
284  point alpha = u - v1;
285  point beta = v2 - v1;
286 
287  return Norm(CrossProduct(alpha, beta)) / Norm(beta);
288  }
289 
290  private:
291  std::vector<WF_vert*>* pvert_list_;
292  std::vector<WF_edge*>* pedge_list_;
293 
299 
300  double maxx_;
301  double maxy_;
302  double maxz_;
303  double minx_;
304  double miny_;
305  double minz_;
306  double basez_;
307 
310  float scaleV_;
311  double unify_size_;
312  double delta_tol_;
313 
314  // from millimeter to ..
315  double unit_scale_;
316 };
int GetDegree(int u) const
Definition: WireFrame.h:242
Vec3f center_pos_
Definition: WireFrame.h:308
void SetID(int id)
Definition: WireFrame.h:91
int Degree() const
Definition: WireFrame.h:81
GLfloat GLfloat GLfloat alpha
double delta_tol_
Definition: WireFrame.h:312
bool isFixed() const
Definition: WireFrame.h:83
trimesh::vec3 Vec3f
Definition: WireFrame.h:52
void SetRenderPos(point p)
Definition: WireFrame.h:89
void SetRenderPos(double x, double y, double z)
Definition: WireFrame.h:90
int pillar_size_
Definition: WireFrame.h:296
GLenum GLuint GLint GLint layer
int ceiling_size_
Definition: WireFrame.h:297
void SetUnitScale(double unit_scale)
Definition: WireFrame.h:225
bool isBase() const
Definition: WireFrame.h:84
double minx_
Definition: WireFrame.h:303
~WF_edge()
Definition: WireFrame.h:120
int SizeOfFixedVert() const
Definition: WireFrame.h:229
double minz_
Definition: WireFrame.h:305
WF_vert()
Definition: WireFrame.h:61
trimesh::point point
Definition: WireFrame.h:51
bool isCeiling() const
Definition: WireFrame.h:126
WF_edge * GetNeighborEdge(int u)
Definition: WireFrame.h:239
double maxx_
Definition: WireFrame.h:300
point RenderPos() const
Definition: WireFrame.h:79
void SetPosition(point p)
Definition: WireFrame.h:87
GLsizei const GLchar *const * path
int SizeOfCeiling() const
Definition: WireFrame.h:232
WF_edge * pnext_
Definition: WireFrame.h:165
bool b_fixed_
Definition: WireFrame.h:109
int SizeOfPillar() const
Definition: WireFrame.h:231
bool isSubgraph() const
Definition: WireFrame.h:127
GLfloat GLfloat v1
double maxz_
Definition: WireFrame.h:302
point GetCenterPos(int i) const
Definition: WireFrame.h:247
void SetSubgraph(bool b_subg)
Definition: WireFrame.h:133
WF_edge * GetEdge(int i)
Definition: WireFrame.h:238
WF_edge * pedge_
Definition: WireFrame.h:99
double miny_
Definition: WireFrame.h:304
double CenterDistanceTo(WF_edge *ej) const
Definition: WireFrame.h:152
reference x()
Definition: Vec.h:194
int id_
Definition: WireFrame.h:105
int id_
Definition: WireFrame.h:169
WF_vert(Vec3f p)
Definition: WireFrame.h:65
void SetCeiling(bool b_ceiling)
Definition: WireFrame.h:132
point render_pos_
Definition: WireFrame.h:103
bool isPillar() const
Definition: WireFrame.h:125
double unify_size_
Definition: WireFrame.h:311
point CenterPos() const
Definition: WireFrame.h:135
int SizeOfBaseVert() const
Definition: WireFrame.h:230
vector< WF_edge * > * GetEdgeList()
Definition: WireFrame.h:236
GLint GLenum GLint x
GLenum GLsizei len
Vec3f GetBaseCenterPos() const
Definition: WireFrame.h:249
double Length() const
Definition: WireFrame.h:142
void SetPillar(bool b_pillar)
Definition: WireFrame.h:131
double Dist(point u, point v) const
Definition: WireFrame.h:268
bool b_subg_
Definition: WireFrame.h:110
void SetLayer(int layer)
Definition: WireFrame.h:130
int ID() const
Definition: WireFrame.h:123
bool b_base_
Definition: WireFrame.h:108
double minY() const
Definition: WireFrame.h:259
void SetFixed(bool b_fixed)
Definition: WireFrame.h:94
WF_edge * ppair_
Definition: WireFrame.h:166
int Layer() const
Definition: WireFrame.h:124
double maxy_
Definition: WireFrame.h:301
int fixed_vert_
Definition: WireFrame.h:294
void SetBase(bool b_base)
Definition: WireFrame.h:95
point CrossProduct(point u, point v) const
Definition: WireFrame.h:276
double maxZ() const
Definition: WireFrame.h:260
int layer_size_
Definition: WireFrame.h:298
WF_vert(double x, double y, double z)
Definition: WireFrame.h:70
int SizeOfVertList() const
Definition: WireFrame.h:227
int layer_
Definition: WireFrame.h:170
void SetPosition(double x, double y, double z)
Definition: WireFrame.h:88
DualQuaternion< Real > Norm(DualQuaternion< Real > &d, bool robust=false)
float scaleV_
Definition: WireFrame.h:310
bool b_subg_
Definition: WireFrame.h:173
double GetUnitScale() const
Definition: WireFrame.h:251
double maxX() const
Definition: WireFrame.h:256
trimesh::vec4 Vec4f
Definition: WireFrame.h:53
vector< WF_vert * > * GetVertList()
Definition: WireFrame.h:235
reference y()
Definition: Vec.h:203
void SetID(int id)
Definition: WireFrame.h:129
Vec3f base_center_pos_
Definition: WireFrame.h:309
void SetSubgraph(bool b_subg)
Definition: WireFrame.h:96
int base_vert_
Definition: WireFrame.h:295
double ArcHeight(point u, point v1, point v2) const
Definition: WireFrame.h:282
~WF_face()
Definition: WireFrame.h:181
int SizeOfLayer() const
Definition: WireFrame.h:233
point position_
Definition: WireFrame.h:102
double minZ() const
Definition: WireFrame.h:261
GLdouble GLdouble GLdouble z
int ID() const
Definition: WireFrame.h:80
bool isSubgraph() const
Definition: WireFrame.h:85
void IncreaseDegree()
Definition: WireFrame.h:92
int GetEndv(int i) const
Definition: WireFrame.h:245
vector< WF_vert * > * bound_points_
Definition: WireFrame.h:184
const GLdouble * v
WF_vert * pvert_
Definition: WireFrame.h:164
GLfloat GLfloat GLfloat v2
bool isPillar(int i) const
Definition: WireFrame.h:254
double minX() const
Definition: WireFrame.h:257
Vec< 3, float > vec
Definition: Vec.h:545
Vec< 3, float > point
Definition: Vec.h:549
bool isFixed(int u) const
Definition: WireFrame.h:253
~WF_vert()
Definition: WireFrame.h:75
double maxY() const
Definition: WireFrame.h:258
bool b_ceiling_
Definition: WireFrame.h:172
WF_edge()
Definition: WireFrame.h:116
double Norm(point u) const
Definition: WireFrame.h:263
WF_face()
Definition: WireFrame.h:180
int GetEndu(int i) const
Definition: WireFrame.h:244
double basez_
Definition: WireFrame.h:306
bool b_pillar_
Definition: WireFrame.h:171
reference z()
Definition: Vec.h:212
point GetPosition(int u) const
Definition: WireFrame.h:241
GLfloat GLfloat p
std::vector< WF_vert * > * pvert_list_
Definition: WireFrame.h:291
std::vector< WF_edge * > * pedge_list_
Definition: WireFrame.h:292
Vec3f GetCenterPos() const
Definition: WireFrame.h:248
GLint y
int degree_
Definition: WireFrame.h:106
int SizeOfEdgeList() const
Definition: WireFrame.h:228
point Position() const
Definition: WireFrame.h:78
double unit_scale_
Definition: WireFrame.h:315
WF_vert * GetVert(int u)
Definition: WireFrame.h:237


choreo_task_sequence_planner
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:03:14