MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
openglView.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _mgOpenGLView_HH_
6 #define _mgOpenGLView_HH_
7 
8 class MGBox;
9 class MGGroup;
10 class MGObject;
11 class MGGLAttrib;
12 class MGAttribedGel;
13 class MGGelPositions;
14 class MGStraight;
15 class MGEdge;
16 class mgVBO;
17 
18 #include <afxwin.h>
19 #include <GL/glew.h>
20 #include <list>
21 #include <set>
22 #include <glm/glm.hpp>
23 #include "mg/Types.h"
24 #include "mg/Pvector.h"
25 #include "mg/PickObjects.h"
26 #include "mg/Position.h"
27 #include "mg/Straight.h"
28 #include "mg/Group.h"
29 #include "mgGL/Color.h"
30 #include "mgGL/sysGLList.h"
31 #include "mgGL/glViewAttrib.h"
32 #include "mgGL/ConstructionPlane.h"
33 #include "mgGL/glslprogram.h"
34 
39 
43 class MG_DLL_DECLR MGOpenGLView{
44 
45 friend class MGglViewAttrib;
46 
47 public:
48 
50 
53 
55 
57  bool perspective=true
58 );
59 
62  const MGglViewAttrib& glatr
63 );
64 
65 virtual ~MGOpenGLView();
66 
68 
71 int attach_drawer(
72  mgVBO* drawer
73  ,bool common=true
74 );
76 
78 void detach_drawer(
79  mgVBO* drawer
80  ,bool common=true
81 );
83 
89 void copy(const MGOpenGLView& glview2);
90 
92 void copy(const MGglViewAttrib& glatr);
93 
96 const MGColor& Bcolor()const;
97 const MGColor& Gcolor()const;
98 static const MGColor& Hcolor(){return mgVBOElement::getHilightColor();};
99 
102 //static const MGColor& BcolorDefault(){ return m_BcolorDefault;};
103 //static const MGColor& GcolorDefault(){ return m_GcolorDefault;};
104 //static const MGColor& HcolorDefault(){ return m_HcolorDefault;};
105 
107 const MGPosition& center()const{return m_viewAttrib.center();};
108 
109 const MGConstructionPlane& cplane()const{return m_viewAttrib.cplane();};
110 MGConstructionPlane& cplane(){return m_viewAttrib.cplane();};
111 
114  return m_sysgllist.delete_lists_by_function_code(fc);
115 }
116 
118  return m_sysgllist.delete_lists_by_function_object_code(fc,gel);
119 }
120 
122 double diameter()const{return m_viewAttrib.diameter();};
123 
124 const MGDrawParam& draw_param()const;
125 MGDrawParam& draw_param();
126 
128 int line_density()const{return draw_param().line_desity_wire_face();};
129 
130 void execDefaultStaticAttrib();
131 
135 void drawScene(const MGPickObjects* pobjs=0);
136 
139 void enable_grid_snap(bool bEnabled);
140 
142 const MGPosition& eye_position()const{return m_viewAttrib.eye_position();};
143 
145 void get_model_matrix(
146  glm::mat4& modelMat //double modelMat[16] ///<OpenGL's model matrix
147 )const;
148 
150 void get_projection_matrix(
151  const int vp[4],
152  glm::mat4& projMat //double projMat[16] ///<OpenGL's projection matrix
153 )const;
154 
158 bool get_surface_parameter_glv(
159  const MGFSurface& surf,
160  int sx,
161  int sy,
162  MGPosition& uv
163 )const;
164 
165 //SysGLリストのを取得する
166 mgSysGL* getSysGLByFunctionCode(int fc){return m_sysgllist.getSysGLByFunctionCode(fc);};
167 
169 void get_viewport(
170  glm::ivec4& vp
173 )const;
174 void get_viewport(
175  int vp[4]
178 )const;
179 
181 void get_window(int& width, int& height)const;
182 
184 HDC getHDC() const{return m_hDC;};
185 
187 HGLRC getRC() const{return m_hRC;};
188 
190 MGOpenGLView* get_parent_OpenGLView(){return m_parent_glView;};
191 const MGOpenGLView* get_parent_OpenGLView()const{return m_parent_glView;};
192 bool has_parent_OpenGLView()const{return m_parent_glView!=0;};
193 
195 static MGOpenGLView* getCurrentOpenGLView(){return m_currentGLView;};
196 
198 bool has_display_list()const;
199 
201 void home(){m_viewAttrib.setHomeMatrix();};
202 
204 void import_context(
205  const MGContext& ctx
206 );
207 
210 void importViewAttribFromContext(
211  const MGContext& ctx
212 );
213 
217 void importDrawAttribFromContext(
218  const MGContext& ctx
219 );
220 
223 void importGridAttrib(const MGContext& ctx);
224 
225 //Initialize the viewing environment.
226 //When the eye position is necessary to update, setEyePositionUpVector() must be invoked
227 //before initializeViewingEnvironmentByBox since the current eye position direction is used.
228 //Initialization is done by the parameter box.
229 //initializeViewingEnvironmentByBox updates only the construction plane's (u,v) direction.
230 //The (u,v) direction is (up-vector*eyePosition, up-vector).
231 void initializeViewingEnvironmentByBox(
232  const MGBox& box
233 );
234 
238 void initialize_viewing_environment(
239  const MGPlane& plane,
240  double diameter,
241  bool rotate=false
243 );
246 
247 bool is_enabled_grid_snap()const;
248 
250 bool is_perspective() const{return m_viewAttrib.is_perspective();};
251 
255 MGPosition locate_glv(int x, int y, MGPosition* uv=0)const;
256 
257 void make_construction_plane(
258  const MGPosition& mid,
259  const MGVector& uderi,
260  const MGVector& vderi,
261  double uspan,
262  double vspan,
263  int ulnum,
264  int lnum
265 );
266 
277 void make_display_list(const MGContext& ctx,const MGGroup& grp);
278 
281 void mglTranslate(const glm::vec3& vec);
282 void mglRotate(float angle, const glm::vec3& axis);
283 void mglScale(const glm::vec3& factor);
284 
288 void pan_zoom(int x0, int y0, int x1, int y1);
289 
292 void pan_zoom(const MGBox& box);
293 
299 MGPickObjects pick_glv(
300  const float center[2],
301  float aperturex=-1.,
302  float aperturey=-1.,
303  const MGAbstractGels& objtype=mgAll_Object
306 );
307 
311 int pick_start_end_glv(
312  const MGCurve& curve,
313  int sx,
314  int sy
315 );
316 
321 int pick_perimeter_glv(
322  const MGSurface& surf,
323  int sx,
324  int sy,
325  MGPosition* uv=0,
326  float aperturex=-1.,
327  float aperturey=-1.
328 );
330 
335 const MGEdge* pick_edge_glv(
336  const MGFace& f,
337  int sx,
338  int sy,
339  MGPosition* uv=0,
340  float aperturex=-1.,
341  float aperturey=-1.
342 );
344 
346 float pick_aperture()const;
347 
349 int pick_to_select_buf(
350  const float center[2],
351  const float delta[2],
352  mgVBO* display_list,
353  std::set<unsigned>& selected
354 );
356 
357 
363 void project(
364  const MGPosition& world,
365  MGPosition& screen,
366  const glm::mat4* modelMat=0,
367  const glm::mat4* projlMat=0,
368  const glm::ivec4* vp=0
369 )const;
370 
381 mgSysGL* push_back_to_sysgl(int fc,const MGGel* oi=0){return m_sysgllist.push_back(fc,oi);};
382 mgSysGL* push_front_to_sysgl(int fc,const MGGel* oi=0){return m_sysgllist.push_front(fc,oi);};
383 
387 void push_back_to_sysgl(mgSysGL* sysgl){m_sysgllist.push_back(sysgl);};
388 
393 void rotate(float angle, float x, float y, float z);
394 
398 void rotate(float angle, float vector[3], const MGPosition& center);
399 
406 void rotate(const float angle[2]);
407 
409 void scale(
410  double factor,
411  int* center=0
412 );
414 
415 void set_center(const MGPosition& pos){ m_viewAttrib.set_center(pos);}
416 void set_center_current(int x, int y);
417 
419 void set_line_density(int line_density=1);
420 
421 //Set line density and tessellation parameter of draw_param.
422 void setDrawParam(const MGContext& ctx);
423 
428 void setProjectionMat2GLSL(bool initialize=false);
429 
431 void setModelViewMat2GLSL();
432 
434 void setNdcMat2GLSL();
435 
436 void set_output_dpi(float dpi){m_dpi = dpi;};
437 
438 float get_output_dpi(){return m_dpi;};
439 
440 void setDpiFactor2GLSL();
441 
444  const MGPosition& eyeP,
445  const MGVector& upVector
446 );
447 
449 void set_parent_OpenGLView(MGOpenGLView* parent=0);
450 
452 void setBcolor(const MGColor& color);
453 
454 void set_fovy(double fovy){m_viewAttrib.set_fovy(fovy);};
455 
456 //void set_defalut_colors();
457 
459 void setGcolor(const MGColor& color);
460 
462 static void setHcolor(const MGColor& color){mgVBOElement::setHilightColor(color);};
463 
464 void set_pick_aperture(double pick_aperture);
465 void set_pick_aperture(float pick_aperture);
466 
468 void set_smooth(float smooth);
469 
472 void set_window(int width, int height);
473 
475 void setProjModelViewMat2GLSL();
476 
478 float smooth()const;
479 
481 double span_length()const{return m_viewAttrib.diameter()*double(smooth())*.1;};
482 
484 void translate(double dx, double dy);
485 
487 void translate_without_scale(double dx, double dy);
488 
493 void unproject(
494  int x,
495  int y,
496  MGStraight& sl,
497  MGCSisect& is
498 )const;
500 
504 void unproject_to_sl_glv(int x, int y, MGStraight& sl)const;
505 
507 const MGVector& view_up_vector()const{return m_viewAttrib.view_up_vector();};
508 
510 double view_volume_far()const{return m_viewAttrib.view_volume_far();}
511 
513 double view_volume_height()const{return m_viewAttrib.view_volume_height();}
514 
516 double view_volume_near()const{return m_viewAttrib.view_volume_near();}
517 
518 double get_scale() {return m_viewAttrib.m_scale;};
519 
522 void get_near_position(
523  const MGCurve* crv,
524  const float center[2],
525  double& t
526 );
527 
529 mgVBO* display_list();
530 
533  mgVBO* dlist
534 ){m_display_list=dlist;};
535 
537 void setViewMode(MGCL::VIEWMODE vmode=MGCL::WIRE);
538 
541 void makeRCCurrent()const;
542 
544 void setDCRC(HDC dc, HGLRC rc);
545 
547 void setupDrawEnv(const MGColor& backColor, bool selection=false);
548 
551 void screen_to_world(
552  int wh[2],
553  double sx,
554  double sy,
555  double& wx,
556  double& wy
557 )const;
558 
559 const MGglViewAttrib& viewAttrib()const{return m_viewAttrib;};
560 MGglViewAttrib& viewAttrib(){return m_viewAttrib;};
561 
562 MGCL::VIEWMODE viewMode()const{return m_viewAttrib.viewMode();};
563 
564 protected:
566  int m_width, m_height;//Window's width and height.
567 
570 
577 
579 
580  //for OpenGL State machine
581  HGLRC m_hRC;
582  HDC m_hDC;
583 
586  float m_smooth;
587  float m_pick_aperture;
590 
593 
594  glm::mat4 m_lookAtMat;
595 
598  glm::vec3 m_XAxis_current;
599  glm::vec3 m_center_current;
602 
603  glm::mat4 m_projMat;
604 
605 
606  float m_dpi; // output device independ value;
607 
608 //Highlight pobjs.
609 void highlight(const MGPickObjects* pobjsP);
610 
612 void set_perspective(bool pers,double fovy=45.){
613  m_viewAttrib.set_perspective(pers,fovy);
614 };
615 
616 private:
617 
618  static MGOpenGLView* m_currentGLView;
619  //static MGColor m_BcolorDefault; ///<Default Background color.
620  //static MGColor m_GcolorDefault; ///<Default Object lines color.
621  //static MGColor m_HcolorDefault; ///<Default Object highlight color.
622 
625 std::list<mgVBO*> m_command_drawersCommon;
626 
629 std::list<mgVBO*> m_command_drawersSpecific;
630 
632 void extractSelected(
633  const int viewport[4],
634  std::set<unsigned>& selected
635 );
637 
639 void drawCommandDrawer(
640  std::list<mgVBO*>& drawers
641 );
642 
644 void setLookAtMat();
645 
646 };
647 
648 unsigned OpenGLStartDisplayName();
649 
650 
652  // end of DisplayHandling group
654 #endif
MGCurve is an abstract class which represents a whole curve.
Definition: Curve.h:63
MGPlane is infinite plane in 3D space.
Definition: Plane.h:38
MGGelPosition Container Class.
Definition: GelPositions.h:23
mgSysGL * getSysGLByFunctionCode(int fc)
Definition: openglView.h:166
glm::vec3 m_up_vector_current
Definition: openglView.h:601
MGGLAttrib is an abstract class which defines the enum of undefined or disabled.
Definition: GLAttrib.h:35
const MGPosition & eye_position() const
Get the eye position.
Definition: openglView.h:142
MGOpenGLView * get_parent_OpenGLView()
Set the parent MGOpenGLView.
Definition: openglView.h:190
MGOpenGLView * m_parent_glView
0.
Definition: openglView.h:569
const MGPosition & center() const
return the center of the box of this view.
Definition: glViewAttrib.h:51
HGLRC m_hRC
Rendering context.
Definition: openglView.h:581
void setEyePositionUpVector(const MGPosition &eyeP, const MGVector &upVector)
Set m_eyeP and m_up_vector(the eye position and view-up-vector of the OpenGL).
bool DeleteDisplayList_by_function_object_code(int fc, const MGGel *gel)
Definition: openglView.h:117
glm::mat4 m_lookAtMat
and view_up_vector().
Definition: openglView.h:594
double view_volume_height() const
compute the view volume height.
Definition: openglView.h:513
bool has_parent_OpenGLView() const
Definition: openglView.h:192
void home()
Transform to the home position.
Definition: openglView.h:201
Is a container of MGAbstractGel, to specify what kind of gels are required.
Definition: AbstractGels.h:25
MGCL::VIEWMODE viewMode() const
Definition: openglView.h:562
MGConstructionPlane & cplane()
Definition: openglView.h:110
mgSysGL * push_back(int fc, const MGGel *oi)
static void setHilightColor(const MGColor &hcolor)
Definition: VBOElement.h:100
mgSysGLList m_sysgllist
System display list manager.
Definition: openglView.h:52
friend class MGOpenGLView
Definition: glViewAttrib.h:137
Is an abstract class which represents a whole geometry and a topology.
Definition: Object.h:42
mgSysGL * push_front_to_sysgl(int fc, const MGGel *oi=0)
Definition: openglView.h:382
float get_output_dpi()
Definition: openglView.h:438
const MGOpenGLView * get_parent_OpenGLView() const
Definition: openglView.h:191
Vector of a general n space dimension.
Definition: Vector.h:26
MGColor m_Bcolor
Background color.
Definition: openglView.h:584
static void setHcolor(const MGColor &color)
Set hilight color;.
Definition: openglView.h:462
MGContext defines the attributes of a document.
Definition: Context.h:33
int line_density() const
Return line density for a surface to draw in wire mode.
Definition: openglView.h:128
float m_dpi
Projection matrix to set into uniform.
Definition: openglView.h:606
HDC getHDC() const
Get redering context.
Definition: openglView.h:184
Defines a Box of any space dimendion.
Definition: Box.h:34
MGColor defines the OpenGL color (R,G,B,A).
Definition: Color.h:26
HGLRC getRC() const
Get redering context.
Definition: openglView.h:187
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
const MGglViewAttrib & viewAttrib() const
Definition: openglView.h:559
const MGVector & view_up_vector() const
Get the view up vector.
Definition: openglView.h:507
MGGel is an abstract class which represents a group element.
Definition: Gel.h:53
glm::vec3 m_XAxis_current
the current unprojected straight line of the input cursor is set.
Definition: openglView.h:598
MGEdge is an instance of MGCellNB, represents a boundary element of 2D manifold.
Definition: Edge.h:33
static const MGColor & getHilightColor()
Definition: VBOElement.h:101
void set_fovy(double fovy)
Definition: openglView.h:454
MGStraight is a curve of any space dimension, represent a straight line.
Definition: Straight.h:49
mgVBO * m_display_list
Definition: openglView.h:576
Is an abstract class which provides interfaces of MGGel that has MGAppearance.
Definition: AttribedGel.h:32
One Intersection of curve and surface.
Definition: CSisect.h:26
double diameter() const
Obtainthe the diameter of the sphere that surround the whole model.
Definition: glViewAttrib.h:65
Represent a positional data.
Definition: Position.h:28
MGSurface is an abstract class of 3D surface.
Definition: Surface.h:54
void push_back_to_sysgl(mgSysGL *sysgl)
Definition: openglView.h:387
MGglViewAttrib m_viewAttrib
Attributes that are saved to .mgl file.
Definition: openglView.h:592
MG_DLL_DECLR const MGAbstractGel mgAll_Object
void set_display_list(mgVBO *dlist)
Update display list name that shows all of the objects in this view.
Definition: openglView.h:532
glm::mat4 m_projMat
Definition: openglView.h:603
Defines OpenGL display class for MGCL objects.
Definition: openglView.h:43
VIEWMODE
Definition: MGCL.h:271
double span_length() const
Get the draw span length(approximate line segment length to draw curves).
Definition: openglView.h:481
const MGPosition & center() const
return the center of the box of this view.
Definition: openglView.h:107
Defines a list of mgSysGL.
Definition: sysGLList.h:33
MGFSurface is an abstract class to provide the comman interfaces to MGFace and MGSurface.
Definition: FSurface.h:33
HDC m_hDC
Device Context.
Definition: openglView.h:582
MGColor m_Gcolor
Object lines color.
Definition: openglView.h:585
void set_perspective(bool pers, double fovy=45.)
Set if this view is a perspective view(true), or orthnormal view(falsle).
double view_volume_far() const
compute the view volume far.
Definition: openglView.h:510
float m_smooth
Definition: openglView.h:586
double view_volume_near() const
compute the view volume near.
Definition: openglView.h:516
mgSysGL * push_back_to_sysgl(int fc, const MGGel *oi=0)
Definition: openglView.h:381
MGglViewAttrib is a class to serialize MGOpenGLView.
Definition: glViewAttrib.h:27
MGGroup is a class which constains MGGel elements.
Definition: Group.h:35
bool delete_lists_by_function_object_code(int fc, const MGGel *gel)
mgSysGL * push_front(int fc, const MGGel *oi)
a container class for MGPickObject.
Definition: PickObjects.h:29
void set_output_dpi(float dpi)
Definition: openglView.h:436
unsigned OpenGLStartDisplayName()
MGglViewAttrib & viewAttrib()
Definition: openglView.h:560
mgSysGL is a class to provide a facility to draw temporal pictures.
Definition: sysGL.h:26
mgSysGL * getSysGLByFunctionCode(int fc)
double get_scale()
Definition: openglView.h:518
bool DeleteDisplayList_by_function(int fc)
delete system display list by the function code.
Definition: openglView.h:113
static const MGColor & Hcolor()
Definition: openglView.h:98
OpenGL 4 用描画のためのクラス, in other words, display list.
Definition: VBO.h:76
MGConstructionPlane defines a construction plane ton input 3D data.
Definition: ConstructionPlane.h:33
void set_perspective(bool pers, double fovy=45.)
Set if this view is a perspective view(true), or orthnormal view(false).
Definition: openglView.h:612
static MGOpenGLView * getCurrentOpenGLView()
Get the current active MGOpenGLView.
Definition: openglView.h:195
bool is_perspective() const
Return if this is a perspective view or not.
Definition: openglView.h:250
const MGConstructionPlane & cplane() const
Definition: openglView.h:109
double diameter() const
Obtainthe the diameter of the sphere that surround the whole model.
Definition: openglView.h:122
bool delete_lists_by_function_code(int fc)
void copy(const MGOpenGLView &glview)
~MGglViewAttrib();
void set_center(const MGPosition &pos)
Definition: openglView.h:415
wire frame mode
Definition: MGCL.h:273