]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataWriterPlus.cxx
2498 BBTK FeatureNewNormal wt-version kernel
[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         surfaceFilter->SetInput(entrada);
91         surfaceFilter->Update();
92         //vtkPolyData* polydata = surfaceFilter->GetOutput();
93         entrada = surfaceFilter->GetOutput();
94
95         if (extension.compare("vtk") == 0)
96         {
97                 vtkPolyDataWriter* writer = vtkPolyDataWriter::New();
98                 writer->SetInput(entrada);
99                 writer->SetFileName(nuevo_nombre.data());
100                 writer->Write();
101                 writer->Delete();
102         }
103
104         if (extension.compare("vtp") == 0)
105         {
106                 vtkXMLPolyDataWriter* writer = vtkXMLPolyDataWriter::New();
107                 writer->SetFileName ( nuevo_nombre.data() );
108                 writer->SetInput ( entrada );
109                 writer->Write();
110                 writer->Delete();
111         }
112
113         if (extension.compare("stl") == 0)
114         {
115                 vtkSTLWriter* writer = vtkSTLWriter::New();
116                 writer->SetFileName ( nuevo_nombre.data() );
117                 writer->SetInput ( entrada );
118                 writer->Write();
119                 writer->Print(std::cout);
120                 writer->Delete();
121         }
122
123         std::cout << "Saving Ok!" << std::endl;
124
125         InvokeEvent(OBS_POST_WRITER_1);
126 }
127 void PolyDataWriterPlus::bbUserSetDefaultValues()
128 {
129
130 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
131 //    Here we initialize the input 'In' to 0
132     bbSetInputIn(NULL);
133         bbSetInputIn2(NULL);
134         bbSetInputInPrePersistObs1(NULL);
135         bbSetInputInPostPersistObs1(NULL);
136         std::string nada = "";
137         std::string prefixDefault = "Data";
138         bbSetInputInPath(nada);
139         bbSetInputInFilePrefix(prefixDefault);
140
141 }
142 void PolyDataWriterPlus::bbUserInitializeProcessing()
143 {
144
145 //  THE INITIALIZATION METHOD BODY :
146 //    Here does nothing
147 //    but this is where you should allocate the internal/output pointers
148 //    if any
149
150
151 }
152 void PolyDataWriterPlus::bbUserFinalizeProcessing()
153 {
154
155 //  THE FINALIZATION METHOD BODY :
156 //    Here does nothing
157 //    but this is where you should desallocate the internal/output pointers
158 //    if any
159         RemoveAllObservers();
160
161         if (bbGetInputInPrePersistObs1() != NULL && bbGetInputInPrePersistObs1()->GetReferenceCount() > 0)
162                 bbGetInputInPrePersistObs1()->SetReferenceCount(bbGetInputInPrePersistObs1()->GetReferenceCount()-1);
163         if (bbGetInputInPostPersistObs1() != NULL)
164                 bbGetInputInPostPersistObs1()->SetReferenceCount(bbGetInputInPostPersistObs1()->GetReferenceCount()-1);
165 }
166 }
167 // EO namespace bbvtk
168
169