Ludobooz  | Code :
 - /*******************************************************************************************************************************/
 - /*                                               Classe 3D                                                                     */
 - /*                                                                                                                             */
 - /* Cette classe permet de visualiser le volume constitué par une pile d'image. Elle offre également la possibilité d'afficher  */
 - /* les coupes X-Z et Y-Z à partir d'un point donné.                                                                            */
 - /*                                                                                                                             */
 - /*******************************************************************************************************************************/
 - #include "stdafx.h"
 - #include "Deblurring.h"
 - #include "Anim3D.h"
 - #include "AVIGenerator.h"
 - #ifdef _DEBUG
 - #define new DEBUG_NEW
 - #undef THIS_FILE
 - static char THIS_FILE[] = __FILE__;
 - #endif
 - #define PI 3.14159265358979
 - #define INITIAL 0
 - #define CURRENT 1
 - #define TOP 0
 - #define BOTTOM 1
 - #define LEFT 2
 - #define RIGHT 3
 - BOOL Anim3D::OnInitDialog()
 - {
 - 	CDialog::OnInitDialog();
 - 	SetIcon(m_hIcon, TRUE);
 - 	SetIcon(m_hIcon, FALSE);
 - 	/*Mise en place de la fenêtre*/
 - 	dispositionScene();
 - 	/*----Initialisation de la fenêtre OpenGl---*/
 - 	m_init = TRUE;
 - 	CWnd * cwnd = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
 - 	m_hgldc = ::GetDC(cwnd->m_hWnd);
 -     if(!SetPixelformat(m_hgldc))
 -     {
 -   ::MessageBox(::GetFocus(),"SetPixelformat Failed!","Error",MB_OK);
 -   return -1;
 -     }
 -     m_hglRC = wglCreateContext(m_hgldc);
 -     wglMakeCurrent(m_hgldc,m_hglRC);
 - 	InitGL();
 - 	CRect rect;
 - 	cwnd->GetWindowRect(&rect);
 - 	ReSizeGLScene(rect.Width(), rect.Height());
 - 	/*------- Initialisation des variables ------*/
 - 	m_stack.m_seuil = m_seuil;
 - 	m_stack.m_fileStack = this->m_fileList;
 - 	m_stack.m_nbFile = this->m_nbFile;
 - 	m_stack.m_ir = this->m_ir;
 - 	m_stack.m_Na = this->m_Na;
 - 	m_stack.m_lambda = this->m_lambda;
 - 	m_stack.m_progressBar = m_progressBar;
 - 	m_stack.loadImages();
 - 	m_stack.makeScene(0);
 - 	m_stack.makeScene(1);
 - 	m_imgWidth = m_stack.m_width;
 - 	m_imgHeight = m_stack.m_height;
 - 	initCamera();
 - 	/*------- Gestion des boutons outils --------*/
 - 	m_button_coupe.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_COUPE));
 - 	m_button_camera.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_INIT_VUE));
 - 	m_button_avi.SetIcon(AfxGetApp()->LoadIcon(IDI_ICON_CAMERA));
 - 	CString s ;
 - 	{
 -   /* Create the ToolTip control.*/
 -   m_tooltip.Create(this);
 -   m_tooltip.Activate(TRUE);
 -   m_button_coupe.GetWindowText(s);
 -   m_tooltip.AddTool((CWnd *)&m_button_coupe, s);
 -   m_button_camera.GetWindowText(s);
 -   m_tooltip.AddTool((CWnd *)&m_button_camera, s);
 -   m_button_avi.GetWindowText(s);
 -   m_tooltip.AddTool((CWnd *)&m_button_avi, s);
 - 	}
 - 	return TRUE;
 - }
 - void Anim3D::OnDestroy()
 - {
 - 	CDialog::OnDestroy();
 - 	wglMakeCurrent(NULL,NULL);
 -     wglDeleteContext(m_hglRC);
 - 	wglDeleteContext(m_hglRC_YZ);
 - 	wglDeleteContext(m_hglRC_XZ);
 - }
 - void Anim3D::OnLButtonDown(UINT nFlags, CPoint point)
 - {
 - 	m_oldX = point.x;
 - 	m_oldY = point.y;
 - 	if(IsDlgButtonChecked(IDC_CHECK_COUPE))
 - 	{
 -   CRect rect_frame;
 -   CWnd * cwnd_frame = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
 -   cwnd_frame->GetWindowRect(&rect_frame);
 -   ScreenToClient(&rect_frame);
 -   double proj[16],model[16];
 -   int view[4];
 -   double coordx, coordy, coordz;
 -   glGetDoublev(GL_MODELVIEW_MATRIX,model);
 -   glGetDoublev(GL_PROJECTION_MATRIX,proj);
 -   glGetIntegerv(GL_VIEWPORT,view);
 -   gluUnProject(point.x-rect_frame.left , point.y-rect_frame.top, 0.0, model, proj, view, &coordx, &coordy, &coordz);
 -   drawCoupeYZ((int)coordx, (int)-coordy);
 -   drawCoupeXZ((int)coordx, (int)-coordy);
 -   wglMakeCurrent(m_hgldc,m_hglRC);
 - 	}
 - 	CDialog::OnLButtonDown(nFlags, point);
 - }
 - void Anim3D::OnMouseMove(UINT nFlags, CPoint point)
 - {
 - 	if(!IsDlgButtonChecked(IDC_CHECK_COUPE))
 - 	{
 -   if((nFlags == MK_LBUTTON)||(nFlags == MK_RBUTTON))
 -   {
 -   	if( (nFlags == MK_LBUTTON) )
 -   	{
 -     m_angleX = m_angleX + 0.5*(point.y - m_oldY);
 -     m_angleY = m_angleY + 0.5*(point.x - m_oldX);
 -   	}
 -   	if(nFlags == MK_RBUTTON)
 -   	{
 -     if(point.y<m_oldY)
 -     	m_tz+=20;
 -     else
 -     	m_tz-=20;
 -   	}
 -   	m_oldX = point.x;
 -   	m_oldY = point.y;
 -   	PosEye(m_rx,m_ry,m_tz);
 -   	DrawGLScenePerspective();
 -   }
 - 	}
 - 	else
 - 	{
 -   drawAxesCoupe(point);
 - 	}
 - }
 - BOOL Anim3D::SetPixelformat(HDC hdc)
 - {
 -     PIXELFORMATDESCRIPTOR *ppfd;
 -     int pixelformat;
 -     PIXELFORMATDESCRIPTOR pfd =
 - 	{
 -   sizeof(PIXELFORMATDESCRIPTOR),  //  size of this pfd  
 -   1,                     // version number  
 -   PFD_DRAW_TO_WINDOW |   // support window  
 -   PFD_SUPPORT_OPENGL |   // support OpenGL  
 -   PFD_GENERIC_FORMAT |
 -   PFD_DOUBLEBUFFER,      // double buffered  
 -   PFD_TYPE_RGBA,         // RGBA type  
 -   32,                    // 24-bit color depth  
 -   0, 0, 0, 0, 0, 0,      // color bits ignored  
 -   8,                     // no alpha buffer  
 -   0,                     // shift bit ignored  
 -   8,                     // no accumulation buffer  
 -   0, 0, 0, 0,            // accum bits ignored  
 -   64,                    // 32-bit z-buffer  
 -   8,                     // no stencil buffer  
 -   8,                     // no auxiliary buffer  
 - 	    PFD_MAIN_PLANE,        // main layer  
 -   0,                     // reserved  
 -   0, 0, 0                // layer masks ignored  
 -     };
 -  
 -     ppfd = &pfd;
 -     if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
 -     {
 -         ::MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
 -         return FALSE;
 -     }
 -     if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
 -     {
 -         ::MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
 -         return FALSE;
 -     }
 -     return TRUE;
 - }
 - GLvoid Anim3D::ReSizeGLScene(GLsizei width, GLsizei height)	// Resize And Initialize The GL Window
 - {
 - 	glViewport(0,0,width,height);      // Reset The Current Viewport
 - }
 - int Anim3D::InitGL(GLvoid)
 - {
 - 	glShadeModel(GL_SMOOTH);      	// Enable Smooth Shading
 - 	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
 - 	glClearDepth(1.0f);        	// Depth Buffer Setup
 - 	glEnable(GL_DEPTH_TEST);      	// Enables Depth Testing
 - 	return TRUE;          // Initialization Went OK
 - }
 - void Anim3D::initCamera()
 - {
 - 	m_rx = -90;
 - 	m_ry = 90;
 - 	m_tz = 1700;
 - 	PosEye(m_rx,m_ry,m_tz);
 - 	m_angleX = m_angleY = m_angleZ = 0;
 - }
 - void Anim3D::PosEye(double teta,double phi,double T)
 - {
 - 	m_xe = T*sin(phi*PI/180)*cos(-teta*PI/180);
 - 	m_ye = T*cos(phi*PI/180);
 - 	m_ze = T*sin(phi*PI/180)*sin(-teta*PI/180);
 - }
 - int Anim3D::DrawGLScenePerspective(GLvoid)
 - {
 - 	CRect rect_frame;
 - 	CWnd * cwnd_frame = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
 - 	cwnd_frame->GetClientRect(&rect_frame);
 - 	glMatrixMode(GL_PROJECTION);
 - 	glLoadIdentity();
 - 	gluPerspective(	45.0, /*rect_frame.Width()/rect_frame.Height()*/ m_imgWidth/m_imgHeight, 1, 10000.0);
 - 	glMatrixMode(GL_MODELVIEW);
 - 	glLoadIdentity();
 - 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 - 	gluLookAt(m_xe,m_ye,m_ze,
 -         0.0,0.0,0.0,
 -   	  0.0,1.0,0.0);
 - 	glRotatef(m_angleX,1,0,0);
 - 	glRotatef(m_angleY,0,1,0);
 - 	glRotatef(m_angleZ,0,0,1);
 - 	m_stack.sceneDisplay(0);
 - 	SwapBuffers(m_hgldc);
 - 	return TRUE;
 - }
 - int Anim3D::DrawGLSceneOrtho(GLvoid)
 - {
 - 	glMatrixMode(GL_PROJECTION);
 - 	glLoadIdentity();
 - 	glOrtho(-m_imgWidth/2 - 5, m_imgWidth/2 + 5, -m_imgHeight/2 - 5, m_imgHeight/2 + 5, -m_nbFile/2 - 5, m_nbFile/2 + 5);
 - 	glMatrixMode(GL_MODELVIEW);
 - 	glLoadIdentity();
 - 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 - 	glRotatef(m_angleX,1,0,0);
 - 	glRotatef(m_angleY,0,1,0);
 - 	glRotatef(m_angleZ,0,0,1);
 - 	m_stack.sceneDisplay(1);
 - 	SwapBuffers(m_hgldc);
 - 	return TRUE;
 - }
 - /*Permet d'afficher les axes de coupes*/
 - void Anim3D::drawAxesCoupe(CPoint point)
 - {
 - 	CRect rect_frame;
 - 	CWnd * cwnd_frame = (CWnd*)GetDlgItem(IDC_STATIC_SCENE);
 - 	cwnd_frame->GetWindowRect(&rect_frame);
 - 	ScreenToClient(&rect_frame);
 - 	double proj[16],model[16];
 - 	int view[4];
 - 	glGetDoublev(GL_MODELVIEW_MATRIX,model);
 - 	glGetDoublev(GL_PROJECTION_MATRIX,proj);
 - 	glGetIntegerv(GL_VIEWPORT,view);
 - 	if( (point.x >= rect_frame.left) && (point.x <= rect_frame.right) && (point.y >= rect_frame.top) && (point.y <= rect_frame.bottom))
 - 	{
 -   double coordx, coordy, coordz;
 -   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 -   gluUnProject(point.x-rect_frame.left , point.y-rect_frame.top, 0.0, model, proj, view, &coordx, &coordy, &coordz);
 -   DrawGLSceneOrtho();
 -   glColor3f(1.0,1.0,1.0);
 -   glBegin(GL_LINES);
 -   	glVertex3f(coordx, -m_imgHeight/2, m_nbFile/2 + 5);
 -   	glVertex3f(coordx, m_imgHeight/2, m_nbFile/2 + 5);
 -   glEnd();
 -   glBegin(GL_LINES);
 -   	glVertex3f(-m_imgWidth/2, -coordy, m_nbFile/2 + 5);
 -   	glVertex3f(m_imgWidth/2, -coordy, m_nbFile/2 + 5);
 -   glEnd();
 -   glFlush();
 -   SwapBuffers(m_hgldc);
 - 	}
 - }
 - void Anim3D::initGLCoupes()
 - {
 - 	CWnd * coupeYZ = GetDlgItem(IDC_STATIC_COUPEYZ);
 - 	CWnd * coupeXZ = GetDlgItem(IDC_STATIC_COUPEXZ);
 - 	m_hdc_YZ = ::GetDC(coupeYZ->m_hWnd);
 - 	m_hdc_XZ = ::GetDC(coupeXZ->m_hWnd);
 - 	SetPixelformat(m_hdc_YZ);
 - 	SetPixelformat(m_hdc_XZ);
 -  
 -     m_hglRC_YZ = wglCreateContext(m_hdc_YZ);
 - 	m_hglRC_XZ = wglCreateContext(m_hdc_XZ);
 - }
 - void Anim3D::drawCoupeYZ(int x, int y)
 - {
 - 	CRect rect;
 - 	CWnd * coupeYZ = GetDlgItem(IDC_STATIC_COUPEYZ);
 - 	coupeYZ->GetClientRect(&rect);
 - 	wglMakeCurrent(m_hdc_YZ,m_hglRC_YZ);
 - 	InitGL();
 - 	ReSizeGLScene(rect.Width(), rect.Height());
 - 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 - 	glMatrixMode(GL_PROJECTION);
 - 	glLoadIdentity();
 - 	glOrtho(-30, 30, -m_imgHeight/2, m_imgHeight/2, -10, 10);
 - 	glMatrixMode(GL_MODELVIEW);
 - 	glLoadIdentity();
 - 	m_stack.coupeYZDisplay(x, y);
 - 	SwapBuffers(m_hdc_YZ);
 - }
 - void Anim3D::drawCoupeXZ(int x, int y)
 - {
 - 	CRect rect;
 - 	CWnd * coupeXZ = GetDlgItem(IDC_STATIC_COUPEXZ);
 - 	coupeXZ->GetClientRect(&rect);
 - 	wglMakeCurrent(m_hdc_XZ,m_hglRC_XZ);
 - 	InitGL();
 - 	ReSizeGLScene(rect.Width(), rect.Height());
 - 	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 - 	glMatrixMode(GL_PROJECTION);
 - 	glLoadIdentity();
 - 	glOrtho(-m_imgWidth/2, m_imgWidth/2, -30, 30, -10, 10);
 - 	glMatrixMode(GL_MODELVIEW);
 - 	glLoadIdentity();
 - 	m_stack.coupeXZDisplay(x, y);
 - 	SwapBuffers(m_hdc_XZ);
 - }
 
  |  
 
       Voila le code ... j'ai enlevé des bouts qui ne servent pas à la comprehension et qui n'ont rien à voir avec mon problème.
 Merci d'avance
   @++    Message édité par Ludobooz le 13-07-2004 à 09:05:13
  |