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