]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Wx/VolumeRenderer/wxMaracasMultipleVolumeRendererPanel.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / GUI / Wx / VolumeRenderer / wxMaracasMultipleVolumeRendererPanel.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 #include "wxMaracasMultipleVolumeRendererPanel.h"
27 #include "wxMaracasMultipleVolumeRendererView.h"
28 #include "wxMaracas_N_ViewersWidget.h"
29 #include "wxMaracasDialog_NViewers.h"
30 #include "wxMaracasRendererView.h"
31
32 #include <wx/colordlg.h>
33
34 #include "vtkImageData.h"
35 #include "vtkRenderer.h"
36
37 #include <OpenImage.xpm>
38 #include <Add.xpm>
39 #include "Color.xpm"
40 #include <vector>
41 //#include <vtkImageCast.h>
42 /**
43 **      Implementation of viewProp3D
44 **/
45
46 /**
47 ** Class constructor
48 **/
49 wxMaracasMultipleVolumeRendererPanel::wxMaracasMultipleVolumeRendererPanel(wxWindow* parent,int propid, vtkImageData* img, bool _isComplexBox)
50 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize)
51 {
52         _propid = propid;
53         isComplexBox = _isComplexBox;
54
55         createControls(img);
56 }
57
58 /**
59 ** Class destructor
60 **/
61 wxMaracasMultipleVolumeRendererPanel::~wxMaracasMultipleVolumeRendererPanel(){
62
63         //if(isComplexBox)
64                 //((wxMaracasRenderTabbedPanel*)(wxMaracasRendererView::getInstance())->getTabbedPanel())->deleteVolume(_propid);
65         //else
66                 //wxMaracasMultipleVolumeRendererView::getInstance()->deleteVolume(_propid);
67         delete mwxwidget;
68 }
69
70 /**
71 ** Sets panel elements
72 **/
73 void wxMaracasMultipleVolumeRendererPanel::createControls(vtkImageData* img){
74
75         wxFlexGridSizer* sizerirmprop = new wxFlexGridSizer(3);
76
77         if(!isComplexBox)
78         {
79 //              wxStaticText* label = new wxStaticText(this, -1, wxString(_T("")));
80 //              wxStaticText* label2 = new wxStaticText(this, -1, wxString(_T("")));
81
82
83                 checkbox = new  wxCheckBox(this,-1,wxString(_T("Show Actor")));
84                 Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onCheckBoxChange);
85                 checkbox->SetValue(true);
86
87                 wxString choices[] = {_T("Composite"), _T("MIP")};
88                 _radiobox = new wxRadioBox(this, -1, wxString(_T("Function")), wxDefaultPosition, wxDefaultSize, 2, choices);
89                 Connect(_radiobox->GetId(), wxEVT_COMMAND_RADIOBOX_SELECTED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onRadioBoxSelectFunction);
90
91                 sizerirmprop->Add(checkbox,wxFIXED_MINSIZE);
92                 sizerirmprop->AddSpacer(5);
93                 sizerirmprop->Add(_radiobox,wxFIXED_MINSIZE);
94                 //sizerirmprop->Add(label2,wxFIXED_MINSIZE);
95         }
96         //wxBitmap bitmap(Color_xpm);
97         //_colorchoose = new wxBitmapButton(this, -1, bitmap,wxDefaultPosition,wxSize(30,30));
98         //Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onColorChange);
99
100         mwxwidget = new HistogramDialogComboBox(this);
101         mwxwidget->setImageData(img);
102     //mwxwidget->PushEventHandler(this);
103         Connect(mwxwidget->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onColorChange);
104         sizerirmprop->Add(mwxwidget,wxFIXED_MINSIZE);
105
106         wxBitmap bitmap0(Add_xpm);
107         _viewimage = new wxBitmapButton(this, -1, bitmap0, wxDefaultPosition, wxSize(30,30));
108         Connect(_viewimage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onViewImage);
109         sizerirmprop->Add(_viewimage,wxFIXED_MINSIZE);
110
111         //std::string iconsdir = wxMaracasMultipleVolumeRendererView::getInstance()->getPath();
112         //iconsdir+="/data/Icons/Add.xmp";
113         //wxBitmap* bitmap = new wxBitmap(wxString(iconsdir.c_str(),wxConvUTF8), wxBITMAP_TYPE_XPM);
114
115         this->SetSizer(sizerirmprop, true);
116         this->SetAutoLayout( true );
117
118         //_frame = new wxFrame(this, 10, _T("Configure Transfer Functions"));
119
120         /*wxButton* button1 = new wxButton(_frame,20,_T("OK"));
121         Connect(button1->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onOK);
122         wxButton* button2 = new wxButton(_frame,30,_T("Cancel") );
123         Connect(button2->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onCancel);
124         wxButton* button3 = new wxButton(_frame,40,_T("Update"));
125         Connect(button3->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasMultipleVolumeRendererPanel::onUpdate);                                */
126
127         /*mwxwidget->erasePointsTransferenceFunction();
128         double range[2];
129         img->GetScalarRange(range);
130         double max = range[1];
131
132
133         //X
134         mwxwidget->addPointToTransferenceFunction(max * 0/2,0.0);
135         mwxwidget->addPointToTransferenceFunction(max * 1/2,100.0);
136         mwxwidget->addPointToTransferenceFunction(max * 2/2,100.0);
137
138         mwxwidget->addColorPoint(max*0/4,(int)(0.0*255),(int)(0.0*255),(int)(0.0*255));
139         mwxwidget->addColorPoint(max*1/4,(int)(1.0*255),(int)(0.0*255),(int)(0.0*255));
140         mwxwidget->addColorPoint(max*2/4,(int)(0.0*255),(int)(0.0*255),(int)(1.0*255));
141         mwxwidget->addColorPoint(max*3/4,(int)(0.0*255),(int)(1.0*255),(int)(0.0*255));
142         mwxwidget->addColorPoint(max*4/4,(int)(0.0*255),(int)(0.0*255),(int)(0.2*255)); */
143
144         /*wxBoxSizer* boxSizer0 = new wxBoxSizer(wxHORIZONTAL);
145         boxSizer0->Add(mwxwidget, 4, wxGROW);
146
147         wxBoxSizer* boxSizer = new wxBoxSizer(wxHORIZONTAL);
148         boxSizer->AddSpacer(40);
149         boxSizer->Add(button1, wxCENTER);
150         boxSizer->AddSpacer(40);
151         boxSizer->Add(button2, wxCENTER);
152         boxSizer->AddSpacer(40);
153         boxSizer->Add(button3, wxCENTER);
154
155         wxBoxSizer* boxsizer2 = new wxBoxSizer(wxVERTICAL);
156         boxsizer2->Add(boxSizer0,1,wxEXPAND);
157         boxsizer2->Add(boxSizer,0,wxCENTER);
158
159         _frame->SetAutoLayout(true);
160
161
162     _frame->SetSizer(boxsizer2);
163
164         _frame->Refresh();
165         _frame->Update();*/
166         //mwxwidget->SetFunctions(wxMaracasMultipleVolumeRendererView::getInstance()->GetTransferFunction(getPropId()),
167         //                                              wxMaracasMultipleVolumeRendererView::getInstance()->GetColorFunction(getPropId()));
168         mwxwidget->Refresh();
169 }
170
171 /**
172 **
173 **/
174 void wxMaracasMultipleVolumeRendererPanel::onOK(wxCommandEvent& event){
175     updateVolume();
176         //_frame->Show(false);
177 }
178
179 /**
180 **
181 **/
182 void wxMaracasMultipleVolumeRendererPanel::onCancel(wxCommandEvent& event){
183         //_frame->Show(false);
184 }
185
186 /**
187 **
188 **/
189 void wxMaracasMultipleVolumeRendererPanel::onUpdate(wxCommandEvent& event){
190         updateVolume();
191 }
192
193 /**
194 **
195 **/
196 void wxMaracasMultipleVolumeRendererPanel::updateVolume(){
197         std::vector<double> greylevelcolors;
198         std::vector<double> red;
199         std::vector<double> green;
200         std::vector<double> blue;
201
202         std::vector<double> greylevel;
203         std::vector<double> values;
204
205     mwxwidget->GetValuesColorPointsFunction(greylevelcolors, red, green, blue);
206         mwxwidget->GetValuesPointsFunction(greylevel, values);
207
208         if(this->isComplexBox)
209         {
210                 ( (wxMaracasRendererView::getInstance())->getTabbedPanel(this->_propid) )->SetValuesColorPointsFunction(this->_propid,greylevelcolors, red, green, blue);
211                 ( (wxMaracasRendererView::getInstance())->getTabbedPanel(this->_propid) )->SetValuesPointsFunction(this->_propid, greylevel, values);
212         }
213         else
214         {
215                 wxMaracasMultipleVolumeRendererView::getInstance()->SetValuesColorPointsFunction(this->_propid, greylevelcolors, red, green, blue);
216                 wxMaracasMultipleVolumeRendererView::getInstance()->SetValuesPointsFunction(this->_propid, greylevel, values);
217         }
218 }
219
220 /**
221 ** Updates the volume visualization
222 **/
223 void wxMaracasMultipleVolumeRendererPanel::onColorChange(wxCommandEvent& event){
224
225         //if(mwxwidget->ShowModal()==wxID_OK){
226         updateVolume();
227         //      mwxwidget->Show(false);
228         //}
229 }
230
231 /**
232 **
233 **/
234 void wxMaracasMultipleVolumeRendererPanel::onViewImage(wxCommandEvent& event)
235 {
236         vtkImageData* img;
237         std::vector<int> type;
238         type.push_back(6);
239
240         wxFrame* frame = new wxFrame(this, -1, wxString(_T("Volume Visualization")));
241         frame->SetSize(wxDefaultSize);
242
243         if(this->isComplexBox)
244         {
245                 img = (wxMaracasRendererView::getInstance())->getTabbedPanel(_propid)->getVolImage();
246         }
247         else
248         {
249                 img = wxMaracasMultipleVolumeRendererView::getInstance()->getVolumeRenderManager()->getImageData();
250         }
251
252         //      wxMaracas_N_ViewersWidget* viewer = new wxMaracas_N_ViewersWidget(frame, img, &type);
253         new wxMaracas_N_ViewersWidget(frame, img, &type);
254         frame->Show();
255 }
256
257 /**
258 **
259 **/
260 void wxMaracasMultipleVolumeRendererPanel::onCheckBoxChange(wxCommandEvent& event){
261         if(this->isComplexBox)
262                 ( (wxMaracasRendererView::getInstance())->getTabbedPanel(this->_propid) )->addRemoveActorV(this->getPropId(), checkbox->GetValue());
263         else
264                 wxMaracasMultipleVolumeRendererView::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());
265 }
266
267 /**
268 ** Gets the propId
269 **/
270 int wxMaracasMultipleVolumeRendererPanel::getPropId(){
271         return _propid;
272 }
273
274 void wxMaracasMultipleVolumeRendererPanel::onRadioBoxSelectFunction(wxCommandEvent& event){
275
276         wxMaracasMultipleVolumeRendererView::getInstance()->changeCompositeMIPFunction(this->getPropId(), _radiobox->GetSelection());
277 }
278
279 /**
280 ** Carolina Perez: Recently added method
281 **/
282 HistogramDialogComboBox* wxMaracasMultipleVolumeRendererPanel::getMwxwidget()
283 {
284         return mwxwidget;
285 }
286