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