예제 #1
0
void moveVertex( Vertex_handle & vh, Point3 & coord, double coef )
{
    // Initialization is very important.
    Vector3 average( 0.0, 0.0, 0.0 );
    int degree = 0;
    Halfedge_vertex_circulator hvc = vh->vertex_begin();
    do {
	average = average + ( hvc->opposite()->vertex()->point() - CGAL::ORIGIN );
	degree++;
#ifdef MYDEBUG
	cerr << "point = " << hvc->opposite()->vertex()->point() << endl;
	cerr << "average = " << average << endl;
#endif	// MYDEBUG
    } while ( --hvc != vh->vertex_begin() );

    average = average / ( double )degree;
#ifdef MYDEBUG
    cerr << "Final average = " << average << endl;
#endif	// MYDEBUG

    Vector3 offset = average - ( vh->point() - CGAL::ORIGIN );
#ifdef MYDEBUG
    cerr << "Final offset = " << offset << endl;
#endif	// MYDEBUG

    coord = vh->point() + coef * offset;
}
예제 #2
0
// compute one cross point between 1-ring of c_vh and cutPlane
bool vertexTo(Vertex_handle &c_vh, Halfedge_handle &c_hh, Vertex_handle center, 
			  Halfedge_vertex_circulator &optimal_start_spoke, 
			  const Plane_3 &cutPlane, Polyhedron* mesh, std::list<Point_3> &cross_points,
			  int nthTarget)
{
	bool result(false);
	Halfedge_vertex_circulator  hc;
	if ( c_vh == center )
		hc =  optimal_start_spoke;
	else
		hc =  c_vh->vertex_begin();

	Halfedge_vertex_circulator end  =  hc;			
	CGAL_For_all(hc,end)
	{
		Vertex_handle lvh = hc->opposite()->vertex();
		Vertex_handle rvh = hc->next()->vertex();
		Point_3 lp = lvh->point();
		Point_3 rp = rvh->point();
		int il = cutPlane.oriented_side(lp);
		int ir = cutPlane.oriented_side(rp);
		int tmp = il*ir;
		if ( tmp<0)//异侧
		{
			Halfedge_handle lrhh = hc->next()->next();
			if (lrhh->tag()==nthTarget)//在找这次的target的过程中已经用过了
			{
				continue;
			}
			else
			{
				lrhh->tag(nthTarget);
				lrhh->opposite()->tag(nthTarget);
			}

			if ( c_vh == center )
			{
				optimal_start_spoke = hc;// ++optimal_start_spoke;
			}

			Point_3 cp = compute_cross_point(cutPlane,lp,rp);
			cross_points.push_back(cp);
			
			c_hh = hc->next()->next()->opposite();
			c_vh = 0;
			result = true;
			break;
		}
		else if(tmp>0)//同侧
		{
			continue;
		}

		if (ir)//lp is on the cut plane
		{		
			if (lvh->tag()==nthTarget)//在找这次的target的过程中已经用过了
			{
				continue;
			}
			else
			{
				lvh->tag(nthTarget);
			}
			if ( c_vh == center)
			{
				optimal_start_spoke = hc;// ++optimal_start_spoke;
			}
			c_vh = lvh;			
		}
		else
		{	
			if (rvh->tag()==nthTarget)//在找这次的target的过程中已经用过了
			{
				continue;
			}
			else
			{
				rvh->tag(nthTarget);
			}
			if ( c_vh == center)
			{
				optimal_start_spoke = hc; ++optimal_start_spoke; //++optimal_start_spoke;
			}
			c_vh = rvh;			
		}				
		cross_points.push_back(c_vh->point());
		c_hh = 0;
		result = true;
		break;
	}