X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FmaracasVisuLib%2Fsrc%2FCutModule%2Fkernel%2FCutModelManager.cxx;h=af045359d32058b33fd2267f9365835c584f693f;hb=d37b5379345cb4c29e10caf62b4d881bd84bf929;hp=6aa18753a7bd70cb0604854bbe6f0a892e2efa11;hpb=2d5984d688d7b149aa7706a0a0bf8c4b4556d788;p=creaMaracasVisu.git diff --git a/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx b/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx index 6aa1875..af04535 100644 --- a/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx +++ b/lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx @@ -3,8 +3,8 @@ Program: wxMaracas Module: $RCSfile: CutModelManager.cxx,v $ Language: C++ - Date: $Date: 2009/08/31 08:46:12 $ - Version: $Revision: 1.1 $ + Date: $Date: 2009/12/08 13:42:39 $ + Version: $Revision: 1.5 $ Copyright: (c) 2002, 2003 License: @@ -15,32 +15,62 @@ =========================================================================*/ #include "CutModelManager.h" +#include "CutModelMainPanel.h" /** ** Start of the manager class **/ -CutModelManager::CutModelManager(){ +CutModelManager::CutModelManager(std::string path){ + _path = path; _img = NULL; - _copyimg = NULL; + _img2 = NULL; _interactor = NULL; _render = NULL; + _currentaction=0; + } CutModelManager::~CutModelManager(){ + std::string files = _path; + files+="/infounrd_0_fig_0.info"; + remove(files.c_str()); + _vectordata.clear(); + _img = NULL; + _img2 = NULL; + _interactor = NULL; + _render = NULL; } void CutModelManager::setImageData(vtkImageData* img){ - _img = img; - if(_copyimg!=NULL){ - _copyimg->Delete(); + int type = CutModelMainPanel::getInstance()->GetType(); + if( type == 0) + { + _img = img; + + if(_img2!=NULL){ + _img2->Delete(); + } + _img2 = vtkImageData::New(); + _img2->SetExtent(_img->GetExtent()); + _img2->SetSpacing(_img->GetSpacing()); + _img2->AllocateScalars(); + + _img2->DeepCopy(_img); } - _copyimg = vtkImageData::New(); - _copyimg->SetExtent(_img->GetExtent()); - _copyimg->SetSpacing(_img->GetSpacing()); - _copyimg->AllocateScalars(); + else + { + _img2 = img; - _copyimg->DeepCopy(_img); + if(_img!=NULL){ + _img->Delete(); + } + _img = vtkImageData::New(); + _img->SetExtent(_img2->GetExtent()); + _img->SetSpacing(_img2->GetSpacing()); + _img->AllocateScalars(); + _img->DeepCopy(_img2); + } } void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){ @@ -54,6 +84,7 @@ void CutModelManager::setRenderer(vtkRenderer* renderer){ void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){ checkInvariant(); + CutModelData* data = new CutModelData(id,_interactor, observer, _img); _vectordata.push_back(data); @@ -67,7 +98,7 @@ void CutModelManager::checkInvariant() throw( CutModelException){ if(_img==NULL){ throw CutModelException("The image is not set"); } - if(_copyimg==NULL){ + if(_img2==NULL){ throw CutModelException("The image is not set"); } if(_interactor==NULL){ @@ -106,11 +137,12 @@ CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){ CutModelData* current = NULL; for(int i= 0; i < _vectordata.size();i++){ + CutModelData* temp = _vectordata[i]; std::cout<<"id in CutModelManager:: "<getId()<getId()<getId()==id){ - current = _vectordata[i]; + if(temp->getId() == id){ + current = temp; } } if(current ==NULL){ @@ -147,7 +179,8 @@ void CutModelManager::RemoveActor(int id)throw( CutModelException){ i = _vectordata.size(); } } - _render->RemoveActor(current->getActor()); + _render->RemoveViewProp(current->getActor()); + //_render->RemoveViewProp(current->get delete current; _vectordata.pop_back(); _render->Render(); @@ -156,12 +189,120 @@ void CutModelManager::RemoveActor(int id)throw( CutModelException){ void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){ checkInvariant(); + CutModelData* current = getCutModelData(id); - current->ExecuteCut(range, isinside,_copyimg); + current->ExecuteCut(range, isinside,_img2); + + + /* + Setting extra information for the undo + */ + CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT); + undoaction->setRange(range); + undoaction->setIsInside(isinside); } vtkImageData* CutModelManager::GetResultImage(){ checkInvariant(); - return _copyimg; + return _img2; +} + +void CutModelManager::RefreshActor(int id){ + checkInvariant(); + CutModelData* current = getCutModelData(id); + _render->RemoveActor(current->getActor()); + _render->AddActor(current->getActor()); + current->RefreshViewBox(); + _render->Render(); +} + +void CutModelManager::SaveCutModelData(std::string filename)throw( CutModelException){ + + + throw CutModelException("not implemented"); + + + + +} + + + +void CutModelManager::LoadCutModelData(std::string filename)throw( CutModelException){ + + throw CutModelException("not implemented"); + +} + +CutModelSaveBinInfo* CutModelManager::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 CutModelManager::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, _img2); + + currentmodel->setCurrentShape(currentundo->getCurrentShape()); + + currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _img2); + + } + //Every thing ok + _currentaction--; + return 0; + } + return -1; +} + +int CutModelManager::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, _img2); + currentmodel->setCurrentShape(currentundo->getCurrentShape()); + currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _img2); + } + + _currentaction++; + + return 0; + } + return -1; } \ No newline at end of file