int superMi::assign_kuv_to_edge(Solid* mesh) { for (SolidEdgeIterator seiter(mesh); !seiter.end(); ++seiter){ Edge* se = *seiter; se->kuv_h() = 0.0; //Point p1 = mesh->edgeVertex1(se)->point(); //Point p3 = mesh->edgeVertex2(se)->point(); //HalfEdge* he2 = se->halfedge(0)->ccw_rotate_about_source(); //HalfEdge* he4 = se->halfedge(0)->clw_rotate_about_source(); //Point p2 = he2->target()->point(); //Point p4 = he4->target()->point(); //double alpha = ((p3 - p2)*(p1 - p2) / ((p3 - p2) ^ (p1 - p2)).norm()) / 2.0; //double beta = ((p3 - p4)*(p1 - p4) / ((p3 - p4) ^ (p1 - p4)).norm()) / 2.0; //se->kuv_h() = alpha + beta; HalfEdge* he = se->halfedge(0); HalfEdge* nhe = he->he_next(); HalfEdge* phe = he->he_prev(); Face* hef = he->face(); double nhel = (nhe->target()->point() - nhe->source()->point()).norm(); double phel = (phe->target()->point() - phe->source()->point()).norm(); double hel = (he->target()->point() - he->source()->point()).norm(); se->kuv_h() += (nhel*nhel + phel*phel - hel*hel) / hef->area() / 8.0; he = se->halfedge(1); nhe = he->he_next(); phe = he->he_prev(); hef = he->face(); nhel = (nhe->target()->point() - nhe->source()->point()).norm(); phel = (phe->target()->point() - phe->source()->point()).norm(); se->kuv_h() += (nhel*nhel + phel*phel - hel*hel) / hef->area() / 8.0; se->kuv_t() = 1.0; //std::cout << se->kuv() << std::endl; } return 0; }
void main(int argc, char *argv[]) { // Read in the obj file Solid mesh; OBJFileReader of; std::ifstream in(argv[1]); string filename = argv[1]; string::size_type npos = filename.find(".obj"); string s = ".m"; filename.replace(npos, 4,s); of.readToSolid(&mesh, in); /******************* Put you subdivision processing here *********************/ //1. highlights all edges zz begin 2013-02-21 16:11:20 SolidEdgeIterator eiter(&mesh); for(; !eiter.end(); ++eiter) { Edge *e = *eiter; e->string ()=std::string("sharp"); } //end zz 2013Äê2ÔÂ21ÈÕ16:18:10 //2. establish the adjacency list [2/21/2013 Zhe] list<int> Graphface[Num]; SolidFaceIterator fiter(&mesh); for(; !fiter.end(); ++fiter) { Face *f = *fiter; FaceHalfedgeIterator hfiter(f); HalfEdge *hf = NULL; for (;!hfiter.end();++hfiter) { hf = *hfiter; hf = hf->he_sym(); Graphface[f->id()].push_back(hf->face()->id()); } } // [2/21/2013 Zhe] /************************************************************************/ /* // 3.MST Algorithm [19:00/2/21/2013 Zhe] */ /************************************************************************/ list<int> Mstqueue; queue<int> nLayer; list<int>::iterator mstiterator,Mstqueueiterator,Layeriterator; fiter.reset(); int a[Num] = {0}; Face *MSTface = *fiter; Mstqueue.push_back(MSTface->id()); nLayer.push(MSTface->id()); //initialization a[MSTface->id()] = TRUE; while (!nLayer.empty()) { int Faceid = nLayer.front(); nLayer.pop(); //MstGraphface[Faceid].push_back(Faceid); for (mstiterator = Graphface[Faceid].begin();mstiterator != Graphface[Faceid].end();++mstiterator) { //Layeriterator = find (Mstqueue.begin(), Mstqueue.end(), *mstiterator); if (a[*mstiterator] == 0) { Mstqueue.push_back(*mstiterator); nLayer.push(*mstiterator); a[*mstiterator] = TRUE; int nFaceid_father = Faceid; int nFaceId_son = *mstiterator; MeshLib::Face *f = mesh.idFace (nFaceid_father); MeshLib::FaceHalfedgeIterator fheiter(f); MeshLib::Edge * inter_edge; for (; !fheiter.end (); ++fheiter) { MeshLib::HalfEdge *he = *fheiter; he = he->he_sym (); if (he->face ()->id ()== nFaceId_son) { inter_edge=he->edge (); inter_edge->string () = std::string(""); break; } } } } } // 3. cut the graph [23:19/2/21/2013 Zhe] SolidVertexIterator iter(&mesh); std::map<int, int> vidToObjID; do { for(; !iter.end(); ++iter) { Vertex *v = *iter; MeshLib::VertexEdgeIterator edgeiter(v); MeshLib::Edge * inter_edge; int nsharp = 0; for (;!edgeiter.end();++edgeiter) { inter_edge = *edgeiter; if (inter_edge->string() == "sharp") { nsharp++; } } //delete nsharp == 1 if (1 == nsharp) { edgeiter.reset(); for (;!edgeiter.end();++edgeiter) { inter_edge = *edgeiter; if (inter_edge->string() == "sharp") { inter_edge->string () = std::string(""); //nsharp = 0; } } } vidToObjID[v->id()] = nsharp; } iter.reset(); } while (ifsharpequalone(vidToObjID)); mesh.write (filename.c_str()); // os.close(); }