2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
28 #include "bbvtkCSVReader.h"
29 #include "bbvtkPackage.h"
33 BBTK_ADD_BLACK_BOX_TO_PACKAGE(vtk,CSVReader)
34 BBTK_BLACK_BOX_IMPLEMENTATION(CSVReader,bbtk::AtomicBlackBox);
35 void CSVReader::Process()
37 if (bbGetInputIn().size() == 0)
39 std::cout << "Set In with the file path to the csv file" << std::endl;
43 std::vector< std::vector< double > > matrix;
48 std::ifstream myfile (bbGetInputIn().c_str());
51 while (! myfile.eof() )
53 getline (myfile,line);
57 std::vector< double > numeros = t.stringTovectorDelimited(line, ",");
58 if (numeros.size() > 0)
60 tamanioy = numeros.size();
61 matrix.push_back(numeros);
68 //Se arma la imagen vtk
70 vtkImageData* ans = createImage(matrix, tamaniox, tamanioy, bbGetInputInType());
80 void CSVReader::bbUserSetDefaultValues()
83 // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX
84 // Here we initialize the input 'In' to 0
85 std::string path = "";
91 void CSVReader::bbUserInitializeProcessing()
94 // THE INITIALIZATION METHOD BODY :
96 // but this is where you should allocate the internal/output pointers
101 void CSVReader::bbUserFinalizeProcessing()
104 // THE FINALIZATION METHOD BODY :
106 // but this is where you should desallocate the internal/output pointers
110 vtkImageData* CSVReader::createImage(std::vector< std::vector<double> > info, int x, int y, int scalar_type)
112 vtkImageData* final = vtkImageData::New();
119 //original->GetSpacing(space);
120 //original->GetExtent(ext);
121 //original->GetOrigin(origin);
122 //original->GetDimensions(newDim);
125 //final->SetSpacing(space);
129 final->SetDimensions(newDim);
133 final->SetOrigin(origin);
136 //EED 2017-01-01 Migration VTK7
137 #if (VTK_MAJOR_VERSION <= 5)
138 final->SetScalarType(scalar_type);
139 final->AllocateScalars();
142 #if (VTK_MAJOR_VERSION >= 6)
143 final->AllocateScalars(scalar_type,1);
147 for (int i=0; i<newDim[0]; i++){
148 for (int j=0; j<newDim[1]; j++){
153 ap2 = (char *) final->GetScalarPointer(i,j,0);
154 *ap2 = (char)info.at(i).at(j);
156 case VTK_UNSIGNED_CHAR:
158 ap3 = (unsigned char *) final->GetScalarPointer(i,j,0);
159 *ap3 = (unsigned char)info.at(i).at(j);
163 ap4 = (short *) final->GetScalarPointer(i,j,0);
164 *ap4 = (short)info.at(i).at(j);
166 case VTK_UNSIGNED_SHORT:
167 unsigned short * ap5;
168 ap5 = (unsigned short *) final->GetScalarPointer(i,j,0);
169 *ap5 = (unsigned short)info.at(i).at(j);
173 ap6 = (int *) final->GetScalarPointer(i,j,0);
174 *ap6 = (int)info.at(i).at(j);
176 case VTK_UNSIGNED_INT:
178 ap7 = (unsigned int *) final->GetScalarPointer(i,j,0);
179 *ap7 = (unsigned int)info.at(i).at(j);
183 ap8 = (long *) final->GetScalarPointer(i,j,0);
184 *ap8 = (long)info.at(i).at(j);
186 case VTK_UNSIGNED_LONG:
188 ap9 = (unsigned long *) final->GetScalarPointer(i,j,0);
189 *ap9 = (unsigned long)info.at(i).at(j);
193 ap10 = (float *) final->GetScalarPointer(i,j,0);
194 *ap10 = (float)info.at(i).at(j);
198 ap11 = (double *) final->GetScalarPointer(i,j,0);
199 *ap11 = (double)info.at(i).at(j);
207 // EO namespace bbPersistence