--- /dev/null
+/*=========================================================================
+
+ Program: wxMaracas
+ Module: $RCSfile: CutModelManager.cxx,v $
+ Language: C++
+ Date: $Date: 2009/11/19 15:24:57 $
+ Version: $Revision: 1.1 $
+
+ 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 "CutModelManager.h"
+
+/**
+** Start of the manager class
+**/
+CutModelManager::CutModelManager(std::string path){
+ _path = path;
+ _img = NULL;
+ _copyimg = NULL;
+ _interactor = NULL;
+ _render = NULL;
+ _currentaction=0;
+}
+CutModelManager::~CutModelManager(){
+ std::string files = _path;
+ files+="/infounrd_0_fig_0.info";
+ remove(files.c_str());
+}
+
+
+void CutModelManager::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 CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
+ _interactor = interactor;
+}
+
+void CutModelManager::setRenderer(vtkRenderer* renderer){
+ _render = renderer;
+}
+
+void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
+ checkInvariant();
+
+ CutModelData* data = new CutModelData(id,_interactor, observer, _img);
+ _vectordata.push_back(data);
+
+ _render->AddActor(data->getActor());
+
+ //_render->UpdateCamera();
+ _render->Render();
+}
+
+void CutModelManager::checkInvariant() throw( CutModelException){
+ if(_img==NULL){
+ throw CutModelException("The image is not set");
+ }
+ if(_copyimg==NULL){
+ throw CutModelException("The image is not set");
+ }
+ if(_interactor==NULL){
+ throw CutModelException("Interactor not set");
+ }
+ if(_render==NULL){
+ throw CutModelException("Render not set");
+ }
+}
+
+double* CutModelManager::getImageRange()throw( CutModelException){
+ checkInvariant();
+ return _img->GetScalarRange();
+}
+
+void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->changeOpacity(opacity);
+}
+
+void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->ShowViewBox(check);
+}
+
+void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->ChangeShape(selection);
+ _render->Render();
+}
+
+CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
+
+ CutModelData* current = NULL;
+ for(int i= 0; i < _vectordata.size();i++){
+ std::cout<<"id in CutModelManager:: "<<id<<std::endl;
+ std::cout<<"vectordataid in CutModelManager:: "<<_vectordata[i]->getId()<<std::endl;
+
+ if(_vectordata[i]->getId()==id){
+ current = _vectordata[i];
+ }
+ }
+ if(current ==NULL){
+
+ throw CutModelException("Data not found");
+ }
+ return current;
+}
+
+void CutModelManager::updateActorDirection(int id)throw( CutModelException){
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->udapteActorDirection();
+
+}
+
+void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
+
+ checkInvariant();
+ CutModelData* current = getCutModelData(id);
+ current->changeColor(r,g,b);
+ _render->Render();
+}
+void CutModelManager::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 CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
+ checkInvariant();
+
+ CutModelData* current = getCutModelData(id);
+ current->ExecuteCut(range, isinside,_copyimg);
+
+
+ /*
+ 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;
+}
+
+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, _copyimg);
+
+ currentmodel->setCurrentShape(currentundo->getCurrentShape());
+
+ currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _copyimg);
+
+ }
+ //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, _copyimg);
+ currentmodel->setCurrentShape(currentundo->getCurrentShape());
+ currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
+ }
+
+ _currentaction++;
+
+ return 0;
+ }
+ return -1;
+}
\ No newline at end of file