]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/MaracasDll.cpp
BUG interaction ROI-creation line, rectangle, circle,
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / MaracasDll.cpp
1 // MaracasDll.cpp : Defines the entry point for the DLL application.
2 //
3
4 #include "stdafx.h"
5 #include "wxMaracasApp.h"
6 #include "MaracasDll.h"
7 #include <wx/log.h>
8
9 BOOL APIENTRY DllMain( HANDLE hModule, 
10                        DWORD  ul_reason_for_call, 
11                        LPVOID lpReserved
12                                          )
13 {
14     switch (ul_reason_for_call)
15         {
16                 case DLL_PROCESS_ATTACH:
17                         break;
18                 case DLL_THREAD_ATTACH:
19                 case DLL_THREAD_DETACH:
20                 case DLL_PROCESS_DETACH:
21                         break;
22     }
23     return TRUE;
24 }
25 // This is the constructor of a class that has been exported.
26 // see MaracasDll.h for the class definition
27 CMaracasController::CMaracasController()
28 :m_pSlicesPixels(NULL)
29 {
30 //EEDxx wxWindows 2.4
31 //      wxEntry(GetModuleHandle(NULL),NULL,NULL,0,FALSE);
32         m_pMarApp = (wxMaracasApp*)wxTheApp;
33         _rpPixels = NULL;
34 }
35
36 CMaracasController::~CMaracasController()
37 {
38         // TODO : verifier le vidage de la mémoire
39         if (m_pSlicesPixels!=NULL) delete m_pSlicesPixels;
40         m_pMarApp->OnExit();
41 //EEDxx wxWindows 2.4
42 //      wxApp::CleanUp();
43         m_pMarApp->CleanUp();
44 }
45
46 int CMaracasController::RunMaracas(void)
47
48         m_pMarApp->SetVolumeData(
49                 m_nX,
50                 m_nY,
51                 m_nSlices,
52                 m_PixelSpacingColumn,
53                 m_PixelSpacingRow, 
54                 m_PixelSpacingSlice,
55                 m_RescaleSlope,
56                 m_RescaleIntercept,
57                 m_pSlicesPixels);
58         m_pMarApp->Run();
59         return 0;
60 }
61
62 int CMaracasController::ShowApp(int nCmdShow) 
63 {
64    if ( SW_HIDE == nCmdShow )
65    {
66           m_pMarApp->ShowFrame(SHOW_WINDOW_MINIMIZED);
67    } 
68    else if ( SW_SHOW == nCmdShow )
69    {
70           m_pMarApp->ShowFrame(SHOW_WINDOW_RESTORE);
71    }
72    else if ( SW_NORMAL == nCmdShow )
73    {
74           m_pMarApp->ShowFrame(SHOW_WINDOW_NORMAL);
75    }
76    else if ( SW_MINIMIZE == nCmdShow )
77    {
78           m_pMarApp->ShowFrame(SHOW_WINDOW_MINIMIZED);
79    }
80    else if ( SW_MAXIMIZE == nCmdShow )
81    {
82           m_pMarApp->ShowFrame(SHOW_WINDOW_MAXIMIZED);
83    }
84    else
85    {
86           m_pMarApp->ShowFrame(SHOW_WINDOW_NORMAL);
87    }
88    return 0;
89 }
90
91 int CMaracasController::Reset(void)
92 {
93         // TODO : verifier le vidage de la mémoire
94         if (m_pSlicesPixels!=NULL) delete m_pSlicesPixels;
95         m_pSlicesPixels=NULL;
96         m_pMarApp->Reset();
97         return 0;
98 }
99
100 void CMaracasController::SetVolumeParams(int nX, int nY, int nSlices)
101 {
102         m_nX=nX;
103         m_nY=nY;
104         m_nSlices=nSlices;
105         if(m_pSlicesPixels==NULL) 
106         {
107                 m_pSlicesPixels=new unsigned short [m_nX*m_nY*m_nSlices];
108         }
109         wxString msg=wxString();
110
111 //EEDxx2.4 DEBuG
112 //      wxLogDebug(msg.Format("Volume dimensions received : %d, %d ,%d",m_nX,m_nY,m_nSlices));
113
114 }
115
116 void CMaracasController::SetSliceParams(float pixelSpacingColumn,
117                                                                                 float pixelSpacingRow,
118                                                                                 float pixelSpacingSlice, 
119                                                                                 float RescaleSlope, 
120                                                                                 float RescaleIntercept)
121 {
122         m_PixelSpacingColumn    = pixelSpacingColumn;
123         m_PixelSpacingRow               = pixelSpacingRow;
124         m_PixelSpacingSlice             = pixelSpacingSlice;
125         m_RescaleSlope                  = RescaleSlope;
126         m_RescaleIntercept              = RescaleIntercept;
127
128         wxString msg=wxString();
129 //EEDxx2.4 DEBuG
130 //      wxLogDebug(msg.Format("Spacings received: %d, %d, %d",m_PixelSpacingColumn,m_PixelSpacingRow,m_PixelSpacingSlice));
131
132 }
133
134 void CMaracasController::SetSlicePixels(int numSlice,unsigned short * pixels)
135 {
136
137         wxString msg=wxString();
138
139 //EEDxx2.4 DEBuG
140 //      wxLogDebug(msg.Format("Data for slice %d received",numSlice));
141         
142         int nbPixels=m_nX*m_nY;
143         int startIndex=numSlice*nbPixels;
144
145         for (int i=0; i<nbPixels;i++)
146         {
147                 m_pSlicesPixels[i+startIndex]=pixels[i];
148         }
149 }
150
151 void CMaracasController::GetSnapshot(   unsigned int&   rWidth,
152                                                                 unsigned int&   rHeight,
153                                                                                 unsigned char*& rpPixels )  /*const*/ {
154
155         wxColour        *colour         = new wxColour();
156         wxBitmap        *wxbitmap       = m_pMarApp->GetSnapshot();
157         wxMemoryDC      *wxmemorydc = new wxMemoryDC();
158         wxmemorydc->SelectObject(*wxbitmap);
159
160         int i,j;
161         unsigned char r,g,b;
162         int w = wxbitmap->GetWidth();
163         int h = wxbitmap->GetHeight();
164
165         _rpPixels=(unsigned char*)malloc( sizeof(unsigned char)*3*w*h );
166         for (i=0;i<w;i++){
167                 for (j=0;j<h;j++){
168                         wxmemorydc->GetPixel(i,j,colour);
169                         r=colour->Red();
170                         g=colour->Green();
171                         b=colour->Blue();
172                         rpPixels[j*3*w+i*3+0]=r;
173                         rpPixels[j*3*w+i*3+1]=g;
174                         rpPixels[j*3*w+i*3+2]=b;
175                 }
176         }
177
178         delete wxbitmap;
179         delete wxmemorydc;
180         wxbitmap->SaveFile("c:/tmp/MaracasPlamavic.bmp", wxBITMAP_TYPE_BMP  );
181
182         rWidth   = w;
183         rHeight  = h;
184         rpPixels = _rpPixels;
185 }
186
187
188 int CMaracasController::ReleaseSnapshot(){
189         if (_rpPixels!=NULL) {
190                 free(_rpPixels);
191                 _rpPixels=NULL;
192         }
193         return 0;
194 }
195