]> Creatis software - bbtk.git/commitdiff
add ReadVectorFromFile
authorjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Tue, 3 May 2011 16:24:22 +0000 (16:24 +0000)
committerjean-pierre roux <jean-pierre.roux@creatis.insa-lyon.fr>
Tue, 3 May 2011 16:24:22 +0000 (16:24 +0000)
packages/std/src/bbstdReadVectorFromFile.cxx [new file with mode: 0644]
packages/std/src/bbstdReadVectorFromFile.h [new file with mode: 0644]

diff --git a/packages/std/src/bbstdReadVectorFromFile.cxx b/packages/std/src/bbstdReadVectorFromFile.cxx
new file mode 100644 (file)
index 0000000..32e5cde
--- /dev/null
@@ -0,0 +1,91 @@
+//===== 
+// 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)
+//===== 
+#include "bbstdReadVectorFromFile.h"
+#include "bbstdPackage.h"
+#include  <vector>
+namespace bbstd
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ReadVectorFromFile)
+BBTK_BLACK_BOX_IMPLEMENTATION(ReadVectorFromFile,bbtk::AtomicBlackBox);
+//===== 
+// 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)
+//===== 
+void ReadVectorFromFile::Process()
+{
+    std::vector< std::vector< double > > Data;
+    std::ifstream openfile( bbGetInputFileName().c_str() );
+    std::string Input;
+    unsigned int LineLength=bbGetInputLineLength();
+    int skip = 0;
+    while ( getline( openfile, Input ) )
+    {
+       std::stringstream Parse;
+       Parse << Input;
+       double Value;
+       std::vector<double> Line;
+       // -------- une ligne sur 10!
+       skip++;
+       if(skip%10 != 0)
+          continue;
+       else
+          skip=1;
+       //--------       
+       while ( Parse >> Value )
+            Line.push_back( Value );
+       if ( Line.size() != LineLength )
+        {
+            std::cout << "Line " << Data.size() + 1 << " expected " <<
+            LineLength << " values, received " << Line.size() << " values, aborting." <<std::endl;
+           Data.clear();
+        }
+       Data.push_back( Line );
+    }
+    openfile.close();
+    
+    bbSetOutputOut(Data);
+    printf("ReadVectorFromFile::Process end \n");      
+       
+}
+//===== 
+// 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)
+//===== 
+void ReadVectorFromFile::bbUserSetDefaultValues()
+{
+
+//  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
+//    Here we initialize the input 'In' to 0
+       bbSetInputFileName("");
+       bbSetInputLineLength(1);          
+}
+//===== 
+// 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)
+//===== 
+void ReadVectorFromFile::bbUserInitializeProcessing()
+{
+
+//  THE INITIALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should allocate the internal/output pointers 
+//    if any 
+    //Data = new vector< vector< double > >;
+  
+}
+//===== 
+// 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)
+//===== 
+void ReadVectorFromFile::bbUserFinalizeProcessing()
+{
+
+//  THE FINALIZATION METHOD BODY :
+//    Here does nothing 
+//    but this is where you should desallocate the internal/output pointers 
+//    if any
+   //delete Data;
+     
+}
+}
+// EO namespace bbstd
+
+
diff --git a/packages/std/src/bbstdReadVectorFromFile.h b/packages/std/src/bbstdReadVectorFromFile.h
new file mode 100644 (file)
index 0000000..65580a3
--- /dev/null
@@ -0,0 +1,50 @@
+//===== 
+// 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)
+//===== 
+#ifndef __bbstdReadVectorFromFile_h_INCLUDED__
+#define __bbstdReadVectorFromFile_h_INCLUDED__
+#include "bbstd_EXPORT.h"
+#include "bbtkAtomicBlackBox.h"
+#include "iostream"
+
+
+namespace bbstd
+{
+
+class bbstd_EXPORT ReadVectorFromFile
+ : 
+   public bbtk::AtomicBlackBox
+{
+  BBTK_BLACK_BOX_INTERFACE(ReadVectorFromFile,bbtk::AtomicBlackBox);
+//===== 
+// 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)
+//===== 
+       BBTK_DECLARE_INPUT(FileName,std::string);
+       BBTK_DECLARE_OUTPUT(Out,std::vector <std::vector<double> >);
+       BBTK_DECLARE_INPUT(LineLength,int);     
+       BBTK_PROCESS(Process);
+  void Process();
+//===== 
+// 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)
+//===== 
+};
+
+BBTK_BEGIN_DESCRIBE_BLACK_BOX(ReadVectorFromFile,bbtk::AtomicBlackBox);
+       BBTK_NAME("ReadVectorFromFile");
+       BBTK_AUTHOR("jpr");
+       BBTK_DESCRIPTION("Read any Vector from a text file");
+       BBTK_CATEGORY("read/write");
+       BBTK_INPUT(ReadVectorFromFile,FileName,"3D Points file name",std::string,"");
+       BBTK_INPUT(ReadVectorFromFile,LineLength,"(default 1) - The number of columns of the file",int,"");     
+       BBTK_OUTPUT(ReadVectorFromFile,Out,"vector of data",std::vector< std::vector <double> >,"");
+
+BBTK_END_DESCRIBE_BLACK_BOX(ReadVectorFromFile);
+//===== 
+// 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)
+//===== 
+
+}
+// EO namespace bbstd
+
+#endif // __bbstdReadVectorFromFile_h_INCLUDED__
+