]> Creatis software - creaMaracasVisu.git/blob - lib/GUI/Wx/SurfaceRenderer/wxMaracasSurfaceRenderingProp3D.cxx
Support #1768 CREATIS Licence insertion
[creaMaracasVisu.git] / lib / GUI / Wx / SurfaceRenderer / wxMaracasSurfaceRenderingProp3D.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 "wxMaracasSurfaceRenderingProp3D.h"
27 #include "wxMaracasDialog_NViewers.h"
28
29 #include <wx/colordlg.h>
30 #include "wxMaracasSurfaceRendering.h"
31 #include "wxMaracasRendererView.h"
32
33 #include "vtkImageData.h"
34
35 #include <OpenImage.xpm>
36 #include <Add.xpm>
37 #include "Color.xpm"
38
39 /**
40 **      Implementation of viewProp3D
41 **/
42 wxMaracasSurfaceRenderingProp3D::wxMaracasSurfaceRenderingProp3D(wxWindow* parent, int propid, bool _isComplexBox, int _panID)
43 :wxMaracasSurfaceRenderingPanel(parent, propid, _isComplexBox, _panID){
44         createControls();       
45 }
46
47 /**
48 ** Panel Destructor
49 **/ 
50 wxMaracasSurfaceRenderingProp3D::~wxMaracasSurfaceRenderingProp3D(){    
51         //wxMaracasSurfaceRendering::getInstance()->addRemoveActor(_propid, false);
52         if(this->isComplex())
53         {       
54                 //if(this->getPanId() == 1)
55                 //      ((wxMaracasRenderTabbedPanel*)(wxMaracasRendererView::getInstance())->getTabbedPanel())->addRemoveActorSA(_propid, false);
56                 //if(this->getPanId() == 2)
57                 //      ((wxMaracasRenderTabbedPanel*)(wxMaracasRendererView::getInstance())->getTabbedPanel())->addRemoveActorSB(_propid, false);
58                 //if(this->getPanId() == 3)
59                 //      ((wxMaracasRenderTabbedPanel*)(wxMaracasRendererView::getInstance())->getTabbedPanel())->addRemoveActorSC(_propid, false);
60         }
61         //else
62                 //wxMaracasSurfaceRendering::getInstance()->deleteActor(_propid);
63 }
64
65 /**
66 ** Constructs the panel. Elements inside may change depending on which tipe of panel construction if being requested
67 **/
68 void wxMaracasSurfaceRenderingProp3D::createControls(){
69
70         wxFlexGridSizer* sizersurfprop = new wxFlexGridSizer(1);
71         
72         if(!isComplexBox) 
73         {
74                 //wxString choices[2];
75                 //choices[0] = wxString(_T("On"));
76                 //choices[1] = wxString(_T("Off"));
77                 wxFlexGridSizer* checkboxsizer = new wxFlexGridSizer(2);
78
79                 checkbox = new  wxCheckBox(this,-1,wxString(_T("Show Actor")));
80                 Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasSurfaceRenderingProp3D::onCheckBoxChange);  
81                 checkbox->SetValue(true);       
82                 checkboxsizer->Add(checkbox,1, wxGROW);
83
84
85                 if(wxMaracasSurfaceRendering::getInstance()->interactorSet()){
86                         checkboxsurface = new  wxCheckBox(this,-1,wxString(_T("Surface Box")));
87                         Connect(checkboxsurface->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&wxMaracasSurfaceRenderingProp3D::onCheckBoxSurfaceChange);    
88                         checkboxsurface->SetValue(true);
89                         checkboxsizer->Add(checkboxsurface,1, wxGROW);
90                 }       
91
92
93                 sizersurfprop->Add(checkboxsizer,1, wxGROW);
94         }
95
96         //this->addControl(checkbox);   
97         wxFlexGridSizer* sizerbut = new wxFlexGridSizer(3);
98
99         wxBitmap bitmap(Color_xpm);
100         _colorchoose = new wxBitmapButton(this, -1, bitmap,wxDefaultPosition,wxSize(30,30));    
101         Connect(_colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasSurfaceRenderingProp3D::onColorChange);                   
102         sizerbut->Add(_colorchoose,1, wxGROW);
103
104         /*
105         wxBitmap bitmap1(Add_xpm);
106         _viewimage = new wxBitmapButton(this, -1, bitmap1, wxDefaultPosition, wxSize(30,30));   
107         Connect(_viewimage->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&wxMaracasSurfaceRenderingProp3D::onViewImage);                       
108         sizerbut->Add(_viewimage,wxFIXED_MINSIZE);
109         */
110         sizersurfprop->Add(sizerbut,1, wxGROW);
111         //sizercolor->Add(checkbox,wxFIXED_MINSIZE);
112         //sizercolor->Add(_colorchoose,wxFIXED_MINSIZE);
113         //this->addControl(sizercolor);
114
115         wxStaticText* label = new wxStaticText(this, -1, wxString(_T("Opacity")));              
116         opacity = new wxSlider(this, -1,100,0,100,wxDefaultPosition,wxDefaultSize,wxSL_HORIZONTAL|wxSL_LABELS); 
117         Connect(opacity->GetId(), wxEVT_SCROLL_CHANGED, (wxObjectEventFunction)&wxMaracasSurfaceRenderingProp3D::onOpacityRelease);     
118         wxFlexGridSizer* sizeropacity = new wxFlexGridSizer(1,1,1);     
119         sizeropacity->Add(label,1, wxGROW);
120         sizeropacity->Add(opacity,1, wxGROW);
121
122         sizersurfprop->Add(sizeropacity,1, wxGROW);
123
124         this->addControl(sizersurfprop);
125         
126 }
127
128 /**
129 ** Method called by setting on or off the actor
130 **/
131 void wxMaracasSurfaceRenderingProp3D::onCheckBoxChange(wxCommandEvent& event){  
132         //if(!isComplexBox)
133         wxMaracasSurfaceRendering::getInstance()->addRemoveActor(this->getPropId(), checkbox->GetValue());      
134 }
135 void wxMaracasSurfaceRenderingProp3D::onCheckBoxSurfaceChange(wxCommandEvent& event){   
136         //if(!isComplexBox)
137         wxMaracasSurfaceRendering::getInstance()->addRemoveSurfaceBox(this->getPropId(), checkboxsurface->GetValue());  
138 }
139
140 /**
141 ** 
142 **/
143 void wxMaracasSurfaceRenderingProp3D::onColorChange(wxCommandEvent& event){
144         wxColourDialog* colourdiag = new wxColourDialog(this);
145         if(colourdiag->ShowModal()==wxID_OK){
146                 wxColour colour = colourdiag->GetColourData().GetColour();
147                 _colorchoose->SetBackgroundColour(colour);
148
149                 double r = (double)(colour.Red())/255.0;
150                 double g = (double)(colour.Green())/255.0;
151                 double b = (double)(colour.Blue())/255.0;
152                 
153                 if(this->isComplex()){
154                         if(this->getPanId() == 1)
155                                 ( (wxMaracasRendererView::getInstance())->getTabbedPanel(getPropId()) )->changeColorA(this->getPropId(), r, g, b);
156                         if(this->getPanId() == 2)
157                                 ( (wxMaracasRendererView::getInstance())->getTabbedPanel(getPropId()) )->changeColorB(this->getPropId(), r, g, b);
158                         if(this->getPanId() == 3)
159                                 ( (wxMaracasRendererView::getInstance())->getTabbedPanel(getPropId()) )->changeColorC(this->getPropId(), r, g, b);
160                 }
161                 else
162                         wxMaracasSurfaceRendering::getInstance()->changeColor(this->getPropId(),r,g,b);
163         }
164         delete colourdiag;
165 }
166 /*void wxMaracasSurfaceRenderingProp3D::onActionButtonPressedEliminate( wxCommandEvent& event ){        
167
168 }*/
169
170 /**
171 ** Changes the opacity of an actor
172 **/
173 void wxMaracasSurfaceRenderingProp3D::onOpacityRelease(wxScrollEvent& event ){
174
175         if(this->isComplex()){
176                 if(this->getPanId() == 1)
177                         ( (wxMaracasRendererView::getInstance())->getTabbedPanel(getPropId()) )->changeOpacityA(this->getPropId(),opacity->GetValue());
178                 if(this->getPanId() == 2)
179                         ( (wxMaracasRendererView::getInstance())->getTabbedPanel(getPropId()) )->changeOpacityB(this->getPropId(),opacity->GetValue());
180                 if(this->getPanId() == 3)
181                         ( (wxMaracasRendererView::getInstance())->getTabbedPanel(getPropId()) )->changeOpacityC(this->getPropId(),opacity->GetValue());
182         }
183         else
184                 wxMaracasSurfaceRendering::getInstance()->changeOpacity(this->getPropId(),opacity->GetValue());
185
186 }
187
188 /**Carolina Perez: Method recently added. Not functionalit yet
189 ** Loads the volume in a separate window
190 **/
191 void wxMaracasSurfaceRenderingProp3D::onViewImage(wxCommandEvent& event){       
192         vtkImageData* img;
193         if(this->isComplexBox){
194                 if(this->getPanId() == 1)
195                         img = (wxMaracasRendererView::getInstance())->getTabbedPanel(_propid)->getSurfAImage();
196                 if(this->getPanId() == 2)
197                         img = (wxMaracasRendererView::getInstance())->getTabbedPanel(_propid)->getSurfBImage();
198                 if(this->getPanId() == 3)
199                         img = (wxMaracasRendererView::getInstance())->getTabbedPanel(_propid)->getSurfCImage();
200                 
201                 std::vector<int> type;
202                 type.push_back(6);
203
204                 wxMaracasDialog_NViewers* dialog1 = new wxMaracasDialog_NViewers(this, img, &type, wxString(_T("Volume Visualization") ));
205                 dialog1->SetSize(730, 700);
206                 dialog1->Show();
207         }
208         else{   
209                 //vtkImageData* img = wxMaracasMultipleVolumeRendererView::getInstance()->getVolImage();
210         }
211 }