Debian Codegraph @

addons/vistaio/test_3dvistaio.cc

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 /* -*- mia-c++ -*-
2 *
3 * This file is part of MIA - a toolbox for medical image analysis
4 * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5 *
6 * MIA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #define VSTREAM_DOMAIN "vista3dImageIOtest"
22
23 #include <mia/internal/autotest.hh>
24
25 #include <boost/mpl/vector.hpp>
26 #include <boost/test/test_case_template.hpp>
27
28
29 #include <vistaio/3dvistaio.hh>
30 #include <unistd.h>
31
32 using namespace mia;
33 using namespace std;
34 using namespace vista_3d_io;
35 namespace bmpl = boost::mpl;
36
37 typedef bmpl::vector <
38 unsigned char,
39 signed short,
40 unsigned short,
41 signed int,
42 unsigned int,
43 float,
44 double
45 > type;
46
47
48 BOOST_AUTO_TEST_CASE_TEMPLATE( test_simple_write_read, T, type )
49 {
50 C3DBounds size(2, 3, 4);
51 T3DImage<T> *image = new T3DImage<T>(size);
52 image->set_voxel_size(C3DFVector(10, 20, 30));
53 image->set_origin(C3DFVector(20, 30, 40));
54 image->set_rotation(C3DRotation(Quaternion(0.5, 0.1, 0.7, 0.5)));
55 P3DImage pimage(image);
56 auto iv = image->begin();
57 auto ev = image->end();
58 int i = 0;
59
60 while (iv != ev)
61 *iv++ = i++;
62
63 CVista3DImageIOPlugin io;
64 CVista3DImageIOPlugin::Data images;
65 images.push_back(pimage);
66 stringstream filename;
67 filename << "testimage-" << __type_descr<T>::value << ".vista3d";
68 cvdebug() << "test with " << filename.str() << "\n";
69 BOOST_REQUIRE(io.save(filename.str(), images));
70 auto loaded = io.load(filename.str());
71 BOOST_REQUIRE(loaded);
72 BOOST_REQUIRE(loaded->size() == 1u);
73 const auto& ploaded = dynamic_cast<const T3DImage<T>&>(*(*loaded)[0]);
74 iv = image->begin();
75 auto il = ploaded.begin();
76
77 while (iv != ev) {
78 BOOST_CHECK_EQUAL(*il, *iv);
79 ++iv;
80 ++il;
81 }
82
83 unlink(filename.str().c_str());
84 }
85
86 BOOST_AUTO_TEST_CASE( test_simple_write_read_bool )
87 {
88 C3DBounds size(2, 3, 4);
89 C3DBitImage *image = new C3DBitImage(size);
90 image->set_voxel_size(C3DFVector(10, 20, 30));
91 image->set_origin(C3DFVector(20, 30, 40));
92 image->set_rotation(C3DRotation(Quaternion(0.5, 0.1, 0.7, 0.5)));
93 P3DImage pimage(image);
94 auto iv = image->begin();
95 auto ev = image->end();
96 bool i = false;
97
98 while (iv != ev) {
99 *iv++ = i;
100 i = !i;
101 }
102
103 CVista3DImageIOPlugin io;
104 CVista3DImageIOPlugin::Data images;
105 images.push_back(pimage);
106 stringstream filename;
107 filename << "testimage-bool.vista3d";
108 cvdebug() << "test with " << filename.str() << "\n";
109 BOOST_REQUIRE(io.save(filename.str(), images));
110 auto loaded = io.load(filename.str());
111 BOOST_REQUIRE(loaded);
112 BOOST_REQUIRE(loaded->size() == 1u);
113 const auto& ploaded = dynamic_cast<const C3DBitImage&>(*(*loaded)[0]);
114 iv = image->begin();
115 auto il = ploaded.begin();
116
117 while (iv != ev) {
118 BOOST_CHECK_EQUAL(*il, *iv);
119 ++iv;
120 ++il;
121 }
122
123 unlink(filename.str().c_str());
124 }