//Construct new curve object by copying to newed area, //and limitting the parameter range to prange. //Returned is newed object and must be deleted. MGCurve* MGRLBRep::copy_limitted(const MGInterval& prange) const{ MGInterval pr=param_range()&prange; return new MGRLBRep(pr.low_point(),pr.high_point(),*this); }
node::param_range node::params () { return param_range (_params.begin (), _params.end ()); }
//Test if part of the surface is planar or not within the tolerance tol. //The part of the surface is input by the surface parameter range uvbox. //Returned is 0(false) if this is not planar, 1(true) if planar. int MGSBRep::planar( const MGBox& uvbox,//This surface parameter range. double tol, //maximum deviation allowed to regard the sub surface as a plane. int* divideU//Direction to subdivide will be output, if this was not planar. //=1: u direction, =0: v direction. ) const{ MGBox uvb=param_range()&uvbox; MGPosition P; MGUnit_vector N; int direction; if(!flat(uvb,tol,direction,P,N)){ if(divideU) *divideU=direction; return 0; }; const MGInterval& urng=uvbox[0]; double u0=urng[0].value(), u1=urng[1].value(); const MGInterval& vrng=uvbox[1]; double v0=vrng[0].value(), v1=vrng[1].value(); double um=(u0+u1)*0.5, vm=(v0+v1)*0.5; int ncd=sdim(); unsigned ku=order_u(), kv=order_v(); const MGKnotVector& tv=knot_vector_v(); int j0=tv.locate(v0)-kv+1, j1=tv.locate(v1); //Coef necessary for v direction part is from j0 to j1 //(B-rep dimension is j1-j0+1). //Knot vector necessary is from j0 to j1+kv. int nunew, nvnew=j1-j0+1; tol*=1.1; size_t nu, nv, sizeu, sizev; surface_bcoef().length(nu, nv); surface_bcoef().capacity(sizeu, sizev); unsigned kmax=ku; if(kmax<kv) kmax=kv; double* work=new double[kmax*kmax]; MGSPointSeq surf1(nvnew, nu, ncd); size_t irc=nvnew*nu; int nmax=nu; if(nmax<nvnew) nmax=nvnew; int nvncd=nvnew; if(nvncd<ncd) nvncd=ncd; MGBPointSeq temp(nmax,nvncd); MGKnotVector t(kmax, nmax); double* tpointer=t.data(); double* temppointer=temp.data(); for(int k=0; k<ncd; k++){ double Pk=P[k]; bluprt_(ku, nu, knot_data_u(), coef_data(0,j0,k), sizeu,nvnew,u0,u1,nmax,work,&nunew,tpointer,temppointer,1); for(int i=0; i<nunew; i++) for(int j=0; j<nvnew; j++) surf1(j,i,k)=temp(i,j)-Pk; } //surf1.set_length(nvnew,nunew);cout<<surf1<<endl;////////// const double* tvnew=knot_data_v()+j0; int nvnew2; double x; int i,j; for(i=0; i<nunew; i++){ bluprt_(kv,nvnew,tvnew,surf1.data(0,i,0), irc,ncd,v0,v1,nmax,work,&nvnew2,tpointer,temppointer,1); //temp.set_length(nvnew2);cout<<temp<<endl;/////////// for(j=0; j<nvnew2; j++){ x=0.; for(int k=0; k<ncd; k++) x-=temp(j,k)*N[k]; if(x<0.) x=-x; if(x>tol) break; } if(j<nvnew2) break; } int retcode=1; if(i<nunew || j<nvnew2){ if(divideU){ // *divideU=direction; MGVector dfdu=eval(um,vm,1,0), dfdv=eval(um,vm,0,1); double ulen=dfdu.len()*(u1-u0), vlen=dfdv.len()*(v1-v0); if(ulen*5.<vlen) *divideU=0; else if(ulen>vlen*5.) *divideU=1; else{ //Compute maximum deviation from the plane along u direction. double udevi0, udevi1, vdevi0, vdevi1; size_t jm=nvnew2/2; x=0.; for(int k=0; k<ncd; k++) x-=surf1(jm,0,k)*N[k]; udevi0=udevi1=x; for(i=1; i<nunew; i++){ x=0.; for(int k=0; k<ncd; k++) x-=surf1(jm,i,k)*N[k]; if(x<udevi0) udevi0=x; if(x>udevi1) udevi1=x; } size_t im=nunew/2; bluprt_(kv,nvnew,tvnew,surf1.data(0,im,0), irc,ncd,v0,v1,nmax,work,&nvnew2,tpointer,temppointer,1); x=0.; for(int k=0; k<ncd; k++) x-=temp(0,k)*N[k]; vdevi0=vdevi1=x; for(j=1; j<nvnew2; j++){ x=0.; for(int k=0; k<ncd; k++) x-=temp(j,k)*N[k]; if(x<vdevi0) vdevi0=x; if(x>vdevi1) vdevi1=x; } if((udevi1-udevi0)>=(vdevi1-vdevi0)) *divideU=1; else *divideU=0; } } retcode=0; } delete[] work; return retcode; }