]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataReaderPlus.cxx
Clean code
[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     {
43         AddObserver(OBS_POST_READER_1, bbGetInputInPostReadObs1());
44     }
45     
46         if (bbGetInputInPath().size()==0)
47         {
48                 std::cout << "Set InPath." << std::endl;
49                 return;
50         }
51
52         //Read!
53         if (!readed)
54         {
55                 std::vector< std::string > partes = StringSplit(bbGetInputInPath(), ".");
56                 std::string extension = partes.at(partes.size()-1);
57                 std::cout << "Extension (vtk o vtp?) = " << extension << std::endl;
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                 } // if vtk
69                 if (extension.compare("vtp") == 0)
70                 {
71                         vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
72                         reader->SetFileName(bbGetInputInPath().data());
73                         informacion = reader->GetOutput();
74
75                         vtkPolyData* old = bbGetOutputOut();  // old unused ? // JPR
76                         bbSetOutputOut(informacion);
77                         readed = true;
78                 } // if vtp
79         }
80         vtkActor *actor = (vtkActor*)bbGetOutputOutActor();
81         vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
82 //EED 2017-01-01 Migration VTK7
83 #if VTK_MAJOR_VERSION <= 5
84         mapper->SetInput(informacion);
85 #else
86         mapper->SetInputData(informacion);
87 #endif
88         actor->SetMapper(mapper);
89         bbSetOutputOutActor(actor);
90         if (bbGetInputInColor().size()  >= 3)
91         {
92                 actor->GetProperty()->SetColor(bbGetInputInColor()[0],bbGetInputInColor()[1],bbGetInputInColor()[2]);
93         } else {
94                 actor->GetProperty()->SetColor(1,1,1);
95         }
96         actor->GetProperty()->SetOpacity(bbGetInputInOpacity()/100);
97         //old->Delete();
98         InvokeEvent(OBS_POST_READER_1, informacion);
99         std::cout << "END [" << this << "]" << "PolyDataReaderPlus::Process()..." << std::endl;
100 }
101
102 void PolyDataReaderPlus::bbUserSetDefaultValues()
103 {
104 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
105 //    Here we initialize the input 'In' to 0
106         vtkPolyData* empty = vtkPolyData::New();
107         vtkActor *actor = vtkActor::New();
108     bbSetOutputOut(empty);
109         bbSetInputInPostReadObs1(NULL);
110         std::string nada = "";
111         bbSetInputInPath(nada);
112         bbSetOutputOutActor(actor);
113         bbSetInputInOpacity(50);
114         readed = false;
115 }
116
117 void PolyDataReaderPlus::bbUserInitializeProcessing()
118 {
119 //  THE INITIALIZATION METHOD BODY :
120 //    Here does nothing
121 //    but this is where you should allocate the internal/output pointers
122 //    if any
123 }
124
125 void PolyDataReaderPlus::bbUserFinalizeProcessing()
126 {
127 //  THE FINALIZATION METHOD BODY :
128 //    Here does nothing
129 //    but this is where you should desallocate the internal/output pointers
130 //    if any
131 }
132
133 }// EO namespace bbvtk
134
135
136