]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataReaderPlus.cxx
#3107 BBTK Bug New Normal - branch vtk7itk4 compilation with vtk7
[bbtk.git] / packages / vtk / src / bbvtkPolyDataReaderPlus.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 "bbvtkPolyDataReaderPlus.h"
29 #include "bbvtkPackage.h"
30 namespace bbvtk
31 {
32
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataReaderPlus)
34 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataReaderPlus,bbtk::AtomicBlackBox);
35 void PolyDataReaderPlus::Process()
36 {
37
38     std::cout << "[" << this << "]" << "PolyDataReaderPlus::Process()..." << std::endl;
39         //Review the observers...
40
41         if (!HasObserver(OBS_POST_READER_1) && bbGetInputInPostReadObs1() != NULL)
42                 AddObserver(OBS_POST_READER_1, bbGetInputInPostReadObs1());
43
44         if (bbGetInputInPath().size()==0)
45         {
46                 std::cout << "Set InPath." << std::endl;
47                 return;
48         }
49
50         //Read!
51         if (!readed)
52         {
53                 std::vector< std::string > partes = StringSplit(bbGetInputInPath(), ".");
54                 std::string extension = partes.at(partes.size()-1);
55
56                 std::cout << "Extension (vtk o vtp?) = " << extension << std::endl;
57
58                 if (extension.compare("vtk") == 0)
59                 {
60                         //vtkPolyDataReader* reader = vtkPolyDataReader::New();
61                         vtkGenericDataObjectReader* reader = vtkGenericDataObjectReader::New();
62                         reader->SetFileName(bbGetInputInPath().data());
63                         informacion = (vtkPolyData*)reader->GetOutput();
64                         reader->CloseVTKFile();
65                         vtkPolyData* old = bbGetOutputOut();  // old unused ? // JPR
66                         bbSetOutputOut(informacion);
67                         readed = true;
68                 }
69
70                 if (extension.compare("vtp") == 0)
71                 {
72                         vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
73                         reader->SetFileName(bbGetInputInPath().data());
74                         informacion = reader->GetOutput();
75
76                         vtkPolyData* old = bbGetOutputOut();  // old unused ? // JPR
77                         bbSetOutputOut(informacion);
78                         readed = true;
79                 }
80         }
81
82         vtkActor *actor = (vtkActor*)bbGetOutputOutActor();
83         vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
84
85 //EED 2017-01-01 Migration VTK7
86 #if VTK_MAJOR_VERSION <= 5
87         mapper->SetInput(informacion);
88 #else
89         mapper->SetInputData(informacion);
90 #endif
91
92         actor->SetMapper(mapper);
93         bbSetOutputOutActor(actor);
94
95         if (bbGetInputInColor().size()  >= 3)
96         {
97                 actor->GetProperty()->SetColor(bbGetInputInColor()[0],bbGetInputInColor()[1],bbGetInputInColor()[2]);
98         }
99         else
100         {
101                 actor->GetProperty()->SetColor(1,1,1);
102         }
103         actor->GetProperty()->SetOpacity(bbGetInputInOpacity()/100);
104
105         //old->Delete();
106
107         InvokeEvent(OBS_POST_READER_1, informacion);
108
109         std::cout << "END [" << this << "]" << "PolyDataReaderPlus::Process()..." << std::endl;
110
111 }
112 void PolyDataReaderPlus::bbUserSetDefaultValues()
113 {
114
115 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
116 //    Here we initialize the input 'In' to 0
117         vtkPolyData* empty = vtkPolyData::New();
118         vtkActor *actor = vtkActor::New();
119     bbSetOutputOut(empty);
120         bbSetInputInPostReadObs1(NULL);
121         std::string nada = "";
122         bbSetInputInPath(nada);
123         bbSetOutputOutActor(actor);
124         bbSetInputInOpacity(50);
125
126         readed = false;
127
128 }
129 void PolyDataReaderPlus::bbUserInitializeProcessing()
130 {
131
132 //  THE INITIALIZATION METHOD BODY :
133 //    Here does nothing
134 //    but this is where you should allocate the internal/output pointers
135 //    if any
136
137
138 }
139 void PolyDataReaderPlus::bbUserFinalizeProcessing()
140 {
141
142 //  THE FINALIZATION METHOD BODY :
143 //    Here does nothing
144 //    but this is where you should desallocate the internal/output pointers
145 //    if any
146
147 }
148
149 }
150 // EO namespace bbvtk
151
152
153