]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerData.cxx
#3109 creaMaracasVisu Bug New Normal - branch vtk7itk4 compilation with vtk7
[creaMaracasVisu.git] / lib / Kernel / VTKObjects / SurfaceRenderer / wxMaracasSurfaceRenderingManagerData.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "wxMaracasSurfaceRenderingManagerData.h"
27
28 #include <vtkSmartPointer.h>
29 #include "vtkSTLWriter.h"
30 #include "vtkPLYWriter.h"
31 #include "vtkPolyDataWriter.h"
32 #include "surfacerenderingimagestencilexport.h"
33 #include "vtkMetaImageWriter.h"
34 #include "vtkPolyDataReader.h"
35 #include "vtkPLYReader.h"
36 #include "vtkSmartPointer.h"
37
38 /********************************************************************************************
39 ** Start of data viewmanagerData
40 *********************************************************************************************/
41
42 wxMaracasSurfaceRenderingManagerData::wxMaracasSurfaceRenderingManagerData(vtkProp3D* prop3Dvect, std::string dataname, vtkRenderWindowInteractor*  interactor){
43
44         _dataMapper = 0;
45         _prop3D = prop3Dvect;   
46         _dataname = dataname;   
47         _boxWidgetS1=NULL;
48         
49         initializeBoxWidget(interactor);
50         
51
52         
53
54         /*_boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(0) );
55         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(1) );
56         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(2) );
57         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(3) );*/
58 }
59
60 wxMaracasSurfaceRenderingManagerData::wxMaracasSurfaceRenderingManagerData(string filename, vtkRenderWindowInteractor*  interactor){
61
62     _prop3D = getProp3D(filename);
63     _dataname = filename;
64     _boxWidgetS1=NULL;
65
66     initializeBoxWidget(interactor);
67 }
68
69 vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(std::string filename){
70
71     if(filename.compare("")!= 0){
72
73         vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
74         std::string ext = filename.substr(filename.find_last_of("."), 4);
75         if(ext.compare(STL)==0){
76             vtkSmartPointer<vtkSTLReader> STLReader=vtkSmartPointer<vtkSTLReader>::New();
77             STLReader->SetFileName(filename.c_str());
78             STLReader->Update();
79             polydata->DeepCopy(STLReader->GetOutput());
80
81         }else if(ext.compare(PLY)==0){
82             vtkSmartPointer<vtkPLYReader> plyreader =vtkSmartPointer<vtkPLYReader>::New();
83             plyreader->SetFileName(filename.c_str());
84             plyreader->Update();
85             polydata->DeepCopy(plyreader->GetOutput());
86         }else if(ext.compare(VTK)==0){
87             vtkSmartPointer<vtkPolyDataReader> polyreader =vtkSmartPointer<vtkPolyDataReader>::New();
88             polyreader->SetFileName(filename.c_str());
89             polyreader->Update();
90             polydata->DeepCopy(polyreader->GetOutput());
91         }
92
93         _dataMapper = vtkPolyDataMapper::New();
94
95 //EED 2017-01-01 Migration VTK7
96 #if VTK_MAJOR_VERSION <= 5
97         _dataMapper->SetInput(polydata);
98 #else
99         _dataMapper->SetInputData(polydata);
100 #endif
101
102         vtkActor* dataActor = vtkActor::New();
103         dataActor->SetMapper(_dataMapper);
104         dataActor->GetProperty()->SetOpacity(1);
105         return dataActor;
106     }
107     return NULL;
108 }
109
110 wxMaracasSurfaceRenderingManagerData::~wxMaracasSurfaceRenderingManagerData(){
111         
112         _prop3D->Delete();      
113         if (_boxWidgetS1!=NULL)                                  { _boxWidgetS1         -> Delete();                                    }
114 }
115
116 void wxMaracasSurfaceRenderingManagerData::initializeBoxWidget(vtkRenderWindowInteractor*  interactor){
117         if(interactor!= NULL){
118         
119         }
120 }
121
122 /**
123 **      Adds a prop3D to the world of the application
124 **/
125 void wxMaracasSurfaceRenderingManagerData::setProp3D(vtkProp3D* prop3D){
126         _prop3D = prop3D;
127 }
128
129 void wxMaracasSurfaceRenderingManagerData::addRemoveSurfaceBox(bool visible)
130 {
131         if(_boxWidgetS1){
132                 if (visible==true){
133                         _boxWidgetS1->On();
134                 } else {
135                         _boxWidgetS1->Off();
136                 }
137         }
138 }
139 /**
140 **      Changes the opacity in a prop3D
141 **/
142 void wxMaracasSurfaceRenderingManagerData::changeOpacity(int value){
143         std::cout<<"chage op"<<value<<std::endl;
144         vtkActor* actor = (vtkActor*)this->_prop3D;     
145         actor->GetProperty()->SetOpacity((double)value/100.0);
146
147         
148
149 }
150 void wxMaracasSurfaceRenderingManagerData::changeColor(double red, double green, double blue){
151         std::cout<<"chage col"<<red<<green<<blue<<std::endl;
152     vtkActor* actor = (vtkActor*)this->_prop3D; 
153         actor->GetProperty()->SetColor(red,green,blue); 
154 }
155 /**
156 **      Check if the variables are setted correctly
157 **/
158 void wxMaracasSurfaceRenderingManagerData::checkInvariant(){
159
160 }
161 /**
162 **      get the prop3D 
163 **/
164 vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(){
165         return this->_prop3D;
166 }
167 /**
168 **      return the id from the daat
169 **/
170 int wxMaracasSurfaceRenderingManagerData::getId(){
171         return _id;
172 }
173 /**
174 **      set data id
175 **/
176 void wxMaracasSurfaceRenderingManagerData::setId(int propid){
177         _id = propid;
178 }
179
180 /**
181 **      Get the filanme
182 **/
183 std::string wxMaracasSurfaceRenderingManagerData::getDataname(){
184         return _dataname;
185 }
186 /**
187 ** Set the filanme
188 **/
189 void wxMaracasSurfaceRenderingManagerData::setDataname(std::string dataname){
190         _dataname = dataname;
191 }
192
193
194
195 void wxMaracasSurfaceRenderingManagerData::saveProp3DSTL(const char* filename){
196     if(_dataMapper){
197
198         std::string filena(filename);
199         std::string ext = filena.substr(filena.find_last_of("."), 4);
200         if(ext.compare(PLY) == 0){
201             vtkSmartPointer<vtkPLYWriter> plywriter =
202             vtkSmartPointer<vtkPLYWriter>::New();
203               plywriter->SetFileName(filename);
204 //EED 2017-01-01 Migration VTK7
205 #if VTK_MAJOR_VERSION <= 5
206               plywriter->SetInput(_dataMapper->GetInput());
207 #else
208               plywriter->SetInputData(_dataMapper->GetInput());
209 #endif
210               plywriter->Write();
211         }else if(ext.compare(STL) == 0){
212             vtkSmartPointer<vtkSTLWriter> stlWriter =
213             vtkSmartPointer<vtkSTLWriter>::New();
214               stlWriter->SetFileName(filename);
215 //EED 2017-01-01 Migration VTK7
216 #if VTK_MAJOR_VERSION <= 5
217               stlWriter->SetInput(_dataMapper->GetInput());
218 #else
219               stlWriter->SetInputData(_dataMapper->GetInput());
220 #endif
221               stlWriter->SetFileTypeToBinary();
222               stlWriter->Write();
223         }else if(ext.compare(VTK) == 0){
224             vtkSmartPointer<vtkPolyDataWriter> polydataWriter =
225             vtkSmartPointer<vtkPolyDataWriter>::New();
226               polydataWriter->SetFileName(filename);
227 //EED 2017-01-01 Migration VTK7
228 #if VTK_MAJOR_VERSION <= 5
229               polydataWriter->SetInput(_dataMapper->GetInput());
230 #else
231               polydataWriter->SetInputData(_dataMapper->GetInput());
232 #endif
233               polydataWriter->SetFileTypeToBinary();
234               polydataWriter->Write();
235         }else{
236             cout<<"unsupported format"<<endl;
237         }
238     }
239 }
240
241 void wxMaracasSurfaceRenderingManagerData::enableBoxWidget(bool enable){
242
243 }
244
245 void wxMaracasSurfaceRenderingManagerData::exportImageStencil(const char* filename){
246     if(_dataMapper){
247         vtkSmartPointer< SurfaceRenderingImageStencilExport> stencilexport = vtkSmartPointer< SurfaceRenderingImageStencilExport >::New();
248 //EED 2017-01-01 Migration VTK7
249 #if VTK_MAJOR_VERSION <= 5
250         stencilexport->SetInput( _dataMapper->GetInput());
251 #else
252         stencilexport->SetInputData( _dataMapper->GetInput());
253 #endif
254         stencilexport->Update();
255         vtkImageData* imgstencil = stencilexport->GetOutput();
256
257         vtkSmartPointer<vtkMetaImageWriter> metawriter = vtkSmartPointer<vtkMetaImageWriter>::New();
258         metawriter->SetFileName(filename);
259 //EED 2017-01-01 Migration VTK7
260 #if VTK_MAJOR_VERSION <= 5
261         metawriter->SetInput(imgstencil);
262 #else
263         metawriter->SetInputData(imgstencil);
264 #endif
265         metawriter->Write();
266     }else{
267         cout<<"No poly data set to data mapper."<<endl;
268     }
269
270 }
271
272
273
274