MaracasDll.cpp

Go to the documentation of this file.
00001 // MaracasDll.cpp : Defines the entry point for the DLL application.
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "wxMaracasApp.h"
00006 #include "MaracasDll.h"
00007 #include <wx/log.h>
00008 
00009 BOOL APIENTRY DllMain( HANDLE hModule, 
00010                        DWORD  ul_reason_for_call, 
00011                        LPVOID lpReserved
00012                                          )
00013 {
00014     switch (ul_reason_for_call)
00015         {
00016                 case DLL_PROCESS_ATTACH:
00017                         break;
00018                 case DLL_THREAD_ATTACH:
00019                 case DLL_THREAD_DETACH:
00020                 case DLL_PROCESS_DETACH:
00021                         break;
00022     }
00023     return TRUE;
00024 }
00025 // This is the constructor of a class that has been exported.
00026 // see MaracasDll.h for the class definition
00027 CMaracasController::CMaracasController()
00028 :m_pSlicesPixels(NULL)
00029 {
00030 //EEDxx wxWindows 2.4
00031 //      wxEntry(GetModuleHandle(NULL),NULL,NULL,0,FALSE);
00032         m_pMarApp = (wxMaracasApp*)wxTheApp;
00033         _rpPixels = NULL;
00034 }
00035 
00036 CMaracasController::~CMaracasController()
00037 {
00038         // TODO : verifier le vidage de la mémoire
00039         if (m_pSlicesPixels!=NULL) delete m_pSlicesPixels;
00040         m_pMarApp->OnExit();
00041 //EEDxx wxWindows 2.4
00042 //      wxApp::CleanUp();
00043         m_pMarApp->CleanUp();
00044 }
00045 
00046 int CMaracasController::RunMaracas(void)
00047 { 
00048         m_pMarApp->SetVolumeData(
00049                 m_nX,
00050                 m_nY,
00051                 m_nSlices,
00052                 m_PixelSpacingColumn,
00053                 m_PixelSpacingRow, 
00054                 m_PixelSpacingSlice,
00055                 m_RescaleSlope,
00056                 m_RescaleIntercept,
00057                 m_pSlicesPixels);
00058         m_pMarApp->Run();
00059         return 0;
00060 }
00061 
00062 int CMaracasController::ShowApp(int nCmdShow) 
00063 {
00064    if ( SW_HIDE == nCmdShow )
00065    {
00066           m_pMarApp->ShowFrame(SHOW_WINDOW_MINIMIZED);
00067    } 
00068    else if ( SW_SHOW == nCmdShow )
00069    {
00070           m_pMarApp->ShowFrame(SHOW_WINDOW_RESTORE);
00071    }
00072    else if ( SW_NORMAL == nCmdShow )
00073    {
00074           m_pMarApp->ShowFrame(SHOW_WINDOW_NORMAL);
00075    }
00076    else if ( SW_MINIMIZE == nCmdShow )
00077    {
00078           m_pMarApp->ShowFrame(SHOW_WINDOW_MINIMIZED);
00079    }
00080    else if ( SW_MAXIMIZE == nCmdShow )
00081    {
00082           m_pMarApp->ShowFrame(SHOW_WINDOW_MAXIMIZED);
00083    }
00084    else
00085    {
00086           m_pMarApp->ShowFrame(SHOW_WINDOW_NORMAL);
00087    }
00088    return 0;
00089 }
00090 
00091 int CMaracasController::Reset(void)
00092 {
00093         // TODO : verifier le vidage de la mémoire
00094         if (m_pSlicesPixels!=NULL) delete m_pSlicesPixels;
00095         m_pSlicesPixels=NULL;
00096         m_pMarApp->Reset();
00097         return 0;
00098 }
00099 
00100 void CMaracasController::SetVolumeParams(int nX, int nY, int nSlices)
00101 {
00102         m_nX=nX;
00103         m_nY=nY;
00104         m_nSlices=nSlices;
00105         if(m_pSlicesPixels==NULL) 
00106         {
00107                 m_pSlicesPixels=new unsigned short [m_nX*m_nY*m_nSlices];
00108         }
00109         wxString msg=wxString();
00110 
00111 //EEDxx2.4 DEBuG
00112 //      wxLogDebug(msg.Format("Volume dimensions received : %d, %d ,%d",m_nX,m_nY,m_nSlices));
00113 
00114 }
00115 
00116 void CMaracasController::SetSliceParams(float pixelSpacingColumn,
00117                                                                                 float pixelSpacingRow,
00118                                                                                 float pixelSpacingSlice, 
00119                                                                                 float RescaleSlope, 
00120                                                                                 float RescaleIntercept)
00121 {
00122         m_PixelSpacingColumn    = pixelSpacingColumn;
00123         m_PixelSpacingRow               = pixelSpacingRow;
00124         m_PixelSpacingSlice             = pixelSpacingSlice;
00125         m_RescaleSlope                  = RescaleSlope;
00126         m_RescaleIntercept              = RescaleIntercept;
00127 
00128         wxString msg=wxString();
00129 //EEDxx2.4 DEBuG
00130 //      wxLogDebug(msg.Format("Spacings received: %d, %d, %d",m_PixelSpacingColumn,m_PixelSpacingRow,m_PixelSpacingSlice));
00131 
00132 }
00133 
00134 void CMaracasController::SetSlicePixels(int numSlice,unsigned short * pixels)
00135 {
00136 
00137         wxString msg=wxString();
00138 
00139 //EEDxx2.4 DEBuG
00140 //      wxLogDebug(msg.Format("Data for slice %d received",numSlice));
00141         
00142         int nbPixels=m_nX*m_nY;
00143         int startIndex=numSlice*nbPixels;
00144 
00145         for (int i=0; i<nbPixels;i++)
00146         {
00147                 m_pSlicesPixels[i+startIndex]=pixels[i];
00148         }
00149 }
00150 
00151 void CMaracasController::GetSnapshot(   unsigned int&   rWidth,
00152                                                                 unsigned int&   rHeight,
00153                                                                                 unsigned char*& rpPixels )  /*const*/ {
00154 
00155         wxColour        *colour         = new wxColour();
00156         wxBitmap        *wxbitmap       = m_pMarApp->GetSnapshot();
00157         wxMemoryDC      *wxmemorydc = new wxMemoryDC();
00158         wxmemorydc->SelectObject(*wxbitmap);
00159 
00160         int i,j;
00161         unsigned char r,g,b;
00162         int w = wxbitmap->GetWidth();
00163         int h = wxbitmap->GetHeight();
00164 
00165         _rpPixels=(unsigned char*)malloc( sizeof(unsigned char)*3*w*h );
00166         for (i=0;i<w;i++){
00167                 for (j=0;j<h;j++){
00168                         wxmemorydc->GetPixel(i,j,colour);
00169                         r=colour->Red();
00170                         g=colour->Green();
00171                         b=colour->Blue();
00172                         rpPixels[j*3*w+i*3+0]=r;
00173                         rpPixels[j*3*w+i*3+1]=g;
00174                         rpPixels[j*3*w+i*3+2]=b;
00175                 }
00176         }
00177 
00178         delete wxbitmap;
00179         delete wxmemorydc;
00180         wxbitmap->SaveFile("c:/tmp/MaracasPlamavic.bmp", wxBITMAP_TYPE_BMP  );
00181 
00182         rWidth   = w;
00183         rHeight  = h;
00184         rpPixels = _rpPixels;
00185 }
00186 
00187 
00188 int CMaracasController::ReleaseSnapshot(){
00189         if (_rpPixels!=NULL) {
00190                 free(_rpPixels);
00191                 _rpPixels=NULL;
00192         }
00193         return 0;
00194 }
00195 

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1