1 #include "bbvtkCSVReader.h"
2 #include "bbvtkPackage.h"
6 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,CSVReader)
7 BBTK_BLACK_BOX_IMPLEMENTATION(CSVReader,bbtk::AtomicBlackBox);
8 void CSVReader::Process()
10 if (bbGetInputIn().size() == 0)
12 std::cout << "Set In with the file path to the csv file" << std::endl;
16 std::vector< std::vector< double > > matrix;
21 std::ifstream myfile (bbGetInputIn().c_str());
24 while (! myfile.eof() )
26 getline (myfile,line);
30 std::vector< double > numeros = t.stringTovectorDelimited(line, ",");
31 if (numeros.size() > 0)
33 tamanioy = numeros.size();
34 matrix.push_back(numeros);
41 //Se arma la imagen vtk
43 vtkImageData* ans = createImage(matrix, tamaniox, tamanioy, bbGetInputInType());
53 void CSVReader::bbUserSetDefaultValues()
56 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
57 // Here we initialize the input 'In' to 0
58 std::string path = "";
64 void CSVReader::bbUserInitializeProcessing()
67 // THE INITIALIZATION METHOD BODY :
69 // but this is where you should allocate the internal/output pointers
74 void CSVReader::bbUserFinalizeProcessing()
77 // THE FINALIZATION METHOD BODY :
79 // but this is where you should desallocate the internal/output pointers
83 vtkImageData* CSVReader::createImage(std::vector< std::vector<double> > info, int x, int y, int scalar_type)
85 vtkImageData* final = vtkImageData::New();
92 //original->GetSpacing(space);
93 //original->GetExtent(ext);
94 //original->GetOrigin(origin);
95 //original->GetDimensions(newDim);
97 final->SetScalarType(scalar_type);
99 //final->SetSpacing(space);
103 final->SetDimensions(newDim);
107 final->SetOrigin(origin);
109 final->AllocateScalars();
112 for (int i=0; i<newDim[0]; i++){
113 for (int j=0; j<newDim[1]; j++){
118 ap2 = (char *) final->GetScalarPointer(i,j,0);
119 *ap2 = (char)info.at(i).at(j);
121 case VTK_UNSIGNED_CHAR:
123 ap3 = (unsigned char *) final->GetScalarPointer(i,j,0);
124 *ap3 = (unsigned char)info.at(i).at(j);
128 ap4 = (short *) final->GetScalarPointer(i,j,0);
129 *ap4 = (short)info.at(i).at(j);
131 case VTK_UNSIGNED_SHORT:
132 unsigned short * ap5;
133 ap5 = (unsigned short *) final->GetScalarPointer(i,j,0);
134 *ap5 = (unsigned short)info.at(i).at(j);
138 ap6 = (int *) final->GetScalarPointer(i,j,0);
139 *ap6 = (int)info.at(i).at(j);
141 case VTK_UNSIGNED_INT:
143 ap7 = (unsigned int *) final->GetScalarPointer(i,j,0);
144 *ap7 = (unsigned int)info.at(i).at(j);
148 ap8 = (long *) final->GetScalarPointer(i,j,0);
149 *ap8 = (long)info.at(i).at(j);
151 case VTK_UNSIGNED_LONG:
153 ap9 = (unsigned long *) final->GetScalarPointer(i,j,0);
154 *ap9 = (unsigned long)info.at(i).at(j);
158 ap10 = (float *) final->GetScalarPointer(i,j,0);
159 *ap10 = (float)info.at(i).at(j);
163 ap11 = (double *) final->GetScalarPointer(i,j,0);
164 *ap11 = (double)info.at(i).at(j);
172 // EO namespace bbPersistence