void VoronoiCgal_Patch::Compute() { m_CgalPatchs = MakePatchs(m_ImageSpline); for (int i = 0; i < m_CgalPatchs.size(); ++i) { m_Delaunay = Delaunay(); insert_polygon(m_Delaunay, m_ImageSpline, i); insert_polygonInter(m_Delaunay, m_ImageSpline, i); Mesher mesher(m_Delaunay); Criteria criteria(0, 100); mesher.set_criteria(criteria); mesher.refine_mesh(); mark_domains(m_Delaunay); LineSegs lineSegs; for (auto e = m_Delaunay.finite_edges_begin(); e != m_Delaunay.finite_edges_end(); ++e) { Delaunay::Face_handle fn = e->first->neighbor(e->second); //CGAL::Object o = m_Delaunay.dual(e); if (!fn->is_in_domain() || !fn->info().in_domain()) { continue; } if (!m_Delaunay.is_constrained(*e) && (!m_Delaunay.is_infinite(e->first)) && (!m_Delaunay.is_infinite(e->first->neighbor(e->second)))) { Delaunay::Segment s = m_Delaunay.geom_traits().construct_segment_2_object() (m_Delaunay.circumcenter(e->first), m_Delaunay.circumcenter(e->first->neighbor(e->second))); const CgalInexactKernel::Segment_2* seg = &s; CgalPoint p1(seg->source().hx(), seg->source().hy()); CgalPoint p2(seg->target().hx(), seg->target().hy()); Vector2 pp1(p1.hx(), p1.hy()); Vector2 pp2(p2.hx(), p2.hy()); if (pp1 == pp2) { continue; } lineSegs.push_back(LineSeg(pp1, pp2)); } } for (auto it = lineSegs.begin(); it != lineSegs.end(); ++it) { //m_PositionGraph.AddNewLine(it->beg, it->end, ); } } m_PositionGraph.ComputeJoints(); //printf("joints: %d\n", m_PositionGraph.m_Joints.size()); //MakeLines(); MakeGraphLines(); }
void VoronoiCgal_Patch::mark_domains(Delaunay& ct, Delaunay::Face_handle start, int index, std::list<Delaunay::Edge>& border) { if (start->info().nesting_level != TRIANGLE_NOT_INIT) { return; } std::list<Delaunay::Face_handle> queue; queue.push_back(start); while (! queue.empty()) { Delaunay::Face_handle fh = queue.front(); queue.pop_front(); if (fh->info().nesting_level == TRIANGLE_NOT_INIT) { fh->info().nesting_level = index; for (int i = 0; i < 3; i++) { Delaunay::Edge e(fh, i); Delaunay::Face_handle n = fh->neighbor(i); if (n->info().nesting_level == TRIANGLE_NOT_INIT) { if (ct.is_constrained(e)) { border.push_back(e); } else { queue.push_back(n); } } } } } }
DelaunayTri::DelaunayTri(const std::vector<cv::Point2i> &XYpoints, const int &width, const int &height, const int &size) { this->width = width; this->height = height; img = cv::Mat::zeros(cv::Size(width, height), CV_8UC1); int i; points.resize(size); for(i = 0; i < size; ++i) { points[i] = std::make_pair(PointCGAL(XYpoints[i].x, XYpoints[i].y), i + 1); } dt.insert(points.begin(),points.end()); int idxSize = 0; size_ = dt.number_of_faces(); indices.resize(size_*3, -1); centers.resize(size_, cv::Point2d(0, 0)); neighbors.resize(size_*3, 0.0); radii.resize(size_, 0.0); for(Delaunay::Finite_faces_iterator it = dt.finite_faces_begin(); it != dt.finite_faces_end(); it++) { cv::Point2d t[3]; int idx[3]; Delaunay::Face_handle face = it; int offset = idxSize * 3; for(i = 0; i < 3; i++) { t[i] = cv::Point2d(dt.triangle(face)[i].x(), dt.triangle(face)[i].y()); *(idx + i) = face->vertex(i)->info(); indices [offset + i] = face->vertex(i)->info(); } this->insertMap(idx, idxSize); cv::Point2d circumCenter = this->GetCircumcenter(t[0], t[1], t[2]); centers[idxSize] = circumCenter; radii[idxSize] = distPoint2Point<double>(circumCenter.x, circumCenter.y, t[1].x, t[1].y); idxSize++; } //this->draw_subdiv(); //cv::imwrite("delaunay.png", img); this->computeNeighbors(); }
void VoronoiCgal_Patch::mark_domains(Delaunay& cdt) { for (Delaunay::All_faces_iterator it = cdt.all_faces_begin(); it != cdt.all_faces_end(); ++it) { it->info().nesting_level = TRIANGLE_NOT_INIT; } int index = 0; std::list<Delaunay::Edge> border; Delaunay::Finite_faces_iterator fc = cdt.finite_faces_begin(); for (; fc != cdt.finite_faces_end(); ++fc) { int domain = fc->vertex(0)->info().nesting_level; domain = fc->vertex(1)->info().nesting_level == 0 ? fc->vertex( 1)->info().nesting_level : domain; domain = fc->vertex(2)->info().nesting_level == 0 ? fc->vertex( 2)->info().nesting_level : domain; if (TRIANGLE_NOT_INIT == fc->info().nesting_level && domain == 0) { mark_domains(cdt, fc, domain, border); break; } // fc->info().nesting_level = TRIANGLE_TRANSPARENT; // int constrained = 0; // // for (int i = 0; i < 3; ++i) // { // Delaunay::Edge e(fc, i); // // if (cdt.is_constrained(e)) // { // constrained++; // } // } // // if (constrained == 1) // { // fc->info().nesting_level = 10; // } if (TRIANGLE_NOT_INIT == fc->info().nesting_level && domain == 0) { mark_domains(cdt, fc, domain, border); break; } } while (! border.empty()) { Delaunay::Edge e = border.front(); border.pop_front(); Delaunay::Face_handle n = e.first->neighbor(e.second); int domain = e.first->vertex(0)->info().nesting_level >= 0; domain += e.first->vertex(1)->info().nesting_level >= 0; domain += e.first->vertex(2)->info().nesting_level >= 0; int transparent = e.first->vertex(0)->info().nesting_level == TRIANGLE_TRANSPARENT; transparent += e.first->vertex(1)->info().nesting_level == TRIANGLE_TRANSPARENT; transparent += e.first->vertex(2)->info().nesting_level == TRIANGLE_TRANSPARENT; if (transparent >= 2 || domain < 2) { mark_domains(cdt, n, TRIANGLE_TRANSPARENT, border); } else if (n->info().nesting_level == TRIANGLE_NOT_INIT) { //mark_domains(cdt, n, e.first->info().nesting_level + 1, border); printf("domain: %d\n", domain); mark_domains(cdt, n, domain, border); } } }
void mud::convertToSpringMass() { std::vector<Point>::iterator begin = pts.begin(); std::vector<Point>::iterator end= pts.end(); dt.insert(begin,end); qDebug() <<" n of v" << dt.number_of_vertices(); Edge_iterator eit; MudParticle tmp_mp1(&mudSp), tmp_mp2(&mudSp); unsigned int tmp_pmp1, tmp_pmp2; int nEdge=0; for (eit = dt.edges_begin();eit != dt.edges_end();eit++) { Delaunay::Face_handle f = (*eit).first; int i = (*eit).second; Delaunay::Vertex_handle vh1 = f->vertex(dt.cw(i)); Delaunay::Vertex_handle vh2 = f->vertex(dt.ccw(i)); float tmpX = (*vh1).point().x(); float tmpY = (*vh1).point().y(); tmp_mp1.pos.setX(tmpX); tmp_mp1.pos.setY(tmpY); tmp_mp1.origPos= tmp_mp1.pos; if (tmpX > -0.9 && tmpY > -0.9 && tmpX < 0.9 && tmpY < 0.9 ) tmp_mp1.type = 0; else tmp_mp1.type = 1; tmpX = (*vh2).point().x(); tmpY = (*vh2).point().y(); tmp_mp2.pos.setX(tmpX); tmp_mp2.pos.setY(tmpY); tmp_mp2.origPos= tmp_mp2.pos; if (tmpX > -0.9 && tmpY > -0.9 && tmpX < 0.9 && tmpY < 0.9 ) tmp_mp2.type = 0; else tmp_mp2.type = 1; //Il faudrait mieux améliorer cette merde. tmp_pmp1 = utils::findOrAdd(mudPa,&tmp_mp1); tmp_pmp2 = utils::findOrAdd(mudPa,&tmp_mp2); mudSp.push_back(new MudSpring (&mudPa, tmp_pmp1, tmp_pmp2)); mudPa[tmp_pmp1]->addSpring(mudSp.size() -1); mudPa[tmp_pmp2]->addSpring(mudSp.size() -1); nEdge++; } qDebug()<<"mudPa : "<<mudPa.size(); qDebug()<<"nEdge : "<<nEdge<< " et "<<mudSp.size(); }