]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataWriterPlus.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / vtk / src / bbvtkPolyDataWriterPlus.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 #include "bbvtkPolyDataWriterPlus.h"
29 #include "bbvtkPackage.h"
30 namespace bbvtk
31 {
32
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataWriterPlus)
34 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataWriterPlus,bbtk::AtomicBlackBox);
35 void PolyDataWriterPlus::Process()
36 {
37         std::cout << "[" << this << "]" << "PolyDataWriterPlus::Process()..." << std::endl;
38         //Review the observers...
39
40         if (!HasObserver(OBS_PRE_WRITER_1) && bbGetInputInPrePersistObs1() != NULL)
41                 AddObserver(OBS_PRE_WRITER_1, bbGetInputInPrePersistObs1());
42  /// \TODO fix warning: NULL used in arithmetic // JPR
43         if (!HasObserver(OBS_POST_WRITER_1) == NULL && bbGetInputInPostPersistObs1() != NULL)
44                 AddObserver(OBS_POST_WRITER_1, bbGetInputInPostPersistObs1());
45
46         InvokeEvent(OBS_PRE_WRITER_1);
47
48         if (bbGetInputInPath().size()==0)
49         {
50                 std::cout << "Set InPath." << std::endl;
51                 return;
52         }
53
54         vtkPolyData* cosa;
55
56         if (bbGetInputIn()==NULL)
57         {
58                 if (bbGetInputIn2()==NULL)
59                 {
60                         std::cout << "Set In." << std::endl;
61                         return;
62                 }
63                 else
64                 {
65                         vtkProp3D* actor = bbGetInputIn2();
66                         vtkPolyDataMapper* mapper = ((vtkPolyDataMapper*)((vtkActor*)actor)->GetMapper());
67                         cosa = mapper->GetInput();
68                 }
69         }
70         else
71         {
72                 cosa = bbGetInputIn();
73         }
74
75         std::string nuevo_nombre = guessName(bbGetInputInPath());
76
77
78         vtkPolyData* entrada = cosa;
79         std::cout << "Before writing" << std::endl;
80         entrada->Print(std::cout);
81
82         std::vector< std::string > partes = StringSplit(nuevo_nombre, ".");
83         std::string extension = partes.at(partes.size()-1);
84
85         std::cout << "Extension (vtk, vtp o stl?) => " << extension << std::endl;
86
87
88
89         vtkDataSetSurfaceFilter* surfaceFilter = vtkDataSetSurfaceFilter::New();
90
91 //EED 2017-01-01 Migration VTK7
92 #if VTK_MAJOR_VERSION <= 5
93         surfaceFilter->SetInput(entrada);
94 #else
95         surfaceFilter->SetInputData(entrada);
96 #endif
97
98         surfaceFilter->Update();
99         //vtkPolyData* polydata = surfaceFilter->GetOutput();
100         entrada = surfaceFilter->GetOutput();
101
102         if (extension.compare("vtk") == 0)
103         {
104                 vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
105
106 //EED 2017-01-01 Migration VTK7
107 #if VTK_MAJOR_VERSION <= 5
108                 writer->SetInput(entrada);
109 #else
110                 writer->SetInputData(entrada);
111 #endif
112
113                 writer->SetFileName(nuevo_nombre.data());
114                 writer->Write();
115                 writer->Delete();
116         }
117
118         if (extension.compare("vtp") == 0)
119         {
120                 vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
121                 writer->SetFileName ( nuevo_nombre.data() );
122
123 //EED 2017-01-01 Migration VTK7
124 #if VTK_MAJOR_VERSION <= 5
125                 writer->SetInput ( entrada );
126 #else
127                 writer->SetInputData ( entrada );
128 #endif
129
130                 writer->Write();
131                 writer->Delete();
132         }
133
134         if (extension.compare("stl") == 0)
135         {
136                 vtkSTLWriter* writer = vtkSTLWriter::New();
137                 writer->SetFileName ( nuevo_nombre.data() );
138
139 //EED 2017-01-01 Migration VTK7
140 #if VTK_MAJOR_VERSION <= 5
141                 writer->SetInput ( entrada );
142 #else
143                 writer->SetInputData ( entrada );
144 #endif
145
146                 writer->Write();
147                 writer->Print(std::cout);
148                 writer->Delete();
149         }
150
151         std::cout << "Saving Ok!" << std::endl;
152
153         InvokeEvent(OBS_POST_WRITER_1);
154 }
155 void PolyDataWriterPlus::bbUserSetDefaultValues()
156 {
157
158 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
159 //    Here we initialize the input 'In' to 0
160     bbSetInputIn(NULL);
161         bbSetInputIn2(NULL);
162         bbSetInputInPrePersistObs1(NULL);
163         bbSetInputInPostPersistObs1(NULL);
164         std::string nada = "";
165         std::string prefixDefault = "Data";
166         bbSetInputInPath(nada);
167         bbSetInputInFilePrefix(prefixDefault);
168
169 }
170 void PolyDataWriterPlus::bbUserInitializeProcessing()
171 {
172
173 //  THE INITIALIZATION METHOD BODY :
174 //    Here does nothing
175 //    but this is where you should allocate the internal/output pointers
176 //    if any
177
178
179 }
180 void PolyDataWriterPlus::bbUserFinalizeProcessing()
181 {
182
183 //  THE FINALIZATION METHOD BODY :
184 //    Here does nothing
185 //    but this is where you should desallocate the internal/output pointers
186 //    if any
187         RemoveAllObservers();
188
189         if (bbGetInputInPrePersistObs1() != NULL && bbGetInputInPrePersistObs1()->GetReferenceCount() > 0)
190                 bbGetInputInPrePersistObs1()->SetReferenceCount(bbGetInputInPrePersistObs1()->GetReferenceCount()-1);
191         if (bbGetInputInPostPersistObs1() != NULL)
192                 bbGetInputInPostPersistObs1()->SetReferenceCount(bbGetInputInPostPersistObs1()->GetReferenceCount()-1);
193 }
194 }
195 // EO namespace bbvtk
196
197