FaceTracker2
OpenGLWndFaceTracker.h
1 #if !defined(AFX_OPENGLWND_H__83310F64_5D53_44AE_9D08_E29D6A961D6F__INCLUDED_)
2 #define AFX_OPENGLWND_H__83310F64_5D53_44AE_9D08_E29D6A961D6F__INCLUDED_
3 
4 #if _MSC_VER > 1000
5 #pragma once
6 #endif // _MSC_VER > 1000
7 // OpenGLWndFaceTracker.h : header file
8 //
9 
10 #ifndef NOMINMAX
11 #define NOMINMAX
12 #endif /* !NOMINMAX */
13 
14 #include <windows.h> // Header File For Windows
15 #include <gl\gl.h>
16 #include <gl\glaux.h>
17 
18 #include "visageVision.h"
19 
20 #include <cv.h>
21 #include "highgui.h"
22 
23 class CExample3Doc;
24 
25 
26 using namespace VisageSDK;
27 
28 
29 /** The OpenGL-enabled window with rendering and basic interaction.
30 * This class provides OpenGL context that is needed to visualize tracking results obtained from VisageTracker through FaceData.
31 */
32 class COpenGLWnd : public CView
33 {
34 public:
35 
36  bool DrawBackgroundImage();
37  bool DrawInstructionsAndInitStatus(bool face_detected,float yaw);
38  int LoadTexture(char *fullPath);
39 
40 
41  /** Implementation of a virtual function from VisageSDK::TrackerGUIInterface.
42  *
43  * VisageTracker calls this function when it needs to display a simple
44  * text prompt to the user. The function displays the message and
45  * lets the user click "OK" to continue. Essentially it is
46  * the same as Windows MessageBox function. Indeed, this implementation
47  * simply calls the Windows MessageBox function.
48  *
49  * @param userMessage message to be displayed
50  * @param caption the caption to be displayed on the message window
51  * @param type type of message
52  */
53  void displayMessage(char *userMessage,char *caption,int type);
54 
55  /** This function is called by method displayResults when it needs to clear the OpenGL
56  * window and set the OpenGL context. The function sets to OpenGL context
57  * to a context dedicated to the tracker, then clears the window.
58  *
59  */
60  void setOpenGLContext();
61 
62  /** This function is called by method displayResults when it needs to swap
63  * OpenGL buffers. The function calls the OpenGL commands to swap buffers.
64  */
65  void swapOpenGLBuffers();
66 
67  /* Implementation of a virtual function from VisageSDK::TrackerOpenGLInterface.
68  *
69  * VisageTracker calls this function to verify the window size
70  * of the OpenGL context. It passes the requested size to
71  * this function. The function must return the actual size of the
72  * window.
73  *
74  * If the actual size is smaller than the requested size, a warining is issued
75  * to the user. The tracker will then use the smaller
76  * window but this may result in degradation of tracking performance.
77  *
78  * An improved implementation of this function may attempt to increase the window to the requested size.
79  *
80  * @param width input: requested window width, output: actual window width
81  * @param height input: requested window height, output: actual window height
82  */
83  void checkOpenGLSize(unsigned int &width, unsigned int &height);
84 
85 protected:
86 
87  // ID's to identify callbacks on timers.
88  enum ID_TIMER_EVENTS {
89  ID_ROTATE = 1,
90  ID_RENDERING = 2 };
91 
92  static const int mTIMER_ROTATE_INTERVAL;
93  static const int mTIMER_RENDERING_INTERVAL;
94 
95  PIXELFORMATDESCRIPTOR pfdMain;
96 
97  bool rendererBusy;
98 
99  // needed for background image drawing
100  GLuint bgtexture[1];
101 
102  // needed for instructions image drawing
103  GLuint insttexture[1];
104 
105 
106  // -------------------------------------------------
107  // VisualC++ added code below
108  // -------------------------------------------------
109 
110 protected:
111  COpenGLWnd(); // protected constructor used by dynamic creation
112  DECLARE_DYNCREATE(COpenGLWnd)
113 
114 // Attributes
115 public:
116  // void (*m_RenderScene) ( CViewerDoc* doc ); // void function pointer to the rendering
117  // function. Used to change to easily
118  // change what a viewport displays.
119 protected:
120  /** Rendering context for drawing the 3D model.
121  * It is mapped to a viewport in the lower right corner of the main window.
122  *
123  */
124  HGLRC m_hRC; //Rendering Context
125  /** Rendering context for tracking.
126  * It is mapped to a viewport that takes the majority of the main window.
127  *
128  */
129  HGLRC m_hRC1; //Rendering Context
130  CDC* m_pDC; //Device Context
131 
132  // HDC m_hDC;
133 
134 // Operations
135 public:
136  bool m_bSwap;
137  // OpenGL init stuff
138  BOOL SetupPixelFormat();
139  BOOL InitOpenGL();
140 
141  // Each viewport uses its own context
142  // so we need to make sure the correct
143  // context is set whenever we make an
144  // OpenGL command. Here we also clear the screen.
145  void SetContext();
146  void SwapGLBuffers();
147 
148  bool trackerActive; // set to true while tracking to disable OpenGL calls that would disturb the tracker
149 
150 // Overrides
151  // ClassWizard generated virtual function overrides
152  //{{AFX_VIRTUAL(COpenGLWnd)
153  public:
154  protected:
155  virtual void OnDraw(CDC* pDC); // overridden to draw this view
156  virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
157  //}}AFX_VIRTUAL
158 
159 // Implementation
160 protected:
161  virtual ~COpenGLWnd();
162 
163 #ifdef _DEBUG
164  virtual void AssertValid() const;
165  virtual void Dump(CDumpContext& dc) const;
166 #endif
167 
168  // Generated message map functions
169 protected:
170  //{{AFX_MSG(COpenGLWnd)
171  afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
172  afx_msg BOOL OnEraseBkgnd(CDC* pDC);
173  afx_msg void OnSize(UINT nType, int cx, int cy);
174  //}}AFX_MSG
175  DECLARE_MESSAGE_MAP()
176 private:
177  bool m_bShowPopup;
178  bool m_bTimerSet;
179 
180 
181 private:
182  int var;
183  int tmp;
184  bool side;
185 
186 
187  /**
188  * Initialise.
189  * Initialise the renderer with a VRMLModel to render. Standard rendering mode is set.
190  * The view is set such that the model is fully visible on screen.
191  *
192  * This function can be called several times with different
193  * models in case more than one model is rendered. Up to 1000 models are supported.
194  */
195 public:
196 
197  /**
198  * Resize window.
199  * Resize And Initialize The GL Window.
200  * @param width the width of the window.
201  * @param height the height of the window.
202  */
203  void ReSizeGLScene(GLsizei width, GLsizei height);
204 
205  /**
206  * Render the model to screen.
207  * Render the loaded model to screen. If no model is loaded, clears the screen.
208  */
209  void RenderToScreen();
210 
211  /**
212  * Closes down and resets renderer.
213  * Call this before Initing next model.
214  */
215  void Close();
216 
217  /**
218  * Frame rate. Calculated based on the last 50 rendered frames.
219  */
220  float renderingFrameRate;
221 
222  GLsizei mWindowWidth, mWindowHeight;
223 
224  /**
225  * Critical section. Used for thread synchronization during rendering.
226  */
227  CRITICAL_SECTION RenderingSection;
228 
229 private:
230  // Current translationvalues.
231  GLfloat mXTranslate, mYTranslate, mZTranslate;
232 
233  // modelViewMatrix set by the user, if any
234  GLfloat *modelViewMatrix;
235 
236  GLfloat mXAccel, mYAccel, mZAccel, Accel;
237 
238  GLfloat mXRotAngle;
239  GLfloat mYRotAngle;
240 
241  GLfloat mMaxRadius;
242 
243  double mVGLR_PERSPECT_FOVY;
244  double mVGLR_PERSPECT_TAN_FOVY;
245  double mVGLR_PERSPECT_NEAR_PLANE;
246 
247  GLfloat mFarPlane;
248 
249  // Backface culling.
250  bool mBackfaceCull;
251 private:
252  float *faceShape;
253 
254 private:
255  float* faceScale;
256 private:
257  float* faceTranslation;
258 
259 private:
260  float* faceRotation;
261 
262 
263 private:
264  bool otvoren_dialog;
265 
266 public:
267  int zatvoren_dialog;
268 private:
269  int nRet;
270  float width;
271  float height;
272  float image_width;
273  float image_height;
274  float widthRight;
275  float widthLeft;
276  float point_x;
277  float imageTop;
278  float imageBottom;
279  float point_y;
280  float centarX;
281  float centarY;
282 
283  VisageTracker *vt2;
284 };
285 
286 /////////////////////////////////////////////////////////////////////////////
287 
288 //{{AFX_INSERT_LOCATION}}
289 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
290 
291 #endif // !defined(AFX_OPENGLWND_H__83310F64_5D53_44AE_9D08_E29D6A961D6F__INCLUDED_)
HGLRC m_hRC1
Rendering context for tracking.
HGLRC m_hRC
Rendering context for drawing the 3D model.
The OpenGL-enabled window with rendering and basic interaction.