]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Wx/VolumeRenderer/wxMaracasMultipleVolumeRendererView.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / GUI / Wx / VolumeRenderer / wxMaracasMultipleVolumeRendererView.cxx
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 /*=========================================================================
27
28   Program:   wxMaracas
29   Module:    $RCSfile: wxMaracasMultipleVolumeRendererView.cxx,v $
30   Language:  C++
31   Date:      $Date: 2012/11/15 14:15:43 $
32   Version:   $Revision: 1.2 $
33
34   Copyright: (c) 2002, 2003
35   License:
36
37      This software is distributed WITHOUT ANY WARRANTY; without even
38      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39      PURPOSE.  See the above copyright notice for more information.
40
41 =========================================================================*/
42
43
44
45 // EOF - wxMaracasMPR.cxx
46
47 #include "wxMaracasMultipleVolumeRendererView.h"
48
49
50 #include <wx/colordlg.h>
51 #include <wx/bmpbuttn.h> 
52
53 #include <OpenImage.xpm>
54 #include <Color.xpm>
55
56 wxMaracasMultipleVolumeRendererView* wxMaracasMultipleVolumeRendererView::instance=NULL;
57
58 wxMaracasMultipleVolumeRendererView::wxMaracasMultipleVolumeRendererView( wxWindow* parent,std::string path)
59 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
60
61         wxauimanager = new wxAuiManager(this);
62
63         _path = path;
64
65         volmanager = new VolumeRendererManager();
66         std::string iconsdir = path;
67         iconsdir+="/data/Icons";
68         this->_toolb = new ToolBarMultipleVolumeRenderer(this,iconsdir);
69         wxStaticText* txt = new wxStaticText(this, -1, wxString(_T("  Volume Rendering  ")));
70         wxAuiPaneInfo paneinfo;
71         wxauimanager->AddPane(txt,paneinfo.ToolbarPane().Top());
72         wxauimanager->AddPane(_toolb,paneinfo.ToolbarPane().Top());
73
74         wxauimanager->Update(); 
75
76 }
77 wxMaracasMultipleVolumeRendererView::~wxMaracasMultipleVolumeRendererView( ){
78
79         delete _toolb;
80 }
81
82 std::string wxMaracasMultipleVolumeRendererView::getPath(){
83         return _path;
84 }
85
86 wxMaracasMultipleVolumeRendererView* wxMaracasMultipleVolumeRendererView::getInstance(wxWindow* parent,std::string path){
87         if(instance==NULL)
88 {
89                 instance = new wxMaracasMultipleVolumeRendererView(parent,path);
90         }
91         return instance;
92 }
93
94 wxMaracasMultipleVolumeRendererView* wxMaracasMultipleVolumeRendererView::getInstance(){
95         return instance;
96 }
97
98 void wxMaracasMultipleVolumeRendererView::changeCompositeMIPFunction(int id, int function){
99         try{
100                 volmanager->changeCompositeMIPFunction(id, function);
101         }
102         catch(char* str){
103                 std::cout << "Exception : " << str << '\n';
104                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
105                 diag->ShowModal();
106         }
107 }
108
109 void wxMaracasMultipleVolumeRendererView::setRenderer(vtkRenderer*  renderer){
110         volmanager->setRenderer(renderer);
111 }
112
113 void wxMaracasMultipleVolumeRendererView::addRemoveActor(int id, bool addremove){
114         try{
115                 volmanager->addRemoveActor(id, addremove);
116         }
117         catch(char* str){
118                 std::cout << "Exception : " << str << '\n';
119                 wxMessageDialog* diag = new wxMessageDialog(this, wxString( str,wxConvUTF8 ), wxString( str,wxConvUTF8 ), wxICON_ERROR);
120                 diag->ShowModal();
121         }
122         
123 }
124
125 void wxMaracasMultipleVolumeRendererView::onLoadImageFile(){
126
127         wxString mhd(_T("mhd"));        
128
129         wxFileDialog* fildial = new wxFileDialog(this, wxString(_T("Select a MHD file")),wxString(_T("")),
130                 wxString(_T("")),wxString(_T("MHD files (*.mhd)|*.mhd")) );
131
132         if(fildial->ShowModal()==wxID_OK){
133         wxString filename = fildial->GetFilename();
134                 wxString pathfile(fildial->GetDirectory() + _T("/") + filename);
135                 if(filename.EndsWith(mhd)){
136                         loadVolume(pathfile,filename);
137                 }
138         }
139         delete fildial;
140
141 }
142
143 void wxMaracasMultipleVolumeRendererView::addVolumeViewPanel(wxMaracasMultipleVolumeRendererPanel* irmview, std::string dataname){
144
145         wxString s(dataname.c_str(),wxConvUTF8 );
146         wxAuiPaneInfo paneinfo;
147         wxauimanager->AddPane(irmview, paneinfo.DefaultPane().Centre().DestroyOnClose().Caption(s));
148         wxauimanager->Update();
149 }
150         
151 void wxMaracasMultipleVolumeRendererView::addVolume(vtkImageData* img, std::string dataname){
152
153         try{
154                 int id = volmanager->addVolume(-1, img,dataname);               
155                 if(id!=-1){
156                         wxMaracasMultipleVolumeRendererPanel* controlpan = new wxMaracasMultipleVolumeRendererPanel(this, id,img, false);
157                         addVolumeViewPanel(controlpan, dataname);
158                         controlpan->updateVolume();
159                 }
160         }catch(char* str){
161                 std::cout << "Exception : " << str << '\n';
162                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
163                 diag->ShowModal();
164         }
165 }
166
167 void wxMaracasMultipleVolumeRendererView::loadVolume(wxString filename, wxString dataname){
168
169         std::string s = std::string(filename.mb_str());
170         vtkImageData* img = volmanager->getImageData(s);
171         imgVect.push_back(img);
172
173         if(img!=NULL){
174                 s = std::string(dataname.mb_str());
175                 addVolume(img, s);
176         }
177 }
178
179 void wxMaracasMultipleVolumeRendererView::deleteVolume(int volid)
180 {
181         try{
182                 volmanager->deleteActor(volid);
183         }
184
185         catch(char* str){
186                 std::cout << "Exception : " << str << '\n';
187                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
188                 diag->ShowModal();
189         }
190 }
191
192 void wxMaracasMultipleVolumeRendererView::SetValuesColorPointsFunction(int volid, std::vector<double> greylevelcolors,std::vector<double> red,std::vector<double> green,std::vector<double> blue)
193 {
194         volmanager->setVolumeColor(volid, greylevelcolors, red, green, blue);
195 }
196 void wxMaracasMultipleVolumeRendererView::SetValuesPointsFunction(int volid, std::vector<double> greylevel, std::vector<double> values)
197 {
198         volmanager->setVolumeOpacity(volid, greylevel, values);
199 }
200
201 vtkPiecewiseFunction* wxMaracasMultipleVolumeRendererView::GetTransferFunction(int volumeid)
202 {
203         return volmanager->GetTransferFunction(volumeid);
204 }
205 vtkColorTransferFunction* wxMaracasMultipleVolumeRendererView::GetColorFunction(int volumeid)
206 {
207     return volmanager->GetColorFunction(volumeid);
208 }
209
210 std::vector<vtkImageData*> wxMaracasMultipleVolumeRendererView::GetOutputImages(){
211         return imgVect;
212 }
213
214 VolumeRendererManager* wxMaracasMultipleVolumeRendererView::getVolumeRenderManager()
215 {
216         return volmanager;
217 }
218
219 /**
220 **
221 **/
222
223 ToolBarMultipleVolumeRenderer::ToolBarMultipleVolumeRenderer(wxWindow * parent,std::string iconsdir)
224 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
225 {
226
227
228         std::string iconfil = iconsdir;
229
230         //iconfil+= "/OpenImage.png";
231         //wxBitmap* bitmap0 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
232         wxBitmap bitmap0(OpenImage_xpm);
233         this->AddTool(1, wxString(_T("test")),bitmap0, NULL, wxITEM_NORMAL, wxString(_T("Open File")));
234
235         /*iconfil+= "/Open.png";
236         wxBitmap* bitmap2 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
237         this->AddTool(2, wxString(_T("test")),*bitmap2);        */
238
239         /*iconfil = iconsdir;
240         iconfil+= "/Open.png";
241         wxBitmap* bitmap30 = new wxBitmap(wxString(iconfil.c_str(),wxConvUTF8), wxBITMAP_TYPE_PNG);
242         this->AddTool(30, wxString(_T("test")),*bitmap30);*/
243
244         this->Realize();
245
246         _evthand = new ToolBarEventHandlerMultipleVolumeRenderer();
247         this->SetEventHandler(_evthand);
248
249 }
250
251 ToolBarMultipleVolumeRenderer::~ToolBarMultipleVolumeRenderer(void){
252 }
253
254 ToolBarEventHandlerMultipleVolumeRenderer::ToolBarEventHandlerMultipleVolumeRenderer()
255 : wxEvtHandler(){
256 }
257 ToolBarEventHandlerMultipleVolumeRenderer::~ToolBarEventHandlerMultipleVolumeRenderer(){
258 }
259
260 void ToolBarEventHandlerMultipleVolumeRenderer::onLoadImageFile(wxCommandEvent& event){
261         wxMaracasMultipleVolumeRendererView::getInstance()->onLoadImageFile();
262 }
263
264
265
266 BEGIN_EVENT_TABLE(ToolBarEventHandlerMultipleVolumeRenderer, wxEvtHandler)
267         EVT_MENU(1, ToolBarEventHandlerMultipleVolumeRenderer::onLoadImageFile)
268 END_EVENT_TABLE()
269
270