]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/include/MaracasDll.cpp
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / include / MaracasDll.cpp
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 // MaracasDll.cpp : Defines the entry point for the DLL application.
27 //
28
29 #include "stdafx.h"
30 #include "wxMaracasApp.h"
31 #include "MaracasDll.h"
32 #include <wx/log.h>
33
34 BOOL APIENTRY DllMain( HANDLE hModule, 
35                        DWORD  ul_reason_for_call, 
36                        LPVOID lpReserved
37                                          )
38 {
39     switch (ul_reason_for_call)
40         {
41                 case DLL_PROCESS_ATTACH:
42                         break;
43                 case DLL_THREAD_ATTACH:
44                 case DLL_THREAD_DETACH:
45                 case DLL_PROCESS_DETACH:
46                         break;
47     }
48     return TRUE;
49 }
50 // This is the constructor of a class that has been exported.
51 // see MaracasDll.h for the class definition
52 CMaracasController::CMaracasController()
53 :m_pSlicesPixels(NULL)
54 {
55 //EEDxx wxWindows 2.4
56 //      wxEntry(GetModuleHandle(NULL),NULL,NULL,0,FALSE);
57         m_pMarApp = (wxMaracasApp*)wxTheApp;
58         _rpPixels = NULL;
59 }
60
61 CMaracasController::~CMaracasController()
62 {
63         // TODO : verifier le vidage de la m�moire
64         if (m_pSlicesPixels!=NULL) delete m_pSlicesPixels;
65         m_pMarApp->OnExit();
66 //EEDxx wxWindows 2.4
67 //      wxApp::CleanUp();
68         m_pMarApp->CleanUp();
69 }
70
71 int CMaracasController::RunMaracas(void)
72
73         m_pMarApp->SetVolumeData(
74                 m_nX,
75                 m_nY,
76                 m_nSlices,
77                 m_PixelSpacingColumn,
78                 m_PixelSpacingRow, 
79                 m_PixelSpacingSlice,
80                 m_RescaleSlope,
81                 m_RescaleIntercept,
82                 m_pSlicesPixels);
83         m_pMarApp->Run();
84         return 0;
85 }
86
87 int CMaracasController::ShowApp(int nCmdShow) 
88 {
89    if ( SW_HIDE == nCmdShow )
90    {
91           m_pMarApp->ShowFrame(SHOW_WINDOW_MINIMIZED);
92    } 
93    else if ( SW_SHOW == nCmdShow )
94    {
95           m_pMarApp->ShowFrame(SHOW_WINDOW_RESTORE);
96    }
97    else if ( SW_NORMAL == nCmdShow )
98    {
99           m_pMarApp->ShowFrame(SHOW_WINDOW_NORMAL);
100    }
101    else if ( SW_MINIMIZE == nCmdShow )
102    {
103           m_pMarApp->ShowFrame(SHOW_WINDOW_MINIMIZED);
104    }
105    else if ( SW_MAXIMIZE == nCmdShow )
106    {
107           m_pMarApp->ShowFrame(SHOW_WINDOW_MAXIMIZED);
108    }
109    else
110    {
111           m_pMarApp->ShowFrame(SHOW_WINDOW_NORMAL);
112    }
113    return 0;
114 }
115
116 int CMaracasController::Reset(void)
117 {
118         // TODO : verifier le vidage de la m�moire
119         if (m_pSlicesPixels!=NULL) delete m_pSlicesPixels;
120         m_pSlicesPixels=NULL;
121         m_pMarApp->Reset();
122         return 0;
123 }
124
125 void CMaracasController::SetVolumeParams(int nX, int nY, int nSlices)
126 {
127         m_nX=nX;
128         m_nY=nY;
129         m_nSlices=nSlices;
130         if(m_pSlicesPixels==NULL) 
131         {
132                 m_pSlicesPixels=new unsigned short [m_nX*m_nY*m_nSlices];
133         }
134         wxString msg=wxString();
135
136 //EEDxx2.4 DEBuG
137 //      wxLogDebug(msg.Format("Volume dimensions received : %d, %d ,%d",m_nX,m_nY,m_nSlices));
138
139 }
140
141 void CMaracasController::SetSliceParams(float pixelSpacingColumn,
142                                                                                 float pixelSpacingRow,
143                                                                                 float pixelSpacingSlice, 
144                                                                                 float RescaleSlope, 
145                                                                                 float RescaleIntercept)
146 {
147         m_PixelSpacingColumn    = pixelSpacingColumn;
148         m_PixelSpacingRow               = pixelSpacingRow;
149         m_PixelSpacingSlice             = pixelSpacingSlice;
150         m_RescaleSlope                  = RescaleSlope;
151         m_RescaleIntercept              = RescaleIntercept;
152
153         wxString msg=wxString();
154 //EEDxx2.4 DEBuG
155 //      wxLogDebug(msg.Format("Spacings received: %d, %d, %d",m_PixelSpacingColumn,m_PixelSpacingRow,m_PixelSpacingSlice));
156
157 }
158
159 void CMaracasController::SetSlicePixels(int numSlice,unsigned short * pixels)
160 {
161
162         wxString msg=wxString();
163
164 //EEDxx2.4 DEBuG
165 //      wxLogDebug(msg.Format("Data for slice %d received",numSlice));
166         
167         int nbPixels=m_nX*m_nY;
168         int startIndex=numSlice*nbPixels;
169
170         for (int i=0; i<nbPixels;i++)
171         {
172                 m_pSlicesPixels[i+startIndex]=pixels[i];
173         }
174 }
175
176 void CMaracasController::GetSnapshot(   unsigned int&   rWidth,
177                                                                 unsigned int&   rHeight,
178                                                                                 unsigned char*& rpPixels )  /*const*/ {
179
180         wxColour        *colour         = new wxColour();
181         wxBitmap        *wxbitmap       = m_pMarApp->GetSnapshot();
182         wxMemoryDC      *wxmemorydc = new wxMemoryDC();
183         wxmemorydc->SelectObject(*wxbitmap);
184
185         int i,j;
186         unsigned char r,g,b;
187         int w = wxbitmap->GetWidth();
188         int h = wxbitmap->GetHeight();
189
190         _rpPixels=(unsigned char*)malloc( sizeof(unsigned char)*3*w*h );
191         for (i=0;i<w;i++){
192                 for (j=0;j<h;j++){
193                         wxmemorydc->GetPixel(i,j,colour);
194                         r=colour->Red();
195                         g=colour->Green();
196                         b=colour->Blue();
197                         rpPixels[j*3*w+i*3+0]=r;
198                         rpPixels[j*3*w+i*3+1]=g;
199                         rpPixels[j*3*w+i*3+2]=b;
200                 }
201         }
202
203         delete wxbitmap;
204         delete wxmemorydc;
205         wxbitmap->SaveFile("c:/tmp/MaracasPlamavic.bmp", wxBITMAP_TYPE_BMP  );
206
207         rWidth   = w;
208         rHeight  = h;
209         rpPixels = _rpPixels;
210 }
211
212
213 int CMaracasController::ReleaseSnapshot(){
214         if (_rpPixels!=NULL) {
215                 free(_rpPixels);
216                 _rpPixels=NULL;
217         }
218         return 0;
219 }
220