]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/CutModule/kernel/CutModelManager.cxx
6aa18753a7bd70cb0604854bbe6f0a892e2efa11
[creaMaracasVisu.git] / lib / maracasVisuLib / src / CutModule / kernel / CutModelManager.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: CutModelManager.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/08/31 08:46:12 $
7   Version:   $Revision: 1.1 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17 #include "CutModelManager.h"
18
19 /**
20 **      Start of the manager class
21 **/
22 CutModelManager::CutModelManager(){
23         _img = NULL;
24         _copyimg = NULL;
25         _interactor = NULL;     
26         _render = NULL;
27 }
28 CutModelManager::~CutModelManager(){
29 }
30
31
32 void CutModelManager::setImageData(vtkImageData* img){
33     _img = img;
34         if(_copyimg!=NULL){
35                 _copyimg->Delete();
36         }
37         _copyimg = vtkImageData::New();
38         _copyimg->SetExtent(_img->GetExtent());
39         _copyimg->SetSpacing(_img->GetSpacing());
40         _copyimg->AllocateScalars();
41
42         _copyimg->DeepCopy(_img);
43
44 }
45
46 void CutModelManager::setInteractor(vtkRenderWindowInteractor* interactor){
47         _interactor = interactor;
48 }
49
50 void CutModelManager::setRenderer(vtkRenderer* renderer){
51         _render = renderer;
52 }
53
54 void CutModelManager::onAddCutModel(int id, vtkCommand* observer) throw( CutModelException){
55         checkInvariant();
56
57         CutModelData* data = new CutModelData(id,_interactor, observer, _img);
58         _vectordata.push_back(data);
59
60         _render->AddActor(data->getActor());
61
62         //_render->UpdateCamera();
63         _render->Render();
64 }
65
66 void CutModelManager::checkInvariant() throw( CutModelException){
67         if(_img==NULL){
68                 throw CutModelException("The image is not set");
69         }
70         if(_copyimg==NULL){
71                 throw CutModelException("The image is not set");
72         }
73         if(_interactor==NULL){
74                 throw CutModelException("Interactor not set");
75         }
76         if(_render==NULL){
77                 throw CutModelException("Render not set");
78         }
79 }
80
81 double* CutModelManager::getImageRange()throw( CutModelException){
82         checkInvariant();
83         return _img->GetScalarRange();
84 }
85
86 void CutModelManager::changeOpacity(int id,int opacity)throw( CutModelException){
87         checkInvariant();
88         CutModelData* current = getCutModelData(id);
89         current->changeOpacity(opacity);
90 }
91
92 void CutModelManager::ShowViewBox(int id,bool check)throw( CutModelException){
93         checkInvariant();
94         CutModelData* current = getCutModelData(id);
95         current->ShowViewBox(check);
96 }
97
98 void CutModelManager::ChangeShape(int id,int selection)throw( CutModelException){
99         checkInvariant();
100         CutModelData* current = getCutModelData(id);
101         current->ChangeShape(selection);                        
102         _render->Render();
103 }
104
105 CutModelData* CutModelManager::getCutModelData(int id)throw( CutModelException){
106
107         CutModelData* current = NULL;
108         for(int i= 0; i < _vectordata.size();i++){
109                 std::cout<<"id in CutModelManager:: "<<id<<std::endl;
110                 std::cout<<"vectordataid in CutModelManager:: "<<_vectordata[i]->getId()<<std::endl;
111
112                 if(_vectordata[i]->getId()==id){
113                         current =  _vectordata[i];
114                 }
115         }
116         if(current ==NULL){
117                 
118                 throw CutModelException("Data not found");
119         }
120         return current;
121 }
122
123 void CutModelManager::updateActorDirection(int id)throw( CutModelException){
124         checkInvariant();
125         CutModelData* current = getCutModelData(id);
126         current->udapteActorDirection();
127         
128 }
129
130 void CutModelManager::changeColor(int id,double r,double g,double b)throw( CutModelException){
131
132         checkInvariant();
133         CutModelData* current = getCutModelData(id);
134         current->changeColor(r,g,b);
135         _render->Render();
136 }
137 void CutModelManager::RemoveActor(int id)throw( CutModelException){
138         
139                 checkInvariant();
140
141                 CutModelData* current = getCutModelData(id);
142                 for(int i = 0; i < _vectordata.size()-1;i++){
143                         if(_vectordata[i]->getId()==id){                                
144                                 for(int j = i; j < _vectordata.size()-1;j++){
145                     _vectordata[j]=_vectordata[j+1];
146                                 }
147                                 i = _vectordata.size();
148                         }
149                 }
150                 _render->RemoveActor(current->getActor());              
151                 delete current;
152                 _vectordata.pop_back();
153                 _render->Render();
154         
155 }
156
157 void CutModelManager::ExecuteCut(int id, double* range, bool isinside)throw( CutModelException){
158     checkInvariant();
159         CutModelData* current = getCutModelData(id);
160         current->ExecuteCut(range, isinside,_copyimg);
161
162 }
163
164 vtkImageData* CutModelManager::GetResultImage(){
165          checkInvariant();
166      return _copyimg;
167 }