1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "wxMaracasSurfaceRenderingManagerData.h"
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"
38 /********************************************************************************************
39 ** Start of data viewmanagerData
40 *********************************************************************************************/
42 wxMaracasSurfaceRenderingManagerData::wxMaracasSurfaceRenderingManagerData(vtkProp3D* prop3Dvect, std::string dataname, vtkRenderWindowInteractor* interactor){
49 initializeBoxWidget(interactor);
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) );*/
60 wxMaracasSurfaceRenderingManagerData::wxMaracasSurfaceRenderingManagerData(string filename, vtkRenderWindowInteractor* interactor){
62 _prop3D = getProp3D(filename);
66 initializeBoxWidget(interactor);
69 vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(std::string filename){
71 if(filename.compare("")!= 0){
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());
79 polydata->DeepCopy(STLReader->GetOutput());
81 }else if(ext.compare(PLY)==0){
82 vtkSmartPointer<vtkPLYReader> plyreader =vtkSmartPointer<vtkPLYReader>::New();
83 plyreader->SetFileName(filename.c_str());
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());
90 polydata->DeepCopy(polyreader->GetOutput());
93 _dataMapper = vtkPolyDataMapper::New();
95 //EED 2017-01-01 Migration VTK7
96 #if VTK_MAJOR_VERSION <= 5
97 _dataMapper->SetInput(polydata);
99 _dataMapper->SetInputData(polydata);
102 vtkActor* dataActor = vtkActor::New();
103 dataActor->SetMapper(_dataMapper);
104 dataActor->GetProperty()->SetOpacity(1);
110 wxMaracasSurfaceRenderingManagerData::~wxMaracasSurfaceRenderingManagerData(){
113 if (_boxWidgetS1!=NULL) { _boxWidgetS1 -> Delete(); }
116 void wxMaracasSurfaceRenderingManagerData::initializeBoxWidget(vtkRenderWindowInteractor* interactor){
117 if(interactor!= NULL){
123 ** Adds a prop3D to the world of the application
125 void wxMaracasSurfaceRenderingManagerData::setProp3D(vtkProp3D* prop3D){
129 void wxMaracasSurfaceRenderingManagerData::addRemoveSurfaceBox(bool visible)
140 ** Changes the opacity in a prop3D
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);
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);
156 ** Check if the variables are setted correctly
158 void wxMaracasSurfaceRenderingManagerData::checkInvariant(){
164 vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(){
165 return this->_prop3D;
168 ** return the id from the daat
170 int wxMaracasSurfaceRenderingManagerData::getId(){
176 void wxMaracasSurfaceRenderingManagerData::setId(int propid){
183 std::string wxMaracasSurfaceRenderingManagerData::getDataname(){
189 void wxMaracasSurfaceRenderingManagerData::setDataname(std::string dataname){
190 _dataname = dataname;
195 void wxMaracasSurfaceRenderingManagerData::saveProp3DSTL(const char* filename){
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());
208 plywriter->SetInputData(_dataMapper->GetInput());
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());
219 stlWriter->SetInputData(_dataMapper->GetInput());
221 stlWriter->SetFileTypeToBinary();
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());
231 polydataWriter->SetInputData(_dataMapper->GetInput());
233 polydataWriter->SetFileTypeToBinary();
234 polydataWriter->Write();
236 cout<<"unsupported format"<<endl;
241 void wxMaracasSurfaceRenderingManagerData::enableBoxWidget(bool enable){
245 void wxMaracasSurfaceRenderingManagerData::exportImageStencil(const char* filename){
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());
252 stencilexport->SetInputData( _dataMapper->GetInput());
254 stencilexport->Update();
255 vtkImageData* imgstencil = stencilexport->GetOutput();
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);
263 metawriter->SetInputData(imgstencil);
267 cout<<"No poly data set to data mapper."<<endl;