| 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 "vista2dImageIOtest" |
| 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/2dvistaio.hh> |
| 30 |
#include <unistd.h> |
| 31 |
|
| 32 |
using namespace mia; |
| 33 |
using namespace std; |
| 34 |
using namespace vista_2d_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 |
C2DBounds size(2, 3); |
| 51 |
T2DImage<T> *image = new T2DImage<T>(size); |
| 52 |
P2DImage pimage(image); |
| 53 |
auto iv = image->begin(); |
| 54 |
auto ev = image->end(); |
| 55 |
int i = 0; |
| 56 |
|
| 57 |
while (iv != ev) |
| 58 |
*iv++ = i++; |
| 59 |
|
| 60 |
CVista2DImageIOPlugin io; |
| 61 |
CVista2DImageIOPlugin::Data images; |
| 62 |
images.push_back(pimage); |
| 63 |
stringstream filename; |
| 64 |
filename << "testimage-" << __type_descr<T>::value << ".vista2d"; |
| 65 |
cvdebug() << "test with " << filename.str() << "\n"; |
| 66 |
BOOST_REQUIRE(io.save(filename.str(), images)); |
| 67 |
auto loaded = io.load(filename.str()); |
| 68 |
BOOST_REQUIRE(loaded); |
| 69 |
BOOST_REQUIRE(loaded->size() == 1u); |
| 70 |
const auto& ploaded = dynamic_cast<const T2DImage<T>&>(*(*loaded)[0]); |
| 71 |
iv = image->begin(); |
| 72 |
auto il = ploaded.begin(); |
| 73 |
|
| 74 |
while (iv != ev) { |
| 75 |
BOOST_CHECK_EQUAL(*il, *iv); |
| 76 |
++iv; |
| 77 |
++il; |
| 78 |
} |
| 79 |
|
| 80 |
unlink(filename.str().c_str()); |
| 81 |
} |
| 82 |
|
| 83 |
BOOST_AUTO_TEST_CASE( test_simple_write_read_bool ) |
| 84 |
{ |
| 85 |
C2DBounds size(2, 3); |
| 86 |
C2DBitImage *image = new C2DBitImage(size); |
| 87 |
P2DImage pimage(image); |
| 88 |
auto iv = image->begin(); |
| 89 |
auto ev = image->end(); |
| 90 |
bool i = false; |
| 91 |
|
| 92 |
while (iv != ev) { |
| 93 |
*iv++ = i; |
| 94 |
i = !i; |
| 95 |
} |
| 96 |
|
| 97 |
CVista2DImageIOPlugin io; |
| 98 |
CVista2DImageIOPlugin::Data images; |
| 99 |
images.push_back(pimage); |
| 100 |
stringstream filename; |
| 101 |
filename << "testimage-bool.vista2d"; |
| 102 |
cvdebug() << "test with " << filename.str() << "\n"; |
| 103 |
BOOST_REQUIRE(io.save(filename.str(), images)); |
| 104 |
auto loaded = io.load(filename.str()); |
| 105 |
BOOST_REQUIRE(loaded); |
| 106 |
BOOST_REQUIRE(loaded->size() == 1u); |
| 107 |
const auto& ploaded = dynamic_cast<const C2DBitImage&>(*(*loaded)[0]); |
| 108 |
iv = image->begin(); |
| 109 |
auto il = ploaded.begin(); |
| 110 |
|
| 111 |
while (iv != ev) { |
| 112 |
BOOST_CHECK_EQUAL(*il, *iv); |
| 113 |
++iv; |
| 114 |
++il; |
| 115 |
} |
| 116 |
|
| 117 |
unlink(filename.str().c_str()); |
| 118 |
} |