1//
2// Copyright 2020 Debabrata Mandal <mandaldebabrata123@gmail.com>
3//
4// Distributed under the Boost Software License, Version 1.0
5// See accompanying file LICENSE_1_0.txt or copy at
6// http://www.boost.org/LICENSE_1_0.txt
7//
8
9#include <boost/gil/histogram.hpp>
10
11#include <boost/core/lightweight_test.hpp>
12
13#include <string>
14
15namespace gil = boost::gil;
16
17void check_sub_histogram_without_tuple()
18{
19 gil::histogram<int, int, std::string, int> h;
20 h(1, 1, "A", 1) = 1;
21 h(1, 2, "B", 1) = 1;
22 h(2, 1, "C", 1) = 1;
23 h(2, 1, "D", 1) = 1;
24 h(2, 3, "E", 4) = 1;
25 auto h1 = h.sub_histogram<0,3>();
26 BOOST_TEST(h1(1, 1) == 2);
27 BOOST_TEST(h1(2, 1) == 2);
28 BOOST_TEST(h1(2, 4) == 1);
29 BOOST_TEST(h1(5, 5) == 0);
30}
31
32void check_sub_histogram_with_tuple()
33{
34 gil::histogram<int, int, std::string, int> h;
35 h(1, 1, "A", 1) = 3;
36 h(1, 2, "C", 1) = 1;
37 h(2, 1, "C", 1) = 1;
38 h(2, 1, "A", 1) = 1;
39 h(2, 3, "E", 4) = 1;
40 h(1, 3, "A", 1) = 2;
41 std::tuple<double, int, std::string, int> t(1.0, 1000, "A", 1);
42 // This means 1st dimension is useless for matching.
43 auto h1 = h.sub_histogram<0,2,3>(t1: t, t2: t);
44 BOOST_TEST(h1(1, 1, "A", 1) == 3);
45 BOOST_TEST(h1(1, 2, "C", 1) == 0);
46 BOOST_TEST(h1(2, 1, "C", 1) == 0);
47 BOOST_TEST(h1(2, 1, "A", 1) == 0);
48 BOOST_TEST(h1(2, 1, "A", 1) == 0);
49 BOOST_TEST(h1(1, 3, "A", 1) == 2);
50}
51
52int main() {
53
54 check_sub_histogram_without_tuple();
55 check_sub_histogram_with_tuple();
56
57 return boost::report_errors();
58}
59

source code of boost/libs/gil/test/core/histogram/sub_histogram.cpp