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);
124 final->SetScalarType(scalar_type);
126 //final->SetSpacing(space);
130 final->SetDimensions(newDim);
134 final->SetOrigin(origin);
136 final->AllocateScalars();
139 for (int i=0; i<newDim[0]; i++){
140 for (int j=0; j<newDim[1]; j++){
145 ap2 = (char *) final->GetScalarPointer(i,j,0);
146 *ap2 = (char)info.at(i).at(j);
148 case VTK_UNSIGNED_CHAR:
150 ap3 = (unsigned char *) final->GetScalarPointer(i,j,0);
151 *ap3 = (unsigned char)info.at(i).at(j);
155 ap4 = (short *) final->GetScalarPointer(i,j,0);
156 *ap4 = (short)info.at(i).at(j);
158 case VTK_UNSIGNED_SHORT:
159 unsigned short * ap5;
160 ap5 = (unsigned short *) final->GetScalarPointer(i,j,0);
161 *ap5 = (unsigned short)info.at(i).at(j);
165 ap6 = (int *) final->GetScalarPointer(i,j,0);
166 *ap6 = (int)info.at(i).at(j);
168 case VTK_UNSIGNED_INT:
170 ap7 = (unsigned int *) final->GetScalarPointer(i,j,0);
171 *ap7 = (unsigned int)info.at(i).at(j);
175 ap8 = (long *) final->GetScalarPointer(i,j,0);
176 *ap8 = (long)info.at(i).at(j);
178 case VTK_UNSIGNED_LONG:
180 ap9 = (unsigned long *) final->GetScalarPointer(i,j,0);
181 *ap9 = (unsigned long)info.at(i).at(j);
185 ap10 = (float *) final->GetScalarPointer(i,j,0);
186 *ap10 = (float)info.at(i).at(j);
190 ap11 = (double *) final->GetScalarPointer(i,j,0);
191 *ap11 = (double)info.at(i).at(j);
199 // EO namespace bbPersistence