$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
write_header.hh
1 // Copyright (C) 2008, 2009, 2010, 2011, 2012 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_IO_FLD_WRITE_HEADER_HH
28 # define MLN_IO_FLD_WRITE_HEADER_HH
29 
32 
33 # include <cstdlib>
34 
35 # include <iostream>
36 
37 # include <mln/version.hh>
38 # include <mln/io/fld/header.hh>
39 
40 
41 namespace mln
42 {
43 
44  namespace io
45  {
46 
47  namespace fld
48  {
49 
57  void write_header(std::ostream& file, const fld_header& h);
58 
59 # ifndef MLN_INCLUDE_ONLY
60 
61  inline
62  void
63  write_header(std::ostream& file, const fld_header& h)
64  {
65  file << "# AVS field file" << std::endl;
66  file << "# Generated by " OLN_PACKAGE_STRING " (" OLN_PACKAGE_URL ")"
67  << std::endl
68  << "# " OLN_PACKAGE_AUTHORS << std::endl;
69 
70  file << "ndim=" << h.ndim << std::endl;
71  for (int i = 0; i < h.ndim; i++)
72  file << "dim" << (i + 1) << "=" << h.dim[i] << std::endl;
73  file << "nspace=" << h.nspace << std::endl
74  << "veclen=" << h.veclen << std::endl;
75 
76  switch (h.data)
77  {
78  case data_type::BYTE :
79  file << "data=byte" << std::endl;
80  break;
81  case data_type::SHORT :
82  file << "data=short" << std::endl;
83  break;
84  case data_type::INTEGER :
85  file << "data=integer" << std::endl;
86  break;
87  case data_type::FLOAT :
88  file << "data=float" << std::endl;
89  break;
90  case data_type::DOUBLE :
91  file << "data=double" << std::endl;
92  break;
93  default:
94  std::cerr << "Data type not supported: abort().";
95  std::abort();
96  }
97 
98  switch (h.field)
99  {
100  case field_type::UNIFORM :
101  file << "field=uniform" << std::endl;
102  break;
103  case field_type::IRREGULAR :
104  file << "field=irregular" << std::endl;
105  break;
107  file << "field=rectilinear" << std::endl;
108  break;
109  default:
110  std::cerr << "Field type not suported: abort().";
111  std::abort();
112  }
113 
114  file << "min_ext=";
115  for (int i = 0; i < h.nspace; i++)
116  file << h.min_ext[i] << " ";
117  file << std::endl;
118 
119  file << "max_ext=";
120  for (int i = 0; i < h.nspace; i++)
121  file << h.max_ext[i] << " ";
122  file << std::endl;
123 
124  file << "\f\f";
125  }
126 
127 #endif // !MLN_INCLUDE_ONLY
128 
129  } // end of namespace mln::io::fld
130 
131  } // end of namespace mln::io
132 
133 } // end of namespace mln
134 
135 #endif // !MLN_IO_FLD_WRITE_HEADER_HH