]> Creatis software - creaMaracasVisu.git/blobdiff - lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx
comment out unused
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / kernel / CutModelManager.cxx
index 652faa7d6d2d1c2efe72b7a52273ae54e8174aaf..bfd82ed15a33a240160200fba3c44687c5fa3e77 100644 (file)
@@ -1,51 +1,82 @@
 /*=========================================================================
 
-  Program:   wxMaracas
-  Module:    $RCSfile: CutModelManager.cxx,v $
-  Language:  C++
-  Date:      $Date: 2009/09/08 08:14:27 $
-  Version:   $Revision: 1.3 $
+Program:   wxMaracas
+Module:    $RCSfile: CutModelManager.cxx,v $
+Language:  C++
+Date:      $Date: 2010/04/02 07:22:25 $
+Version:   $Revision: 1.9 $
 
-  Copyright: (c) 2002, 2003
-  License:
+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.
+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"
 
+//Machete
+#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;
-    files+="/infounrd_0_fig_0.info";   
-       remove(files.c_str());
+       files+="/infounrd_0_fig_0.info";        
+       remove(files.c_str());  
+       _vectordata.clear();
+       _img = NULL;
+       _img2 = NULL;
+       _interactor = NULL;     
+       _render = NULL;
 }
 
 
+vtkImageData* CutModelManager::getImageData(){
+       return _img2;
+}
+
 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){
@@ -59,6 +90,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);
 
@@ -72,7 +104,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){
@@ -111,15 +143,16 @@ 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:: "<<id<<std::endl;
-               std::cout<<"vectordataid in CutModelManager:: "<<_vectordata[i]->getId()<<std::endl;
+               std::cout<<"vectordataid in CutModelManager:: "<<temp->getId()<<std::endl;
 
-               if(_vectordata[i]->getId()==id){
-                       current =  _vectordata[i];
+               if(temp->getId() == id){
+                       current =  temp;
                }
        }
        if(current ==NULL){
-               
+
                throw CutModelException("Data not found");
        }
        return current;
@@ -129,7 +162,7 @@ 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){
@@ -140,30 +173,31 @@ void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutMo
        _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();
+
+       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();
-       
+       }
+       _render->RemoveViewProp(current->getActor());           
+       //_render->RemoveViewProp(current->get
+       delete current;
+       _vectordata.pop_back();
+       _render->Render();
+
 }
 
 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
-    checkInvariant();
-               
+       checkInvariant();
+
        CutModelData* current = getCutModelData(id);
-       current->ExecuteCut(range, isinside,_copyimg);
+       current->ExecuteCut(range, isinside,_img2);
 
 
        /*
@@ -176,12 +210,12 @@ void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( Cut
 }
 
 vtkImageData* CutModelManager::GetResultImage(){
-        checkInvariant();
-     return _copyimg;
+       checkInvariant();
+       return _img2;
 }
 
 void CutModelManager::RefreshActor(int id){
-     checkInvariant();
+       checkInvariant();
        CutModelData* current = getCutModelData(id);    
        _render->RemoveActor(current->getActor());
        _render->AddActor(current->getActor()); 
@@ -191,24 +225,24 @@ void CutModelManager::RefreshActor(int id){
 
 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();           
@@ -224,12 +258,12 @@ CutModelSaveBinInfo* CutModelManager::AddActionUndo(int idc, UNDOTYPE type)throw
 
        _currentaction++;// = _undoredo.size();
        //std::cout<<"current index "<<_currentaction;
-               
+
        return cutmodel;
 }
 
 int CutModelManager::Undo()    throw( CutModelException){
- //&& _currentaction < _undoredo.size()
      //&& _currentaction < _undoredo.size()
        if(_currentaction > 0){
                int tempaction = _currentaction-1;
                CutModelSaveBinInfo* currentundo = _undoredo[tempaction];
@@ -241,11 +275,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
@@ -258,7 +292,6 @@ int CutModelManager::Undo() throw( CutModelException){
 int CutModelManager::Redo()    throw( CutModelException){
 
        if(_currentaction >= 0 && _currentaction < _undoredo.size()){
-               
 
                CutModelSaveBinInfo* currentundo = _undoredo[_currentaction];
                CutModelData* currentmodel;
@@ -267,9 +300,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++;
@@ -277,4 +310,99 @@ int CutModelManager::Redo()        throw( CutModelException){
                return 0;
        }
        return -1;
-}
\ No newline at end of file
+}
+
+void CutModelManager::ParallelProjectionOn(){
+       _render->GetActiveCamera()->ParallelProjectionOn();
+}
+
+void CutModelManager::ParallelProjectionOff(){
+       _render->GetActiveCamera()->ParallelProjectionOff();
+}
+
+
+//RaC
+void CutModelManager::UpdatePolygon(bool mode)
+{
+       if(mode)
+       {
+               cutterstyle->Delete();
+               cutterstyle = vtkInteractorStyleCutter::New();
+
+               cutterstyle->SetInteractor ( _interactor );
+               _interactor ->SetInteractorStyle( cutterstyle );
+       }
+       else
+       {
+               cutterstyle->VisibilityOff();
+
+               loop = vtkImplicitSelectionLoop::New();
+               mapper = vtkPolyDataMapper::New();
+               if(cutterstyle->Finished())
+               {
+                       if(actor3D != NULL)
+                       {
+                               _render->RemoveActor(actor3D);
+                       }
+
+                       loop->SetLoop( cutterstyle->GetLoopPoints() );
+                       loop->SetNormal( cutterstyle->GetDirection());
+
+
+                       /// Printing Points
+                       int numPoints = cutterstyle->GetLoopPoints()->GetNumberOfPoints();
+                       contourDirection = cutterstyle->GetDirection();
+
+                       contourPoints = cutterstyle->GetLoopPoints();
+
+                       _polygonCutter = new CutModelPolygon();
+
+                       cout<<"RaC Printing points......"<<endl;
+                       for(int t=0;t<numPoints;t++)
+                       {
+                               double point[3];
+                               cutterstyle->GetLoopPoints()->GetPoint(t,point);
+                               cout<<"Initial Point:"<<t<<" XX:"<<point[0]<<" YY:"<<point[1]<<" ZZ:"<<point[2]<<endl;
+                       }
+                       cout<<endl;
+
+                       sample = vtkSampleFunction::New();
+
+                       sample->SetImplicitFunction(loop);
+                       sample->CappingOn();                    
+
+                       contour = vtkContourFilter::New();
+                       contour->SetInput((vtkDataObject *)sample->GetOutput());
+                       contour->SetValue(0,1);
+
+                       actor = contour->GetOutput();
+
+                       actor3D = vtkActor::New();                      
+                       mapper->SetInput(actor);                         
+                       mapper->SetScalarModeToUseCellData();
+                       actor3D->SetMapper( mapper);
+                       _render->AddActor(actor3D);                     
+               }               
+
+               interactorstyle->SetInteractor (  _interactor );
+               _interactor->SetInteractorStyle( interactorstyle );
+       } 
+
+       _interactor->Render();
+       _render->ResetCameraClippingRange();
+}
+void CutModelManager::ExecuteCutPolygon(bool inOutCut){
+
+       _polygonCutter->setInImage(_img2);
+       _polygonCutter->setPoints(contourPoints);
+       _polygonCutter->setDirection(contourDirection);
+       _polygonCutter->processOutImage(inOutCut);
+}
+
+void CutModelManager::InitializePolygonInteractorStyle(){
+
+       cutterstyle = vtkInteractorStyleCutter::New();          
+       interactorstyle = vtkInteractorStyleTrackballCamera ::New();
+       interactorstyle->SetInteractor (  _interactor );
+       _interactor->SetInteractorStyle( interactorstyle );
+}