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