]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataReaderPlus.cxx
e6bc5b639627b5d8f2870c771ff2a554c1c0ef4e
[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         mapper->SetInput(informacion);
86         actor->SetMapper(mapper);
87
88         bbSetOutputOutActor(actor);
89
90         if (bbGetInputInColor().size()  >= 3)
91         {
92                 actor->GetProperty()->SetColor(bbGetInputInColor()[0],bbGetInputInColor()[1],bbGetInputInColor()[2]);
93         }
94         else
95         {
96                 actor->GetProperty()->SetColor(1,1,1);
97         }
98         actor->GetProperty()->SetOpacity(bbGetInputInOpacity()/100);
99
100         //old->Delete();
101
102         InvokeEvent(OBS_POST_READER_1, informacion);
103
104         std::cout << "END [" << this << "]" << "PolyDataReaderPlus::Process()..." << std::endl;
105
106 }
107 void PolyDataReaderPlus::bbUserSetDefaultValues()
108 {
109
110 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
111 //    Here we initialize the input 'In' to 0
112         vtkPolyData* empty = vtkPolyData::New();
113         vtkActor *actor = vtkActor::New();
114     bbSetOutputOut(empty);
115         bbSetInputInPostReadObs1(NULL);
116         std::string nada = "";
117         bbSetInputInPath(nada);
118         bbSetOutputOutActor(actor);
119         bbSetInputInOpacity(50);
120
121         readed = false;
122
123 }
124 void PolyDataReaderPlus::bbUserInitializeProcessing()
125 {
126
127 //  THE INITIALIZATION METHOD BODY :
128 //    Here does nothing
129 //    but this is where you should allocate the internal/output pointers
130 //    if any
131
132
133 }
134 void PolyDataReaderPlus::bbUserFinalizeProcessing()
135 {
136
137 //  THE FINALIZATION METHOD BODY :
138 //    Here does nothing
139 //    but this is where you should desallocate the internal/output pointers
140 //    if any
141
142 }
143
144 }
145 // EO namespace bbvtk
146
147
148