| 1 |
|
|---|
| 2 | /******************************************************************************
|
|---|
| 3 | * __LICENCE_BEGIN__
|
|---|
| 4 | *
|
|---|
| 5 | * __LICENCE_END__ |
|---|
| 6 | *****************************************************************************/
|
|---|
| 7 |
|
|---|
| 8 | /// @file
|
|---|
| 9 | /// @brief Test for i3dea::transform_view<>
|
|---|
| 10 | ///
|
|---|
| 11 | /// @author john.femiani@asu.edu
|
|---|
| 12 | ///
|
|---|
| 13 | ///
|
|---|
| 14 |
|
|---|
| 15 | #include <i3dea/test.hpp>
|
|---|
| 16 |
|
|---|
| 17 | #include <i3dea/gil/transform_view.hpp>
|
|---|
| 18 | #include <i3dea/gil/rgb_functions.hpp>
|
|---|
| 19 |
|
|---|
| 20 | #include <boost/gil/gil_all.hpp>
|
|---|
| 21 |
|
|---|
| 22 | #include <functional>
|
|---|
| 23 |
|
|---|
| 24 | #include <boost/iterator/transform_iterator.hpp>
|
|---|
| 25 |
|
|---|
| 26 | using namespace i3dea;
|
|---|
| 27 |
|
|---|
| 28 | //TODO: Add checks for different combinations of qualifiers for result_type
|
|---|
| 29 | // and argument_type.
|
|---|
| 30 |
|
|---|
| 31 | struct doubles {
|
|---|
| 32 | typedef gil::gray8_pixel_t result_type;
|
|---|
| 33 | typedef gil::gray8_pixel_t argument_type;
|
|---|
| 34 |
|
|---|
| 35 | gil::gray8_pixel_t operator()(gil::gray8_pixel_t const& value) const {
|
|---|
| 36 | return gil::gray8_pixel_t(gray(value)*2);
|
|---|
| 37 | }
|
|---|
| 38 | };
|
|---|
| 39 |
|
|---|
| 40 | template<class XfmView, class Fn, class SrcView >
|
|---|
| 41 | static
|
|---|
| 42 | inline
|
|---|
| 43 | void test_view(XfmView result, Fn f, SrcView src){
|
|---|
| 44 | I3DEA_CHECK( result(5, 5) == f(src(5,5)));
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void test_transform_view_with_gil(){
|
|---|
| 48 |
|
|---|
| 49 | using boost::is_same;
|
|---|
| 50 |
|
|---|
| 51 | gil::gray8_image_t test_(10,10, gil::gray8_pixel_t(1));
|
|---|
| 52 | gil::gray8_view_t test = view(test_);
|
|---|
| 53 |
|
|---|
| 54 | typedef gil::image<unsigned char> uint8_image;
|
|---|
| 55 | uint8_image uint8_test_(10,10, 0);
|
|---|
| 56 | uint8_image::view_t uint8_test = view(uint8_test_);
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | test_view(i3dea::transform_view(doubles(), test),
|
|---|
| 60 | doubles(),
|
|---|
| 61 | test);
|
|---|
| 62 |
|
|---|
| 63 | typedef
|
|---|
| 64 | i3dea::result_of::transform_view<std::binder2nd<std::plus<unsigned char> >,
|
|---|
| 65 | uint8_image::view_t
|
|---|
| 66 | >::type
|
|---|
| 67 | fplusf;
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 | BOOST_MPL_ASSERT((is_same<fplusf::value_type, unsigned char>));
|
|---|
| 71 | BOOST_MPL_ASSERT((mpl::or_<is_same<fplusf::reference, unsigned char>,
|
|---|
| 72 | is_same<fplusf::referecne, const unsigned char&>
|
|---|
| 73 | >));
|
|---|
| 74 |
|
|---|
| 75 | test_view(i3dea::transform_view(std::bind2nd(std::plus<unsigned char>(), 3),
|
|---|
| 76 | test),
|
|---|
| 77 | std::bind2nd(std::plus<unsigned char>(), 3),
|
|---|
| 78 | test);
|
|---|
| 79 |
|
|---|
| 80 | test_view(i3dea::transform_view(std::bind2nd(std::plus<unsigned char>(), 3),
|
|---|
| 81 | i3dea::transform_view(std::bind2nd(std::plus<unsigned char>(), 4),
|
|---|
| 82 | test)),
|
|---|
| 83 | std::bind2nd(std::plus<unsigned char>(), 7),
|
|---|
| 84 | test);
|
|---|
| 85 |
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | int main(int, char**)
|
|---|
| 89 | {
|
|---|
| 90 | test_transform_view_with_gil();
|
|---|
| 91 | return 0;
|
|---|
| 92 | }
|
|---|