]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMaracasIRMViewManager.cxx
wxMaracasIRMViewManager.cxx
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMaracasIRMViewManager.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMaracasIRMViewManager.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/05/29 14:25:26 $
7   Version:   $Revision: 1.6 $
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 "wxMaracasIRMViewManager.h"
18
19 #include "wxMaracasIRMViewManagerDataMhd.h"
20
21 /**
22 **      Start of the manager class
23 **/
24 wxMaracasIRMViewManager::wxMaracasIRMViewManager(){
25         _renderer = NULL;
26         _idCount=0;
27 }
28 wxMaracasIRMViewManager::~wxMaracasIRMViewManager(){
29 }
30
31 /**
32 **      Sets the renderer to manage the prop3D from the view
33 **/
34 void wxMaracasIRMViewManager::setRenderer(vtkRenderer*  renderer){
35         _renderer = renderer;
36 }
37 /**
38 **      Adds a prop3D to the manager and returns the identifier
39 **/
40 int wxMaracasIRMViewManager::addProp3D(vtkProp3D* prop3D, std::string dataname)  throw(char*){
41         checkInvariant();
42         if(prop3D != NULL){
43                 wxMaracasIRMViewManagerData* data = new wxMaracasIRMViewManagerData(prop3D, dataname);
44                 prop3Dvect.push_back(data);             
45                 _renderer->AddActor(data->getProp3D());
46                 data->setId(_idCount);
47                 _idCount++;
48                 return data->getId();
49         }else{
50                 throw "Check vtkProp3D file or input";
51         }
52         return -1;
53 }
54 int wxMaracasIRMViewManager::addPropMHD(vtkImageData* imagedata, std::string dataname) throw(char*){
55
56         checkInvariant();
57         if(imagedata != NULL){
58                 wxMaracasIRMViewManagerData* data = new wxMaracasIRMViewManagerDataMhd(imagedata, dataname);
59                 prop3Dvect.push_back(data);             
60                 _renderer->AddActor(data->getProp3D());
61                 data->setId(_idCount);
62                 _idCount++;
63                 return data->getId();
64         }else{
65                 throw "Check ImageData file or input";
66         }
67         return -1;
68
69 }
70 /**
71 **      adds or removes an actor depending of the bool value
72 **/
73 void wxMaracasIRMViewManager::addRemoveActor(int propid, bool addremove)  throw(char*){
74         checkInvariant();
75         
76         wxMaracasIRMViewManagerData* data = this->getViewData(propid);          
77         if(data->getProp3D()!=NULL){
78                 if(addremove){
79                         _renderer->AddViewProp(data->getProp3D());
80                 }else{
81                         _renderer->RemoveViewProp(data->getProp3D());
82                 }
83                 _renderer->Render();
84         }
85         
86 }
87 /**
88 **      Changes the opacity in a prop3D
89 **/
90 void wxMaracasIRMViewManager::changeOpacity(int propid, int value)  throw(char*){
91         checkInvariant();       
92
93
94         this->getViewData(propid)->changeOpacity(value);
95         
96         _renderer->Render();
97
98 }
99
100 /**
101 **      changes the isovalue in a prop3D
102 **/
103 void wxMaracasIRMViewManager::changeIsoValue(int propid, double value )throw(char*){
104         checkInvariant();       
105
106         wxMaracasIRMViewManagerData* data = this->getViewData(propid);          
107
108         //_renderer->RemoveActor(data->getProp3D());
109         ((wxMaracasIRMViewManagerDataMhd*)data)->changeIsoValue(value);
110         //_renderer->AddActor(data->getProp3D());
111
112         _renderer->Render();
113 }
114
115 vtkProp3D* wxMaracasIRMViewManager:: getProp3D(std::string filename){
116         if(filename.compare("")!= 0){
117                 vtkSTLReader *STLReader=vtkSTLReader::New();
118                 STLReader->SetFileName(filename.c_str());
119                 STLReader->Update();
120                 vtkPolyDataMapper* dataMapper = vtkPolyDataMapper::New();
121                 dataMapper->SetInput(STLReader->GetOutput());
122                 
123                 vtkActor* dataActor = vtkActor::New();
124                 dataActor->SetMapper(dataMapper);       
125                 dataActor->GetProperty()->SetOpacity(1);
126                 
127                 return dataActor;
128         }       
129         return NULL;
130 }
131
132 vtkImageData* wxMaracasIRMViewManager::getImageData(std::string filename){
133         if(filename.compare("")!= 0){   
134                 
135                 
136                 vtkMetaImageReader* reader =  vtkMetaImageReader::New();        
137                 reader->SetFileName(filename.c_str());
138                 reader->Update();
139                 vtkImageData* img = reader->GetOutput();
140                 //reader->Delete();
141                 return img;
142         }       
143         return NULL;
144 }
145
146 void wxMaracasIRMViewManager::checkInvariant()  throw(char*){
147         if(this->_renderer==NULL){
148                 throw "Renderer not set";
149         }
150 }
151
152 wxMaracasIRMViewManagerData* wxMaracasIRMViewManager::getViewData(int id) throw(char*){
153     int i;
154         for(i = 0; i < (int)(prop3Dvect.size());i++){
155                 if(prop3Dvect[i]->getId() == id){
156                         return prop3Dvect[i];
157                 }
158         }
159         throw "id not found in the data";
160
161         return NULL;
162 }
163
164 int wxMaracasIRMViewManager::getMaxIsoValue(int propid) throw(char*){
165         
166         return ((wxMaracasIRMViewManagerDataMhd*)this->getViewData(propid))->getMaxGreyLevel();
167
168 }
169
170 void wxMaracasIRMViewManager::changeColor(int propid, double red, double green, double blue) throw(char*){
171         checkInvariant();       
172         this->getViewData(propid)->changeColor(red, green, blue);
173
174         _renderer->Render();
175 }
176
177 void wxMaracasIRMViewManager::deleteActor(int propid) throw (char *){
178         checkInvariant();       
179
180         this->addRemoveActor(propid, false);
181
182         int i,n;
183         bool exit = false;
184         for(i = 0; i < (int)(prop3Dvect.size())&&!exit;i++){
185                 if(prop3Dvect[i]->getId() == propid){                   
186                         n=i;
187                         exit = true;
188                 }
189         }
190         if(exit){
191                 wxMaracasIRMViewManagerData* data = prop3Dvect[n];                      
192                 int j;
193                 for(j = i; j < (int)(prop3Dvect.size())-1;j++){
194                         prop3Dvect[j] = prop3Dvect[j+1];
195                 }               
196                 delete data;
197                 prop3Dvect.pop_back();
198         }else{
199                 throw "id not found in the data";
200         }
201
202         
203         
204     
205 }
206
207