Program: wxMaracas
Module: $RCSfile: CutModel2MainPanel.cxx,v $
Language: C++
- Date: $Date: 2009/11/19 17:00:27 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2009/11/23 13:00:20 $
+ Version: $Revision: 1.5 $
Copyright: (c) 2002, 2003
License:
void CutModel2MainPanel::initialize(std::string path){
- cutmanager = new CutModelManager(path);
+ cutmanager = new CutModel2Manager(path);
_panelid = 0;
_wxauimanager = new wxAuiManager(this);
checkInvariant();
int id = addNewViewPanel();
- cutmanager->onAddCutModel(id, getModelView(id));
+ cutmanager->onAddCutModel2(id, getModelView(id));
_panelid++;
}
int CutModel2MainPanel::addNewViewPanel()throw( CutModelException){
- CutModelView* viewpanel = new CutModelView(this,cutmanager->getImageRange());
+ CutModel2View* viewpanel = new CutModel2View(this,cutmanager->getImageRange());
wxAuiPaneInfo paneinfo0;
_wxauimanager->AddPane(viewpanel, paneinfo0.DefaultPane().DestroyOnClose().Centre());
}
-CutModelView* CutModel2MainPanel::getModelView(int id)throw( CutModelException){
+CutModel2View* CutModel2MainPanel::getModelView(int id)throw( CutModelException){
- CutModelView* current = NULL;
+ CutModel2View* current = NULL;
for(int i = 0; i < viewpanels.size();i++){
if(viewpanels[i]->getId()==id){
current = viewpanels[i];
delete histo;
}
-void CutModel2MainPanel::SaveCutModel2Data(std::string filename){
+void CutModel2MainPanel::SaveCutModelData(std::string filename){
cutmanager->SaveCutModelData(filename);
}
-void CutModel2MainPanel::LoadCutModel2Data(std::string filename){
+void CutModel2MainPanel::LoadCutModelData(std::string filename){
cutmanager->LoadCutModelData(filename);
}
/**
Program: wxMaracas
Module: $RCSfile: CutModel2MainPanel.h,v $
Language: C++
- Date: $Date: 2009/11/19 17:00:27 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2009/11/23 13:00:21 $
+ Version: $Revision: 1.5 $
Copyright: (c) 2002, 2003
License:
#include "marTypes.h"
-#include "CutModelManager.h"
+#include "CutModel2Manager.h"
#include "CutModelException.h"
-#include "CutModelView.h"
+#include "CutModel2View.h"
#include "vtkImageData.h"
#include "vtkRenderWindowInteractor.h"
static CutModel2MainPanel* instance;
- CutModelManager* cutmanager;
+ CutModel2Manager* cutmanager;
void checkInvariant() throw( CutModelException);
void showErrorDialog(std::string str);
- void SaveCutModel2Data(std::string filename);
+ void SaveCutModelData(std::string filename);
- void LoadCutModel2Data(std::string filename);
+ void LoadCutModelData(std::string filename);
- std::vector<CutModelView*> viewpanels;
+ std::vector<CutModel2View*> viewpanels;
wxAuiManager* _wxauimanager;
int addNewViewPanel()throw( CutModelException);
- CutModelView* getModelView(int id)throw( CutModelException);
+ CutModel2View* getModelView(int id)throw( CutModelException);
int _panelid;
};
--- /dev/null
+/*=========================================================================
+
+ Program: wxMaracas
+ Module: $RCSfile: CutModel2View.cxx,v $
+ Language: C++
+ Date: $Date: 2009/11/23 13:00:26 $
+ Version: $Revision: 1.3 $
+
+ Copyright: (c) 2002, 2003
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+=========================================================================*/
+
+
+
+// EOF - wxMaracasMPR.cxx
+
+#include "CutModel2View.h"
+
+
+#include <wx/colordlg.h>
+#include <wx/bmpbuttn.h>
+
+#include <OpenImage.xpm>
+#include <Color.xpm>
+#include <Ok1.xpm>
+#include <Statistics.xpm>
+
+#include "vtkBoxWidget.h"
+
+#include "CutModel2MainPanel.h"
+
+CutModel2View::CutModel2View( wxWindow* parent, double* range)
+: wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize){
+
+ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+
+ this->SetSizer(sizer);
+
+ sizer->Add(getBoxControls(this, range),wxSizerFlags().FixedMinSize());
+
+ sizer->AddSpacer(5);
+
+ sizer->Add(getActorProperties(this),wxSizerFlags().FixedMinSize());
+
+
+ wxBitmap bitmapok(Ok1_xpm);
+ wxBitmapButton* okbutton = new wxBitmapButton(this, -1, bitmapok,wxDefaultPosition,wxSize(30,30));
+ Connect(okbutton->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModel2ViewEventHandler::onExecute));
+
+ sizer->AddSpacer(5);
+ sizer->Add(okbutton,wxSizerFlags().FixedMinSize());
+
+
+
+
+
+}
+CutModel2View::~CutModel2View( ){
+ CutModel2MainPanel::getInstance()->RemoveActor(this->getId());
+}
+
+wxSizer* CutModel2View::getBoxControls(wxWindow* parent,double* range){
+
+ wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
+ wxCheckBox* checkbox = new wxCheckBox(parent,-1,_T("View Box"));
+ sizer->Add(checkbox,wxSizerFlags().FixedMinSize());
+ checkbox->SetValue(true);
+ Connect(checkbox->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onViewBoxChecked));
+
+ wxString choices1[3];
+ //choices1[0] = _T("Select a shape...");
+ choices1[0] = _T("Sphere");
+ choices1[1] = _T("Cylinder");
+ choices1[2] = _T("Cube");
+ wxComboBox* combo = new wxComboBox(parent, -1,_T(""),wxDefaultPosition,wxDefaultSize,3,choices1);
+ combo->SetValue(_T("Sphere"));
+ sizer->Add(combo,wxSizerFlags().FixedMinSize());
+ Connect(combo->GetId(), wxEVT_COMMAND_COMBOBOX_SELECTED,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onShapeChange));
+
+ wxStaticText* labelgreyv = new wxStaticText(parent, -1, wxString(_T("Grey value range")));
+ _sliderrange = new wxSlider(parent, -1, range[0],range[0],range[1],wxDefaultPosition,wxDefaultSize,wxSL_LABELS|wxSL_SELRANGE);
+ wxBoxSizer* sizergreyv = new wxBoxSizer(wxVERTICAL);
+ sizergreyv->Add(labelgreyv,wxSizerFlags().FixedMinSize());
+ sizergreyv->Add(_sliderrange,wxSizerFlags().FixedMinSize());
+ sizer->Add(sizergreyv,wxSizerFlags().FixedMinSize().Border());
+
+ wxString choices0[2];
+ choices0[0] = _T("inside");
+ choices0[1] = _T("outside");
+ _radioinsideout = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices0);
+ sizer->Add(_radioinsideout,wxSizerFlags().FixedMinSize());
+
+ /*wxString choices[2];
+ choices[0] = _T("Cut");
+ choices[1] = _T("Statistics");
+ _radiocutstat = new wxRadioBox(parent,-1,_T(""), wxDefaultPosition, wxDefaultSize,2,choices);
+ sizer->Add(_radiocutstat,wxSizerFlags().FixedMinSize());*/
+
+ wxBitmap bitmap(Statistics_xpm);
+ wxBitmapButton* statbut = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
+ Connect(statbut->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)(&CutModel2ViewEventHandler::onStatistics));
+ sizer->Add(statbut,wxSizerFlags().FixedMinSize());
+
+
+
+ return sizer;
+}
+wxSizer* CutModel2View::getActorProperties(wxWindow* parent){
+
+ wxBoxSizer* sizeractorproperties = new wxBoxSizer(wxVERTICAL);
+
+ wxStaticText* labelshapeactor = new wxStaticText(parent, -1, wxString(_T("Actor's properties")));
+
+ sizeractorproperties->Add(labelshapeactor,wxSizerFlags().FixedMinSize());
+
+ sizeractorproperties->Add(getColorChooseActor(parent),wxSizerFlags().FixedMinSize());
+
+ sizeractorproperties->Add(getOpacityActor(parent),wxSizerFlags().FixedMinSize());
+
+ return sizeractorproperties;
+
+}
+
+wxSizer* CutModel2View::getOpacityActor(wxWindow* parent){
+ wxBoxSizer* sizeropacity = new wxBoxSizer(wxVERTICAL);
+
+ wxStaticText* labelopacity = new wxStaticText(parent, -1, wxString(_T("Opacity")));
+ wxSlider* slider0 = new wxSlider(parent, -1, 60,0,100,wxDefaultPosition,wxDefaultSize,wxSL_LABELS);
+ Connect(slider0->GetId(), wxEVT_SCROLL_THUMBRELEASE,(wxObjectEventFunction)(&CutModel2ViewEventHandler::onOpacityChange));
+
+ sizeropacity->Add(labelopacity,wxSizerFlags().FixedMinSize());
+ sizeropacity->Add(slider0,wxSizerFlags().FixedMinSize());
+
+ return sizeropacity;
+}
+
+wxSizer* CutModel2View::getColorChooseActor(wxWindow* parent){
+ wxBoxSizer* sizercolor = new wxBoxSizer(wxHORIZONTAL);
+ wxBitmap bitmap(Color_xpm);
+ wxBitmapButton* colorchoose = new wxBitmapButton(parent, -1, bitmap,wxDefaultPosition,wxSize(30,30));
+ wxObjectEventFunction f = (wxObjectEventFunction)(&CutModel2ViewEventHandler::onColorChange);
+ Connect(colorchoose->GetId(), wxEVT_COMMAND_BUTTON_CLICKED, f);
+
+ _currentcolor = new wxStaticText(parent,-1,_T(""),wxDefaultPosition,wxSize(20,20));
+ this->SetCurrentColor(wxColour(255.0,0.0,0.0));
+
+ sizercolor->Add(colorchoose,wxSizerFlags().FixedMinSize());
+ sizercolor->AddSpacer(5);
+ sizercolor->Add(_currentcolor,wxSizerFlags().FixedMinSize().Centre());
+ return sizercolor;
+}
+
+void CutModel2View::checkInvariant()throw (CutModelException){
+
+}
+
+void CutModel2View::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) { // virtual
+ //vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
+
+ if(eventId==vtkCommand::StartInteractionEvent){
+ CutModel2MainPanel::getInstance()->ShowCurrentPanel(this->getId());
+ }else if(eventId==vtkCommand::InteractionEvent){
+ CutModel2MainPanel::getInstance()->updateActorDirection(this->getId());
+ }else if(eventId==vtkCommand::RightButtonReleaseEvent){
+ // =(
+ CutModel2MainPanel::getInstance()->ShowPopUpMenu(this->getId());
+ }
+}
+
+void CutModel2View::ExecuteCut(){
+ if(this->isCut()){
+ CutModel2MainPanel::getInstance()->ExecuteCut(this->getId(),this->getRange(),this->isInside());
+ }else{
+ }
+
+}
+
+double* CutModel2View::getRange(){
+ double* x = new double[3];
+ x[0] = 0;
+ x[1] = _sliderrange->GetValue();
+ x[2] = 100000;
+
+ return x;
+}
+bool CutModel2View::isCut(){
+ return true;
+ //return _radiocutstat->GetSelection()==0;
+}
+bool CutModel2View::isInside(){
+ return _radioinsideout->GetSelection()==0;
+}
+void CutModel2View::SetCurrentColor(wxColour colour){
+ _currentcolor->SetBackgroundColour(colour);
+
+ this->Refresh();
+ this->Layout();
+}
+
+void CutModel2ViewEventHandler::onColorChange(wxCommandEvent& event){
+ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
+ wxColourDialog* colourdiag = new wxColourDialog(parent);
+ if(colourdiag->ShowModal()==wxID_OK){
+ wxColour colour = colourdiag->GetColourData().GetColour();
+
+ parent->SetCurrentColor(colour);
+
+ double r = (double)(colour.Red())/255.0;
+ double g = (double)(colour.Green())/255.0;
+ double b = (double)(colour.Blue())/255.0;
+ CutModel2MainPanel::getInstance()->changeColor(parent->getId(),r,g,b);
+
+
+ }
+ delete colourdiag;
+}
+
+void CutModel2ViewEventHandler::onOpacityChange(wxScrollEvent& event){
+ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
+
+ CutModel2MainPanel::getInstance()->changeOpacity(parent->getId(),event.GetInt());
+}
+void CutModel2ViewEventHandler::onViewBoxChecked(wxCommandEvent& event){
+ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
+
+ CutModel2MainPanel::getInstance()->ShowViewBox(parent->getId(),event.IsChecked());
+}
+void CutModel2ViewEventHandler::onShapeChange(wxCommandEvent& event){
+ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
+
+ //if(event.GetSelection()>0){
+ //std::cout<<"id in CutModel2ViewEventHandler:: "<<parent->getId()<<std::endl;
+ CutModel2MainPanel::getInstance()->ChangeShape(parent->getId(),event.GetSelection());
+ //}
+}
+void CutModel2ViewEventHandler::onStatistics(wxCommandEvent& event){
+ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
+ CutModel2MainPanel::getInstance()->ShowStatistics(parent->getId());
+}
+void CutModel2ViewEventHandler::onExecute(wxCommandEvent& event){
+ CutModel2View* parent = (CutModel2View*)((wxWindow*)event.GetEventObject())->GetParent();
+
+ parent->ExecuteCut();
+
+}
--- /dev/null
+/*=========================================================================
+
+ Program: wxMaracas
+ Module: $RCSfile: CutModel2View.h,v $
+ Language: C++
+ Date: $Date: 2009/11/23 13:00:27 $
+ Version: $Revision: 1.3 $
+
+ Copyright: (c) 2002, 2003
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+=========================================================================*/
+
+#ifndef __CutModel2ViewPanelH__
+#define __CutModel2ViewPanelH__
+
+#include <vector>
+#include <wx/wx.h>
+#include <wx/radiobut.h>
+#include "wx/aui/aui.h"
+#include <iostream>
+#include "marTypes.h"
+
+
+#include "CutModel2Manager.h"
+#include "CutModelException.h"
+
+#include "vtkObject.h"
+#include "vtkCommand.h"
+
+
+class creaMaracasVisu_EXPORT CutModel2View : public wxPanel, public vtkCommand
+{
+
+public:
+ CutModel2View( wxWindow* parent,double* range);
+ ~CutModel2View( );
+
+ virtual void Execute(vtkObject *wdg, unsigned long eventId, void* calldata) ;
+
+ int getId(){
+ return _id;
+ }
+ void setId(int id){
+ _id = id;
+ }
+
+ void ExecuteCut();
+
+ void SetCurrentColor(wxColour colour);
+
+private:
+
+ int _id;
+
+ wxSlider* _sliderrange;
+ wxRadioBox* _radioinsideout;
+ //wxRadioBox* _radiocutstat;
+ wxStaticText* _currentcolor;
+
+ double* getRange();
+ bool isCut();
+ bool isInside();
+
+
+
+ wxSizer* getBoxControls(wxWindow* parent, double* range);
+
+
+ wxSizer* getActorProperties(wxWindow* parent);
+ wxSizer* getColorChooseActor(wxWindow* parent);
+ wxSizer* getOpacityActor(wxWindow* parent);
+
+ void checkInvariant() throw( CutModelException);
+
+};
+
+class CutModel2ViewEventHandler : public wxEvtHandler{
+
+ public:
+ CutModel2ViewEventHandler(): wxEvtHandler(){};
+ ~CutModel2ViewEventHandler(){};
+
+ void onColorChange(wxCommandEvent& event);
+ void onOpacityChange(wxScrollEvent& event);
+ void onViewBoxChecked(wxCommandEvent& event);
+ void onShapeChange(wxCommandEvent& event);
+ void onStatistics(wxCommandEvent& event);
+ void onExecute(wxCommandEvent& event);
+
+
+
+ private:
+
+};
+
+
+#endif
+
--- /dev/null
+/*=========================================================================
+
+ Program: wxMaracas
+ Module: $RCSfile: CutModel2Manager.cxx,v $
+ Language: C++
+ Date: $Date: 2009/11/23 13:00:30 $
+ Version: $Revision: 1.3 $
+
+ Copyright: (c) 2002, 2003
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+=========================================================================*/
+#include "CutModel2Manager.h"
+
+/**
+** Start of the manager class
+**/
+CutModel2Manager::CutModel2Manager(std::string path){
+ _path = path;
+ _img = NULL;
+ _copyimg = NULL;
+ _interactor = NULL;
+ _render = NULL;
+ _currentaction=0;
+}
+CutModel2Manager::~CutModel2Manager(){
+ std::string files = _path;
+ files+="/infounrd_0_fig_0.info";
+ remove(files.c_str());
+}
+
+
+void CutModel2Manager::setImageData(vtkImageData* img){
+ _img = img;
+ if(_copyimg!=NULL){
+ _copyimg->Delete();
+ }
+ _copyimg = vtkImageData::New();
+ _copyimg->SetExtent(_img->GetExtent());
+ _copyimg->SetSpacing(_img->GetSpacing());
+ _copyimg->AllocateScalars();
+
+ _copyimg->DeepCopy(_img);
+
+}
+
+void CutModel2Manager::setInteractor(vtkRenderWindowInteractor* interactor){
+ _interactor = interactor;
+}
+
+void CutModel2Manager::setRenderer(vtkRenderer* renderer){
+ _render = renderer;
+}
+
+void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutModelException){
+ checkInvariant();
+
+
+ CutModelData* data = new CutModelData(id,_interactor, observer, _copyimg);
+ _vectordata.push_back(data);
+
+ _render->AddActor(data->getActor());
+
+ //_render->UpdateCamera();
+ _render->Render();
+}
+
+void CutModel2Manager::checkInvariant() throw( CutModelException){
+ if(_img==NULL){
+ throw CutModelException("The image is not set");
+ }
+ if(_copyimg==NULL){
+ throw CutModelException("The copyimage is not set");
+ }
+ if(_interactor==NULL){
+ throw CutModelException("Interactor not set");
+ }
+ if(_render==NULL){
+ throw CutModelException("Render not set");
+ }
+}
+
+double* CutModel2Manager::getImageRange()throw( CutModelException){
+ checkInvariant();
+ return _copyimg->GetScalarRange();
+}
+
+void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->changeOpacity(opacity);
+}
+
+void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->ShowViewBox(check);
+}
+
+void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->ChangeShape(selection);
+ _render->Render();
+}
+
+CutModelData* CutModel2Manager::getCutModelData(int id)throw( CutModelException){
+
+ CutModelData* current = NULL;
+ for(int i= 0; i < _vectordata.size();i++){
+ std::cout<<"id in CutModel2Manager:: "<<id<<std::endl;
+ std::cout<<"vectordataid in CutModel2Manager:: "<<_vectordata[i]->getId()<<std::endl;
+
+ if(_vectordata[i]->getId()==id){
+ current = _vectordata[i];
+ }
+ }
+ if(current ==NULL){
+
+ throw CutModelException("Data not found");
+ }
+ return current;
+}
+
+void CutModel2Manager::updateActorDirection(int id)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->udapteActorDirection();
+
+}
+
+void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModelException){
+
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->changeColor(r,g,b);
+ _render->Render();
+}
+void CutModel2Manager::RemoveActor(int id)throw( CutModelException){
+
+ checkInvariant();
+
+ CutModelData* current = getCutModelData(id);
+ for(int i = 0; i < _vectordata.size()-1;i++){
+ if(_vectordata[i]->getId()==id){
+ for(int j = i; j < _vectordata.size()-1;j++){
+ _vectordata[j]=_vectordata[j+1];
+ }
+ i = _vectordata.size();
+ }
+ }
+ _render->RemoveActor(current->getActor());
+ delete current;
+ _vectordata.pop_back();
+ _render->Render();
+
+}
+
+void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
+ checkInvariant();
+
+ CutModelData* current = getCutModelData(id);
+ current->ExecuteCut(range, isinside, _img);
+
+
+ /*
+ Setting extra information for the undo
+ */
+ CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
+ undoaction->setRange(range);
+ undoaction->setIsInside(isinside);
+
+}
+
+vtkImageData* CutModel2Manager::GetResultImage(){
+ checkInvariant();
+ return _copyimg;
+}
+
+void CutModel2Manager::RefreshActor(int id){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ _render->RemoveActor(current->getActor());
+ _render->AddActor(current->getActor());
+ current->RefreshViewBox();
+ _render->Render();
+}
+
+void CutModel2Manager::SaveCutModelData(std::string filename)throw( CutModelException){
+
+
+ throw CutModelException("not implemented");
+
+
+
+
+}
+
+
+
+void CutModel2Manager::LoadCutModelData(std::string filename)throw( CutModelException){
+
+ throw CutModelException("not implemented");
+
+}
+
+CutModelSaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
+
+ for(int i = _undoredo.size()-1; i > _currentaction;i--){
+ delete _undoredo[i];
+ _undoredo.pop_back();
+ }
+
+ CutModelSaveBinInfo* cutmodel = new CutModelSaveBinInfo(idc, _currentaction, type, _path);
+ if(type == CUTMODEL_CUT){
+ cutmodel->saveMatrix4x4(this->getCutModelData(idc)->getCurrentMatrix()->GetMatrix());
+ cutmodel->setCurrentShape(this->getCutModelData(idc)->getCurrentShape());
+ }
+
+ _undoredo.push_back(cutmodel);
+
+ _currentaction++;// = _undoredo.size();
+ //std::cout<<"current index "<<_currentaction;
+
+ return cutmodel;
+}
+
+int CutModel2Manager::Undo() throw( CutModelException){
+ //&& _currentaction < _undoredo.size()
+ if(_currentaction > 0){
+ int tempaction = _currentaction-1;
+ CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
+ CutModelData* currentmodel;
+
+ if(currentundo->getActionType()==CUTMODEL_CUT){
+ //Undo the cut
+ vtkTransform* transform = currentundo->getTransformFromMatrixFile();
+
+ currentmodel = getCutModelData(currentundo->getId());
+
+ currentmodel->setTransform(transform, _img);
+
+ currentmodel->setCurrentShape(currentundo->getCurrentShape());
+
+ currentmodel->ExecuteUnCut(currentundo->getIsInside(), _copyimg, _img);
+
+ }
+ //Every thing ok
+ _currentaction--;
+ return 0;
+ }
+ return -1;
+}
+
+int CutModel2Manager::Redo() throw( CutModelException){
+
+ if(_currentaction >= 0 && _currentaction < _undoredo.size()){
+
+
+ CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
+ CutModelData* currentmodel;
+
+ if(currentundo->getActionType()==CUTMODEL_CUT){
+ //Redo the cut
+ vtkTransform* transform = currentundo->getTransformFromMatrixFile();
+ currentmodel = getCutModelData(currentundo->getId());
+ currentmodel->setTransform(transform, _copyimg);
+ currentmodel->setCurrentShape(currentundo->getCurrentShape());
+ currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
+ }
+
+ _currentaction++;
+
+ return 0;
+ }
+ return -1;
+}
\ No newline at end of file
--- /dev/null
+/*=========================================================================
+
+ Program: wxMaracas
+ Module: $RCSfile: CutModel2Manager.h,v $
+ Language: C++
+ Date: $Date: 2009/11/23 13:00:31 $
+ Version: $Revision: 1.3 $
+
+ Copyright: (c) 2002, 2003
+ License:
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE. See the above copyright notice for more information.
+
+=========================================================================*/
+
+
+
+
+#ifndef __CutModel2ManagerH__
+#define __CutModel2ManagerH__
+
+#include <iostream>
+#include <stdio.h>
+#include <vector>
+
+#include "vtkImageData.h"
+#include "vtkRenderWindowInteractor.h"
+#include "vtkRenderer.h"
+#include <vtkPolyDataWriter.h>
+
+#include "CutModelException.h"
+#include "CutModelData.h"
+#include "CutModelSaveBinInfo.h"
+
+
+
+class CutModel2Manager {
+
+public:
+ CutModel2Manager(std::string path);
+ ~CutModel2Manager();
+
+ void setImageData(vtkImageData* img);
+
+ void setInteractor(vtkRenderWindowInteractor* interactor);
+
+ void setRenderer(vtkRenderer* renderer);
+
+ void onAddCutModel2(int id, vtkCommand* observer) throw( CutModelException);
+
+ double* getImageRange()throw( CutModelException);
+
+ void changeOpacity(int id,int opacity)throw( CutModelException);
+
+ void ShowViewBox(int id,bool check)throw( CutModelException);
+
+ void ChangeShape(int id,int selection)throw( CutModelException);
+
+ void changeColor(int id,double r,double g,double b)throw( CutModelException);
+
+ void updateActorDirection(int id)throw( CutModelException);
+
+ void RemoveActor(int id)throw( CutModelException);
+
+ void ExecuteCut(int id, double* range, bool isinside)throw( CutModelException);
+
+ vtkImageData* GetResultImage();
+
+ void RefreshActor(int id);
+
+ void SaveCutModelData(std::string filename)throw( CutModelException);
+
+ void LoadCutModelData(std::string filename)throw( CutModelException);
+
+ CutModelSaveBinInfo* AddActionUndo(int id, UNDOTYPE type)throw( CutModelException);
+
+ int Undo()throw( CutModelException);
+
+ int Redo()throw( CutModelException);
+private:
+
+ int _currentaction;
+
+ void checkInvariant() throw( CutModelException);
+ std::string _path;
+ vtkImageData* _img;
+ vtkImageData* _copyimg;
+ vtkRenderer* _render;
+ vtkRenderWindowInteractor* _interactor;
+
+ std::vector<CutModelData*> _vectordata;
+ std::vector<CutModelSaveBinInfo*> _undoredo;
+ CutModelData* getCutModelData(int id)throw( CutModelException);
+
+};
+
+#endif