]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkPolyDataReaderPlus.cxx
no message
[bbtk.git] / packages / vtk / src / bbvtkPolyDataReaderPlus.cxx
1 #include "bbvtkPolyDataReaderPlus.h"
2 #include "bbvtkPackage.h"
3 namespace bbvtk
4 {
5
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,PolyDataReaderPlus)
7 BBTK_BLACK_BOX_IMPLEMENTATION(PolyDataReaderPlus,bbtk::AtomicBlackBox);
8 void PolyDataReaderPlus::Process()
9 {
10
11     std::cout << "[" << this << "]" << "PolyDataReaderPlus::Process()..." << std::endl;
12         //Review the observers...
13
14         if (!HasObserver(OBS_POST_READER_1) && bbGetInputInPostReadObs1() != NULL)
15                 AddObserver(OBS_POST_READER_1, bbGetInputInPostReadObs1());
16
17         if (bbGetInputInPath().size()==0)
18         {
19                 std::cout << "Set InPath." << std::endl;
20                 return;
21         }
22
23         //Read!
24         if (!readed)
25         {
26                 std::vector< std::string > partes = StringSplit(bbGetInputInPath(), ".");
27                 std::string extension = partes.at(partes.size()-1);
28
29                 std::cout << "Extension (vtk o vtp?) = " << extension << std::endl;
30
31                 if (extension.compare("vtk") == 0)
32                 {
33                         //vtkPolyDataReader* reader = vtkPolyDataReader::New();
34                         vtkGenericDataObjectReader* reader = vtkGenericDataObjectReader::New();
35                         reader->SetFileName(bbGetInputInPath().data());
36                         informacion = (vtkPolyData*)reader->GetOutput();
37                         reader->CloseVTKFile();
38                         vtkPolyData* old = bbGetOutputOut();  // old unused ? // JPR
39                         bbSetOutputOut(informacion);
40                         readed = true;
41                 }
42
43                 if (extension.compare("vtp") == 0)
44                 {
45                         vtkXMLPolyDataReader* reader = vtkXMLPolyDataReader::New();
46                         reader->SetFileName(bbGetInputInPath().data());
47                         informacion = reader->GetOutput();
48
49                         vtkPolyData* old = bbGetOutputOut();  // old unused ? // JPR
50                         bbSetOutputOut(informacion);
51                         readed = true;
52                 }
53         }
54
55         vtkActor *actor = (vtkActor*)bbGetOutputOutActor();
56         vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
57
58         mapper->SetInput(informacion);
59         actor->SetMapper(mapper);
60
61         bbSetOutputOutActor(actor);
62
63         if (bbGetInputInColor().size()  >= 3)
64         {
65                 actor->GetProperty()->SetColor(bbGetInputInColor()[0],bbGetInputInColor()[1],bbGetInputInColor()[2]);
66         }
67         else
68         {
69                 actor->GetProperty()->SetColor(1,1,1);
70         }
71         actor->GetProperty()->SetOpacity(bbGetInputInOpacity()/100);
72
73         //old->Delete();
74
75         InvokeEvent(OBS_POST_READER_1, informacion);
76
77         std::cout << "END [" << this << "]" << "PolyDataReaderPlus::Process()..." << std::endl;
78
79 }
80 void PolyDataReaderPlus::bbUserSetDefaultValues()
81 {
82
83 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
84 //    Here we initialize the input 'In' to 0
85         vtkPolyData* empty = vtkPolyData::New();
86         vtkActor *actor = vtkActor::New();
87     bbSetOutputOut(empty);
88         bbSetInputInPostReadObs1(NULL);
89         std::string nada = "";
90         bbSetInputInPath(nada);
91         bbSetOutputOutActor(actor);
92         bbSetInputInOpacity(50);
93
94         readed = false;
95
96 }
97 void PolyDataReaderPlus::bbUserInitializeProcessing()
98 {
99
100 //  THE INITIALIZATION METHOD BODY :
101 //    Here does nothing
102 //    but this is where you should allocate the internal/output pointers
103 //    if any
104
105
106 }
107 void PolyDataReaderPlus::bbUserFinalizeProcessing()
108 {
109
110 //  THE FINALIZATION METHOD BODY :
111 //    Here does nothing
112 //    but this is where you should desallocate the internal/output pointers
113 //    if any
114
115 }
116
117 }
118 // EO namespace bbvtk
119
120
121