1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 /*=========================================================================
29 Module: $RCSfile: CutModelMainPanel.cxx,v $
31 Date: $Date: 2012/11/15 14:16:20 $
32 Version: $Revision: 1.14 $
34 Copyright: (c) 2002, 2003
37 This software is distributed WITHOUT ANY WARRANTY; without even
38 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
39 PURPOSE. See the above copyright notice for more information.
41 =========================================================================*/
45 // EOF - wxMaracasMPR.cxx
47 #include "CutModelMainPanel.h"
48 #include "HistogramDialog.h"
49 #include "creaSystem.h"
51 #include <wx/colordlg.h>
52 #include <wx/bmpbuttn.h>
61 CutModelMainPanel* CutModelMainPanel::instance=NULL;
63 CutModelMainPanel::CutModelMainPanel( wxWindow* parent, std::string path)
64 : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
72 CutModelMainPanel::~CutModelMainPanel( ){
77 void CutModelMainPanel::initialize(std::string path){
78 cutmanager = new CutModelManager(path);
80 _wxauimanager = new wxAuiManager(this);
82 wxAuiPaneInfo paneinfo;
84 //RaC 5-02-2010 Add tabs
85 _notebook = new wxAuiNotebook(this,wxID_ANY,wxDefaultPosition,wxDefaultSize,wxAUI_NB_TOP |wxAUI_NB_TAB_MOVE | wxAUI_NB_SCROLL_BUTTONS);
87 _notebook->AddPage(new ToolBarCutModel(_notebook),_T("Cutter"),true);
88 //_wxauimanager->AddPane(new ToolBarCutModel(this),paneinfo.ToolbarPane().Top());
89 _wxauimanager->AddPane(_notebook,paneinfo.Center().CloseButton(false));
90 addPolygonCutterTab();
93 _wxauimanager->Update();
96 CutModelMainPanel* CutModelMainPanel::getInstance(wxWindow* parent, std::string path){
99 parent = new wxFrame();
101 instance = new CutModelMainPanel(parent, path);
106 /*CutModelMainPanel* CutModelMainPanel::getInstance(){
111 void CutModelMainPanel::setImageData(vtkImageData* img){
114 cutmanager->setImageData(img);
115 }catch(CutModelException e){
116 showErrorDialog(e.getCause());
120 void CutModelMainPanel::setInteractor(vtkRenderWindowInteractor* interactor){
123 cutmanager->setInteractor(interactor);
124 }catch(CutModelException e){
125 showErrorDialog(e.getCause());
129 void CutModelMainPanel::setRenderer(vtkRenderer* renderer){
132 cutmanager->setRenderer(renderer);
133 }catch(CutModelException e){
134 showErrorDialog(e.getCause());
138 void CutModelMainPanel::checkInvariant()throw (CutModelException){
139 if(cutmanager==NULL){
140 throw CutModelException("The manager is not initialize");
144 void CutModelMainPanel::showErrorDialog(std::string str){
145 wxMessageDialog* diag = new wxMessageDialog(this, wxString(str.c_str(),wxConvUTF8 ), wxString(str.c_str(),wxConvUTF8 ), wxICON_ERROR);
149 void CutModelMainPanel::RemoveActor(int id){
153 if(!this->IsBeingDeleted()){
155 for(i = 0; i < (int)viewpanels.size()-1;i++){
156 CutModelView* view = viewpanels[i];
157 if(view->getId()==id){
158 for(j = i; j < (int)viewpanels.size()-1;j++){
159 viewpanels[j]=viewpanels[j+1];
161 i = viewpanels.size();
164 viewpanels.pop_back();
165 cutmanager->RemoveActor(id);
168 }catch(CutModelException e){
169 showErrorDialog(e.getCause());
174 void CutModelMainPanel::onCheckChanged(){
176 if(_isFirstTime==true){
178 cutmanager->InitializePolygonInteractorStyle();
186 cutmanager->ParallelProjectionOn();
187 btnExecutePolygonCut->Enable(false);
188 _notebook->GetPage(0)->Enable(false);
189 _radioinsideout->Enable(false);
190 lblMessagePolygon->SetLabel(_T("Drawing polygon..."));
196 cout<<"Finish Drawing"<<endl;
197 cutmanager->ParallelProjectionOff();
198 btnExecutePolygonCut->Enable(true);
199 _notebook->GetPage(0)->Enable(true);
200 _radioinsideout->Enable(true);
201 lblMessagePolygon->SetLabel(_T("Contour saved! Click on Execute Cut"));
204 cutmanager->UpdatePolygon(_isCheck);
210 void CutModelMainPanel::onExecuteCutPolygon()
213 cutmanager->ExecuteCutPolygon(_radioinsideout->GetSelection());
214 lblMessagePolygon->SetLabel(_T("No contour drawed"));
218 void CutModelMainPanel::onAddCutModel(){
222 int id = addNewViewPanel();
223 cutmanager->onAddCutModel(id, getModelView(id));
227 ShowCurrentPanel(id);
229 }catch(CutModelException e){
230 showErrorDialog(e.getCause());
234 void CutModelMainPanel::ShowCurrentPanel(int id)
237 for(i = 0; i < (int) viewpanels.size();i++){
238 if(viewpanels[i]->getId()==id){
239 _wxauimanager->GetPane(viewpanels[i]).Show(true);
240 cutmanager->RefreshActor(id);
242 _wxauimanager->GetPane(viewpanels[i]).Show(false);
245 _wxauimanager->Update();
247 int CutModelMainPanel::addNewViewPanel()throw( CutModelException){
249 CutModelView* viewpanel = new CutModelView(this,cutmanager->getImageRange());
251 wxAuiPaneInfo paneinfo0;
252 _wxauimanager->AddPane(viewpanel, paneinfo0.DefaultPane().DestroyOnClose().Centre().Bottom());
254 viewpanel->setId(_panelid);
255 viewpanels.push_back(viewpanel);
257 return viewpanel->getId();
261 CutModelView* CutModelMainPanel::getModelView(int id)throw( CutModelException)
263 CutModelView* current = NULL;
265 for(i = 0; i < (int)viewpanels.size();i++)
267 if(viewpanels[i]->getId()==id)
269 current = viewpanels[i];
274 std::string s = "Id not found";
275 throw CutModelException(s);
280 void CutModelMainPanel::onUndo()
284 /*int result = */ cutmanager->Undo(); // result unused// JPR
286 }catch(CutModelException e){
287 showErrorDialog(e.getCause());
291 void CutModelMainPanel::onRedo(){
294 /*int result = */ cutmanager->Redo();
296 }catch(CutModelException e){
297 showErrorDialog(e.getCause());
301 void CutModelMainPanel::changeOpacity(int id,int opacity){
304 cutmanager->changeOpacity(id, opacity);
306 }catch(CutModelException e){
307 showErrorDialog(e.getCause());
311 void CutModelMainPanel::ShowViewBox(int id,bool check){
314 cutmanager->ShowViewBox(id, check);
316 }catch(CutModelException e){
317 showErrorDialog(e.getCause());
321 void CutModelMainPanel::ShowPopUpMenu(int id){
322 showErrorDialog("test");
325 void CutModelMainPanel::changeColor(int id,double r,double g,double b){
329 cutmanager->changeColor(id, r, g, b);
331 }catch(CutModelException e){
332 showErrorDialog(e.getCause());
336 void CutModelMainPanel::ChangeShape(int id,int selection){
340 cutmanager->ChangeShape(id, selection);
342 }catch(CutModelException e){
343 showErrorDialog(e.getCause());
346 void CutModelMainPanel::updateActorDirection(int id){
350 cutmanager->updateActorDirection(id);
352 }catch(CutModelException e){
353 showErrorDialog(e.getCause());
357 void CutModelMainPanel::ExecuteCut(int id, double* range, bool isinside){
361 cutmanager->ExecuteCut(id, range, isinside);
362 }catch(CutModelException e){
363 showErrorDialog(e.getCause());
367 void CutModelMainPanel::ExecuteAll(){
369 for(i = 0; i < (int)viewpanels.size(); i++){
370 viewpanels[i]->ExecuteCut();
374 vtkImageData* CutModelMainPanel::GetResultImage(){
377 return cutmanager->GetResultImage();
378 }catch(CutModelException e){
379 showErrorDialog(e.getCause());
384 void CutModelMainPanel::ShowStatistics(int id){
387 HistogramDialog *histo = new HistogramDialog(this, _T("Statistics"));
389 histo->initializeHistogram(cutmanager->GetResultImage());
396 void CutModelMainPanel::SaveCutModelData(std::string filename){
397 cutmanager->SaveCutModelData(filename);
400 void CutModelMainPanel::LoadCutModelData(std::string filename){
401 cutmanager->LoadCutModelData(filename);
404 void CutModelMainPanel::SetType(int type){
408 int CutModelMainPanel::GetType(){
412 void CutModelMainPanel::addPolygonCutterTab(){
413 wxPanel *panel = new wxPanel(_notebook);
414 panel->SetAutoLayout(true);
415 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
416 panel->SetSizer(sizer);
417 sizer->AddSpacer(20);
419 wxCheckBox *item = new wxCheckBox(panel,10,_T("Draw Polygon"),wxDefaultPosition,wxDefaultSize,0,wxDefaultValidator,_T("") );
420 item->SetValue(false);
421 Connect(item->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&PolygonCutterEventHandlerCutModel::onCheckChanged));
422 sizer->Add(item, 0, wxALIGN_LEFT);
424 lblMessagePolygon = new wxStaticText(panel,30,_T("No contour drawed"),wxDefaultPosition,wxDefaultSize,0,_T("") );
425 sizer->Add(lblMessagePolygon, 0, wxALIGN_LEFT);
427 wxString choices0[2];
428 choices0[0] = _T("inside");
429 choices0[1] = _T("outside");
430 _radioinsideout = new wxRadioBox(panel,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
431 sizer->Add(_radioinsideout, wxALIGN_LEFT);
433 btnExecutePolygonCut = new wxButton(panel,20,_T("Execute Cut"),wxDefaultPosition,wxDefaultSize,0,wxDefaultValidator,_T("") );
434 Connect(btnExecutePolygonCut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)(&PolygonCutterEventHandlerCutModel::onExecuteCutPolygon));
435 sizer->Add(btnExecutePolygonCut, 0, wxALIGN_LEFT);
437 _notebook->AddPage(panel, _T("Polygon Cutter"), false);
440 void PolygonCutterEventHandlerCutModel::onCheckChanged(wxCommandEvent& event){
441 CutModelMainPanel::getInstance()->onCheckChanged();
444 void PolygonCutterEventHandlerCutModel::onExecuteCutPolygon(wxCommandEvent& event){
445 CutModelMainPanel::getInstance()->onExecuteCutPolygon();
451 ToolBarCutModel::ToolBarCutModel(wxWindow * parent)
452 : wxToolBar(parent, -1, wxDefaultPosition, wxDefaultSize)
454 wxBitmap bitmap10(Add_xpm);
455 this->AddTool(10, wxString(_T("Add")),bitmap10);
457 this->AddSeparator();
459 wxBitmap bitmap20(Undo_xpm);
460 this->AddTool(20, wxString(_T("Undo")),bitmap20);
462 wxBitmap bitmap30(Redo_xpm);
463 this->AddTool(30, wxString(_T("Redo")),bitmap30);
465 this->AddSeparator();
467 wxBitmap bitmap40(OkAll_xpm);
468 this->AddTool(40, wxString(_T("Ok All")),bitmap40);
472 _evthand = new ToolBarEventHandlerCutModel();
473 this->SetEventHandler(_evthand);
476 ToolBarCutModel::~ToolBarCutModel(void){
479 ToolBarEventHandlerCutModel::ToolBarEventHandlerCutModel()
482 ToolBarEventHandlerCutModel::~ToolBarEventHandlerCutModel(){
485 void ToolBarEventHandlerCutModel::onAdd(wxCommandEvent& event){
486 CutModelMainPanel::getInstance()->onAddCutModel();
489 void ToolBarEventHandlerCutModel::onUndo(wxCommandEvent& event){
490 CutModelMainPanel::getInstance()->onUndo();
493 void ToolBarEventHandlerCutModel::onRedo(wxCommandEvent& event){
494 CutModelMainPanel::getInstance()->onRedo();
497 void ToolBarEventHandlerCutModel::onExecuteAll(wxCommandEvent& event){
498 CutModelMainPanel::getInstance()->ExecuteAll();
501 BEGIN_EVENT_TABLE(ToolBarEventHandlerCutModel, wxEvtHandler)
502 EVT_MENU(10, ToolBarEventHandlerCutModel::onAdd)
503 EVT_MENU(20, ToolBarEventHandlerCutModel::onUndo)
504 EVT_MENU(30, ToolBarEventHandlerCutModel::onRedo)
505 EVT_MENU(40, ToolBarEventHandlerCutModel::onExecuteAll)