/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #ifndef _MGLBRep_HH_ #define _MGLBRep_HH_ #include "mg/MGCL.h" #include "mg/Vector.h" #include "mg/KnotVector.h" #include "mg/BPointSeq.h" #include "mg/Curve.h" // MGLBRep.h // Forward Declaration class MGInterval; class MGNDDArray; class MGPosition; class MGOscuCircle; class MGKnotArray; class MGCParam_list; class MGPosition_list; class MGLBRepEndC; class MGRLBRep; class MGPPRep; class MGSBRepTP; class MGIfstream; class MGOfstream; // Defines Line B-Representation. /** @file */ /** @addtogroup GEO * @{ */ ///MGLBRep is a class for B-SPline representation. ///For a general NURBS(non uniform rational B-Spline) is MGRLBRep. ///LBRep abbrebiates Line B-Representation. MGLBRep consists of a knot vector(MGKnotVector) ///and a control polygon(MGBPointSeq) whose B-representaiton dimension are the same. class MG_DLL_DECLR MGLBRep: public MGCurve{ public: ///translation by a vector. MG_DLL_DECLR friend MGLBRep operator+ (const MGVector& v, const MGLBRep& lb); ///scaling by a scalar. MG_DLL_DECLR friend MGLBRep operator* (double scale, const MGLBRep&); ///曲線列のノットベクトルを再構築する ///入力された複数曲線列を指定オーダーで再構築する。トレランスはline_zero()を使用している。 ///オーダーが指定されていないとき曲線列のうちで最も大きいオーダーを使用する。このとき、 ///Ellipse, Straightのオーダーは4として考える。 ///パラメータ範囲は1次微分値の大きさが1になるようにしたときの長さの平均を使用している。 ///戻り値は再構築後の曲線列が返却される。エラーのときヌルが返却される。 MG_DLL_DECLR friend MGPvector rebuild_knot( const std::vector& brepl,///<入力曲線列 int order = 0, ///<指定オーダー MGLBRep** tp=0 ///<接続面 ); ///Same as above, except that the input is MGPvector<>. MG_DLL_DECLR friend MGPvector rebuild_knot( const MGPvector& brepl, ///<入力曲線列 int order = 0, ///<指定オーダー MGLBRep** tp=0 ///<接続面 ); ///複数カーブの共通で削除できるノットを削除する。 ///ただし、入力カーブは同じノットベクトルを持つものとする。 MG_DLL_DECLR friend void remove_knot_curves( MGPvector& brepList, ///<曲線列 MGLBRep** tp=0, ///<接続面 input and output. ///>//////// ///Default(dummy) constructor. MGLBRep():MGCurve(),m_line_bcoef(),m_knot_vector(){;} ///Dummy constructor that specifies area length. MGLBRep(int bdim, ///< b-rep dimension of the lbrep. int order, ///ratio or ///< d(i-1)/d(i)>ratio, either tau[i] or tau[i-1] will be removed. ///< This is done to prevent control polygon computation error. ///< When ratio<0. no data point removal will be done. ); ///Construct Line B-rep of any order number by interpolation ///from Point data only with knot vector. MGLBRep( const MGNDDArray& tau, ///=0. int which, ///=0. ///< =0: start of brep1 and start of brep2. ///< =1: start of brep1 and end of brep2. ///< =2: end of brep1 and start of brep2. ///< =3: end of brep1 and end of brep2. const MGLBRep& brep2 ///=Sum(((points(i)-pout(i))/dp[i])**2), ///=Max((points(i)-pout(i))**2), ///eval(tau(i)). bool dev_is_sum=false///=Sum(((points(i)-pout(i))/dp[i])**2), ///=Max((points(i)-pout(i))**2), ///eval(tau(i)). bool dev_is_sum=false///=0. int which, ///=0. ///< =0: start of this to start of brep2. ///< =1: start of this to end of brep2. ///< =2: end of this to start of brep2. ///< =3: end of this to end of brep2. double& ratio///< Ratio of 1st derivatives of the two line will be returned. ///< ratio= d2/d1, where d1=1st deriv of this and d2=of brep2 ) const; ///Exchange ordering of the coordinates. ///Exchange coordinates (j1) and (j2). MGLBRep& coordinate_exchange(int j1, int j2); ///Construct new curve object by copying to newed area. ///User must delete this copied object by "delete". virtual MGLBRep* clone()const; ///Convert this curve to Bezier curve. ///If this is MGLBRep or MGStraight, the shape is exactly the same ///as the original. Otherwise, this is apporoximated by MGLBRep. ///The result MGLBRep is of order 2 if original order is 2 ///and is of order4 otherwise. void convert_to_Bezier(MGLBRep& bezier)const; ///copy as a newed curve. The new curve will be MGLBRep or MGRLBRep. ///When original curve was a MGRLBRep, the new curve will be a MGRLBRep. ///Otherwise, the new curve will be a MGLBRep. ///Returned object must be deleted. MGCurve* copy_as_nurbs() const{return clone();}; ///copy as a newed curve. The new curve will be MGLBRep. ///Returned object must be deleted. MGLBRep* copy_as_LBRep() const; ///Construct new curve object by changing ///the original object's space dimension. ///User must delete this copied object by "delete". MGLBRep* copy_change_dimension( int sdim, ///< new space dimension int start1=0, ///< Destination order of new line. int start2=0 ///< Source order of this line. )const; ///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* copy_limitted(const MGInterval& prange) const; ///Compute curvilinear integral of the 1st two coordinates. ///This integral can be used to compute area sorounded by the curve. ///(線積分)を求める。 double curvilinear_integral(double t1, double t2) const; #ifdef __sgi double curvilinear_integral()const {return curvilinear_integral(param_s(), param_e());} #endif ///Divide this curve at the designated knot multiplicity point. ///Function's return value is the number of the curves after divided. int divide_multi( MGPvector& crv_list, ///=order(), order() is assumed. ) const; ///Display control polygons using mgVBO::MGDrawPointSeq() void display_control_polygon(mgSysGL& sgl)const; virtual void drawSE( mgVBO& vbo,///=4. MGLBRep& extend( int start, ///param_e(), extension will be done at the end point. double dk ///=2, order is also tested if this Bezier's order is the same as input order. ///If input ordr<=1, any ordr>=2 is allowed for Bezier curve. ///Bezier curve is defined as follows. Here t=knot_vector(), k is this LBRep's order, ///n=bdim(), and m=(n-k)/(k-1). ///(1) n=k+(k-1)*m. ///(2) t(0)=t(1)=,...,=t(k-1)=0 ///(3) t(i)=t(i+1)=,...,=t(i+k-2)=j+1 /// for i=k, k+(k-1),...,k+j*(k-1) and j=0,...,m-1. ///(4) t(n)=t(n+1)=,...,=t(n+k-1)=m+1 const MGLBRep* is_Bezier(int ordr=0)const; ///Test if this cure is co-planar with the 2nd curve curve2. ///MGPlane expression will be out to plane if this is co-planar. ///Function's return value is true if co-planar. bool is_coplanar(const MGCurve& curve2, MGPlane& plane)const; ///Test if this cure is planar or not. ///MGPlane expression will be out to plane if this is planar. ///Function's return value is true if planar. bool is_planar(MGPlane& plane)const; /// Spline と Curve の交点を求める。 ///Intersection point of spline and curve. MGCCisect_list isect(const MGCurve& curve2) const; MGCCisect_list isect(const MGStraight& curve2)const; MGCCisect_list isect(const MGRLBRep& curve2)const; MGCCisect_list isect(const MGEllipse& curve2)const; MGCCisect_list isect(const MGLBRep& curve2)const; MGCCisect_list isect(const MGSurfCurve& curve2)const; MGCCisect_list isect(const MGBSumCurve& curve2)const; ///Intersection of MGLBRep and Surface MGCSisect_list isect(const MGSurface& surf) const; MGCSisect_list isect(const MGPlane& surf) const; MGCSisect_list isect(const MGSphere& surf)const; MGCSisect_list isect(const MGCylinder& surf)const; MGCSisect_list isect(const MGSBRep& surf)const; MGCSisect_list isect(const MGRSBRep& surf)const; MGCSisect_list isect(const MGBSumSurf& surf)const; ///Access to i-th element of knot. ///( left-hand side version) double& knot(int i){return m_knot_vector(i);}; ///Access to i-th element of knot. ///(right hand side version) double knot(int i) const{return m_knot_vector(i);}; ///Returns a pointer to /// the knot vector data. const double* knot_data() const{return m_knot_vector.data();}; double* knot_data(){return m_knot_vector.data();}; ///Returns the knot vector. ///(RHS version) const MGKnotVector& knot_vector() const{return m_knot_vector;}; ///Returns the knot vector. ///(LHS version) MGKnotVector& knot_vector(){return m_knot_vector;}; //Update this by limiting the parameter range of the curve. virtual MGLBRep& limit(const MGInterval& i1); ///Returns the B-coef's(RHS version). const MGBPointSeq& line_bcoef() const{return m_line_bcoef;}; ///Returns the B-coef's(LHS version). MGBPointSeq& line_bcoef(){ update_mark(); return m_line_bcoef; }; ///Modify the original line by moving move_point to to_point. fix_point can be ///applied according to move_kind. /// move_kind=1: Start and end point of the line are fixed. The line is modified /// linearly so that move_point_param point is the maximum move. /// =2: The point fix_point[0] is fixed and the other end of /// the move_point_param side is moved. In this case, maximum move /// is the end point of the line. /// =3: fix_point[0]=0: number of curves obtained, <0 : Some error detected. int project( const MGFSurface& surf, //given surface. MGPvector& vec_crv_uv, //uv projection curve will be appended. MGPvector& vec_crv, //3d projection curve will be appended. const MGVector& vec //projection vector. //if vec = NULL then calculate perpendicular project. )const; int project( const MGPlane& plane, //given surface. MGPvector& vec_crv_uv, //uv projection curve will be appended. MGPvector& vec_crv, //3d projection curve will be appended. const MGVector& vec //projection vector. //if vec = NULL then calculate perpendicular project. )const; ///Change the B-Rep by decreasing B-Rep dimension by ndec. This is ///an approximation of the origimal B-Rep. Return value is error flag. int reduce( int ndec ///=2; ///If this space dimension is lager than 2, the remaining coordinates are unchanged. void updatePolarCoordinates2Ordinary(); /// limitをはずす。 MGCurve& unlimit(){return *this;}; ///Unlimit parameter range of the curve to the end point direction ///(終点方向にlimitをはずす) MGCurve& unlimit_end(){return *this;}; ///Unlimit parameter range of the curve to the start point direction ///(始点方向にlimitをはずす) MGCurve& unlimit_start(){return *this;}; ///Returns the knot vector. ///MGKnotVector knot_vector_real() const{return knot_vector();} ///IGES output function. PD126. int out_to_IGES( MGIgesOfstream& igesfile, int SubordinateEntitySwitch=0 )const; ///Debug Function virtual std::ostream& out(std::ostream&)const; std::string whoami()const{return "LBRep";}; protected: ///Compute intersection point of 1D sub B-Rep of original B-rep.(BLIPP) ///Parameter values of intersection point will be returned. ///isect_1D covers this LBRep's C0 ontinuity. MGCParam_list intersect_1D( double f, ///< Coordinate value int coordinate=0 ///< Coordinate kind of the data f(from 0). ///< Id of m_line_bcoef. )const; ///Obtain so transformed 1D curve expression of this curve that ///f(t)={sum(xi(t)*g[i]) for i=0(x), 1(y), 2(z)}-g[3], where f(t) is the output ///of oneD and xi(t) is i-th coordinate expression of this curve. ///This is used to compute intersections with a plane g[4]. std::unique_ptr oneD( const double g[4] ///