Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
cloud/load.hh
1 // Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
16 //
17 // As a special exception, you may use this file as part of a free
18 // software project without restriction. Specifically, if other files
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_IO_CLOUD_LOAD_HH
27 # define MLN_IO_CLOUD_LOAD_HH
28 
40 
41 # include <iostream>
42 # include <fstream>
43 
44 # include <mln/core/concept/image.hh>
45 # include <mln/core/site_set/p_array.hh>
46 
47 namespace mln
48 {
49 
50  namespace io
51  {
52 
53  namespace cloud
54  {
55 
60  template <typename P>
61  void load(p_array<P>& arr, const std::string& filename);
62 
63 
64 # ifndef MLN_INCLUDE_ONLY
65 
66  namespace internal
67  {
68 
69  template <typename P>
70  inline
71  void load_data(p_array<P>& arr, std::ifstream& file)
72  {
73  std::string line;
74  while (std::getline(file, line))
75  {
76  algebra::vec<P::dim,float> v;
77  std::istringstream sline(line);
78  sline >> v[0] >> v[1] >> v[2];
79  arr.append(v);
80  }
81  }
82 
83  } // end of namespace mln::io::cloud::internal
84 
85 
86 
87  template <typename P>
88  void load(p_array<P>& arr, const std::string& filename)
89  {
90  trace::entering("mln::io::cloud::load");
91 
93  mln_precondition(P::dim == 3u);
94 
95  std::ifstream file(filename.c_str());
96  if (! file)
97  {
98  std::cerr << "error: cannot open file '" << filename << "'!";
99  abort();
100  }
101 
102  internal::load_data(arr, file);
103 
104  trace::exiting("mln::io::cloud::load");
105  }
106 
107 
108 # endif // ! MLN_INCLUDE_ONLY
109 
110  } // end of namespace mln::io::cloud
111 
112  } // end of namespace mln::io
113 
114 } // end of namespace mln
115 
116 #endif // ! MLN_IO_CLOUD_LOAD_HH