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();
94 _dataMapper->SetInput(polydata);
96 vtkActor* dataActor = vtkActor::New();
97 dataActor->SetMapper(_dataMapper);
98 dataActor->GetProperty()->SetOpacity(1);
104 wxMaracasSurfaceRenderingManagerData::~wxMaracasSurfaceRenderingManagerData(){
107 if (_boxWidgetS1!=NULL) { _boxWidgetS1 -> Delete(); }
110 void wxMaracasSurfaceRenderingManagerData::initializeBoxWidget(vtkRenderWindowInteractor* interactor){
111 if(interactor!= NULL){
117 ** Adds a prop3D to the world of the application
119 void wxMaracasSurfaceRenderingManagerData::setProp3D(vtkProp3D* prop3D){
123 void wxMaracasSurfaceRenderingManagerData::addRemoveSurfaceBox(bool visible)
134 ** Changes the opacity in a prop3D
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);
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);
150 ** Check if the variables are setted correctly
152 void wxMaracasSurfaceRenderingManagerData::checkInvariant(){
158 vtkProp3D* wxMaracasSurfaceRenderingManagerData::getProp3D(){
159 return this->_prop3D;
162 ** return the id from the daat
164 int wxMaracasSurfaceRenderingManagerData::getId(){
170 void wxMaracasSurfaceRenderingManagerData::setId(int propid){
177 std::string wxMaracasSurfaceRenderingManagerData::getDataname(){
183 void wxMaracasSurfaceRenderingManagerData::setDataname(std::string dataname){
184 _dataname = dataname;
189 void wxMaracasSurfaceRenderingManagerData::saveProp3DSTL(const char* filename){
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());
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();
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();
215 cout<<"unsupported format"<<endl;
220 void wxMaracasSurfaceRenderingManagerData::enableBoxWidget(bool enable){
224 void wxMaracasSurfaceRenderingManagerData::exportImageStencil(const char* filename){
226 vtkSmartPointer< SurfaceRenderingImageStencilExport> stencilexport = vtkSmartPointer< SurfaceRenderingImageStencilExport >::New();
227 stencilexport->SetInput( _dataMapper->GetInput());
228 stencilexport->Update();
229 vtkImageData* imgstencil = stencilexport->GetOutput();
231 vtkSmartPointer<vtkMetaImageWriter> metawriter = vtkSmartPointer<vtkMetaImageWriter>::New();
232 metawriter->SetFileName(filename);
233 metawriter->SetInput(imgstencil);
236 cout<<"No poly data set to data mapper."<<endl;