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(); }
bool Polygon::pointBelongsTo ( Coord c ) { LineSeg seg = axis.front(); Coord middle = seg.getVector() * 0.5 + seg.getStart(); seg = LineSeg ( c, middle ); ///faz uma linha do ponto c até o meio de uma aresta do poligono. int count = 0; for ( auto w: axis ) { double time = w.timeToInterSect ( seg ); double time2 = seg.timeToInterSect ( w ); if ( time2 > 0 && time <= 1 && time >= 0 ) { count++; } } if ( count % 2 == 0 ) return false; return true; }