]> Creatis software - bbtk.git/blob - packages/std/src/bbstdReadVectorFromFile.cxx
Feature #1774
[bbtk.git] / packages / std / src / bbstdReadVectorFromFile.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 //=====
29 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
30 //===== 
31 #include "bbstdReadVectorFromFile.h"
32 #include "bbstdPackage.h"
33 #include  <vector>
34 namespace bbstd
35 {
36
37 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ReadVectorFromFile)
38 BBTK_BLACK_BOX_IMPLEMENTATION(ReadVectorFromFile,bbtk::AtomicBlackBox);
39 //===== 
40 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
41 //===== 
42 void ReadVectorFromFile::Process()
43 {
44     std::vector< std::vector< double > > Data;
45     std::ifstream openfile( bbGetInputFileName().c_str() );
46     std::string Input;
47     unsigned int LineLength=bbGetInputLineLength();
48     int skip = 0;
49     while ( getline( openfile, Input ) )
50     {
51        std::stringstream Parse;
52        Parse << Input;
53        double Value;
54        std::vector<double> Line;
55        // -------- une ligne sur 10!
56        skip++;
57        if(skip%10 != 0)
58           continue;
59        else
60           skip=1;
61        //--------       
62        while ( Parse >> Value )
63             Line.push_back( Value );
64        if ( Line.size() != LineLength )
65         {
66             std::cout << "Line " << Data.size() + 1 << " expected " <<
67             LineLength << " values, received " << Line.size() << " values, aborting." <<std::endl;
68             Data.clear();
69         }
70        Data.push_back( Line );
71     }
72     openfile.close();
73     
74     bbSetOutputOut(Data);
75     printf("ReadVectorFromFile::Process end \n");       
76         
77 }
78 //===== 
79 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
80 //===== 
81 void ReadVectorFromFile::bbUserSetDefaultValues()
82 {
83
84 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
85 //    Here we initialize the input 'In' to 0
86         bbSetInputFileName("");
87         bbSetInputLineLength(1);          
88 }
89 //===== 
90 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
91 //===== 
92 void ReadVectorFromFile::bbUserInitializeProcessing()
93 {
94
95 //  THE INITIALIZATION METHOD BODY :
96 //    Here does nothing 
97 //    but this is where you should allocate the internal/output pointers 
98 //    if any 
99     //Data = new vector< vector< double > >;
100   
101 }
102 //===== 
103 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
104 //===== 
105 void ReadVectorFromFile::bbUserFinalizeProcessing()
106 {
107
108 //  THE FINALIZATION METHOD BODY :
109 //    Here does nothing 
110 //    but this is where you should desallocate the internal/output pointers 
111 //    if any
112    //delete Data;
113      
114 }
115 }
116 // EO namespace bbstd
117
118