bool Curve::RobustTraceBoundaryLoop(HalfEdge* startHe, int & loopSize) { HalfEdge * che = startHe; if (!che->source()->boundary() || !che->target()->boundary()) { std::cerr << "Error: the input halfedge is not on the boundary!" << std::endl; loopSize=0; return false; } bool ccw; Vertex * ver = che->source(); HalfEdge * the = ver->most_ccw_out_halfedge(); if (the == che) { //Possiblly ccw is right, except the case that there is only one out halfedge starting from ver //in that case, check one more step forward is enough HalfEdge * tempthe = the->target()->most_ccw_out_halfedge(); if (tempthe->edge()->boundary()) ccw = true; else { assert(ver->most_ccw_out_halfedge() == ver->most_clw_out_halfedge()); ccw = false; } } else { ccw = false; the = ver->most_clw_out_halfedge(); assert(the == che); } the = che; std::vector<HalfEdge *>::iterator finditer; while (the->target() != ver) { finditer = std::find(helist.begin(), helist.end(), the); if (finditer != helist.end()) {//found std::cerr << "Possible Error: not go back to the starting point!" << std::endl; helist.erase(helist.begin(), finditer-1); loopSize = helist.size(); return false; } else {//not found helist.push_back(the); } if (ccw) the = the->target()->most_ccw_out_halfedge(); else the = the->target()->most_clw_out_halfedge(); } helist.push_back(the); loopSize = helist.size(); return true; }
void Curve::ReplaceSections(Vertex * startV, Vertex * endV, std::vector<HalfEdge *> & replaceList) { int i,j; int startInd, endInd; startInd = endInd = -1; for (i=0;i<helist.size(); ++i) { HalfEdge * he = helist[i]; if (he->source() == startV) { startInd = i; break; } } assert(startInd != -1); for (j=i; j<helist.size();++j) { HalfEdge * he = helist[j]; if (he->target() == endV) { endInd = j; break; } } assert(endInd != -1); ReplaceSections(startInd, endInd, replaceList); }
bool Face::include_vertex(Vertex *v) { HalfEdge * he = m_halfedge; if(he->target () == v || he->source () == v || he->he_next ()->target () == v) return true; return false; }
Curve::Curve(std::list<Edge *> edges) { std::list<Edge *>::iterator eiter = edges.begin(); Edge * e = *eiter; HalfEdge * he = e->halfedge(0); Vertex * v = he->source(); BuildList(edges, v); }
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 Curve::TraceBoundary(HalfEdge * startHe, Vertex * endV) { HalfEdge * che = startHe; if (!che->source()->boundary() || !che->target()->boundary()) { std::cerr << "Error: the input halfedge is not on the boundary!" << std::endl; return; } bool ccw; Vertex * ver = che->source(); HalfEdge * the = ver->most_ccw_out_halfedge(); if (the == che) { //Possiblly ccw is right, except the case that there is only one out halfedge starting from ver //in that case, check one more step forward is enough HalfEdge * tempthe = the->target()->most_ccw_out_halfedge(); if (tempthe->edge()->boundary()) ccw = true; else { assert(ver->most_ccw_out_halfedge() == ver->most_clw_out_halfedge()); ccw = false; } } else { ccw = false; the = ver->most_clw_out_halfedge(); assert(the == che); } the = che; std::vector<HalfEdge *>::iterator finditer; while (the->vertex() != endV) { helist.push_back(the); if (ccw) the = the->target()->most_ccw_out_halfedge(); else the = the->target()->most_clw_out_halfedge(); if (helist.size()>10000000) { assert(0); } } }
Point Face::norm() { HalfEdge * he = m_halfedge; Point p1 = he->target ()->point () - he->source ()->point (); Point p2 = he->he_next ()->target ()->point () - he->target ()->point (); Point n = p1 ^ p2; n /= n.norm (); return n; }
int Curve::TraceFeatureCurve(Mesh * mesh, HalfEdge * heStart) { helist.clear(); MeshUtility::MarkSharpEdges(mesh); HalfEdge * che = heStart; Edge * ce = che->edge(); if (!ce->sharp()) { std::cerr << "Error: the input halfedge is not a feature edge!" << std::endl; return 0; } helist.push_back(che); Vertex * startV = che->source(); Vertex * cv = che->target(); while (cv!=startV) { bool flag = false; for (VertexOutHalfedgeIterator vhe(mesh, cv); !vhe.end(); ++vhe) { HalfEdge * he = *vhe; if (he->edge()->sharp() && he->edge() != ce) { che = he; cv = che->target(); ce = che->edge(); flag = true; break; } } if (!flag) { std::cerr << "Cannot find a circle!" << std::endl; helist.clear(); return 0; } helist.push_back(che); if (che->target() == startV) { //succeed return helist.size(); } } return helist.size(); }
bool Curve::WriteToFile(const char file[]) { //if (!valid) //{ // std::cerr << "Error: The curve is invalid" << std::endl; // return false; //} std::ofstream fp; fp.open(file); if (!fp.good()) { std::cerr << "I/O Error: Cannot write into file " << file << " !" << std::endl; return false; } fp << helist.size() << std::endl; for (int i=0;i<helist.size(); ++i) { HalfEdge * he = helist[i]; fp << he->source()->id() << " " << he->target()->id() << std::endl; } fp.close(); return true; }