links_decision_image.hh 3.34 KB
Newer Older
1
// Copyright (C) 2009, 2010, 2013 EPITA Research and Development Laboratory
2
// (LRDE)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// This file is part of Olena.
//
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
//
// As a special exception, you may use this file as part of a free
// software project without restriction.  Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to produce
// an executable, this file does not by itself cause the resulting
// executable to be covered by the GNU General Public License.  This
// exception does not however invalidate any other reasons why the
// executable file might be covered by the GNU General Public License.

#ifndef SCRIBO_DEBUG_LINKS_DECISION_IMAGE_HH
# define SCRIBO_DEBUG_LINKS_DECISION_IMAGE_HH

/// \file
///
/// Save a color image showing the difference between to object groups.

# include <mln/core/concept/image.hh>
# include <mln/data/convert.hh>
# include <mln/value/rgb8.hh>
# include <mln/literal/colors.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
38
39
# include <mln/draw/box.hh>
# include <mln/draw/line.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
40

41
# include <scribo/core/object_links.hh>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
42
43
44
45
46
47
48
49
50
51
52
53
54


namespace scribo
{

  namespace debug
  {

    using namespace mln;

    /// FIXME: DOC!
    template <typename I, typename L>
    mln_ch_value(I,value::rgb8)
55
56
57
    links_decision_image(const Image<I>& input_,
			 const object_links<L>& links,
			 const object_links<L>& filtered_links);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
58
59
60
61
62
63
64

# ifndef MLN_INCLUDE_ONLY

    template <typename I, typename L>
    mln_ch_value(I,value::rgb8)
    links_decision_image(const Image<I>& input_,
			 const object_links<L>& links,
65
			 const object_links<L>& filtered_links)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
66
67
68
69
    {
      trace::entering("scribo::debug::links_decision_image");
      const I& input = exact(input_);

70
      const component_set<L>& comps = links.components();
Guillaume Lazzara's avatar
Guillaume Lazzara committed
71
72

      mln_precondition(input.is_valid());
73
      mln_precondition(comps.is_valid());
Guillaume Lazzara's avatar
Guillaume Lazzara committed
74
75
76
77
78
      mln_precondition(links.is_valid());
      mln_precondition(filtered_links.is_valid());
      mln_precondition(links.size() == filtered_links.size());
      /// Fixme: check that objects has been computed from input.

79
      mln_ch_value(I,value::rgb8)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
80
81
	links_decision_image = data::convert(value::rgb8(), input);

82
83
      for_all_comps(i, comps)
	mln::draw::box(links_decision_image, comps(i).bbox(), literal::blue);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
84

85
86
      for_all_links(i, links)
	if (links(i) != i)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
87
88
	{
	  value::rgb8 value = literal::green;
89
	  if (links(i) != filtered_links(i))
Guillaume Lazzara's avatar
Guillaume Lazzara committed
90
91
92
	    value = literal::red;

	  mln_site(I)
93
94
	    p1 = comps(i).mass_center(),
	    p2 = comps(links(i)).mass_center();
Guillaume Lazzara's avatar
Guillaume Lazzara committed
95

96
	  mln::draw::line(links_decision_image, p1, p2, value);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
	}

      trace::exiting("scribo::debug::links_decision_image");
      return links_decision_image;
    }


# endif // ! MLN_INCLUDE_ONLY

  } // end of namespace scribo::debug

} // end of namespace scribo


#endif // ! SCRIBO_DEBUG_LINKS_DECISION_IMAGE_HH