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);
35 void PolyDataWriterPlus::Process()
37 std::cout << "[" << this << "]" << "PolyDataWriterPlus::Process()..." << std::endl;
38 //Review the observers...
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());
46 InvokeEvent(OBS_PRE_WRITER_1);
48 if (bbGetInputInPath().size()==0)
50 std::cout << "Set InPath." << std::endl;
56 if (bbGetInputIn()==NULL)
58 if (bbGetInputIn2()==NULL)
60 std::cout << "Set In." << std::endl;
65 vtkProp3D* actor = bbGetInputIn2();
66 vtkPolyDataMapper* mapper = ((vtkPolyDataMapper*)((vtkActor*)actor)->GetMapper());
67 cosa = mapper->GetInput();
72 cosa = bbGetInputIn();
75 std::string nuevo_nombre = guessName(bbGetInputInPath());
78 vtkPolyData* entrada = cosa;
79 std::cout << "Before writing" << std::endl;
80 entrada->Print(std::cout);
82 std::vector< std::string > partes = StringSplit(nuevo_nombre, ".");
83 std::string extension = partes.at(partes.size()-1);
85 std::cout << "Extension (vtk, vtp o stl?) => " << extension << std::endl;
89 vtkDataSetSurfaceFilter* surfaceFilter = vtkDataSetSurfaceFilter::New();
90 surfaceFilter->SetInput(entrada);
91 surfaceFilter->Update();
92 //vtkPolyData* polydata = surfaceFilter->GetOutput();
93 entrada = surfaceFilter->GetOutput();
95 if (extension.compare("vtk") == 0)
97 vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
98 writer->SetInput(entrada);
99 writer->SetFileName(nuevo_nombre.data());
104 if (extension.compare("vtp") == 0)
106 vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
107 writer->SetFileName ( nuevo_nombre.data() );
108 writer->SetInput ( entrada );
113 if (extension.compare("stl") == 0)
115 vtkSTLWriter* writer = vtkSTLWriter::New();
116 writer->SetFileName ( nuevo_nombre.data() );
117 writer->SetInput ( entrada );
119 writer->Print(std::cout);
124 std::cout << "Saving Ok!" << std::endl;
126 InvokeEvent(OBS_POST_WRITER_1);
128 void PolyDataWriterPlus::bbUserSetDefaultValues()
131 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
132 // Here we initialize the input 'In' to 0
135 bbSetInputInPrePersistObs1(NULL);
136 bbSetInputInPostPersistObs1(NULL);
137 std::string nada = "";
138 std::string prefixDefault = "Data";
139 bbSetInputInPath(nada);
140 bbSetInputInFilePrefix(prefixDefault);
143 void PolyDataWriterPlus::bbUserInitializeProcessing()
146 // THE INITIALIZATION METHOD BODY :
148 // but this is where you should allocate the internal/output pointers
153 void PolyDataWriterPlus::bbUserFinalizeProcessing()
156 // THE FINALIZATION METHOD BODY :
158 // but this is where you should desallocate the internal/output pointers
160 RemoveAllObservers();
162 if (bbGetInputInPrePersistObs1() != NULL && bbGetInputInPrePersistObs1()->GetReferenceCount() > 0)
163 bbGetInputInPrePersistObs1()->SetReferenceCount(bbGetInputInPrePersistObs1()->GetReferenceCount()-1);
164 if (bbGetInputInPostPersistObs1() != NULL)
165 bbGetInputInPostPersistObs1()->SetReferenceCount(bbGetInputInPostPersistObs1()->GetReferenceCount()-1);
168 // EO namespace bbvtk