5 :delta_tol_(1e-1), unify_size_(2.0), layer_size_(0), unit_scale_(1.0)
15 for (
int i = 0; i < N; i++)
17 delete (*pvert_list_)[i];
18 (*pvert_list_)[i] = NULL;
24 for (
int i = 0; i < M; i++)
26 delete (*pedge_list_)[i];
27 (*pedge_list_)[i] = NULL;
38 FILE *fp = fopen(path,
"r");
43 fseek(fp, 0, SEEK_SET);
46 vector<WF_vert*> tmp_points;
47 while (fgets(pLine, 512, fp))
49 if (pLine[0] ==
'v' && pLine[1] ==
' ')
53 tok = strtok(pLine,
" ");
54 for (
int i = 0; i < 3; i++)
56 tok = strtok(NULL,
" ");
58 tmp[strcspn(tmp,
" ")] = 0;
59 p[i] = (float)atof(tmp);
64 tmp_points.push_back(u);
72 fseek(fp, 0, SEEK_SET);
73 while (c = fgetc(fp), c != EOF)
75 while (c !=
'l' && c != EOF)
80 if (c ==
'\n' || c == EOF || (c = fgetc(fp)) !=
' ')
86 while (c !=
'\n' && c != EOF)
88 while (c = fgetc(fp), c !=
'\n' && c != EOF && !isdigit(c))
91 if (c ==
'\n' || c == EOF)
96 for (curv = 0; isdigit(c); c = fgetc(fp))
98 curv = curv * 10 + c -
'0';
104 InsertEdge(tmp_points[prev], tmp_points[curv]);
112 fseek(fp, 0, SEEK_SET);
113 while (fgets(pLine, 512, fp))
115 if (pLine[0] ==
'f' && pLine[1] ==
' ')
117 vector<WF_vert*> bound_points;
118 tok = strtok(pLine,
" ");
120 while (tok = strtok(NULL,
" "))
123 tmp[strcspn(tmp,
" ")] = 0;
124 int u = (
int)atof(tmp) - 1;
125 bound_points.push_back(tmp_points[u]);
128 int Bn = bound_points.size();
129 for (
int i = 0; i < Bn - 1; i++)
131 InsertEdge(bound_points[i], bound_points[i + 1]);
133 InsertEdge(bound_points[Bn - 1], bound_points[0]);
152 FILE *fp = fopen(path,
"r");
159 fseek(fp, 0, SEEK_SET);
162 while (fgets(pLine, 512, fp))
164 if (pLine[0] ==
'v' && pLine[1] ==
' ')
168 tok = strtok(pLine,
" ");
169 for (
int i = 0; i < 3; i++)
171 tok = strtok(NULL,
" ");
173 tmp[strcspn(tmp,
" ")] = 0;
174 p[i] = (float)atof(tmp);
183 fseek(fp, 0, SEEK_SET);
184 while (fgets(pLine, 512, fp))
186 if (pLine[0] ==
'g' && pLine[1] ==
' ')
188 tok = strtok(pLine,
" ");
191 tok = strtok(NULL,
" ");
193 tmp[strcspn(tmp,
" ")] = 0;
194 int u = (
int)atof(tmp) - 1;
196 tok = strtok(NULL,
" ");
198 tmp[strcspn(tmp,
" ")] = 0;
199 int v = (
int)atof(tmp) - 1;
201 tok = strtok(NULL,
" ");
203 tmp[strcspn(tmp,
" ")] = 0;
206 if(!(0 <= u && u < pvert_list_->
size()))
209 assert(0 <= u && u < pvert_list_->
size());
223 <<
", current id: " << layer);
224 assert(e->
Layer() == -1);
237 fseek(fp, 0, SEEK_SET);
238 while (c = fgetc(fp), c != EOF)
240 while (c !=
'l' && c != EOF)
245 if (c ==
'\n' || c == EOF || (c = fgetc(fp)) !=
' ')
251 while (c !=
'\n' && c != EOF)
253 while (c = fgetc(fp), c !=
'\n' && c != EOF && !isdigit(c))
256 if (c ==
'\n' || c == EOF)
261 for (curv = 0; isdigit(c); c = fgetc(fp))
263 curv = curv * 10 + c -
'0';
269 if(!(0 <= prev && prev < pvert_list_->
size()))
272 assert(0 <= prev && prev < pvert_list_->
size());
274 if(!(0 <= curv && curv < pvert_list_->
size()))
277 assert(0 <= curv && curv < pvert_list_->
size());
288 fseek(fp, 0, SEEK_SET);
289 while (fgets(pLine, 512, fp))
291 if (pLine[0] ==
'p' && pLine[1] ==
' ')
293 tok = strtok(pLine,
" ");
296 tok = strtok(NULL,
" ");
298 tmp[strcspn(tmp,
" ")] = 0;
299 int u = (
int)atof(tmp) - 1;
301 tok = strtok(NULL,
" ");
303 tmp[strcspn(tmp,
" ")] = 0;
304 int v = (
int)atof(tmp) - 1;
322 fseek(fp, 0, SEEK_SET);
323 while (fgets(pLine, 512, fp))
325 if (pLine[0] ==
'c' && pLine[1] ==
' ')
327 tok = strtok(pLine,
" ");
330 tok = strtok(NULL,
" ");
332 tmp[strcspn(tmp,
" ")] = 0;
333 int u = (
int)atof(tmp) - 1;
335 tok = strtok(NULL,
" ");
337 tmp[strcspn(tmp,
" ")] = 0;
338 int v = (
int)atof(tmp) - 1;
362 FILE *fp = fopen(path,
"wb+");
366 vector<int> export_vert;
368 fill(hash.begin(), hash.end(), -1);
370 for (
int i = 0; i < N; i++)
374 export_vert.push_back(i);
375 hash[i] = export_vert.size();
379 int Ne = export_vert.size();
380 for (
int i = 0; i < Ne; i++)
382 point p = (*pvert_list_)[export_vert[i]]->Position();
383 fprintf(fp,
"v %lf %lf %lf\n", p.
x(), p.
y(), p.
z());
386 for (
int i = 0; i < M; i++)
388 WF_edge *e1 = (*pedge_list_)[i];
390 if (i < e2->ID() && !e1->
isPillar())
394 fprintf(fp,
"l %d %d\n", hash[u], hash[v]);
403 bool bVert,
bool bLine,
404 bool bPillar,
bool bCeiling,
405 bool bCut,
int min_layer,
int max_layer,
410 min_layer = -(1 << 20);
411 max_layer = (1 << 20);
415 FILE *fp = fopen(path,
"wb+");
419 vector<int> export_vert;
421 fill(hash.begin(), hash.end(), -1);
423 for (
int i = 0; i < M; i++)
425 WF_edge *e1 = (*pedge_list_)[i];
427 if (i < e2->ID() && e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
438 export_vert.push_back(u);
439 hash[u] = export_vert.size();
443 export_vert.push_back(v);
444 hash[v] = export_vert.size();
449 int Ne = export_vert.size();
452 for (
int i = 0; i < Ne; i++)
454 point p = (*pvert_list_)[export_vert[i]]->Position();
455 fprintf(fp,
"v %lf %lf %lf\n", p.
x(), p.
y(), p.
z());
461 for (
int i = 0; i < M; i++)
463 WF_edge *e1 = (*pedge_list_)[i];
465 if (i < e2->ID() && !e1->
isPillar() &&
466 e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
470 fprintf(fp,
"l %d %d\n", hash[u], hash[v]);
477 for (
int i = 0; i < M; i++)
479 WF_edge *e1 = (*pedge_list_)[i];
482 && e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
487 fprintf(fp,
"p %d %d\n", hash[u], hash[v]);
494 for (
int i = 0; i < M; i++)
496 WF_edge *e1 = (*pedge_list_)[i];
499 && e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
503 fprintf(fp,
"c %d %d\n", hash[u], hash[v]);
510 for (
int i = 0; i < M; i++)
512 WF_edge *e1 = (*pedge_list_)[i];
514 if (i < e2->ID() && e1->
Layer() != -1
515 && e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
519 fprintf(fp,
"g %d %d %d\n", hash[u], hash[v], e1->
Layer());
530 FILE *fp = fopen(path,
"r");
535 fseek(fp, 0, SEEK_SET);
538 while (fgets(pLine, 512, fp))
541 for (
int i = 2; i < 9; i++)
543 flag = flag + pLine[i];
545 if (pLine[0] ==
'#' && flag ==
"element")
548 while (fgets(pLine, 512, fp) && pLine[0] ==
' ')
553 tok = strtok(pLine,
" ");
555 tmp[strcspn(tmp,
" ")] = 0;
556 p[0] = (float)atof(tmp);
558 for (
int i = 1; i < 3; i++)
560 tok = strtok(NULL,
" ");
562 tmp[strcspn(tmp,
" ")] = 0;
563 p[i] = (float)atof(tmp);
590 FILE *fp = fopen(path,
"wb+");
594 vector<int> export_vert;
596 fill(hash.begin(), hash.end(), -1);
598 for (
int i = 0; i < M; i++)
600 WF_edge *e1 = (*pedge_list_)[i];
608 export_vert.push_back(u);
609 hash[u] = export_vert.size();
613 export_vert.push_back(v);
614 hash[v] = export_vert.size();
619 int Ne = export_vert.size();
620 for (
int i = 0; i < Ne; i++)
622 point p = (*pvert_list_)[export_vert[i]]->Position();
623 fprintf(fp,
"v %lf %lf %lf\n", p.
x(), p.
y(), p.
z());
626 for (
int i = 0; i < M; i++)
628 WF_edge *e1 = (*pedge_list_)[i];
634 fprintf(fp,
"l %d %d\n", hash[u], hash[v]);
646 min_layer = -(1 << 20);
647 max_layer = (1 << 20);
653 vector<bool> is_export_vert(N);
654 fill(is_export_vert.begin(), is_export_vert.end(),
false);
656 FILE *fp = fopen(path,
"wb+");
657 for (
int i = 0; i < M; i++)
659 WF_edge *e1 = (*pedge_list_)[i];
661 if (i < e2->ID() && e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
663 is_export_vert[e2->
pvert_->
ID()] =
true;
664 is_export_vert[e1->
pvert_->
ID()] =
true;
668 for (
int i = 0; i < N; i++)
670 if (is_export_vert[i])
675 point u = (*pvert_list_)[i]->RenderPos();
676 fprintf(fp,
"%lf %lf %lf\r\n", u.
x(), u.
y(), u.
z());
688 min_layer = -(1 << 20);
689 max_layer = (1 << 20);
695 FILE *fp = fopen(path,
"wb+");
696 for (
int i = 0; i < M; i++)
698 WF_edge *e1 = (*pedge_list_)[i];
700 if (i < e2->ID() && e1->
Layer() >= min_layer - 1 && e1->
Layer() < max_layer)
710 fprintf(fp,
"%lf %lf %lf %lf %lf %lf\r\n",
711 u.
x(), u.
y(), u.
z(), v.
x(), v.
y(), v.
z());
723 for (
int i = 0; i < N; i++)
727 ROS_WARN_STREAM(
"duplicate point read! (" << p.
x() <<
", " << p.
y() <<
", " << p.
z() <<
")");
798 for (
int i = 0; i < N; i++)
800 (*pvert_list_)[i]->SetID(i);
801 point p = (*pvert_list_)[i]->Position();
839 for (
int i = 0; i < M; i++)
841 (*pedge_list_)[i]->SetID(i);
864 for (
int i = 0; i < M; i++)
870 (*pedge_list_)[i]->SetLayer(1);
879 (*pedge_list_)[i]->SetLayer(0);
890 float scaleMax = scaleX;
891 if (scaleMax < scaleY)
895 if (scaleMax < scaleZ)
904 for (
size_t i = 0; i < N; i++)
930 vector<bool> delete_vert;
931 delete_vert.resize(N);
932 fill(delete_vert.begin(), delete_vert.end(),
false);
934 vector<bool> delete_edge;
935 delete_edge.resize(M);
936 fill(delete_edge.begin(), delete_edge.end(),
false);
938 for (
int i = 0; i < N; i++)
940 WF_vert *u = (*pvert_list_)[i];
943 WF_edge *e1 = (*pvert_list_)[i]->pedge_;
950 delete_vert[u->
ID()] =
true;
951 delete_edge[e1->
ID()] =
true;
952 delete_edge[e2->
ID()] =
true;
958 e1_pair->
ppair_ = e2_pair;
959 e2_pair->
ppair_ = e1_pair;
964 vector<WF_vert*>::iterator itv =
pvert_list_->begin();
967 if (delete_vert[(*itv)->ID()])
977 vector<WF_edge*>::iterator ite =
pedge_list_->begin();
980 if (delete_edge[(*ite)->ID()])
1002 for (
int i = 0; i < N; i++)
1004 WF_vert *u = (*pvert_list_)[i];
1031 for (
int i = 0; i < N; i++)
1033 WF_vert *u = (*pvert_list_)[i];
1049 if (bound_e.size() == 0)
1055 for (
int i = 0; i < M; i++)
1057 (*pedge_list_)[i]->SetCeiling(
false);
1060 int Mb = bound_e.size();
1061 for (
int i = 0; i < Mb; i++)
1074 if (base_v.size() == 0)
1080 for (
int i = 0; i < M; i++)
1082 (*pedge_list_)[i]->SetPillar(
false);
1086 for (
int i = 0; i < N; i++)
1088 (*pvert_list_)[i]->SetBase(
false);
1089 (*pvert_list_)[i]->SetFixed(
false);
1092 int Nb = base_v.size();
1093 for (
int i = 0; i < Nb; i++)
1105 if (subg_e.size() == 0)
1111 for (
int i = 0; i < N; i++)
1113 (*pvert_list_)[i]->SetSubgraph(
false);
1117 for (
int i = 0; i < M; i++)
1119 (*pedge_list_)[i]->SetSubgraph(
false);
1122 int Mb = subg_e.size();
1123 for (
int i = 0; i < Mb; i++)
void WriteToOBJ(const char *path)
void WriteToPWF(bool bVert, bool bLine, bool bPillar, bool bCeiling, bool bCut, int min_layer, int max_layer, const char *path)
GLenum GLuint GLint GLint layer
WF_edge * InsertOneWayEdge(WF_vert *u, WF_vert *v)
int SizeOfFixedVert() const
void SetPosition(point p)
GLsizei const GLchar *const * path
void ModifyProjection(double len)
WF_vert * InsertVertex(const Vec3f p)
void SetSubgraph(bool b_subg)
WF_edge * InsertEdge(WF_vert *u, WF_vert *v)
void MakeSubGraph(vector< WF_edge * > &subg_e)
void SetCeiling(bool b_ceiling)
void MakeBase(vector< WF_vert * > &base_v)
void LoadFromPWF(const char *path)
void ExportPoints(int min_layer, int max_layer, const char *path)
void SetPillar(bool b_pillar)
double Dist(point u, point v) const
void SetFixed(bool b_fixed)
void SetBase(bool b_base)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
int SizeOfVertList() const
void SetSubgraph(bool b_subg)
#define ROS_WARN_STREAM(args)
GLboolean GLboolean GLboolean b
double ArcHeight(point u, point v1, point v2) const
GLdouble GLdouble GLdouble z
void ProjectBound(double len)
void LoadFromOBJ(const char *path)
GLfloat GLfloat GLfloat v2
void ImportFrom3DD(const char *path)
bool isPillar(int i) const
bool isFixed(int u) const
void ExportLines(int min_layer, int max_layer, const char *path)
void ExportSubgraph(const char *path)
#define ROS_ERROR_STREAM(args)
std::vector< WF_vert * > * pvert_list_
std::vector< WF_edge * > * pedge_list_
int SizeOfEdgeList() const
void MakeCeiling(vector< WF_edge * > &bound_e)