]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx
*** empty log message ***
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / kernel / CutModelManager.cxx
index 101afaa0a3432ad909dbe6d3ac1bad99e88db444..af045359d32058b33fd2267f9365835c584f693f 100644 (file)
@@ -3,8 +3,8 @@
   Program:   wxMaracas
   Module:    $RCSfile: CutModelManager.cxx,v $
   Language:  C++
-  Date:      $Date: 2009/11/25 16:35:37 $
-  Version:   $Revision: 1.4 $
+  Date:      $Date: 2009/12/08 13:42:39 $
+  Version:   $Revision: 1.5 $
 
   Copyright: (c) 2002, 2003
   License:
@@ -15,6 +15,7 @@
 
 =========================================================================*/
 #include "CutModelManager.h"
+#include "CutModelMainPanel.h"
 
 /**
 **     Start of the manager class
 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;
@@ -33,24 +35,42 @@ CutModelManager::~CutModelManager(){
        remove(files.c_str());  
        _vectordata.clear();
        _img = NULL;
-       _copyimg = 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){
@@ -64,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);
 
@@ -77,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){
@@ -170,7 +191,7 @@ void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( Cut
     checkInvariant();
                
        CutModelData* current = getCutModelData(id);
-       current->ExecuteCut(range, isinside,_copyimg);
+       current->ExecuteCut(range, isinside,_img2);
 
 
        /*
@@ -184,7 +205,7 @@ void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( Cut
 
 vtkImageData* CutModelManager::GetResultImage(){
         checkInvariant();
-     return _copyimg;
+     return _img2;
 }
 
 void CutModelManager::RefreshActor(int id){
@@ -248,11 +269,11 @@ int CutModelManager::Undo()       throw( CutModelException){
 
                        currentmodel = getCutModelData(currentundo->getId());
 
-                       currentmodel->setTransform(transform, _copyimg);
+                       currentmodel->setTransform(transform, _img2);
 
                        currentmodel->setCurrentShape(currentundo->getCurrentShape());
 
-                       currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _copyimg);
+                       currentmodel->ExecuteUnCut(currentundo->getIsInside(), _img, _img2);
 
                }
                //Every thing ok
@@ -274,9 +295,9 @@ int CutModelManager::Redo() throw( CutModelException){
                        //Redo the cut
                        vtkTransform* transform = currentundo->getTransformFromMatrixFile();
                        currentmodel = getCutModelData(currentundo->getId());
-                       currentmodel->setTransform(transform, _copyimg);
+                       currentmodel->setTransform(transform, _img2);
                        currentmodel->setCurrentShape(currentundo->getCurrentShape());
-                       currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _copyimg);
+                       currentmodel->ExecuteCut(currentundo->getRange(), currentundo->getIsInside(), _img2);
                }
 
                _currentaction++;