/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #ifndef _MGCompositeCurve_HH_ #define _MGCompositeCurve_HH_ #include #include "mg/Interval.h" #include "mg/Position_list.h" #include "mg/Straight.h" #include "mg/RLBRep.h" #include "mg/Ellipse.h" #include "mg/LBRep.h" #include "mg/SurfCurve.h" #include "mg/BSumCurve.h" class MGPlane; class MGIgesDirectoryEntry; class MGSurfCurve; class MGStraight; class MGCompositeCurve; class mgVBO; /** @file */ /** @addtogroup GEO * @{ */ ///MGCompositeCurve is a composite of other leaf curves. ///Assumedly they are connected as C0 continuity. However, MGCompositeCurve ///does not check their continuity, but only put first or last as the user says /// (in connect_to_end or in connect_to_start). ///Parameter ranges of the member curves are always continuous. param_s() of the ///1st curve to param_e() of the last form MGCompositeCurve's paramter range. ///number_of_curves() indicates the number of leaf curves(in other words, ///element curves to construct the MGCompositeCurve). class MG_DLL_DECLR MGCompositeCurve:public MGCurve{ public: typedef std::deque container_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef container_type::reverse_iterator reverse_iterator; typedef container_type::const_reverse_iterator const_reverse_iterator; MG_DLL_DECLR friend MGCompositeCurve operator+ (const MGVector& v, const MGCompositeCurve& lb); MG_DLL_DECLR friend MGCompositeCurve operator* (double scale, const MGCompositeCurve&); //////////////Constructor/////////////// ///Void constructor(初期化なしでオブジェクトを作成する。) MGCompositeCurve(){;}; ///Constructor of no curves. ///Constructor of one curve. ///crv is a newed object pointer and MGCompositeCurve takes the ownership. explicit MGCompositeCurve(MGCurve* crv); ///Copy constructor. MGCompositeCurve(const MGCompositeCurve&); //////////// Destructor //////////// ~MGCompositeCurve(); //////////// Operator overload(演算子多重定義) //////////// ///Assignment. ///When the leaf object of this and crv2 are not equal, this assignment ///does nothing. MGCompositeCurve& operator=(const MGGel& gel2); MGCompositeCurve& operator=(const MGCompositeCurve& original); ///Transformation object construction MGCompositeCurve operator+ (const MGVector& v) const; MGCompositeCurve operator- (const MGVector& v) const; MGCompositeCurve operator* (double scale) const; MGCompositeCurve operator* (const MGMatrix& mat) const; MGCompositeCurve operator* (const MGTransf& tr) const; ///Object transformation. MGCompositeCurve& operator+=(const MGVector& v); MGCompositeCurve& operator-=(const MGVector& v); MGCompositeCurve& operator*=(double scale); MGCompositeCurve& operator*=(const MGMatrix& mat); MGCompositeCurve& operator*=(const MGTransf& tr); ///Comparison of two curves. bool is_same_curve(const MGCurve& curve2)const; bool operator==(const MGCompositeCurve& gel2)const; bool operator==(const MGGel& gel2)const; bool operator==(const MGTrimmedCurve& gel2)const; bool operator<(const MGCompositeCurve& gel2)const; bool operator<(const MGGel& gel2)const; //////////// Member Function //////////// ///Approximate this curve as a MGLBRep curve ///within the tolerance MGTolerance::line_zero(). ///When parameter_normalization=0, reparameterization will not done, and ///the evaluation at the same parameter has the same values before and after ///of approximate_as_LBRep. void approximate_as_LBRep( MGLBRep& lb, ///& vec_param ( /O) 共通部分のパラメータ範囲 /// MGCCisect_list& isect ( /O) 交点 /// 4nの配列で、t(4*i+0),t(4*i+1)が自身のパラメータ範囲(t(4*i+0) < t(4*i+1))、 /// t(4*i+2),t(4*i+3)が与曲線のパラメータ範囲(f(t(4*i+0))=f(t(4*i+2)) ///戻り値: /// 3:交点も共通部分も求まった /// 2:交点のみが求まった /// 1:共通部分のみが求まった /// 0:交点も共通部分もなかった /// -1:共通エッジの収束計算エラー /// -2:共通エッジが4個以上求まった(のっていないと見なす) ///追記: /// 曲線が共通かどうかの誤差にはline_zero()、をパラメータ範囲の収束計算の /// 誤差には、パラメータ範囲*rc_zero()を使用した int common( const MGCurve& crv2, std::vector& vecComSpan, MGCCisect_list& isect )const; ///関数名: /// common ///目的: /// 与えられた曲線と自身の共通部分があるかどうか調べる。 ///引数: /// const MGCurve& crv2, (I/ ) 与えられる曲線 /// std::vector& vec_param ( /O) 共通部分のパラメータ範囲 /// 4nの配列で、t(4*i+0),t(4*i+1)が自身のパラメータ範囲(t(4*i+0) < t(4*i+1))、 /// t(4*i+2),t(4*i+3)が与曲線のパラメータ範囲(f(t(4*i+0))=f(t(4*i+2)) ///戻り値: /// 共通部分の数: 共通部分が求まった /// 0: 共通部分がなかった /// -1: 共通エッジの収束計算エラー /// -2: 共通エッジが4個以上求まった(のっていないと見なす) ///追記: /// 曲線が共通かどうかの誤差にはline_zero()を、パラメータ範囲の収束計算の誤差には、 /// パラメータ範囲*rc_zero()を使用した int common( const MGCurve& crv2, std::vector& vecComSpan )const; ///Connect the input curve to the end(to_end) or start(to_start) of this curve. ///(1) End(start) point of this curve is assumedly the same as the start(end) point ///of add_curve. However, connect_to_xxx does not check the continuity except when ///connecting two curves are both MGLBRep. ///(2) add_curve must be a newed object pointer and connect_to_end takes the ownership. ///(3) add_curve can be a MGCompositeCurve. In this case each curves in add_curve ///become members of this MGCompositeCurve. ///(4) When add_curve is a SurfCurve, or a TrimmedCurve, it is changed to non SurfCurve ///or non TrimmedCurve. Thus the original surface or curve can be deleted or modified. ///(5) When MGCompositeCurve was not an empty curve, the original part of ///the MGCompositeCurve's parameter range will not be changed by this connect_to_end. ///Instead add_curve's parameter range will be so modified that the magnitude of ///1st derivatives of the two curves are the same at the connecting point and ///the modified add_curve's parameter range is continuous to the original. ///(6) connect_to_end(start) will change add_curve's direction if necessary. ///Function's return value is the new parameter range of add_curve after added. ///connect() connects to either start or end of this depending the distance ///of the start or end points of this curve to the start or end points of add_curve. ///connect_to_end() connects either start or end points of add_curve to the end to this curve. ///connect_to_start() connects either start or end points of add_curve to the start to this curve. MGInterval connect(MGCurve* add_curve); MGInterval connect_to_end(MGCurve* add_curve); MGInterval connect_to_start(MGCurve* add_curve); ///Exchange ordering of the coordinates. ///Exchange coordinates (i) and (j). MGCompositeCurve& coordinate_exchange(int i, int j); ///Construct new curve object by copying to newed area. ///User must delete this copied object by "delete". MGCompositeCurve* clone() 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; ///Construct new curve object by changing ///the original object's space dimension. ///User must delete this copied object by "delete". MGCompositeCurve* 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; ///Get the i-th curve in this CompositeCurve. const MGCurve& curve(int i)const{return *(m_composite[i]);}; MGCurve& curve(int i){return *(m_composite[i]);}; ///Compute curvilinear integral of the 1st two coordinates from parameter t0 ///to t1. ///This integral can be used to compute area sorrounded by the curve. ///The sum of all the member curve's curvilinear_integral. double curvilinear_integral(double t1, double t2) const; ///Compute curvilinear integral of the 1st two coordinates. ///(All the parameter range of the curve.) ///This integral can be used to compute area sorrounded by the curve. ///The sum of all the member curve's curvilinear_integral. double curvilinear_integral() const; void display_break_points(mgSysGL& sgl)const; void display_control_polygon(mgSysGL& sgl)const; void display_curvatures( mgSysGL& sgl, ///& crv_list, ///=order(), order() is assumed. ) const; void drawSE( mgVBO& vbo,///=1, or find will abort. int find(double t, bool right_continuous=true) const; /// Return This object's typeID long identify_type() const; ///Test if this cure is planar or not. ///MGPlane expression will be output to plane if this is planar. ///Function's return value is true if planar. bool is_planar(MGPlane& plane)const; ///Intersection of CompositeCurve and another curve crv2. MGCCisect_list isect(const MGCurve& crv2) 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; MGCCisect_list isect(const MGTrimmedCurve& curve2)const; MGCCisect_list isect(const MGCompositeCurve& curve2)const; ///Intersection with a 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. double knot(int i) const; ///Returns the knot vector of the curve. ///This should not be used. const MGKnotVector& knot_vector() const; ///Cmpute curve length of the interval. ///If t1 is greater than t2, return negative value. /// パラメータが昇順で与えられたときは正値、降順のときは負値を返す。 ///The sum of all the member curve's length. double length(double t1, double t2) const; double length()const{return MGCurve::length();} ///Update this by limiting the parameter range of the curve. /// 自身に指定したパラメータ範囲のlimitをつける。 MGCompositeCurve& limit(const MGInterval& rng); ///Negate the curve direction(曲線の方向を反転する) void negate(); ///Obtain parameter value if this curve is negated by "negate()". double negate_param(double t)const; ///Get the number of included curves in this CompositeCurve. int number_of_curves()const{return int(m_composite.size());}; //****Offset of CompositeCurve is CompositeCurve of the offsets of each //member curves******** ///一定オフセット関数 ///オフセット方向は、法線方向から見て入力曲線の進行方向左側を正とする。 ///法線ベクトルがヌルの場合、始点において曲率中心方向を正とする。ただし、曲率中心へ曲率半径以上のオフセット ///は行わない。トレランスはline_zero()を使用している。戻り値は、オフセット曲線リストが返却される。 ///costant offset curve. if the norm_vector is given, the positive offset direction decide ///to left hand side from ahead, or the direction to center of curvature at start parameter. ///the offset value is less than radius of curvature. line_zero() is used. MGPvector offset( double ofs_value, ///<オフセット量 const MGVector& norm_vector = mgNULL_VEC ///<法線ベクトル ) const; ///可変オフセット関数 ///オフセット量は空間次元1の線B表現で与えられる。 ///オフセット方向は、法線方向から見て入力曲線の進行方向左側を正とする。 ///法線ベクトルがヌルの場合、始点において曲率中心方向を正とする。ただし、曲率中心へ曲率半径以上のオフセット ///は行わない。トレランスはline_zero()を使用している。戻り値は、オフセット曲線リストが返却される。 ///valuable offset curve. if the norm_vector is given, the positive offset direction decide ///to left hand side from ahead, or the direction to center of curvature at start parameter. ///the offset value is less than radius of curvature. line_zero() is used. MGPvector offset( const MGLBRep& ofs_value_lb, ///<空間次元1の線B表現で示したオフセット量 const MGVector& norm_vector = mgNULL_VEC ///<法線ベクトル )const; ///C2連続曲線の一定オフセット関数 ///オフセット方向は、法線方向から見て入力曲線の進行方向左側を正とする。 ///法線ベクトルがヌルの場合、始点において曲率中心方向を正とする。ただし、曲率中心へ曲率半径以上のオフセット ///は行わない。トレランスはline_zero()を使用している。戻り値は、オフセット曲線が返却される。 ///costant offset curve of C2 continuous curve. if the norm_vector is given, the positive offset direction ///decide to left hand side from ahead, or the direction to center of curvature at start parameter. ///the offset value is less than radius of curvature. line_zero() is used. MGLBRep offset_c2( double ofs_value, ///<オフセット量 const MGVector& norm_vector = mgNULL_VEC ///<法線ベクトル ) const; ///C2連続曲線の可変オフセット関数 ///オフセット量は空間次元1の線B表現で与えられる。 ///オフセット方向は、法線方向から見て入力曲線の進行方向左側を正とする。 ///法線ベクトルがヌルの場合、始点において曲率中心方向を正とする。ただし、曲率中心へ曲率半径以上のオフセット ///は行わない。トレランスはline_zero()を使用している。戻り値は、オフセット曲線が返却される。 ///valuable offset curveof C2 continuous curve. if the norm_vector is given, the positive offset direction ///decide to left hand side from ahead, or the direction to center of curvature at start parameter. ///the offset value is less than radius of curvature. line_zero() is used. MGLBRep offset_c2( const MGLBRep& ofs_value_lb, ///<空間次元1の線B表現で示したオフセット量 const MGVector& norm_vector = mgNULL_VEC ///<法線ベクトル ) const; ///Test if given point is on the curve or not. If yes, return parameter ///value of the curve. Even if not, return nearest point's parameter. /// 指定点が自身上にあるかを調べる。曲線上にあれば,そのパラメーター値を, /// なくても最近傍点のパラメータ値を返す。 /// Function's return value is >0 if the point is on the curve, /// and 0 if the point is not on the curve. bool on( const MGPosition&, ///=t1) indicates no range specified. const MGPosition& P, ///=s1, no limit for this parameter range. const MGCurve& curve2, ///<2nd curve. double t0, ///=t1, no limit for curve2 parameter range. double sg, ///=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; ///Obtain the projected curve of this onto the surface srf. ///The direction of the projection is along the vector vec if the vec is not ///NULL, and normal to the surface if the vec is NULL. ///Output of 'project' is two kind of curves: ///one is general world coordinate curves('vec_crv'), and the other is (u,v) curves of ///the parameter space of the surfaces(vec_crv_uv). ///vec_crv_uv.size() is equal to vec_crv.size(). Let the size be n, then /// (vec_crv_uv[i], vec_crv[i]) is one pair for 0<=i& vec_crv_uv, ///& vec_crv, /// oneD( const double g[4] ///