2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 #include "bbvtkPolyDataWriterPlus.h"
29 #include "bbvtkPackage.h"
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataWriterPlus)
34 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataWriterPlus,bbtk::AtomicBlackBox);
36 void PolyDataWriterPlus::Process()
38 // std::cout << "[" << this << "]" << "PolyDataWriterPlus::Process()..." << std::endl;
39 //Review the observers...
41 if (!HasObserver(OBS_PRE_WRITER_1) && bbGetInputInPrePersistObs1() != NULL)
42 AddObserver(OBS_PRE_WRITER_1, bbGetInputInPrePersistObs1());
43 /// \TODO fix warning: NULL used in arithmetic // JPR
44 if (!HasObserver(OBS_POST_WRITER_1) == NULL && bbGetInputInPostPersistObs1() != NULL)
45 AddObserver(OBS_POST_WRITER_1, bbGetInputInPostPersistObs1());
47 InvokeEvent(OBS_PRE_WRITER_1);
49 if (bbGetInputInPath().size()==0)
51 std::cout << "Set InPath." << std::endl;
57 if (bbGetInputIn()==NULL)
59 if (bbGetInputIn2()==NULL)
61 std::cout << "Set In." << std::endl;
64 vtkProp3D* actor = bbGetInputIn2();
65 vtkPolyDataMapper* mapper = ((vtkPolyDataMapper*)((vtkActor*)actor)->GetMapper());
66 cosa = mapper->GetInput();
69 cosa = bbGetInputIn();
72 std::string nuevo_nombre = guessName(bbGetInputInPath());
74 vtkPolyData* entrada = cosa;
75 // std::cout << "Before writing" << std::endl;
76 // entrada->Print(std::cout);
78 std::vector< std::string > partes = StringSplit(nuevo_nombre, ".");
79 std::string extension = partes.at(partes.size()-1);
81 // std::cout << "Extension (vtk, vtp o stl?) => " << extension << std::endl;
83 vtkDataSetSurfaceFilter* surfaceFilter = vtkDataSetSurfaceFilter::New();
85 //EED 2017-01-01 Migration VTK7
86 #if VTK_MAJOR_VERSION <= 5
87 surfaceFilter->SetInput(entrada);
89 surfaceFilter->SetInputData(entrada);
92 surfaceFilter->Update();
93 //vtkPolyData* polydata = surfaceFilter->GetOutput();
94 entrada = surfaceFilter->GetOutput();
96 if (extension.compare("vtk") == 0)
98 vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
100 //EED 2017-01-01 Migration VTK7
101 #if VTK_MAJOR_VERSION <= 5
102 writer->SetInput(entrada);
104 writer->SetInputData(entrada);
107 writer->SetFileName(nuevo_nombre.data());
112 if (extension.compare("vtp") == 0)
114 vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
115 writer->SetFileName ( nuevo_nombre.data() );
117 //EED 2017-01-01 Migration VTK7
118 #if VTK_MAJOR_VERSION <= 5
119 writer->SetInput ( entrada );
121 writer->SetInputData ( entrada );
128 if (extension.compare("stl") == 0)
130 vtkSTLWriter* writer = vtkSTLWriter::New();
131 writer->SetFileName ( nuevo_nombre.data() );
133 //EED 2017-01-01 Migration VTK7
134 #if VTK_MAJOR_VERSION <= 5
135 writer->SetInput ( entrada );
137 writer->SetInputData ( entrada );
141 writer->Print(std::cout);
145 std::cout << "Saving Ok!" << std::endl;
147 InvokeEvent(OBS_POST_WRITER_1);
150 void PolyDataWriterPlus::bbUserSetDefaultValues()
153 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
154 // Here we initialize the input 'In' to 0
157 bbSetInputInPrePersistObs1(NULL);
158 bbSetInputInPostPersistObs1(NULL);
159 std::string nada = "";
160 std::string prefixDefault = "Data";
161 bbSetInputInPath(nada);
162 bbSetInputInFilePrefix(prefixDefault);
165 void PolyDataWriterPlus::bbUserInitializeProcessing()
168 // THE INITIALIZATION METHOD BODY :
170 // but this is where you should allocate the internal/output pointers
175 void PolyDataWriterPlus::bbUserFinalizeProcessing()
178 // THE FINALIZATION METHOD BODY :
180 // but this is where you should desallocate the internal/output pointers
182 RemoveAllObservers();
184 if (bbGetInputInPrePersistObs1() != NULL && bbGetInputInPrePersistObs1()->GetReferenceCount() > 0)
185 bbGetInputInPrePersistObs1()->SetReferenceCount(bbGetInputInPrePersistObs1()->GetReferenceCount()-1);
186 if (bbGetInputInPostPersistObs1() != NULL)
187 bbGetInputInPostPersistObs1()->SetReferenceCount(bbGetInputInPostPersistObs1()->GetReferenceCount()-1);
190 // EO namespace bbvtk