$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vtk/save.cc
1 // Copyright (C) 2010 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 #include <mln/io/off/load.hh>
27 #include <mln/io/vtk/save.hh>
28 
29 #include <mln/literal/colors.hh>
30 
31 #include "tests/data.hh"
32 
33 
34 template <typename I>
35 inline
36 I
37 make_image(const mln::bin_2complex_image3df& bin_ima,
38  const std::vector<mln_value(I)>& values)
39 {
40  I ima;
41  mln::initialize(ima, bin_ima);
42  mln_piter(I) p(ima.domain());
43  unsigned i = 0;
44  for_all(p)
45  ima(p) = values[i++ % values.size()];
46  return ima;
47 }
48 
49 
50 int
51 main()
52 {
53  using namespace mln;
54 
55  // Boolean values.
56  typedef bin_2complex_image3df bin_ima_t;
57  bin_ima_t bin_ima;
58  /* FIXME: It would be better not to depend on the OFF file loader to
59  create the complex-based image, to be saved as a VTK file; build
60  this image by hand instead? */
61  io::off::load(bin_ima, MLN_MESH_DIR "/tetrahedron.off");
62 
63  io::vtk::save(bin_ima, "save-tetrahedron-bool.vtk");
64 
65  unsigned nfaces = bin_ima.domain().cplx().nfaces();
66 
67  // `int_u8' values.
68  {
69  std::vector<value::int_u8> values(nfaces);
70  for (unsigned i = 0; i < nfaces; ++i)
71  values[i] = mln_max(value::int_u8) * i / nfaces;
72  io::vtk::save(make_image<int_u8_2complex_image3df>(bin_ima, values),
73  "save-tetrahedron-int_u8.vtk");
74  }
75 
76  // Unsigned integer values.
77  {
78  std::vector<unsigned> values(nfaces);
79  for (unsigned i = 0; i < nfaces; ++i)
80  values[i] = mln_max(unsigned) / nfaces * i;
81  io::vtk::save(make_image<unsigned_2complex_image3df>(bin_ima, values),
82  "save-tetrahedron-unsigned.vtk");
83  }
84 
85  // Floating-point values.
86  {
87  std::vector<float> values(nfaces);
88  for (unsigned i = 0; i < nfaces; ++i)
89  values[i] = mln_max(float) / nfaces * i;
90  io::vtk::save(make_image<float_2complex_image3df>(bin_ima, values),
91  "save-tetrahedron-float.vtk");
92  }
93 
94  // `rgb8' values.
95  {
96  value::rgb8 colors_array[] =
101  const unsigned colors_size = sizeof(colors_array) / sizeof(value::rgb8);
102  std::vector<value::rgb8> colors (colors_array, colors_array + colors_size);
103  io::vtk::save(make_image<rgb8_2complex_image3df>(bin_ima, colors),
104  "save-tetrahedron-rgb8.vtk");
105  }
106 }