MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
Box.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _MGBox_HH_
6 #define _MGBox_HH_
7 
12 #include <vector>
13 #include <assert.h>
14 #include "mg/Interval.h"
15 
16 // MGBox.h
17 // Header for class MGBox.
18 //
19 
20 //Forward Declaration
21 class MGVector;
22 class MGPosition;
23 class MGMatrix;
24 class MGTransf;
25 class MGStraight;
26 class MGPlane;
27 class MGIfstream;
28 class MGOfstream;
29 
31 
34 class MG_DLL_DECLR MGBox{
35 
36 public:
37 
39 MG_DLL_DECLR friend MGBox operator+(const MGVector& v, const MGBox& b);
40 
43 MG_DLL_DECLR friend MGBox operator* (double scale, const MGBox&);
44 
46 MG_DLL_DECLR friend std::ostream& operator<< (std::ostream&, const MGBox&);
47 
49 
51 MGBox(const MGBox& box2);
52 
55 explicit MGBox(int dim=0):m_sdim(0), m_range(0){if(dim) get_area(dim);};
56 
59 MGBox(const MGInterval& xspan, const MGInterval& yspan);
60 
63 MGBox(const MGInterval& xspan, const MGInterval& yspan, const MGInterval& zspan);
64 
68 MGBox(const MGPosition& center, double* size);
69 
73 MGBox(const MGPosition& center, double size=0.);
74 
77 MGBox(const MGPosition&, const MGPosition&);
78 
80 MGBox(const MGBox&, const MGPosition&);
81 
84 MGBox(int dim, const MGInterval*);
85 
89 MGBox(
90  int dim,
91  const MGBox& box,
92  int start1=0,
93  int start2=0
94 );
95 
97 ~MGBox();
98 
100 
102 MGBox& operator= (const MGBox& box2);
103 
105 const MGInterval& operator[](int i) const {return ref(i);}
106 const MGInterval& operator()(int i) const {return ref(i);}
107 
109 MGInterval& operator[](int i){assert(i<sdim());return m_range[i];}
110 MGInterval& operator()(int i){assert(i<sdim());return m_range[i];}
111 
114 MGBox operator+ (const MGVector& v) const;
115 
118 MGBox& operator+= (const MGVector&);
119 
122 MGBox operator- (const MGVector&) const;
123 
126 MGBox& operator-= (const MGVector&);
127 
132 MGBox operator* (double) const;
133 
136 MGBox operator* (const MGMatrix& ) const;
137 
141 MGBox operator* (const MGTransf& ) const;
142 
147 MGBox& operator*= ( double scalar);
148 
151 MGBox& operator*= (const MGMatrix& );
152 
156 MGBox& operator*= (const MGTransf& );
157 
162 MGBox operator/ ( double a) const;
163 
168 MGBox& operator/= ( double );
169 
172 MGBox operator| ( const MGBox& ) const;
173 
177 MGBox& operator|= ( const MGBox& );
178 
181 MGBox operator& ( const MGBox& ) const;
182 
186 MGBox& operator &= ( const MGBox& );
187 
192 bool operator== (const MGBox& box2) const;
193 bool operator!= (const MGBox& box2) const{return !(*this==box2);}
194 
199 bool operator >> (const MGPosition&) const;
200 
205 bool operator>> (const MGBox&) const;
206 
209 bool operator<< (const MGPosition& pt) const{return !((*this)>>pt);}
210 
213 bool operator<< (const MGBox& box2) const{return box2>>(*this);}
214 
216 
220 bool crossing(const MGStraight& sl)const;
221 
225 bool cutting(const MGPlane& plane)const;
226 
228 double distance(const MGPosition& P) const;
229 
231 int dump(MGOfstream& ) const;
232 
234 int dump_size() const;
235 
239 void expand();
240 
246 void expand(double len);
247 
253 void expand(double* len);
254 
256 void expand(const MGPosition& P);
257 
260 bool empty() const;
261 
263 bool finite() const;
264 
269 MGPosition high() const;
270 MGPosition low() const;
271 MGPosition mid() const;
272 
275 bool includes_origin()const;
276 
278 bool includes(const MGPosition& P)const{return operator>>(P);};
279 
281 bool is_null()const{return m_sdim==0;}
282 
285 double len() const;
286 
288 double length()const{return len();};
289 
291 const MGInterval& ref(int i) const;
292 
294 int restore(MGIfstream& );
295 
297 int sdim() const{return m_sdim;};
298 
301 MGBox& set_high(const MGPosition&);
302 
305 MGBox& set_low(const MGPosition&);
306 
308 void set_null();
309 
311 MGINTERVAL_TYPE type(int i) const{
312  if(i>=m_sdim) return MGINTERVAL_EMPTY;
313  return m_range[i].type();
314 }
315 
318 std::vector<MGPosition> vertex() const;
319 
320 private:
322  MGInterval m_rData[3];
323  int m_sdim;
324  MGInterval* m_range;
327 
332 bool crossing2D(const MGStraight& sl)const;
333 
337 void get_area(int dim);
338 
341 void resize(int dim);
342 
343 };
344  // end of BASE group
346 #endif
const MGInterval & operator[](int i) const
Return i-th Inteval.
Definition: Box.h:105
const MGInterval & operator()(int i) const
Definition: Box.h:106
bool includes(const MGPosition &P) const
Test if the point P is included in this box.
Definition: Box.h:278
MGPlane is infinite plane in 3D space.
Definition: Plane.h:38
MGTransf represents a transformation of a space dimension.
Definition: Transf.h:35
double length() const
Return diagonal line length.
Definition: Box.h:288
MGIfstream is a class to read the serialized data generated by MGOfstream.
Definition: Ifstream.h:30
std::ostream & operator<<(std::ostream &ostrm, const MGisect &is)
Debug Function.
Definition: isect.h:95
MGInterval & operator()(int i)
Definition: Box.h:110
MG_DLL_DECLR MGVector & operator*=(MGVector &v, const MGMatrix &m)
Vector of a general n space dimension.
Definition: Vector.h:26
Defines a Box of any space dimendion.
Definition: Box.h:34
int sdim() const
Return space dimension.
Definition: Box.h:297
MGBox(int dim=0)
Definition: Box.h:55
MGStraight is a curve of any space dimension, represent a straight line.
Definition: Straight.h:49
Interval of 1 dimension, i.e. MGInterval is a real line.
Definition: Interval.h:22
MG_DLL_DECLR MGVector operator*(const MGVector &v, const MGMatrix &m)
Represent a positional data.
Definition: Position.h:28
MGINTERVAL_TYPE type(int i) const
Return the type of i-th interval.
Definition: Box.h:311
MGInterval & operator[](int i)
Access to i-th Inteval.
Definition: Box.h:109
MGOfstream is a class to serialize all of the subclasses of MGGel.
Definition: Ofstream.h:31
Empty interval. Interval は空集合
Definition: MGCL.h:118
MGINTERVAL_TYPE
MGInterval type.
Definition: MGCL.h:117
bool is_null() const
Test if this is null box.
Definition: Box.h:281
MGMatrix is a matix of m by m, where m is the space dimension.
Definition: Matrix.h:30