/********************************************************************/ /* Copyright (c) 2017 System fugen G.K. and Yuzi Mizuno */ /* All rights reserved. */ /********************************************************************/ #ifndef _MGBox_HH_ #define _MGBox_HH_ /** @file */ /** @addtogroup BASE * @{ */ #include #include #include "mg/Interval.h" // MGBox.h // Header for class MGBox. // //Forward Declaration class MGVector; class MGPosition; class MGMatrix; class MGTransf; class MGStraight; class MGPlane; class MGIfstream; class MGOfstream; ///Defines a Box of any space dimendion. /// MGBox expresses n-dimensional space range using MGInterval, which is /// one dimension range of double values. All of the MGObject's have box. class MG_DLL_DECLR MGBox{ public: ///box translation. MG_DLL_DECLR friend MGBox operator+(const MGVector& v, const MGBox& b); ///Boxを拡大してできるオブジェクトを生成する. ///Generates a box by scaling. MG_DLL_DECLR friend MGBox operator* (double scale, const MGBox&); ///Print out Debug Function. MG_DLL_DECLR friend std::ostream& operator<< (std::ostream&, const MGBox&); ////////Constructor//////// ///Copy constructor. MGBox(const MGBox& box2); ///Void constructor. ///初期化なしでBoxを生成する。 explicit MGBox(int dim=0):m_sdim(0), m_range(0){if(dim) get_area(dim);}; ///Construct 2D Box, given x and y intervals. ///x,yの各インターバルを指定して2D Boxを生成する。 MGBox(const MGInterval& xspan, const MGInterval& yspan); ///Construct 3D Box, given x, y, and z intervals. ///x,y,zの各インターバルを指定して3D Boxを生成する。 MGBox(const MGInterval& xspan, const MGInterval& yspan, const MGInterval& zspan); ///Construct Box, given center point and sizes of each coordinates. ///中心点と各辺の幅を指定しBoxを生成する。 ///The size's dimension is center.sdim(). MGBox(const MGPosition& center, double* size); ///Construct Box, given center point and a size of each coordinates. ///中心点と幅を指定しBoxを生成する(すべての辺にたいして同一の値)。 ///The size is applied to all the coordinates. MGBox(const MGPosition& center, double size=0.); ///Construct Box, given two points. ///2点からBoxを生成する。 MGBox(const MGPosition&, const MGPosition&); ///Construct Box which contains both input box and a point. MGBox(const MGBox&, const MGPosition&); ///Construct Box by providing each Interval. ///****This is the fundamental constructor.**** MGBox(int dim, const MGInterval*); ///Construct Box by copying old Box, changing space dimension and ///ordering of old coordinates. ///(*this)(start1)=box(start2), and so on. MGBox( int dim, ///> (const MGPosition&) const; ///Returns true if the box includes the second box. ///自身のBoxが与えられたBoxを囲んでいるか返却する。 ///与えられたBoxが自身のBox内にある場合 TRUE を返却する。 ///与えられたBoxがNULL の場合は、FALSE 。 bool operator>> (const MGBox&) const; ///Returns true if the box does not includes the position. ///与えられたポジションが自身のBoxの範囲外にあるかどうか返却する。 bool operator<< (const MGPosition& pt) const{return !((*this)>>pt);} ///Returns true if the box does not include the second box. ///与えられたBoxが自身のBoxを囲んでいるかどうか返却する。 bool operator<< (const MGBox& box2) const{return box2>>(*this);} ////////Member Function//////// ///Test if the straight line sl is crossing this box or not. ///Function's return value is true if a part of sl is included in this box, ///false if not. bool crossing(const MGStraight& sl)const; ///Test if the plane is cutting this box or not. ///Function's return value is true: if the plane is cutting the box, ///false if all of the vertices of the box are in one side of the plane. bool cutting(const MGPlane& plane)const; ///Compute the distance from a point to the box. double distance(const MGPosition& P) const; ///Dump Function. int dump(MGOfstream& ) const; ///Calculate dump size. int dump_size() const; ///Expand the box by MGTolerance::rc_zero(). ///That is, ///operator*=(1.+ MGTolerance::rc_zero() ) will be executed. void expand(); ///Expand the box by len. ///This box will be updated so that the center of ///the box will not be moved and the box is widened by len for each coordinate. ///That is, ref(i).high() is set to ref(i).high()+len ///and ref(i).low() is set to ref(i).low()-len for each i. void expand(double len); ///Expand the box by len[]. ///This box will be updated so that the center of ///the box will not be moved and the box is widened by len[i] ///for each coordinate. That is, ref(i).high() is set to ref(i).high()+len[i] ///and ref(i).low() is set to ref(i).low()-len[i] for each i. void expand(double* len); ///Expand the box so that this contains the position P. void expand(const MGPosition& P); ///Return ture if Box is empty. ///Boxが empty かどうか返却する bool empty() const; ///Return true if box is finite. bool finite() const; ///Return maximum(high), minimum(low), or middle(mid) points of ///the Box. ///Boxの対角線の両端と中心を返却する。全ての座標値が ///最小の点が low () で、最大の点が high () で返却される。 MGPosition high() const; MGPosition low() const; MGPosition mid() const; ///Test if this includes the origin(0., 0., ...). ///原点が自身のBox内に含まれているか返却する。 bool includes_origin()const; ///Test if the point P is included in this box. bool includes(const MGPosition& P)const{return operator>>(P);}; ///Test if this is null box. bool is_null()const{return m_sdim==0;} ///Return diagonal line length. ///ボックスの対角線長さを求める double len() const; ///Return diagonal line length. double length()const{return len();}; ///Reference to i-th Interval. const MGInterval& ref(int i) const; ///Restore Function. int restore(MGIfstream& ); ///Return space dimension. int sdim() const{return m_sdim;}; ///Update maximum coordinate values by input data. ///自身のBoxの最大座標値を指定された点に変更する. MGBox& set_high(const MGPosition&); ///Update minimum coordinate values by input data. ///自身のBoxの最小座標値を指定された点に変更する. MGBox& set_low(const MGPosition&); ///Set this box as a null box. void set_null(); ///Return the type of i-th interval. MGINTERVAL_TYPE type(int i) const{ if(i>=m_sdim) return MGINTERVAL_EMPTY; return m_range[i].type(); } /// vertex computes all the vertices of the box. /// Return array of Position as the vertices. std::vector vertex() const; private: ///Member Data MGInterval m_rData[3]; ///3, newed area will be used. ///Test if the straight line sl is crossing this box or not. ///Function's return value is true if a part of sl is included in this box, ///false if not. 2D version of crossing(). bool crossing2D(const MGStraight& sl)const; ///Get the area of m_range for the space dimension sdim. ///Result area will contain garbages. ///get_area will use m_sdim as input. m_sdim must be valid. void get_area(int dim); ///Resize the m_range. ///If sim> current sdim(), the old data are guaranteed to hold in resized box. void resize(int dim); }; /** @} */ // end of BASE group #endif