File: propagator.hpp

package info (click to toggle)
sight 25.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 42,184 kB
  • sloc: cpp: 289,476; xml: 17,257; ansic: 9,878; python: 1,379; sh: 144; makefile: 33
file content (147 lines) | stat: -rw-r--r-- 5,618 bytes parent folder | download | duplicates (2)
1
2
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/************************************************************************
 *
 * Copyright (C) 2024-2025 IRCAD France
 *
 * This file is part of Sight.
 *
 * Sight is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Sight 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with Sight. If not, see <https://www.gnu.org/licenses/>.
 *
 ***********************************************************************/

#pragma once

#include <core/progress/has_monitors.hpp>

#include <data/boolean.hpp>
#include <data/image.hpp>
#include <data/integer.hpp>
#include <data/real.hpp>
#include <data/string.hpp>

#include <filter/image/min_max_propagation.hpp>

#include <service/filter.hpp>

namespace sight::module::filter::image
{

/**
 * @brief Service propagating in an image from seeds.
 *
 * The update() slot is called when the image changes in order to resize the output mask.
 *
 * @section Signals Signals
 * - \b computed() : Signal sent after propagation when the mouse has been released.
 *
 * @section Slots Slots
 * - \b propagate() : launch the propagation.
 * - \b clear() : reset the mask and the output samples images.
 *
 * @section XML XML Configuration
 * @code{.xml}
   <service type="sight::module::filter::image::propagator">
       <in key="image_in" uid="..." />
       <in key="seeds" uid="..." />
       <inout key="image_out" uid="..." />
       <inout key="samples_out" uid="..." />
       <config value="1" radius="50" overwrite="true" mode="min" />
   </service>
   @endcode
 *
 * @subsection Input Input
 * - \b image_in [sight::data::image]: The background image, whose values we read from during propagation.
 * - \b seeds [sight::data::point_list]: List of world coordinates points used to start the propagation.
 *
 * @subsection In-Out In-Out
 * - \b image_out [sight::data::image]: The output image, in which we will draw.
 * - \b samples_out [sight::data::image]: A 1D output image, in which the raw voxels values traversed during the
 * propagation are stored. It may be used to perform statistics on the collected samples, for instance.
 *
 * @subsection Properties Properties
 * - \b value (optional) : The initial value used in the output image. Default 1.
 * - \b radius(optional) : The maximum propagation distance. Infinity by default.
 * - \b overwrite (optional) : The overwrite mode. true by default.
 * - \b mode (optional) : Propagation mode. Possible values are 'min', 'max', 'minmax' and 'stddev'. 'min' by default.
 *  'stddev' stands for standar deviation, in this case the min is set to mean - stddev and mex to mean + stddev.
 */
class propagator : public service::filter,
                   public sight::core::progress::has_monitors
{
public:

    SIGHT_DECLARE_SERVICE(propagator, sight::service::filter);

    struct slots final
    {
        static inline const sight::core::com::slots::key_t CLEAR     = "clear";
        static inline const sight::core::com::slots::key_t PROPAGATE = "propagate";
    };

    /// Initializes slots signals and member variables.
    propagator();

    /// Destroys the service.
    ~propagator() override = default;

protected:

    ///Configures the services' parameters.
    void configuring(const config_t& _config) override;

    /// Initializes line drawer and propagator.
    void starting() override;

    /// Destroys line drawer and propagator.
    void stopping() override;

    /// Allocate the output image and launch the propagation.
    void updating() override;

    /// Launch the propagation.
    void propagate();

    /// Clear the mask and the voxels output
    void clear();

    /**
     * @brief Proposals to connect service slots to associated object signals.
     * @return A map of each proposed connection.
     *
     * Connect data::image::MODIFIED_SIG of s_IMAGE_IN to service::slots::UPDATE
     * Connect data::point_list::MODIFIED_SIG of s_SEEDS_IN to slots::PROPAGATE
     */
    connections_t auto_connections() const override;

private:

    using coordinates_t = sight::filter::image::min_max_propagation::coordinates_t;

    static constexpr std::string_view IMAGE_IN      = "image_in";
    static constexpr std::string_view SEEDS_IN      = "seeds";
    static constexpr std::string_view IMAGE_INOUT   = "image_out";
    static constexpr std::string_view SAMPLES_INOUT = "samples_out";

    sight::data::ptr<sight::data::image, sight::data::access::in> m_image_in {this, IMAGE_IN};
    sight::data::ptr<sight::data::point_list, sight::data::access::in> m_seeds_in {this, SEEDS_IN};
    sight::data::ptr<sight::data::image> m_image_out {this, IMAGE_INOUT, false};
    sight::data::ptr<sight::data::image> m_samples_out {this, SAMPLES_INOUT, true};
    sight::data::ptr<sight::data::boolean> m_mask_filled_out {this, "mask_filled_out", true};

    sight::data::property<sight::data::real> m_radius {this, "radius", 25.0};
    sight::data::property<sight::data::integer> m_value {this, "value", 1};
    sight::data::property<sight::data::boolean> m_overwrite {this, "overwrite", true};
    sight::data::property<sight::data::string> m_mode {this, "mode", std::string("minmax")};
};

} // namespace sight::module::filter::image.