1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| FILE* fpLog = fopen("log.txt", "w"); char szStr[MAX_PATH]; CString str; str.Format("%d", pt3ds.size());
sprintf(szStr, "pt3ds.size():%d\n", pt3ds.size()); fprintf(fpLog, "%s", szStr);
if (pt3ds.size() == 0) { return; }
double fX = CGAL::to_double(pt3ds[0].x()); double fY = CGAL::to_double(pt3ds[0].y()); double fZ = CGAL::to_double(pt3ds[0].z()); double fX1, fY1, fZ1;
Halfedge_handle heClosed = facets_begin()->halfedge(); double fDiff = 1e10; for(Face_iterator pf = facets_begin(); pf != facets_end(); pf++) { Halfedge_handle he = pf->halfedge();
do { Point_3 p = he->vertex()->point(); fX1 = CGAL::to_double(p.x()); fY1 = CGAL::to_double(p.y()); fZ1 = CGAL::to_double(p.z()); double fTemp = (fX1 - fX) * (fX1 - fX) + (fY1 - fY) * (fY1 - fY) + (fZ1 - fZ) * (fZ1 - fZ); if (fTemp < fDiff) { fDiff = fTemp; heClosed = he; } he = he->next(); }while(he!= pf->halfedge()); }
vector<Halfedge_handle> vh; vh.push_back(heClosed); for (unsigned i = 1; i < pt3ds.size(); ++i) { sprintf(szStr, "处理第:%d个笔画点\n", i); fprintf(fpLog, szStr);
fX = CGAL::to_double(pt3ds[i].x()); fY = CGAL::to_double(pt3ds[i].y()); fZ = CGAL::to_double(pt3ds[i].z()); sprintf(szStr, "笔画点坐标为:%f,%f,%f\n", fX, fY, fZ); fprintf(fpLog, szStr);
Halfedge_handle next = heClosed; Point_3 p = heClosed->vertex()->point();
fX1 = CGAL::to_double(p.x()); fY1 = CGAL::to_double(p.y()); fZ1 = CGAL::to_double(p.z()); sprintf(szStr, "heClosed坐标为:%f,%f,%f\n", fX1, fY1, fZ1); fprintf(fpLog, szStr);
fDiff = (fX1 - fX) * (fX1 - fX) + (fY1 - fY) * (fY1 - fY) + (fZ1 - fZ) * (fZ1 - fZ);
Vertex_handle v = heClosed->vertex(); Halfedge_around_vertex_circulator he, end; he = end = v->vertex_begin(); CGAL_For_all(he, end) { Halfedge_handle heTemp = he->opposite(); p = heTemp->vertex()->point(); fX1 = CGAL::to_double(p.x()); fY1 = CGAL::to_double(p.y()); fZ1 = CGAL::to_double(p.z());
double fTemp = (fX1 - fX) * (fX1 - fX) + (fY1 - fY) * (fY1 - fY) + (fZ1 - fZ) * (fZ1 - fZ);
if (fTemp < fDiff heClosed != he) { sprintf(szStr, "heTemp坐标为:%f,%f,%f\n", fX1, fY1, fZ1); fprintf(fpLog, szStr);
sprintf(szStr, "fDiff:%f,fTemp:%f\n", fDiff, fTemp); fprintf(fpLog, szStr);
if (std::find(vh.begin(), vh.end(), heTemp) != vh.end()) { continue; }
{ } fDiff = fTemp; next = heTemp; } }
if (next != heClosed) { heClosed = next; vh.push_back(heClosed); } }
glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glColor3f(1.0, 0.0, 0.0); glLineWidth(3.0); glBegin(GL_LINE_STRIP); for (int i = 0; i < vh.size(); ++i) { glVertex3d(CGAL::to_double(vh[i]->vertex()->point().x()), CGAL::to_double(vh[i]->vertex()->point().y()), CGAL::to_double(vh[i]->vertex()->point().z())); sprintf(szStr, "i:%d, x:%f,y:%f,z:%f\n", i, CGAL::to_double(vh[i]->vertex()->point().x()), CGAL::to_double(vh[i]->vertex()->point().y()), CGAL::to_double(vh[i]->vertex()->point().z())); fprintf(fpLog, szStr); } glEnd(); glFlush();
|