MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
MGStl.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _MGStl_HH_
6 #define _MGStl_HH_
7 
8 #include <map>
9 #include "mg/drawParam.h"
10 #include "mg/object.h"
11 #include "mg/Curve.h"
12 #include "mg/Surface.h"
13 #include "mg/FSurface.h"
14 #include "topo/Face.h"
15 #include "topo/Shell.h"
16 
17 class mgTL2Triangles;
18 class mgVBO;
19 
24 //Define MGStl Class.
25 
27 
34 class MG_DLL_DECLR MGStl : public MGObject{
35 
38  class vertId{
39  public:
40  int id1;
41  int id2;
42  int id3;
43  };
44 
46  class positionComp{
47  public:
48  bool operator()(const MGPosition& p1, const MGPosition& p2) const{
50  if(p1(0) < p2(0)){
51  return true;
52  }else if(p2(0) < p1(0)){
53  return false;
54  }
55  if(p1(1) < p2(1)){
56  return true;
57  }else if(p2(1) < p1(1)){
58  return false;
59  }
60  if(p1(2) < p2(2)){
61  return true;
62  }else if(p2(2) < p1(2)){
63  return false;
64  }
66  return false;
67  }
68  };
69 
71  typedef std::map<MGPosition, int, positionComp> triangleMap;
72 
74  typedef std::map<int, MGPosition> IndexPosMap;
75 
77  typedef std::map<int, vertId> TriVertMap;
78 
79 public:
81  MGStl(void){;};
82 
84  MGStl(const MGStl& stl);
85 
87  MGStl(
88  const mgTL2Triangles& tris
89  );
90 
91  MGStl(
92  double error,
93  const mgTL2Triangles& tris
94  );
95 
97  MGStl(const std::vector<mgTL2Triangles>& tlDataVector);
98 
102  MGStl(
103  int nTriang,
104  const int* triang,
105  const double* verts
107  );
110 
114  MGStl(
115  const std::vector<MGPosition>& vertices,
116  const std::vector<int>& indices
119  );
121 
123  ~MGStl(void);
124 
126  MGStl& operator+=(const MGVector& v);
127 
129  MGStl& operator-=(const MGVector& v);
130 
132  MGStl& operator*=(double scale);
133 
135  MGStl& operator*=(const MGMatrix& mat);
136 
138  MGStl& operator*=(const MGTransf& tr);
139 
141  bool operator==(const MGStl& stl);
142 
144  MGStl& operator=(const MGStl& stl);
145 
146  std::ostream& out(std::ostream& ostrm)const;
147 
150  const MGBox& box()const;
151 
154  MGStl* clone()const;
155 
157  long identify_type()const;
158 
161  void drawWire(
162  mgVBO& vbo,
163  double span_length,
164  int line_density=1
165  )const;
166 
170  void draw3DVertex(
171  mgVBO& vbo
172  )const;
173 
175  void shade(
176  mgVBO& vbo,
177  const MGDrawParam& para,
179  )const;
180 
183  MGisects intersection(const MGObject& obj2)const{return MGisects(this,&obj2);};
184  MGisects intersection(const MGCurve& obj2)const{return MGisects(this,&obj2);};
185  MGisects intersection(const MGFSurface& obj2)const{return MGisects(this,obj2.object_pointer());};
186  MGisects intersection(const MGSurface& obj2)const{return MGisects(this,&obj2);};
187  MGisects intersection(const MGFace& obj2)const{return MGisects(this,&obj2);};
188  MGisects intersection(const MGShell& obj2)const{return MGisects(this,&obj2);};
189 
191  int manifold_dimension()const{return 2;};
192 
194  void WriteMembers(MGOfstream& buf)const;
195 
197  void ReadMembers(MGIfstream& buf);
198 
200  const std::vector<MGPosition>& positions()const{return m_vecPos;};
201  std::vector<MGPosition>& positions(){return m_vecPos;};
202 
204  const std::vector<MGUnit_vector>& normals()const{return m_vecNormlTriang;};
205  std::vector<MGUnit_vector>& normals(){return m_vecNormlTriang;};
206 
209  int GetTriangleCount()const{return int(m_vecNormlTriang.size());};
210 
212  void GetVertIndices(
213  int i,
214  int pos[3]
215  )const;
216 
223  int LoadFile(
224  const TCHAR* strFilePath
225  );
226 
231  int SaveAscii(
232  std::ofstream& fout
233  )const;
234 
240  int SaveBinary(
241  const TCHAR* rSTLFilePath
242  )const;
243 
244 // 3点から作成した三角形の情報をメンバ変数に値を設定する
245 // 事前条件:入力するpos1, pos2, pos3は反時計回りになっていること
246 // 事後条件:m_vecPos, m_vecNormlTriang, m_indicesに三角形の情報が設定される
247 // まず、入力された3点から面の法線を求め、m_vecNormlTriangへpush_backする
248 // 次に、指定した頂点の座標が既に保存されているか調べ
249 // 保存されている場合は、該当する頂点のインデックスを受け取る
250 // これをm_indicesへpush_backする
251 // 保存されていない場合は、頂点をm_vecPosへpush_backし
252 // 次にインデックスを+1し、それを受け取りm_indicesにpush_backする
253  void push_back_triangle(
254  const MGPosition& pos1,
255  const MGPosition& pos2,
256  const MGPosition& pos3,
257  triangleMap& VertexMap
258  );
259 
261  void display_arrows(mgSysGL& sgl)const;
262 
264  void set_all_data(
265  const std::vector<MGPosition>& vertices,
266  const std::vector<int>& indices);
267 
269  void update_bounds();
270 
272  void update_normals();
273 
275  std::string whoami()const{return "Stl";};
276 
281  int SaveObjFormatFromStl(std::ofstream& fout)const;
282 
283 private:
286  void Initialize();
287 
290  void push_back_Position(
291  const MGPosition& pos
292  );
293 
298  void add_indices_and_calc_normal(
299  const int vertId[3],
300  int triIndex
301  );
303 
311  int LoadAscii(
312  std::ifstream& in,
313  std::vector<MGPosition>& vecPos
314  );
315 
323  int LoadBinary(
324  std::ifstream& in,
325  std::vector<MGPosition>& vecPos
326  );
327 
334  void set_mesh_data(
335  const std::vector<MGPosition>& vecPos
336  );
337 
342  int IdentifyPosition(
343  const MGPosition& position,
344  triangleMap& VertexMap
345  );
346 
348  void AddTL2Data(
349  const mgTL2Triangles& tris,
350  triangleMap& VertexMap
351  );
352 
354  void AddTL2Data(
355  double error,
356  const mgTL2Triangles& tris,
357  triangleMap& VertexMap
358  );
359 
360 
361 
363 
365  mutable MGBox m_box;
366 
369  std::vector<MGPosition> m_vecPos;
370 
376  std::vector<MGUnit_vector> m_vecNormlTriang;
377 
384  std::vector<int> m_indices;
385 };
386  // end of MGObjectRelated group
388 
389 #endif
MGStl(void)
デフォルトコンストラクタ
Definition: MGStl.h:81
const std::vector< MGUnit_vector > & normals() const
return the ref to m_vecPos.
Definition: MGStl.h:204
std::string whoami() const
オブジェクト名を返却する.
Definition: MGStl.h:275
MGCurve is an abstract class which represents a whole curve.
Definition: Curve.h:63
MGTransf represents a transformation of a space dimension.
Definition: Transf.h:35
virtual const MGObject * object_pointer() const =0
Get the object point of this MGFSurface.
MGisects intersection(const MGObject &obj2) const
Definition: MGStl.h:183
std::vector< MGPosition > & positions()
Definition: MGStl.h:201
virtual long identify_type() const =0
Return This object's typeID.
A vector of mgTL2Triangle's.
Definition: TL2Triangles.h:25
MGisects intersection(const MGShell &obj2) const
Definition: MGStl.h:188
const std::vector< MGPosition > & positions() const
return the ref to m_vecPos.
Definition: MGStl.h:200
MGisects intersection(const MGFSurface &obj2) const
Definition: MGStl.h:185
MGisects intersection(const MGCurve &obj2) const
Definition: MGStl.h:184
MGIfstream is a class to read the serialized data generated by MGOfstream.
Definition: Ifstream.h:30
virtual void drawWire(mgVBO &vbo, double span_length, int line_density=1) const =0
virtual void WriteMembers(MGOfstream &buf) const
Write all member data.
Definition: VBO.h:86
Is an abstract class which represents a whole geometry and a topology.
Definition: Object.h:42
MGShell is a composition of MGFace's(trimmed surface).
Definition: Shell.h:32
Vector of a general n space dimension.
Definition: Vector.h:26
int manifold_dimension() const
Get manifold dimension.
Definition: MGStl.h:191
Defines a Box of any space dimendion.
Definition: Box.h:34
Defines parameters to draw MGObject, maily to approximate by lines and facets.
Definition: drawParam.h:53
MGFace is a trimmed surface.
Definition: Face.h:51
MGisects intersection(const MGSurface &obj2) const
Definition: MGStl.h:186
virtual MGObject * clone() const =0
Represent a positional data.
Definition: Position.h:28
MGSurface is an abstract class of 3D surface.
Definition: Surface.h:54
ELEMENT_TARGET
Definition: VBO.h:84
int GetTriangleCount() const
Definition: MGStl.h:209
virtual void ReadMembers(MGIfstream &buf)
general transformation.
virtual MGObject & operator-=(const MGVector &v)=0
MGFSurface is an abstract class to provide the comman interfaces to MGFace and MGSurface.
Definition: FSurface.h:33
MGStl is a concrete class which represents an STL information.
Definition: MGStl.h:34
MGOfstream is a class to serialize all of the subclasses of MGGel.
Definition: Ofstream.h:31
std::vector< MGUnit_vector > & normals()
Definition: MGStl.h:205
virtual void shade(mgVBO &vbo, const MGDrawParam &para, mgVBO::ELEMENT_TARGET target=mgVBO::SHADING) const
Shade the object in world coordinates.
Definition: Object.h:101
virtual std::ostream & out(std::ostream &) const
Output virtual function.
virtual void draw3DVertex(mgVBO &vbo) const =0
virtual const MGBox & box() const =0
Get the box of the object.
MGisects defines a vector of MGisect.
Definition: isects.h:44
virtual MGObject & operator+=(const MGVector &v)=0
Object transformation.
virtual MGObject & operator*=(double scale)=0
virtual bool operator==(const MGGel &gel2) const
Comparison.
Definition: Gel.h:80
mgSysGL is a class to provide a facility to draw temporal pictures.
Definition: sysGL.h:26
OpenGL 4 用描画のためのクラス, in other words, display list.
Definition: VBO.h:76
virtual MGObject & operator=(const MGObject &obj2)
Definition: Object.h:60
MGisects intersection(const MGFace &obj2) const
Definition: MGStl.h:187
virtual void display_arrows(mgSysGL &sgl) const
Definition: Gel.h:192
MGMatrix is a matix of m by m, where m is the space dimension.
Definition: Matrix.h:30