]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/CutModule/kernel/CutModel2Manager.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / kernel / CutModel2Manager.cxx
index e472becc6ecef2999fbbda6a71791e77a7ef9266..6e00b2f52fb8f7f78be8fa07b10ec5ca8ad56d28 100644 (file)
@@ -3,8 +3,8 @@
   Program:   wxMaracas
   Module:    $RCSfile: CutModel2Manager.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/11/19 15:00:33 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2009/12/08 13:42:39 $
+  Version:   $Revision: 1.4 $
 
   Copyright: (c) 2002, 2003
   License:
@@ -22,7 +22,7 @@
 CutModel2Manager::CutModel2Manager(std::string path){
        _path = path;
        _img = NULL;
-       _copyimg = NULL;
+       _img2 = NULL;
        _interactor = NULL;     
        _render = NULL;
        _currentaction=0;
@@ -31,20 +31,25 @@ CutModel2Manager::~CutModel2Manager(){
        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 CutModel2Manager::setImageData(vtkImageData* img){
     _img = img;
-       if(_copyimg!=NULL){
-               _copyimg->Delete();
+       if(_img2!=NULL){
+               _img2->Delete();
        }
-       _copyimg = vtkImageData::New();
-       _copyimg->SetExtent(_img->GetExtent());
-       _copyimg->SetSpacing(_img->GetSpacing());
-       _copyimg->AllocateScalars();
+       _img2 = vtkImageData::New();
+       _img2->SetExtent(_img->GetExtent());
+       _img2->SetSpacing(_img->GetSpacing());
+       _img2->AllocateScalars();
 
-       _copyimg->DeepCopy(_img);
+       _img2->DeepCopy(_img);
 
 }
 
@@ -56,10 +61,10 @@ void CutModel2Manager::setRenderer(vtkRenderer* renderer){
        _render = renderer;
 }
 
-void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutModel2Exception){
+void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutModelException){
        checkInvariant();
 
-       CutModel2Data* data = new CutModel2Data(id,_interactor, observer, _copyimg);
+       CutModelData* data = new CutModelData(id,_interactor, observer, _img2);
        _vectordata.push_back(data);
 
        _render->AddActor(data->getActor());
@@ -68,48 +73,48 @@ void CutModel2Manager::onAddCutModel2(int id, vtkCommand* observer) throw( CutMo
        _render->Render();
 }
 
-void CutModel2Manager::checkInvariant() throw( CutModel2Exception){
+void CutModel2Manager::checkInvariant() throw( CutModelException){
        if(_img==NULL){
-               throw CutModel2Exception("The image is not set");
+               throw CutModelException("The image is not set");
        }
-       if(_copyimg==NULL){
-               throw CutModel2Exception("The image is not set");
+       if(_img2==NULL){
+               throw CutModelException("The copyimage is not set");
        }
        if(_interactor==NULL){
-               throw CutModel2Exception("Interactor not set");
+               throw CutModelException("Interactor not set");
        }
        if(_render==NULL){
-               throw CutModel2Exception("Render not set");
+               throw CutModelException("Render not set");
        }
 }
 
-double* CutModel2Manager::getImageRange()throw( CutModel2Exception){
+double* CutModel2Manager::getImageRange()throw( CutModelException){
        checkInvariant();
-       return _copyimg->GetScalarRange();
+       return _img2->GetScalarRange();
 }
 
-void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModel2Exception){
+void CutModel2Manager::changeOpacity(int id,int opacity)throw( CutModelException){
        checkInvariant();
-       CutModel2Data* current = getCutModel2Data(id);
+       CutModelData* current = getCutModelData(id);
        current->changeOpacity(opacity);
 }
 
-void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModel2Exception){
+void CutModel2Manager::ShowViewBox(int id,bool check)throw( CutModelException){
        checkInvariant();
-       CutModel2Data* current = getCutModel2Data(id);
+       CutModelData* current = getCutModelData(id);
        current->ShowViewBox(check);
 }
 
-void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModel2Exception){
+void CutModel2Manager::ChangeShape(int id,int selection)throw( CutModelException){
        checkInvariant();
-       CutModel2Data* current = getCutModel2Data(id);
+       CutModelData* current = getCutModelData(id);
        current->ChangeShape(selection);                        
        _render->Render();
 }
 
-CutModel2Data* CutModel2Manager::getCutModel2Data(int id)throw( CutModel2Exception){
+CutModelData* CutModel2Manager::getCutModelData(int id)throw( CutModelException){
 
-       CutModel2Data* current = NULL;
+       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;
@@ -120,30 +125,30 @@ CutModel2Data* CutModel2Manager::getCutModel2Data(int id)throw( CutModel2Excepti
        }
        if(current ==NULL){
                
-               throw CutModel2Exception("Data not found");
+               throw CutModelException("Data not found");
        }
        return current;
 }
 
-void CutModel2Manager::updateActorDirection(int id)throw( CutModel2Exception){
+void CutModel2Manager::updateActorDirection(int id)throw( CutModelException){
        checkInvariant();
-       CutModel2Data* current = getCutModel2Data(id);
+       CutModelData* current = getCutModelData(id);
        current->udapteActorDirection();
        
 }
 
-void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModel2Exception){
+void CutModel2Manager::changeColor(int id,double r,double g,double b)throw( CutModelException){
 
        checkInvariant();
-       CutModel2Data* current = getCutModel2Data(id);
+       CutModelData* current = getCutModelData(id);
        current->changeColor(r,g,b);
        _render->Render();
 }
-void CutModel2Manager::RemoveActor(int id)throw( CutModel2Exception){
+void CutModel2Manager::RemoveActor(int id)throw( CutModelException){
        
                checkInvariant();
 
-               CutModel2Data* current = getCutModel2Data(id);
+               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++){
@@ -159,17 +164,17 @@ void CutModel2Manager::RemoveActor(int id)throw( CutModel2Exception){
        
 }
 
-void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModel2Exception){
+void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
     checkInvariant();
                
-       CutModel2Data* current = getCutModel2Data(id);
+       CutModelData* current = getCutModelData(id);
        current->ExecuteCut(range, isinside, _img);
 
 
        /*
        Setting extra information for the undo
        */
-       CutModel2SaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL2_CUT);
+       CutModelSaveBinInfo* undoaction = this->AddActionUndo(id, CUTMODEL_CUT);
        undoaction->setRange(range);
        undoaction->setIsInside(isinside);
 
@@ -177,22 +182,22 @@ void CutModel2Manager::ExecuteCut(int id, double* range, bool isinside)throw( Cu
 
 vtkImageData* CutModel2Manager::GetResultImage(){
         checkInvariant();
-     return _copyimg;
+     return _img2;
 }
 
 void CutModel2Manager::RefreshActor(int id){
      checkInvariant();
-       CutModel2Data* current = getCutModel2Data(id);  
+       CutModelData* current = getCutModelData(id);    
        _render->RemoveActor(current->getActor());
        _render->AddActor(current->getActor()); 
        current->RefreshViewBox();
        _render->Render();
 }
 
-void CutModel2Manager::SaveCutModel2Data(std::string filename)throw( CutModel2Exception){      
+void CutModel2Manager::SaveCutModelData(std::string filename)throw( CutModelException){        
 
        
-       throw CutModel2Exception("not implemented");
+       throw CutModelException("not implemented");
        
        
        
@@ -201,23 +206,23 @@ void CutModel2Manager::SaveCutModel2Data(std::string filename)throw( CutModel2Ex
 
 
 
-void CutModel2Manager::LoadCutModel2Data(std::string filename)throw( CutModel2Exception){
+void CutModel2Manager::LoadCutModelData(std::string filename)throw( CutModelException){
        
-       throw CutModel2Exception("not implemented");
+       throw CutModelException("not implemented");
        
 }
 
-CutModel2SaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModel2Exception){
+CutModelSaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)throw( CutModelException){
        
        for(int i = _undoredo.size()-1; i > _currentaction;i--){
                delete _undoredo[i];
                _undoredo.pop_back();           
        }
 
-       CutModel2SaveBinInfo* cutmodel = new CutModel2SaveBinInfo(idc, _currentaction, type, _path);
-       if(type == CUTMODEL2_CUT){
-               cutmodel->saveMatrix4x4(this->getCutModel2Data(idc)->getCurrentMatrix()->GetMatrix());
-               cutmodel->setCurrentShape(this->getCutModel2Data(idc)->getCurrentShape());
+       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);
@@ -228,24 +233,24 @@ CutModel2SaveBinInfo* CutModel2Manager::AddActionUndo(int idc, UNDOTYPE type)thr
        return cutmodel;
 }
 
-int CutModel2Manager::Undo()   throw( CutModel2Exception){
+int CutModel2Manager::Undo()   throw( CutModelException){
  //&& _currentaction < _undoredo.size()
        if(_currentaction > 0){
                int tempaction = _currentaction-1;
-               CutModel2SaveBinInfo* currentundo = _undoredo[tempaction];
-               CutModel2Data* currentmodel;
+               CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
+               CutModelData* currentmodel;
 
-               if(currentundo->getActionType()==CUTMODEL2_CUT){
+               if(currentundo->getActionType()==CUTMODEL_CUT){
                        //Undo the cut
                        vtkTransform* transform = currentundo->getTransformFromMatrixFile();
 
-                       currentmodel = getCutModel2Data(currentundo->getId());
+                       currentmodel = getCutModelData(currentundo->getId());
 
                        currentmodel->setTransform(transform, _img);
 
                        currentmodel->setCurrentShape(currentundo->getCurrentShape());
 
-                       currentmodel->ExecuteUnCut(currentundo->getIsInside(), _copyimg, _img);
+                       currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img2, _img);
 
                }
                //Every thing ok
@@ -255,21 +260,21 @@ int CutModel2Manager::Undo()      throw( CutModel2Exception){
        return -1;
 }
 
-int CutModel2Manager::Redo()   throw( CutModel2Exception){
+int CutModel2Manager::Redo()   throw( CutModelException){
 
        if(_currentaction >= 0 && _currentaction < _undoredo.size()){
                
 
-               CutModel2SaveBinInfo* currentundo = _undoredo[_currentaction];
-               CutModel2Data* currentmodel;
+               CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
+               CutModelData* currentmodel;
 
-               if(currentundo->getActionType()==CUTMODEL2_CUT){
+               if(currentundo->getActionType()==CUTMODEL_CUT){
                        //Redo the cut
                        vtkTransform* transform = currentundo->getTransformFromMatrixFile();
-                       currentmodel = getCutModel2Data(currentundo->getId());
-                       currentmodel->setTransform(transform, _copyimg);
+                       currentmodel = getCutModelData(currentundo->getId());
+                       currentmodel->setTransform(transform, _img2);
                        currentmodel->setCurrentShape(currentundo->getCurrentShape());
-                       currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
+                       currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _img2);
                }
 
                _currentaction++;