]> Creatis software - creaMaracasVisu.git/blob - lib/Kernel/VTKObjects/SurfaceRenderer/wxMaracasSurfaceRenderingManagerData.cxx
Support #1768 CREATIS Licence insertion
[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         _dataMapper->SetInput(polydata);
95
96         vtkActor* dataActor = vtkActor::New();
97         dataActor->SetMapper(_dataMapper);
98         dataActor->GetProperty()->SetOpacity(1);
99         return dataActor;
100     }
101     return NULL;
102 }
103
104 wxMaracasSurfaceRenderingManagerData::~wxMaracasSurfaceRenderingManagerData(){
105         
106         _prop3D->Delete();      
107         if (_boxWidgetS1!=NULL)                                  { _boxWidgetS1         -> Delete();                                    }
108 }
109
110 void wxMaracasSurfaceRenderingManagerData::initializeBoxWidget(vtkRenderWindowInteractor*  interactor){
111         if(interactor!= NULL){
112         
113         }
114 }
115
116 /**
117 **      Adds a prop3D to the world of the application
118 **/
119 void wxMaracasSurfaceRenderingManagerData::setProp3D(vtkProp3D* prop3D){
120         _prop3D = prop3D;
121 }
122
123 void wxMaracasSurfaceRenderingManagerData::addRemoveSurfaceBox(bool visible)
124 {
125         if(_boxWidgetS1){
126                 if (visible==true){
127                         _boxWidgetS1->On();
128                 } else {
129                         _boxWidgetS1->Off();
130                 }
131         }
132 }
133 /**
134 **      Changes the opacity in a prop3D
135 **/
136 void wxMaracasSurfaceRenderingManagerData::changeOpacity(int value){
137         std::cout<<"chage op"<<value<<std::endl;
138         vtkActor* actor = (vtkActor*)this->_prop3D;     
139         actor->GetProperty()->SetOpacity((double)value/100.0);
140
141         
142
143 }
144 void wxMaracasSurfaceRenderingManagerData::changeColor(double red, double green, double blue){
145         std::cout<<"chage col"<<red<<green<<blue<<std::endl;
146     vtkActor* actor = (vtkActor*)this->_prop3D; 
147         actor->GetProperty()->SetColor(red,green,blue); 
148 }
149 /**
150 **      Check if the variables are setted correctly
151 **/
152 void wxMaracasSurfaceRenderingManagerData::checkInvariant(){
153
154 }
155 /**
156 **      get the prop3D 
157 **/
158 vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(){
159         return this->_prop3D;
160 }
161 /**
162 **      return the id from the daat
163 **/
164 int wxMaracasSurfaceRenderingManagerData::getId(){
165         return _id;
166 }
167 /**
168 **      set data id
169 **/
170 void wxMaracasSurfaceRenderingManagerData::setId(int propid){
171         _id = propid;
172 }
173
174 /**
175 **      Get the filanme
176 **/
177 std::string wxMaracasSurfaceRenderingManagerData::getDataname(){
178         return _dataname;
179 }
180 /**
181 ** Set the filanme
182 **/
183 void wxMaracasSurfaceRenderingManagerData::setDataname(std::string dataname){
184         _dataname = dataname;
185 }
186
187
188
189 void wxMaracasSurfaceRenderingManagerData::saveProp3DSTL(const char* filename){
190     if(_dataMapper){
191
192         std::string filena(filename);
193         std::string ext = filena.substr(filena.find_last_of("."), 4);
194         if(ext.compare(PLY) == 0){
195             vtkSmartPointer<vtkPLYWriter> plywriter =
196             vtkSmartPointer<vtkPLYWriter>::New();
197               plywriter->SetFileName(filename);
198               plywriter->SetInput(_dataMapper->GetInput());
199               plywriter->Write();
200         }else if(ext.compare(STL) == 0){
201             vtkSmartPointer<vtkSTLWriter> stlWriter =
202             vtkSmartPointer<vtkSTLWriter>::New();
203               stlWriter->SetFileName(filename);
204               stlWriter->SetInput(_dataMapper->GetInput());
205               stlWriter->SetFileTypeToBinary();
206               stlWriter->Write();
207         }else if(ext.compare(VTK) == 0){
208             vtkSmartPointer<vtkPolyDataWriter> polydataWriter =
209             vtkSmartPointer<vtkPolyDataWriter>::New();
210               polydataWriter->SetFileName(filename);
211               polydataWriter->SetInput(_dataMapper->GetInput());
212               polydataWriter->SetFileTypeToBinary();
213               polydataWriter->Write();
214         }else{
215             cout<<"unsupported format"<<endl;
216         }
217     }
218 }
219
220 void wxMaracasSurfaceRenderingManagerData::enableBoxWidget(bool enable){
221
222 }
223
224 void wxMaracasSurfaceRenderingManagerData::exportImageStencil(const char* filename){
225     if(_dataMapper){
226         vtkSmartPointer< SurfaceRenderingImageStencilExport> stencilexport = vtkSmartPointer< SurfaceRenderingImageStencilExport >::New();
227         stencilexport->SetInput( _dataMapper->GetInput());
228         stencilexport->Update();
229         vtkImageData* imgstencil = stencilexport->GetOutput();
230
231         vtkSmartPointer<vtkMetaImageWriter> metawriter = vtkSmartPointer<vtkMetaImageWriter>::New();
232         metawriter->SetFileName(filename);
233         metawriter->SetInput(imgstencil);
234         metawriter->Write();
235     }else{
236         cout<<"No poly data set to data mapper."<<endl;
237     }
238
239 }
240
241
242
243