// MainFrm.cpp : implementation of class CMainFrame // #include "stdafx.h" #include "MainFrm.h" #include "Resource.h" #include "MAth.h" #include "ToolsMAth.h" // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_COMMAND(ID_APP_EXIT, OnClose) ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_RBUTTONUP() ON_WM_MOUSEMOVE() ON_WM_CREATE() ON_WM_SETCURSOR() ON_WM_SETFOCUS() ON_WM_MOVE() ON_WM_KEYDOWN() ON_COMMAND(ID_OPENFILE, OnOpenfile) //}}AFX_MSG_MAP END_MESSAGE_MAP() // CMainFrame constructor CMainFrame::CMainFrame() { firstPoint = 1; m_canChange = FALSE; m_initialized = FALSE; m_nbPts =0; m_bPlaque1 = FALSE; m_bPlaque2 = FALSE; m_bPlaque3 = FALSE; m_bCaptured = FALSE; m_input = (int *) malloc( 4 * sizeof(int) ); m_points = (unsigned char *) malloc( 1024 * sizeof(unsigned char *) ); } CMainFrame::~CMainFrame() { free(m_input); free(m_points); m_image.ReleaseDC(); } void CMainFrame::SetRect( RECT& rect ) { m_wRect = rect; m_cRect = rect; m_cRect.DeflateRect( 0, 0, 0, 32 ); } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; static UINT indicators[] = { ID_SEPARATOR, ID_SEPARATOR, ID_SEPARATOR }; m_sBar.Create( this ); m_sBar.SetIndicators( indicators, 3 ); m_sBar.SetPaneInfo( 2, m_sBar.GetItemID( 2 ), SBPS_NORMAL, 200 ); m_sBar.SetPaneInfo( 1, m_sBar.GetItemID( 1 ), SBPS_NORMAL, 200 ); m_sBar.SetPaneInfo( 0, m_sBar.GetItemID( 0 ), SBPS_STRETCH, NULL ); m_hArrow = AfxGetApp()->LoadStandardCursor( IDC_ARROW ); m_hCross = AfxGetApp()->LoadStandardCursor( IDC_CROSS ); if ( !plaqueInterface.IsValid() ) { AfxMessageBox( _T( "LibPlaqueDLL.dll not found in the directory of the executable" ) ); return -1; } return 0; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { if ( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; cs.style = WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU; return TRUE; } // Calcul de la distance entre 2 points double CMainFrame::computeDistance(CPoint pt1, CPoint pt2) { double distance; distance = sqrt((double) (pt1.x - pt2.x) * (pt1.x - pt2.x) + (pt1.y - pt2.y) * (pt1.y - pt2.y)); return distance; } void CMainFrame::onInit() { m_bCaptured = FALSE; m_nbPts = 1; m_bPlaque1 = FALSE; m_bPlaque2 = FALSE; m_bPlaque3 = FALSE; ReleaseCapture(); m_tbPtsNouveauxTrouvesFin.clear(); if ( !m_image.IsNull() ) { DrawCurves(); } } void CMainFrame::OnRButtonUp( UINT nFlags, CPoint point ) { onInit(); } void CMainFrame::OnLButtonDown( UINT nFlags, CPoint point ) { BOOL trouve; if ((m_bPlaque3 == TRUE) && (m_bCaptured == FALSE)&& (m_lastPoint.x != point.x) && (m_lastPoint.y != point.y)) { // On va voir s'il est dans la zone de capture std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(), pe = m_tbPtsNouveauxTrouvesFin.end(); trouve = FALSE; while (( p < pe ) && (trouve == FALSE)) { if (abs((*p).y - point.y) < 10) { trouve = TRUE; } ++p; } // if (trouve == TRUE) { // Capture SetCapture(); ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); // On recherche le point qui est le plus proche de celui cliqué m_bCaptured = TRUE; m_previousPoint.x = point.x; m_previousPoint.y = point.y; m_pointCaptured.x = point.x; m_pointCaptured.y = point.y; std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(); pe = m_tbPtsNouveauxTrouvesFin.end(); m_positionxCaptured = 0; trouve = FALSE; while (( p < pe ) && (!trouve)) { if (((*p).x >= m_pointCaptured.x)) { trouve = TRUE; } m_positionxCaptured++; ++p; } m_positionxCaptured--; // Beep(100, 100); if ( !m_image.IsNull() ) { DrawCurves(); } } } } // Message manager for CMainFrame void CMainFrame::OnLButtonUp( UINT nFlags, CPoint point ) { int i; unsigned char *dadd; int retour; CString vStr; int iVector; CPoint vPoint; plaque::PlaqueResult* plaqueResult; Point oldP; CPoint pt = point; ClientToScreen( &pt ); m_canChange = m_cRect.PtInRect( pt ); if ( m_canChange && m_initialized ) { if (m_nbPts < 2) DrawMyText(TRUE); if ((m_nbPts > 0) && (m_nbPts < 32) && (m_bPlaque1 == FALSE) && (m_bCaptured == FALSE) && (m_lastPoint.x != point.x) && (m_lastPoint.y != point.y)) { m_pts[m_nbPts-1].x = point.x; m_pts[m_nbPts-1].y = point.y; updateDisplay(point); } if ((m_bPlaque1 == FALSE) && (m_bCaptured == FALSE) && (m_lastPoint.x != point.x) && (m_lastPoint.y != point.y)) { m_nbPts++; } if ((m_bPlaque3 == TRUE) && (m_bCaptured == TRUE) && (m_lastPoint.x != point.x) && (m_lastPoint.y != point.y)) { ReleaseCapture(); m_bCaptured = FALSE; // On va voir s'il est dans la zone de capture dadd = m_points; for (i = 0; i < m_oldnbPts; i++) { m_input[0] = ((m_pts[i].x & 0xFF000000) >> 24); m_input[1] = ((m_pts[i].x & 0x00FF0000) >> 16); m_input[2] = ((m_pts[i].x & 0x0000FF00) >> 8); m_input[3] = ((m_pts[i].x & 0x000000FF)); *dadd = m_input[0]; dadd++; *dadd = m_input[1]; dadd++; *dadd = m_input[2]; dadd++; *dadd = m_input[3]; dadd++; m_input[0] = ((m_pts[i].y & 0xFF000000) >> 24); m_input[1] = ((m_pts[i].y & 0x00FF0000) >> 16); m_input[2] = ((m_pts[i].y & 0x0000FF00) >> 8); m_input[3] = ((m_pts[i].y & 0x000000FF)); *dadd = m_input[0]; dadd++; *dadd = m_input[1]; dadd++; *dadd = m_input[2]; dadd++; *dadd = m_input[3]; dadd++; } std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.end(), pe = m_tbPtsNouveauxTrouvesFin.begin(); // Il faut itérer dans le sens inverse pour garder la continuité du contour if ( p > pe ) { p--; } i = 0; while ( p > pe ) { /* if (i == 0) { CString vStr; vStr.Format(_T("%d, %d"),(*p).x, (*p).y); AfxMessageBox(vStr); } */ m_input[0] = (((*p).x & 0xFF000000) >> 24); m_input[1] = (((*p).x & 0x00FF0000) >> 16); m_input[2] = (((*p).x & 0x0000FF00) >> 8); m_input[3] = (((*p).x & 0x000000FF)); *dadd = m_input[0]; dadd++; *dadd = m_input[1]; dadd++; *dadd = m_input[2]; dadd++; *dadd = m_input[3]; dadd++; m_input[0] = (((*p).y & 0xFF000000) >> 24); m_input[1] = (((*p).y & 0x00FF0000) >> 16); m_input[2] = (((*p).y & 0x0000FF00) >> 8); m_input[3] = (((*p).y & 0x000000FF)); *dadd = m_input[0]; dadd++; *dadd = m_input[1]; dadd++; *dadd = m_input[2]; dadd++; *dadd = m_input[3]; dadd++; i++; p--; } retour = plaqueInterface.CalculerPlaqueManuelle( m_oldnbPts + i, m_points ); plaqueResult = plaqueInterface.GetResult(); DrawMyText(FALSE); } if ((m_bPlaque2 == TRUE) && (m_bPlaque3 == FALSE) && (m_lastPoint.x != point.x) && (m_lastPoint.y != point.y) && (m_bCaptured == FALSE)) { dadd = m_points; for (i = 0; i < m_nbPts; i++) { m_input[0] = ((m_pts[i].x & 0xFF000000) >> 24); m_input[1] = ((m_pts[i].x & 0x00FF0000) >> 16); m_input[2] = ((m_pts[i].x & 0x0000FF00) >> 8); m_input[3] = ((m_pts[i].x & 0x000000FF)); *dadd = m_input[0]; dadd++; *dadd = m_input[1]; dadd++; *dadd = m_input[2]; dadd++; *dadd = m_input[3]; dadd++; m_input[0] = ((m_pts[i].y & 0xFF000000) >> 24); m_input[1] = ((m_pts[i].y & 0x00FF0000) >> 16); m_input[2] = ((m_pts[i].y & 0x0000FF00) >> 8); m_input[3] = ((m_pts[i].y & 0x000000FF)); *dadd = m_input[0]; dadd++; *dadd = m_input[1]; dadd++; *dadd = m_input[2]; dadd++; *dadd = m_input[3]; dadd++; } retour = plaqueInterface.computePlaque( point.x, point.y, m_nbPts, m_points, 60, 90 ); plaqueResult = plaqueInterface.GetResult(); for (iVector = 0; iVector < plaqueResult->m_nVecteursTrouves - 1; iVector++) { oldP.x = plaqueResult->m_tbPtsTrouvesFin[iVector].x; oldP.y = plaqueResult->m_tbPtsTrouvesFin[iVector].y; m_tbPtsNouveauxTrouvesFin.push_back( oldP ); } ::SetCursor( m_hCross ); m_bPlaque3 = TRUE; // vStr.Format(_T("C1 = %d, C2 = %d, C3 = %d, C4 = %d, C5 = %d,"), plaqueResult->code_debug1, plaqueResult->code_debug2, plaqueResult->code_debug3, plaqueResult->code_debug4, plaqueResult->code_debug5); // m_sBar.SetPaneText( 0, vStr ); if (!m_image.IsNull()) { DrawCurves(); } DrawMyText(FALSE); m_oldnbPts = m_nbPts; // onInit(); m_nbPts = 1; m_bPlaque1 = FALSE; m_bPlaque2 = FALSE; } if ((m_bPlaque3 == TRUE) && (m_bCaptured == TRUE)) { /* m_newPoint.x = point.x; m_newPoint.y = point.y; minDist = INT_MAX; m_posModif = 0; std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(), pe = m_tbPtsNouveauxTrouvesFin.end(); iVector = 0; while ( p < pe ) { vPoint.x = (*p).x; vPoint.y = (*p).y; vDist = computeDistance(vPoint, m_newPoint); if (vDist < minDist) { minDist = vDist; m_posModif = iVector; } iVector++; ++p; } p = m_tbPtsNouveauxTrouvesFin.begin(); pe = m_tbPtsNouveauxTrouvesFin.end(); iVector = 0; while ( p < pe ) { if (iVector == m_posModif) { (*p).x = point.x; (*p).y = point.y; } iVector++; ++p; } DrawCurves(); */ } // Double click if ((m_bPlaque1 == FALSE) && (m_nbPts > 3) && (m_bCaptured == FALSE) && (m_bPlaque3 == FALSE)) { if ((m_lastPoint.x == point.x) && (m_lastPoint.y == point.y)) { // Remplissage du nouveau tableau de points plaqueResult = plaqueInterface.GetResult(); if (m_bPlaque1 == FALSE) { m_bPlaque1 = TRUE; m_nbPts -=1; } if ( (m_bPlaque1 == TRUE) && (m_bPlaque2 == FALSE) ) { m_bPlaque2 = TRUE; ::SetCursor (theApp.LoadCursor (IDC_TACHE)); updateDisplay(point); } } } m_lastPoint.x = point.x; m_lastPoint.y = point.y; // retour = plaqueInterface.OnLButtonUp( point.x, point.y ); /* m_pts[0].x = 267; m_pts[0].y = 218; m_pts[1].x = 300; m_pts[1].y = 227; m_pts[2].x = 364; m_pts[2].y = 232; m_pts[3].x = 446; m_pts[3].y = 238; m_pts[4].x = 509; m_pts[4].y = 238; m_pts[5].x = 561; m_pts[5].y = 234; */ } } void CMainFrame::updateDisplay(CPoint point) { int i; CDC *pDC = GetDC(); CRect rect; GetClientRect(&rect); m_image.StretchBlt( pDC->m_hDC, rect.left, rect.top, m_cRect.Width(), m_cRect.Height() ); CPen pen( PS_SOLID, 2, RGB( 255, 0, 255 ) ); CPen *pOldPen = pDC->SelectObject( &pen ); if (m_nbPts > 1) { for (i = 1; i < m_nbPts-1; i++) { pDC->MoveTo( m_pts[i-1].x, m_pts[i-1].y ); pDC->LineTo( m_pts[i].x, m_pts[i].y ); } pDC->MoveTo( m_pts[m_nbPts-2].x, m_pts[m_nbPts-2].y ); pDC->LineTo( point ); pDC->SelectObject( pOldPen ); } } void CMainFrame::OnMouseMove(UINT nFlags, CPoint point) { int i, rayon; dpoint p0, d1, d2; dpoint sr1, sr2; BOOL askReplace; dpoint vPoint, vPoint2; int iVector; std::vector< Point >::iterator p, pe; CString vStr; int ng; CString text; rayon = 7; CDC *pDC = GetDC(); if (pDC != NULL) { COLORREF colorPixel = pDC->GetPixel(point.x, point.y); ng = (GetRValue(colorPixel) + GetGValue(colorPixel) + GetBValue(colorPixel)) / 3; text.Format( _T("x,y: %d,%d Gsl: %d"),point.x,point.y,ng ); m_sBar.SetPaneText (2, text); } if (((m_bPlaque3 == TRUE) && (m_bCaptured == TRUE)) || (GetKeyState (VK_UP) < 0) || (GetKeyState (VK_DOWN) < 0) || (GetKeyState (VK_RIGHT) < 0) || (GetKeyState (VK_LEFT) < 0)) { // Point du centre // p0.x = (double) m_pointCaptured.x; p0.x = (double) m_pointCaptured.x; /* deltay = (m_previousPoint.y - point.y); // if (deltay > 4) deltay /= 2; p = m_tbPtsNouveauxTrouvesFin.begin(); pe = m_tbPtsNouveauxTrouvesFin.end(); while ( p < pe ) { if ((*p).x == p0.x) { if (m_previousPoint.y >= point.y) { // Beep(100, 100); p0.y = (double) point.y - rayon; // vStr.Format(_T("%d"), deltay); // AfxMessageBox(vStr); } else { p0.y = (double) point.y + rayon; } } ++p } */ if (m_previousPoint.y >= point.y) // En montant { p0.y = (double) point.y - rayon; } else { p0.y = (double) point.y + rayon; } for (i = -rayon; i < rayon; i++) { d1.x = p0.x + i; d1.y = p0.y; d2.x = p0.x + i; d2.y = p0.y + 2; // On rechercle le point sur la courbe p = m_tbPtsNouveauxTrouvesFin.begin(); pe = m_tbPtsNouveauxTrouvesFin.end(); iVector = 0; while ( p < pe ) { if ((*p).x == d1.x) { vPoint.x = d1.x; vPoint.y = (*p).y; m_posModif = iVector; } iVector++; ++p; } InterCercleDroite(p0, rayon, d1, d2, &sr1, &sr2); askReplace = FALSE; if (m_previousPoint.y >= point.y) { if (sr1.y < p0.y) // En montant : Demi cercle du haut { if ((fabs(vPoint.y - p0.y) < rayon) && (vPoint.y >= sr1.y)) { askReplace = TRUE; vPoint2.x = vPoint.x; vPoint2.y = sr1.y; } } else { if ((fabs(vPoint.y - p0.y) < rayon) && (vPoint.y >= sr2.y)) { askReplace = TRUE; vPoint2.x = vPoint.x; vPoint2.y = sr2.y; } } } else { if (sr1.y > p0.y) // En descendant : Demi cercle du haut { if ((fabs(vPoint.y - p0.y) < rayon) && (vPoint.y < sr1.y)) { askReplace = TRUE; vPoint2.x = vPoint.x; vPoint2.y = sr1.y; } } else { if ((fabs(vPoint.y - p0.y) < rayon) && (vPoint.y < sr2.y)) { askReplace = TRUE; vPoint2.x = vPoint.x; vPoint2.y = sr2.y; } } } if ((askReplace == TRUE) && ((m_keyPress == 3) || (m_keyPress == 4))) { p = m_tbPtsNouveauxTrouvesFin.begin(); pe = m_tbPtsNouveauxTrouvesFin.end(); iVector = 0; while ( p < pe ) { if (iVector == m_posModif) { (*p).x = (int) vPoint2.x; (*p).y = (int) vPoint2.y; } iVector++; ++p; } } } m_previousPoint.x = point.x; m_previousPoint.y = point.y; DrawCurves(); } if ((m_bPlaque1 == FALSE) && (m_nbPts > 1)) { updateDisplay(point); CDC *pDC = GetDC(); CPen pen( PS_SOLID, 1, RGB( 0, 255, 0 ) ); CPen *pOldPen = pDC->SelectObject( &pen ); pDC->SelectObject( pOldPen ); PrintDistance( point ); } } BOOL CMainFrame::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { if ( m_initialized && firstPoint && m_canChange && ( nHitTest == HTCLIENT )) { if ((m_bPlaque1 != TRUE) || (m_bPlaque3 == TRUE)) { ::SetCursor(::LoadCursor(NULL, IDC_ARROW)); return TRUE; } else if ((m_bPlaque1 != TRUE) || (m_bPlaque3 == TRUE)) { ::SetCursor( m_hCross ); } else { ::SetCursor (theApp.LoadCursor (IDC_TACHE)); return TRUE; } } return CFrameWnd::OnSetCursor( pWnd, nHitTest, message ); } void CMainFrame::OnSetFocus( CWnd* wnd ) { CFrameWnd::OnSetFocus( wnd ); if ( !m_image.IsNull() ) { DrawCurves(); } } void CMainFrame::OnMove( int cx, int cy ) { CFrameWnd::OnMove( cx, cy ); if ( !m_image.IsNull() ) { DrawCurves(); } } void CMainFrame::OnDraw( CDC* pDC ) { if ( !m_image.IsNull() ) { DrawCurves(); } } CRect CMainFrame::GetTextRect() { CRect rect( 0, m_cRect.Height(), m_wRect.Width(), m_wRect.Height() ); return rect; } void CMainFrame::DrawPoint( CDC *pDC, CPoint& pt, COLORREF color ) { pDC->SetPixel( pt, color ); } void CMainFrame::DrawCurves() { CDC *pDC = GetDC(); CRect rect; GetClientRect(&rect); CBrush brush( RGB( 0, 0, 0 ) ); pDC->FillRect( GetTextRect(), &brush ); m_image.StretchBlt( pDC->m_hDC, rect.left, rect.top, m_cRect.Width(), m_cRect.Height() ); if ( !m_image.IsNull() ) { plaque::PlaqueResult* plaqueResult = plaqueInterface.GetResult(); if (((plaqueResult->m_nVecteursTrouves > 0) || (plaqueResult->m_nPtLongeantPlaque > 0)) && (m_bPlaque1||m_bPlaque2||m_bPlaque3 || (m_bCaptured)) ) { short iVector; CPen *pOldPen; CString vStr; if (plaqueResult->m_type == typeRGB) { pOldPen = pDC->SelectObject (&theApp.m_penVert); } else { pOldPen = pDC->SelectObject (&theApp.m_penDraw); } if (plaqueResult->m_Etape == etapeTacheSeuil) { // Mesure en cours de saisie : Afficher croix au pt du seuil inférieur pDC->MoveTo (plaqueResult->m_ptInferieur.x - 4, plaqueResult->m_ptInferieur.y); pDC->LineTo (plaqueResult->m_ptInferieur.x + 5, plaqueResult->m_ptInferieur.y); pDC->MoveTo (plaqueResult->m_ptInferieur.x, plaqueResult->m_ptInferieur.y - 4); pDC->LineTo (plaqueResult->m_ptInferieur.x, plaqueResult->m_ptInferieur.y + 5); } /* Draw the contour of the plaque */ /* if ( plaqueResult->m_ptList.size() ) { pDC->MoveTo( plaqueResult->m_ptList[0].x, plaqueResult->m_ptList[0].y ); for (int i = 1; i < plaqueResult->m_ptList.size(); ++i) { pDC->LineTo( plaqueResult->m_ptList[i].x, plaqueResult->m_ptList[i].y ); } } */ pDC->SelectObject (&theApp.m_penVert); // pDC->MoveTo (plaqueResult->m_tbPtsTrouvesFin [0].x, plaqueResult->m_tbPtsTrouvesFin [0].y); for (iVector = 0; iVector < plaqueResult->m_nVecteursTrouves - 1; iVector++) { // pDC->LineTo (plaqueResult->m_tbPtsTrouvesFin [iVector + 1].x, plaqueResult->m_tbPtsTrouvesFin [iVector + 1].y); } pDC->MoveTo (plaqueResult->m_tPtLongeantPlaque[0].x, plaqueResult->m_tPtLongeantPlaque[0].y); for (iVector = 1; iVector < plaqueResult->m_nPtLongeantPlaque; iVector++) { pDC->LineTo(plaqueResult->m_tPtLongeantPlaque[iVector].x, plaqueResult->m_tPtLongeantPlaque[iVector].y); } pDC->SelectObject (&theApp.m_penBleu); if ((m_bPlaque3) || (m_bCaptured)) { m_spline.fit( m_tbPtsNouveauxTrouvesFin ); std::vector< Point > fit = m_spline.getValues( 20 ); std::vector< Point >::iterator p = fit.begin(), pe = fit.end(); iVector = 0; if ( p < pe ) { pDC->MoveTo( (*p).x, (*p).y ); ++p; } while ( p < pe ) { if ((*p).x == (m_pointCaptured.x)) { pDC->SelectObject (&theApp.m_penRouge); } else if ( ((*p).x >= (m_pointCaptured.x - 8)) && ((*p).x <= (m_pointCaptured.x + 8)) ) { pDC->SelectObject (&theApp.m_penVert); } else { pDC->SelectObject (&theApp.m_penBleu); } pDC->LineTo( (*p).x, (*p).y ); ++p; } } } if (plaqueResult->m_Etape == etapeSegments) { // pDC->LineTo (ptCurrent); } else if ( (plaqueResult->m_Etape == etapeReglage) || (plaqueResult->m_Etape == etapeTacheSeuil)) { // if ( (plaqueResult->m_pointLimite1.x != 0) // || (plaqueResult->m_pointLimite1.y != 0)) { // pOldPen = pDC->SelectObject (&theApp.m_penDraw); // pDC->LineTo (plaqueResult->m_pointLimite1.x, plaqueResult->m_pointLimite1.y);// // pDC->MoveTo (plaqueResult->m_pointLimite2.x, plaqueResult->m_pointLimite2.y); // pDC->LineTo (plaqueResult->m_tPtLongeantPlaque [0].x, plaqueResult->m_tPtLongeantPlaque [0].y); } } } } void CMainFrame::DrawMyText(BOOL init) { CDC *pDC = GetDC(); CString text; plaque::PlaqueResult* plaqueResult = plaqueInterface.GetResult(); if (init == TRUE) { text.Format( IDS_DEMO_MEASURE_PLAQUE, 0.0, 0.0, 0, 0.0, 0.0); } else { text.Format( IDS_DEMO_MEASURE_PLAQUE, plaqueResult->plaque_max_thickness, plaqueResult->plaque_mean_thickness, plaqueResult->numberOfMeasures, plaqueResult->plaque_area, plaqueResult->plaque_mean_density); } PrintText( text ); } void CMainFrame::PrintCoordinates( CPoint pt ) { CString text; text.Format( IDS_DEMO_COORDINATES, pt.x, pt.y ); m_sBar.SetPaneText( 1, text ); } void CMainFrame::PrintDistance( CPoint pt ) { CString text; float d = plaqueInterface.getDistanceToFirstPoint( pt.x, pt.y, m_pts[0].x, m_pts[0].y); text.Format( IDS_DEMO_LONGUEUR, pt.x, pt.y, d ); m_sBar.SetPaneText( 0, text ); } void CMainFrame::PrintText( CString text ) { CDC *pDC = GetDC(); DRAWTEXTPARAMS textParam; textParam.cbSize = sizeof( DRAWTEXTPARAMS ); textParam.iLeftMargin = 0; textParam.iRightMargin = 0; textParam.iTabLength = 3; textParam.uiLengthDrawn = 0; COLORREF colorText = pDC->SetTextColor( RGB( 255, 255, 255 ) ); COLORREF colorBk = pDC->SetBkColor( RGB( 0, 0, 0 ) ); CFont newFont; newFont.CreateFont( 12, 0, 0, 0, FW_THIN, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY ,FIXED_PITCH | FF_MODERN, _T( "Courier" ) ); CFont* pOldFont = pDC->SelectObject( &newFont ); CBrush brush( RGB( 0, 0, 0 ) ); pDC->FillRect( GetTextRect(), &brush ); pDC->DrawTextEx( text, GetTextRect(), DT_NOCLIP | DT_VCENTER, &textParam ); pDC->SelectObject( pOldFont ); if ( newFont.m_hObject != NULL ) newFont.Detach(); pDC->SetTextColor( colorText ); pDC->SetBkColor( colorBk ); } void CMainFrame::OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags) { CPoint point; int rayon; rayon = 7; bool trouve; int iVector; m_keyPress = 0; switch (nChar) { case VK_RIGHT: { m_keyPress = 1; std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(), pe = m_tbPtsNouveauxTrouvesFin.end(); trouve = false; iVector = 0; while (( p < pe ) && (!trouve)) { if (iVector == (m_positionxCaptured + 1)) { point.x = (*p).x; m_pointCaptured.x = point.x; point.y = (*p).y + rayon + 6; m_previousPoint.y = point.y + rayon; trouve = true; m_positionxCaptured++; OnMouseMove(nFlags, point); DrawCurves(); } iVector++; ++p ; } } break; case VK_LEFT: { m_keyPress = 2; std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(), pe = m_tbPtsNouveauxTrouvesFin.end(); trouve = false; iVector = 0; while (( p < pe ) && (!trouve)) { if (iVector == (m_positionxCaptured - 1)) { point.x = (*p).x; m_pointCaptured.x = point.x; point.y = (*p).y + rayon + 6; m_previousPoint.y = point.y + rayon; trouve = true; m_positionxCaptured--; OnMouseMove(nFlags, point); DrawCurves(); } iVector++; ++p ; } } break; case VK_UP: { m_keyPress = 3; std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(), pe = m_tbPtsNouveauxTrouvesFin.end(); iVector = 0; trouve = false; while (( p < pe )&& (!trouve)) { if (iVector == m_positionxCaptured ) { trouve = true; point.x = (*p).x; point.y = (*p).y + rayon + 6; m_previousPoint.y = point.y + rayon; OnMouseMove(nFlags, point); DrawCurves(); } iVector++; ++p ; } } break; case VK_DOWN: { m_keyPress = 4; std::vector< Point >::iterator p = m_tbPtsNouveauxTrouvesFin.begin(), pe = m_tbPtsNouveauxTrouvesFin.end(); iVector = 0; trouve = false; while (( p < pe ) && (!trouve)) { if (iVector == m_positionxCaptured ) { trouve = true; point.x = (*p).x; point.y = (*p).y - rayon - 6; m_previousPoint.y = point.y - rayon; OnMouseMove(nFlags, point); DrawCurves(); } iVector++; ++p ; } } break; } } void CMainFrame::OnOpenfile() { CPoint point; point.x = 0; point.y = 0; CFileDialog cfd( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER, _T( "Test Dicom file|*|Test jpgbmp|*.jpg;*.jpeg;*.bmp||" ), NULL ); if ( cfd.DoModal() == IDOK ) { m_image.Destroy(); onInit(); m_nbPts = 0; USES_CONVERSION; if ( cfd.GetOFN().nFilterIndex == 1 ) { m_initialized = plaqueInterface.initializeFromFile( T2A( cfd.GetPathName() ) ); if ( m_initialized ) { int x, dimX = plaqueInterface.getImageWidth(); int y, dimY = plaqueInterface.getImageHeight(); m_image.Create( dimX, dimY, plaqueInterface.getImageBitsPerPixel() ); char* buffer = plaqueInterface.getPixelArray(); for ( y = 0; y < dimY; y++ ) { for ( x = 0; x < dimX; x++ ) { m_image.SetPixelRGB( x, y, *buffer++, *buffer++, *buffer++ ); } } } } else { if ( SUCCEEDED( m_image.Load( cfd.GetPathName() ) ) ) { char* buffer = NULL; int width = m_image.GetWidth(); int height = m_image.GetHeight(); int x, y, bpp; unsigned long count = width * height; // test for a 24 bits buffer bpp = 24; buffer = new char[ 3 * count ]; if ( buffer ) { char* p = buffer; for ( y = 0; y < height; y++ ) { for ( x = 0; x < width; x++ ) { *p++ = GetRValue( m_image.GetPixel( x, y ) ); *p++ = GetGValue( m_image.GetPixel( x, y ) ); *p++ = GetBValue( m_image.GetPixel( x, y ) ); } } } if ( buffer ) { m_initialized = plaqueInterface.initializeFromRaw( buffer, width, height, bpp, FALSE, 0.0826440, 0.0826440 ); } } } if ( m_initialized ) { plaqueInterface.Clear(); ResizeWindow(); Invalidate( FALSE ); updateDisplay(point); DrawMyText(TRUE); } else { AfxMessageBox( _T( "File cannot be loaded" ), MB_ICONSTOP | MB_OK ); } } } void CMainFrame::ResizeWindow() { CRect winRect; CRect cRect; CRect sRect; GetWindowRect( &winRect ); GetClientRect( &cRect ); int imgWidth = plaqueInterface.getImageWidth(); int imgHeight = plaqueInterface.getImageHeight(); m_sBar.GetWindowRect( &sRect ); m_cRect = CRect( 0, 0, imgWidth, imgHeight ); m_wRect = m_cRect; m_wRect.InflateRect( 0, 0, 0, 32 ); ClientToScreen( &m_cRect ); ClientToScreen( &m_wRect ); SetWindowPos( NULL, 0, 0, winRect.Width() + imgWidth - cRect.Width(), winRect.Height() + imgHeight + 32 + sRect.Height() - cRect.Height(), SWP_NOMOVE | SWP_NOZORDER ); DrawCurves(); }