]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasRenderTabbedPanel.cpp
\ No newline at end of file
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasRenderTabbedPanel.cpp
1 #include "wxMaracasRenderTabbedPanel.h"
2 #include "HistogramDialogComboBox.h"
3
4 #include "wxMaracasMultipleVolumeRendererPanel.h"
5 #include "wxMaracasSurfaceRenderingPanel.h"
6 #include "wxMaracasSurfaceRenderingProp3DMHD.h"
7 #include "wxMaracasMultipleVolumeRendererManagerData.h"
8
9 #include <wx/colordlg.h>
10 #include <wx/button.h> 
11
12 #include <OpenImage.xpm>
13 #include "Color.xpm"
14
15 #include <vtkProp3D.h>
16
17 /**
18 ** Class constructor
19 **/
20 wxMaracasRenderTabbedPanel::wxMaracasRenderTabbedPanel(wxWindow* parent)
21 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize)
22 {
23         //_propid = propid;
24         volmanager = new wxMaracasMultipleVolumeRendererManager();
25         surrendmanager1 = new wxMaracasSurfaceRenderingManager();
26         surrendmanager2 = new wxMaracasSurfaceRenderingManager();
27         surrendmanager3 = new wxMaracasSurfaceRenderingManager();
28 }
29
30 /**
31 ** Class Destructor
32 **/
33 wxMaracasRenderTabbedPanel::~wxMaracasRenderTabbedPanel()
34 {       
35         //wxMaracasRenderTabbedPanel::getInstance()->addRemoveActorV(_propid, false);
36         //wxMaracasRenderTabbedPanel::getInstance()->addRemoveActorSA(_propid, false);
37         //wxMaracasRenderTabbedPanel::getInstance()->addRemoveActorSB(_propid, false);
38         //wxMaracasRenderTabbedPanel::getInstance()->addRemoveActorSC(_propid, false);
39         this->deleteVolume(_propidV);
40         delete wxtabs;  
41 }
42
43 /**
44 ** Initializes rendered images, and creates and adds elements to the panel
45 **/
46 void wxMaracasRenderTabbedPanel::createControls(vtkImageData* inImg, std::string pathfile, std::string filename)
47 {
48         wxFlexGridSizer* sizerrenderprop = new wxFlexGridSizer(1);
49
50         wxFlexGridSizer* sizercheck = new wxFlexGridSizer(2);
51         checkboxVol = new  wxCheckBox(this,-1,wxString(_T("Volume Rendering")));
52         Connect(checkboxVol->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasRenderTabbedPanel::onCheckBoxVChange);   
53         checkboxVol->SetValue(true);    
54         sizercheck->Add(checkboxVol, wxFIXED_MINSIZE);
55
56         checkboxSA = new  wxCheckBox(this,-1,wxString(_T("Surface Rendering A")));
57         Connect(checkboxSA->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasRenderTabbedPanel::onCheckBoxSAChange);   
58         checkboxSA->SetValue(true);     
59         sizercheck->Add(checkboxSA, wxFIXED_MINSIZE);   
60
61         checkboxSB = new  wxCheckBox(this,-1,wxString(_T("Surface Rendering B")));
62         Connect(checkboxSB->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasRenderTabbedPanel::onCheckBoxSBChange);   
63         checkboxSB->SetValue(true);     
64         sizercheck->Add(checkboxSB, wxFIXED_MINSIZE);
65
66         checkboxSC = new  wxCheckBox(this,-1,wxString(_T("Surface Rendering C")));
67         Connect(checkboxSC->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasRenderTabbedPanel::onCheckBoxSCChange);   
68         checkboxSC->SetValue(true);     
69         sizercheck->Add(checkboxSC, wxFIXED_MINSIZE);
70
71         wxButton* _openParameters = new wxButton(this, -1, wxString(_T("Apply Transformation")));       
72         Connect(_openParameters->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasRenderTabbedPanel::onOpenParameters);                  
73         sizercheck->Add(_openParameters,wxFIXED_MINSIZE);
74
75         wxButton* _openCutter = new wxButton(this, -1, wxString(_T("Open Cutter View")));       
76         Connect(_openCutter->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasRenderTabbedPanel::onOpenCutter);                  
77         sizercheck->Add(_openCutter,wxFIXED_MINSIZE);
78         sizerrenderprop->Add(sizercheck, wxFIXED_MINSIZE);
79
80         wxtabs = new wxNotebook(this, -1);
81
82         if(inImg == NULL)
83         {
84                 //std::string s = std::string(pathfile.mb_str());
85                 vtkImageData* img = volmanager->getImageData(pathfile);
86                 vtkImageData* img1 = surrendmanager1->getImageData(pathfile);
87                 vtkImageData* img2 = surrendmanager2->getImageData(pathfile);
88                 vtkImageData* img3 = surrendmanager3->getImageData(pathfile);
89                 if(img!=NULL && img1!=NULL && img2!=NULL && img3!=NULL)
90                 {
91                         //s = std::string(filename.mb_str());
92                         addVolume(img, filename);
93                         addSurface1(img1, filename);
94                         addSurface2(img2, filename);
95                         addSurface3(img3, filename);    
96                         wxtabs->Refresh();
97                 }
98         }       
99         else
100         {
101                 //s = std::string(filename.mb_str());
102                 addVolume(inImg, filename);
103                 addSurface1(inImg, filename);
104                 addSurface2(inImg, filename);
105                 addSurface3(inImg, filename);   
106                 wxtabs->Refresh();
107         }
108
109         sizerrenderprop->Add(wxtabs, wxSizerFlags().Expand().Center());
110
111         this->SetSizer(sizerrenderprop, true);          
112         this->SetAutoLayout( true );
113 }
114
115
116 /**
117 ** Sets given renderer
118 **/
119 void wxMaracasRenderTabbedPanel::setRenderer(vtkRenderer* renderer)
120 {
121         volmanager->setRenderer(renderer);
122         surrendmanager1->setRenderer(renderer);
123         surrendmanager2->setRenderer(renderer);
124         surrendmanager3->setRenderer(renderer);
125 }
126
127 /**
128 ** Adds a volume using Volume Rendering
129 **/
130 void wxMaracasRenderTabbedPanel::addVolume(vtkImageData* img, std::string dataname)
131 {
132         try
133         {
134                 _propidV = volmanager->addVolume(img, dataname);
135                 if(_propidV!=-1)
136                 {
137                         wxMaracasMultipleVolumeRendererPanel* controlpanV = new wxMaracasMultipleVolumeRendererPanel(wxtabs, _propidV, img, true);
138                         wxtabs->AddPage(controlpanV, _T("Vol Rendering"), true);
139                         controlpanV->updateVolume();
140                 }
141         }
142         catch(char* str)
143         {
144                 std::cout << "Exception : " << str << '\n';
145                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
146                 diag->ShowModal();
147                 delete diag;
148         }
149 }
150
151 /**
152 ** Adds a volume using surface rendering
153 **/
154 void wxMaracasRenderTabbedPanel::addSurface1(vtkImageData* img, std::string dataname)
155 {
156         try
157         {
158                 _propidSA = surrendmanager1->addPropMHD(img, dataname);
159                 
160                 if(_propidSA!=-1)
161                 {
162                         wxMaracasSurfaceRenderingPanel* controlpanSA = new wxMaracasSurfaceRenderingProp3DMHD(wxtabs, _propidSA, true, 1);
163                         int maxiso = surrendmanager1->getMaxIsoValue(_propidSA);
164                         ((wxMaracasSurfaceRenderingProp3DMHD*)controlpanSA)->createControls(maxiso);
165                         wxtabs->AddPage(controlpanSA, _T("SR A"));
166                 }
167         }
168         catch(char* str)
169         {
170                 std::cout << "Exception : " << str << '\n';
171                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
172                 diag->ShowModal();
173                 delete diag;
174         }
175 }
176
177 /**
178 ** Adds a volume using surface rendering
179 **/
180 void wxMaracasRenderTabbedPanel::addSurface2(vtkImageData* img, std::string dataname)
181 {
182         try
183         {
184                 _propidSB = surrendmanager2->addPropMHD(img, dataname);
185                 if(_propidSB!=-1)
186                 {
187                         wxMaracasSurfaceRenderingPanel* controlpanSB = new wxMaracasSurfaceRenderingProp3DMHD(wxtabs, _propidSB, true, 2);
188                         int maxiso = surrendmanager2->getMaxIsoValue(_propidSB);
189                         ((wxMaracasSurfaceRenderingProp3DMHD*)controlpanSB)->createControls(maxiso);
190                         wxtabs->AddPage(controlpanSB, _T("SR B"));
191
192                 }
193         }
194         catch(char* str)
195         {
196                 std::cout << "Exception : " << str << '\n';
197                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
198                 diag->ShowModal();
199                 delete diag;
200         }
201 }
202
203 /**
204 ** Adds a volume using Surface Rendering
205 **/
206 void wxMaracasRenderTabbedPanel::addSurface3(vtkImageData* img, std::string dataname)
207 {
208         try
209         {
210                 _propidSC = surrendmanager3->addPropMHD(img, dataname);
211
212                 if(_propidSC!=-1)
213                 {
214                         wxMaracasSurfaceRenderingPanel* controlpanSC = new wxMaracasSurfaceRenderingProp3DMHD(wxtabs, _propidSC, true, 3);
215                         int maxiso = surrendmanager3->getMaxIsoValue(_propidSC);
216                         ((wxMaracasSurfaceRenderingProp3DMHD*)controlpanSC)->createControls(maxiso);
217                         wxtabs->AddPage(controlpanSC, _T("SR C"));
218                 }
219         }
220         catch(char* str)
221         {
222                 std::cout << "Exception : " << str << '\n';
223                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
224                 diag->ShowModal();
225                 delete diag;
226         }
227 }
228
229 /**
230 ** Deletes complete volume
231 **/
232 void wxMaracasRenderTabbedPanel::deleteVolume(int volid)
233 {
234         try
235         {
236                 volmanager->deleteActor(volid);
237                 surrendmanager1->deleteActor(volid);
238                 surrendmanager2->deleteActor(volid);
239                 surrendmanager3->deleteActor(volid);
240         }
241         catch(char* str)
242         {
243                 std::cout << "Exception : " << str << '\n';
244                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
245                 diag->ShowModal();
246                 delete diag;
247         }
248 }
249
250 /**
251 ** Adds or removes volume rendering actor with given ID
252 **/
253 void wxMaracasRenderTabbedPanel::addRemoveActorV(int id, bool addremove)
254 {
255         try{
256                 volmanager->addRemoveActor(id, addremove);
257         }
258         catch(char* str){
259                 std::cout << "Exception : " << str << '\n';
260                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
261                 diag->ShowModal();
262                 delete diag;
263         }
264 }
265
266 /**
267 ** Adds or removes surface rendering actor with given ID
268 **/
269 void wxMaracasRenderTabbedPanel::addRemoveActorSA(int id, bool addremove)
270 {
271         try{
272                 surrendmanager1->addRemoveActor(id, addremove);
273         }
274         catch(char* str){
275                 std::cout << "Exception : " << str << '\n';
276                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
277                 diag->ShowModal();
278                 delete diag;
279         }
280 }
281
282 /**
283 ** Adds or removes surface rendering actor with given ID
284 **/
285 void wxMaracasRenderTabbedPanel::addRemoveActorSB(int id, bool addremove)
286 {
287         try{
288                 surrendmanager2->addRemoveActor(id, addremove);
289         }
290         catch(char* str){
291                 std::cout << "Exception : " << str << '\n';
292                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
293                 diag->ShowModal();
294                 delete diag;
295         }
296 }
297
298 /**
299 ** Adds or removes surface rendering actor with given ID
300 **/
301 void wxMaracasRenderTabbedPanel::addRemoveActorSC(int id, bool addremove)
302 {       
303         try{
304                 surrendmanager3->addRemoveActor(id, addremove);
305         }
306         catch(char* str){
307                 std::cout << "Exception : " << str << '\n';
308                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
309                 diag->ShowModal();
310                 delete diag;
311         }
312 }       
313
314 /**
315 ** Sets color points values for the given volume rendering identified by parameter: volumeid
316 **/
317 void wxMaracasRenderTabbedPanel::SetValuesColorPointsFunction(int volid, std::vector<double> greylevelcolors,std::vector<double> red,std::vector<double> green,std::vector<double> blue)
318 {
319         volmanager->setVolumeColor(volid, greylevelcolors, red, green, blue);
320 }
321
322 /**
323 ** Sets points values for the given volume rendering identified by parameter: volumeid
324 **/
325 void wxMaracasRenderTabbedPanel::SetValuesPointsFunction(int volid, std::vector<double> greylevel, std::vector<double> values)
326 {
327         try{
328                 volmanager->setVolumeOpacity(volid, greylevel, values);
329         }
330         catch(char* str)
331         {
332                 wxString s( str,wxConvUTF8 );
333                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
334                 diag->ShowModal();
335                 delete diag;
336         }
337         
338 }
339
340 /**
341 ** Returns transfer function for the given volume rendering identified by parameter: volumeid
342 **/
343 vtkPiecewiseFunction* wxMaracasRenderTabbedPanel::GetTransferFunction(int volumeid)
344 {
345         return volmanager->GetTransferFunction(volumeid);
346 }
347
348 /**
349 ** Returns color function for the given volume rendering identified by parameter: volumeid
350 **/
351 vtkColorTransferFunction* wxMaracasRenderTabbedPanel::GetColorFunction(int volumeid)
352 {
353     return volmanager->GetColorFunction(volumeid);
354 }
355
356 /**
357 ** Changes color function by the given value for the given volume rendering identified by parameter: volumeid
358 **/
359 void wxMaracasRenderTabbedPanel::changeOpacityA(int _propid, int value)
360 {
361         surrendmanager1->changeOpacity(_propid,value);
362 }
363
364 /**
365 ** Changes isoValue by the given value for the given surface rendering image identified by parameter: propid
366 **/
367 void wxMaracasRenderTabbedPanel::changeIsoValueA(int propid, double value)
368 {
369         surrendmanager1->changeIsoValue(propid, value);
370 }
371
372 /**
373 ** Changes color for the given surface rendering image identified by parameter: propid
374 **/
375 void wxMaracasRenderTabbedPanel::changeColorA(int propid, double red, double green, double blue)
376 {
377         try
378         {
379                 surrendmanager1->changeColor(propid, red, green, blue);
380         }
381         catch(char* str)
382         {
383                 wxString s( str,wxConvUTF8 );
384                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
385                 diag->ShowModal();
386                 delete diag;
387         }
388 }
389
390 /**
391 ** Changes color function by the given value for the given volume rendering identified by parameter: volumeid
392 **/
393 void wxMaracasRenderTabbedPanel::changeOpacityB(int _propid, int value)
394 {
395         surrendmanager2->changeOpacity(_propid,value);
396 }
397
398 /**
399 ** Changes isoValue by the given value for the given surface rendering image identified by parameter: propid
400 **/
401 void wxMaracasRenderTabbedPanel::changeIsoValueB(int propid, double value)
402 {
403         surrendmanager2->changeIsoValue(propid, value);
404 }
405
406 /**
407 ** Changes color for the given surface rendering image identified by parameter: propid
408 **/
409 void wxMaracasRenderTabbedPanel::changeColorB(int propid, double red, double green, double blue)
410 {
411         try
412         {
413                 surrendmanager2->changeColor(propid, red, green, blue);
414         }
415         catch(char* str)
416         {
417                 wxString s( str,wxConvUTF8 );
418                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
419                 diag->ShowModal();
420                 delete diag;
421         }
422 }
423
424 /**
425 ** Changes color function by the given value for the given volume rendering identified by parameter: volumeid
426 **/
427 void wxMaracasRenderTabbedPanel::changeOpacityC(int _propid, int value)
428 {
429         surrendmanager3->changeOpacity(_propid,value);
430 }
431
432 /**
433 ** Changes isoValue by the given value for the given surface rendering image identified by parameter: propid
434 **/
435 void wxMaracasRenderTabbedPanel::changeIsoValueC(int propid, double value)
436 {
437         surrendmanager3->changeIsoValue(propid, value);
438 }
439
440 /**
441 ** Changes color for the given surface rendering image identified by parameter: propid
442 **/
443 void wxMaracasRenderTabbedPanel::changeColorC(int propid, double red, double green, double blue)
444 {
445         try
446         {
447                 surrendmanager3->changeColor(propid, red, green, blue);
448         }
449         catch(char* str)
450         {
451                 wxString s( str,wxConvUTF8 );
452                 wxMessageDialog* diag = new wxMessageDialog(this, s, s, wxICON_ERROR);
453                 diag->ShowModal();
454                 delete diag;
455         }
456 }
457
458 /**
459 ** Method called when VolumeRendering checkbox status changes: Either shows or hides VolumeRendering image
460 **/
461 void wxMaracasRenderTabbedPanel::onCheckBoxVChange(wxCommandEvent& event)
462 {
463         try{
464                 volmanager->addRemoveActor(this->getPropIdV(), checkboxVol->GetValue());        
465         }
466         catch(char* str){
467                 std::cout << "Exception : " << str << '\n';
468                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
469                 diag->ShowModal();
470                 delete diag;
471         }
472 }
473
474 /**
475 ** Method called when SurfaceRendering A checkbox status changes: Either shows or hides SurfaceRendering image
476 **/
477 void wxMaracasRenderTabbedPanel::onCheckBoxSAChange(wxCommandEvent& event)
478 {       
479         try{
480                 surrendmanager1->addRemoveActor(this->getPropIdSA(), checkboxSA->GetValue());   
481         }
482         catch(char* str){
483                 std::cout << "Exception : " << str << '\n';
484                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
485                 diag->ShowModal();
486                 delete diag;
487         }
488 }
489
490 /**
491 ** Method called when SurfaceRendering B checkbox status changes: Either shows or hides SurfaceRendering B image
492 **/
493 void wxMaracasRenderTabbedPanel::onCheckBoxSBChange(wxCommandEvent& event)
494 {       
495         try{
496                 surrendmanager2->addRemoveActor(this->getPropIdSB(), checkboxSB->GetValue());   
497         }
498         catch(char* str){
499                 std::cout << "Exception : " << str << '\n';
500                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
501                 diag->ShowModal();
502                 delete diag;
503         }
504 }
505
506 /**
507 ** Method called when SurfaceRendering C checkbox status changes: Either shows or hides SurfaceRendering C image
508 **/
509 void wxMaracasRenderTabbedPanel::onCheckBoxSCChange(wxCommandEvent& event)
510 {       
511         try{
512                 surrendmanager3->addRemoveActor(this->getPropIdSC(), checkboxSC->GetValue());   
513         }
514         catch(char* str){
515                 std::cout << "Exception : " << str << '\n';
516                 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str,wxConvUTF8 ), wxString(str,wxConvUTF8 ), wxICON_ERROR);
517                 diag->ShowModal();
518                 delete diag;
519         }
520 }
521
522 /**
523 **
524 **/
525 void wxMaracasRenderTabbedPanel::onOpenParameters(wxCommandEvent& event){       
526         
527         dialog = new wxMaracasRenderImageManagementPanel(this, volmanager, surrendmanager1, surrendmanager2, surrendmanager3, this->getPropIdV());
528         dialog->SetSize(400, 580);
529         dialog->Show();
530 }
531
532
533 /**
534 ** Gets volume rendering image asociated to the given ID
535 **/
536 void wxMaracasRenderTabbedPanel::onColorChange(wxCommandEvent& event)
537 {       
538         /*Temporarily disabled*/
539
540         //if(mwxwidget->ShowModal()==wxID_OK){
541         //updateVolume();
542         //      mwxwidget->Show(false);
543         //}     
544 }
545
546 /**
547 ** 
548 **/
549 vtkImageData* wxMaracasRenderTabbedPanel::getVolImage(int id)
550 {       
551         return volmanager->getImageData();
552 }
553
554 /**
555 ** Gets surface rendering A image asociated to the given ID
556 **/
557 vtkImageData* wxMaracasRenderTabbedPanel::getSurfAImage(int id)
558 {       
559         return surrendmanager1->getImageData();
560 }
561
562 /**
563 ** Gets surface rendering B image asociated to the given ID
564 **/
565 vtkImageData* wxMaracasRenderTabbedPanel::getSurfBImage(int id)
566 {       
567         return surrendmanager2->getImageData();
568 }
569
570 /**
571 ** Gets surface rendering C image asociated to the given ID
572 **/
573 vtkImageData* wxMaracasRenderTabbedPanel::getSurfCImage(int id)
574 {       
575         return surrendmanager3->getImageData();
576 }
577
578 /**
579 **
580 **/
581 void wxMaracasRenderTabbedPanel::onOpenCutter(wxCommandEvent& event)
582 {       
583         
584 }
585
586 /**
587 **
588 **/
589 int wxMaracasRenderTabbedPanel::getPropIdV()
590 {
591         return _propidV;
592 }
593
594 /**
595 **
596 **/
597 int wxMaracasRenderTabbedPanel::getPropIdSA()
598 {
599         return _propidSA;
600 }
601
602 /**
603 **
604 **/
605 int wxMaracasRenderTabbedPanel::getPropIdSB()
606 {
607         return _propidSB;
608 }
609
610 /**
611 **
612 **/
613 int wxMaracasRenderTabbedPanel::getPropIdSC()
614 {
615         return _propidSC;
616 }
617