]> Creatis software - bbtk.git/blob - packages/vtk/src/bbvtkImageToPlainText.cxx
4d79b852e6653d4a9f4f0270b09310d45c5b4d39
[bbtk.git] / packages / vtk / src / bbvtkImageToPlainText.cxx
1 //=====
2 // Don't edit this file. This file is generated from xml description..
3 //=====
4 #include "bbvtkImageToPlainText.h"
5 #include "bbvtkPackage.h"
6
7 namespace bbvtk
8 {
9
10 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,ImageToPlainText)
11 BBTK_BLACK_BOX_IMPLEMENTATION(ImageToPlainText,bbtk::AtomicBlackBox);
12 //=====
13 // Don't edit this file. This file is generated from xml description..
14 //=====
15 void ImageToPlainText::Process()
16 {
17
18 // THE MAIN PROCESSING METHOD BODY
19 //   Here we simply set the input 'In' value to the output 'Out'
20 //   And print out the output value
21 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
22 //    void bbSet{Input|Output}NAME(const TYPE&)
23 //    const TYPE& bbGet{Input|Output}NAME() const
24 //    Where :
25 //    * NAME is the name of the input/output
26 //      (the one provided in the attribute 'name' of the tag 'input')
27 //    * TYPE is the C++ type of the input/output
28 //      (the one provided in the attribute 'type' of the tag 'input')
29 if (bbGetInputIn() == NULL || bbGetInputInPath().size() == 0)
30 {
31         std::cout << "Set In and InPath" << std::endl;
32         return;
33 }
34
35 ejecutar(bbGetInputInPath(), bbGetInputIn());
36
37 }
38 //=====
39 // Don't edit this file. This file is generated from xml description..
40 //=====
41 void ImageToPlainText::bbUserSetDefaultValues()
42 {
43
44 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
45 //    Here we initialize the input 'In' to 0
46         std::string vacio = "";
47         bbSetInputInPath(vacio);
48    bbSetInputIn(NULL);
49
50 }
51 //=====
52 // Don't edit this file. This file is generated from xml description..
53 //=====
54 void ImageToPlainText::bbUserInitializeProcessing()
55 {
56
57 //  THE INITIALIZATION METHOD BODY :
58 //    Here does nothing
59 //    but this is where you should allocate the internal/output pointers
60 //    if any
61
62
63 }
64 //=====
65 // Don't edit this file. This file is generated from xml description..
66 //=====
67 void ImageToPlainText::bbUserFinalizeProcessing()
68 {
69
70 //  THE FINALIZATION METHOD BODY :
71 //    Here does nothing
72 //    but this is where you should desallocate the internal/output pointers
73 //    if any
74
75 }
76
77 void ImageToPlainText::ejecutar(std::string path, vtkImageData* image)
78 {
79         int ext[6];
80     std::ofstream outFile;
81     outFile.open(path.data(), std::ios::out);
82     image->GetExtent(ext);
83     if (outFile)
84     {
85         outFile << (ext[1]-ext[0]+1) << std::endl;
86         std::cout << (ext[1]-ext[0]+1) << std::endl;
87         outFile << (ext[3]-ext[2]+1) << std::endl;
88         std::cout << (ext[3]-ext[2]+1) << std::endl;
89         outFile << (ext[5]-ext[4]+1) << std::endl;
90         std::cout << (ext[5]-ext[4]+1) << std::endl;
91
92         for (int i=ext[0]; i<=ext[1]; i++)
93         {
94                 for (int j=ext[2]; j<=ext[3]; j++)
95                 {
96                         for (int k=ext[4]; k<=ext[5]; k++)
97                         {
98                                 double valor = lector.getPixelValue(i,j,k, image);
99                                 if (valor > 0)
100                                 {
101                                         outFile << "1";
102                                         //std::cout << "1";
103                                 }
104                                 else
105                                 {
106                                         outFile << "0";
107                                         //std::cout << "0";
108                                 }
109                         }
110                 }
111         }
112         outFile.close();
113     }
114     else
115     {
116         std::cout << "No pudo escribir en " << path << std::endl;
117     }
118 }
119
120 }
121 // EO namespace bbvtk
122
123