void onDraw(SkCanvas* canvas) override { drawJpeg(canvas, this->getISize()); canvas->scale(2, 2); static const char* kLabel1 = "Original Img"; static const char* kLabel2 = "Modified Img"; static const char* kLabel3 = "Cur Surface"; static const char* kLabel4 = "Full Crop"; static const char* kLabel5 = "Over-crop"; static const char* kLabel6 = "Upper-left"; static const char* kLabel7 = "No Crop"; static const char* kLabel8 = "Pre-Alloc Img"; static const char* kLabel9 = "New Alloc Img"; static const char* kLabel10 = "GPU"; SkPaint textPaint; textPaint.setAntiAlias(true); sk_tool_utils::set_portable_typeface(&textPaint); textPaint.setTextSize(8); canvas->drawText(kLabel1, strlen(kLabel1), 10, 60, textPaint); canvas->drawText(kLabel2, strlen(kLabel2), 10, 140, textPaint); canvas->drawText(kLabel3, strlen(kLabel3), 10, 220, textPaint); canvas->drawText(kLabel4, strlen(kLabel4), 10, 300, textPaint); canvas->drawText(kLabel5, strlen(kLabel5), 10, 380, textPaint); canvas->drawText(kLabel6, strlen(kLabel6), 10, 460, textPaint); canvas->drawText(kLabel7, strlen(kLabel7), 10, 540, textPaint); canvas->drawText(kLabel8, strlen(kLabel8), 80, 10, textPaint); canvas->drawText(kLabel9, strlen(kLabel9), 160, 10, textPaint); canvas->drawText(kLabel10, strlen(kLabel10), 265, 10, textPaint); canvas->translate(80, 20); // since we draw into this directly, we need to start fresh sk_bzero(fBuffer, fBufferSize); SkImageInfo info = SkImageInfo::MakeN32Premul(W, H); SkAutoTUnref<SkSurface> surf0(SkSurface::NewRasterDirect(info, fBuffer, RB)); SkAutoTUnref<SkSurface> surf1(SkSurface::NewRaster(info)); SkAutoTUnref<SkSurface> surf2; // gpu #if SK_SUPPORT_GPU surf2.reset(SkSurface::NewRenderTarget(canvas->getGrContext(), SkSurface::kNo_Budgeted, info)); #endif test_surface(canvas, surf0, true); canvas->translate(80, 0); test_surface(canvas, surf1, true); if (surf2) { canvas->translate(80, 0); test_surface(canvas, surf2, true); } }
//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; }