/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #include "MGCLStdAfx.h" #include "mg/Transf.h" #include "mg/Position.h" #include "mg/CParam_list.h" #include "mg/CCisect_list.h" #include "mg/CSisect_list.h" #include "mg/Position_list.h" #include "mg/Curve.h" #include "mg/Straight.h" #include "mg/Ellipse.h" #include "mg/SurfCurve.h" #include "mg/BSumCurve.h" #include "mg/Knot.h" #include "mg/LBRep.h" #include "mg/RLBRep.h" #include "mg/Surface.h" #include "mg/Plane.h" #include "mg/Sphere.h" #include "mg/Cylinder.h" #include "mg/SBRep.h" #include "mg/RSBRep.h" #include "mg/BSumSurf.h" #include "mg/Tolerance.h" #include "cskernel/Blipp.h" #include "cskernel/Bkdnp.h" #if defined(_DEBUG) #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif // MGLBRep.cpp // // Implement MGLBRep class. //Member Function //Compute continuity with brep2. maximum continuity conputed is 2. int MGLBRep::continuity(const MGLBRep& brep2, int& which, double& ratio)const{ const double ts1=param_s(); const double te1=param_e(); const double ts2=brep2.param_s(); const double te2=brep2.param_e(); double dataArea[3]; int sd=sdim(); double* data=sd>3? new double[sd] : dataArea; data[0]=data[1]=data[2]=0.0; int cn; MGVector deriv1(0.,0.,0.), deriv2(0.,0.,0.); MGVector d21(0.,0.,0.), d22(0.,0.,0.); double dlen1,dlen2; which=2; ratio=1.0; //Determine which point of brep1 is continuous to which //point of brep2. MGPosition p1[2]; MGPosition p2[2]; p1[0]=eval(ts1, 0); p1[1]=eval(te1, 0); p2[0]=brep2.eval(ts2, 0); p2[1]=brep2.eval(te2, 0); double tratio; // Check of C-0 continuity. const MGLBRep *bl1, *bl2; double t1,t2; if(p1[1]==p2[0]){ which=2; //which=2 means end of brep1 connects // to start of brep2. bl1=this; t1=te1; bl2=&brep2; t2=ts2; }else if(p1[0]==p2[1]){ which=1; //which=1 means start of brep1 connects // to end of brep2. bl1=&brep2; t1=te2; bl2=this; t2=ts1; }else if(p1[1]==p2[1]){ which=3; //which=3 means end of brep1 connects // to end of brep2. bl1=this; t1=te1; bl2=&brep2; t2=te2; }else if(p1[0]==p2[0]){ which=0; //which=0 means start of brep1 connects // to start of brep2. bl1=&brep2; t1=ts2; bl2=this; t2=ts1; }else{ cn=-1; goto end_process; } // Check of C-1 continuity. deriv1=bl1->eval(t1, 1); dlen1=deriv1.len(); deriv2=bl2->eval(t2, 1); dlen2=deriv2.len(); if(MGRZero(dlen1) || MGRZero(dlen2)){ cn=0; goto end_process; } if(which==0) deriv1 *= -1.; else if(which==3) deriv2 *= -1.; tratio=dlen2/dlen1; if(deriv1.parallel(deriv2) && (deriv1%deriv2 > 0.)){ d21=bl1->eval(t1, 2); d22=bl2->eval(t2, 2); d22 /=(tratio*tratio); if(d22==d21) cn=2; else cn=1; }else cn=0; if(which<=1) ratio=dlen1/dlen2; else ratio=tratio; end_process: if(sd>3) delete[] data; return cn; } //Provide divide number of curve span for function intersect. int MGLBRep::intersect_dnum() const{ int k=order(); int nspan=bdim()+1-k; int km2=k-2; if(km2<=0) km2=1; return nspan*km2+1; } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGCurve& curve2)const{ return isect_by_split_to_C1(curve2); } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGStraight& curve2)const{ return isect_by_split_to_C1(curve2); } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGRLBRep& curve2)const{ return isect_by_split_to_C1(curve2); } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGEllipse& curve2)const{ return isect_by_split_to_C1(curve2); } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGLBRep& curve2)const{ return isect_by_split_to_C1(curve2); } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGSurfCurve& curve2)const{ return isect_by_split_to_C1(curve2); } //Intersection point of spline and curve. MGCCisect_list MGLBRep::isect(const MGBSumCurve& curve2)const{ return isect_by_split_to_C1(curve2); } //compute isects by splitting this curve to sub-curves that do not have //C0 points in it. MGCCisect_list MGLBRep::isect_by_split_to_C1(const MGCurve& curve2)const{ MGCCisect_list list(this, &curve2); if(!has_common(curve2)) return list; int k=order(); if(k==2) list.append(isect_order2(curve2)); else{ int index, n=bdim(), multi_found; int orderm1=k-1, start=k; const MGKnotVector& t1=knot_vector(); do{ //Compute intersections by dividing to parts of continuity>=C1. multi_found=t1.locate_multi(start,orderm1,index); //Locate C0 continuity point. if(start==k && index==n) list.append(C1isect(curve2)); //Use original. else{ MGLBRep spanC1(t1[start-1],t1[index],*this); list.append(spanC1.C1isect(curve2)); } start=index+multi_found; }while(index=C1. multi_found=t1.locate_multi(start,orderm1,index); //Locate C0 continuity point. if(start==k && index==n) list.append(intersect(curve2)); //Use original. else{ MGLBRep spanC1(t1[start-1],t1[index],*this); list.append(spanC1.intersect(curve2)); } start=index+multi_found; }while(index=C1. multi_found=(knot_vector()).locate_multi(start,orderm1,index); //Locate C0 continuity point. if(start==k && index==n) list.append(surf.isect_withC1LB(*this)); //Use original. else{ MGLBRep spanC1(t1[start-1],t1[index],*this); list.append(surf.isect_withC1LB(spanC1)); } start=index+multi_found; }while(index=C1. multi_found=t.locate_multi(start,orderm1,index); //Locate C0 continuity point. if(start==k && index==n){ //Use original. nspan=n; knotp=knot_data(); coefp=m_line_bcoef.data(0,coordinate); ts=param_s(); ts-=delta; blipp_(k,nspan,knotp,coefp,f,error,ts,n,work,&nx,x_temp,&iend); for(int i=0; i=k && t(start-1) MGLBRep::oneD( const double g[4] //Plane expression(a,b,c,d) where ax+by+cz=d. ) const{ int i, n=bdim(); int j, m=sdim(); if(m>3) m=3; int k=order(); MGLBRep* brep=new MGLBRep(); MGBPointSeq& rcoef=brep->line_bcoef(); rcoef.resize(n,1); MGKnotVector& knotv=brep->knot_vector(); knotv.size_change(k,n); double min,max; const MGKnotVector& t=knot_vector(); double rt=0; for(j=0; jrt) min=rt; if(maxm_box=new MGBox(1,&minmax); return std::unique_ptr(brep); } // 与ポイントから曲線へ下ろした垂線の足の,曲線のパラメータ値を // すべて求める。 MGCParam_list MGLBRep::perps( const MGPosition& point // 与ポイント )const{ MGCParam_list tlist(this); // Points normal from a point can be obtained as extremum of // the folowing expression G**2(square of length from the point P). // G=(f-p)=sum of (Pij-Pj)*Bi about i, where j is index of axis. // Hence the first derivative of the square is: // 2*(sum about j of Gj*Gj'). The extremum is obtained by solving; // (sum about j of Gj*Gj')=0 . //std::cout<<(*this); //1. Compute knot vector of the B-rep of (sum about j of Gj*Gj'). int k=order(); int km1=k-1; int nold=bdim(); int knew=k+km1; int nnew=nold+km1; MGKnotVector t(m_knot_vector); //std::cout<=C1. multi_found=t1.locate_multi(start,orderm1,index); //Locate C0 continuity point. if(start==k1 && index==nb) list.append(*this, crv2, C1perps(crv2)); //Use original. else{ MGLBRep spanC1(t1[start-1],t1[index],*this); list.append(*this, crv2, spanC1.C1perps(crv2)); } start=index+multi_found; }while(index=C1. multi_found=t1.locate_multi(start,orderm1,index); //Locate C0 continuity point. if(start==k && index==nb) list.append(*this, lbC1, perpendiculars(lbC1)); //Use original. else{ MGLBRep spanC1(t1[start-1],t1[index],*this); list.append(*this, lbC1, spanC1.perpendiculars(lbC1)); } start=index+multi_found; }while(index