#include <filter_chain.hpp>
Public Types | |
typedef ::std::function< void(const F &data, const size_t filterNum, const ::std::string &name, const ::std::string &type, bool success)> | FilterFinishedCallback |
Callback to be called after each filter processes the data. More... | |
typedef ::std::function< void(const F &data, const size_t filterNum, const ::std::string &name, const ::std::string &type)> | FilterStartCallback |
Callback to be called before each filter processes the data. More... | |
Public Member Functions | |
bool | clear () |
Clear all filters from this chain. This function intentionally shadows filters::FilterChain::clear() which is non-virtual. More... | |
void | disableFilter (const ::std::string &name) |
Temporarily disable the filter with the given name. More... | |
void | enableFilter (const ::std::string &name) |
Enable the temporarily disabled filter with the given name. More... | |
FilterChain (const ::std::string &dataType, const FilterFinishedCallback &filterFinishedCallback={}, const FilterStartCallback &filterStartCallback={}, const ::cras::LogHelperPtr &logHelper=::std::make_shared<::cras::NodeLogHelper >()) | |
Construct a filter chain. More... | |
::std::vector<::std::shared_ptr<::filters::FilterBase< F > > > | getActiveFilters () const |
Get a copy of the list of active filters. More... | |
::std::unordered_set<::std::string > | getDisabledFilters () const |
Get which filters are temporarily disabled. More... | |
void | setDisabledFilters (::std::unordered_set<::std::string > filters) |
Set which filters are temporarily disabled. This overrides any previous calls to disableFilter() and enableFilter(). More... | |
void | setFilterFinishedCallback (const FilterFinishedCallback &callback) |
Set the filter finished callback. More... | |
void | setFilterStartCallback (const FilterStartCallback &callback) |
Set the filter start callback. More... | |
void | setNodelet (const ::nodelet::Nodelet *nodelet) |
Inform this chain that it is running in the given nodelet, so that it can do appropriate optimizations. This should be done after the filters are configured. More... | |
bool | update (const F &data_in, F &data_out) |
Do the filtering. This function intentionally shadows filters::FilterChain::update() which is non-virtual. More... | |
Public Member Functions inherited from filters::FilterChain< F > | |
bool | clear () |
bool | configure (std::string param_name, ros::NodeHandle node=ros::NodeHandle()) |
bool | configure (XmlRpc::XmlRpcValue &config, const std::string &filter_ns) |
FilterChain (std::string data_type) | |
std::vector< std::shared_ptr< filters::FilterBase< T > > > | getFilters () const |
bool | update (const T &data_in, T &data_out) |
~FilterChain () | |
Protected Member Functions | |
void | callFinishedCallback (const F &data, size_t filterNum, bool succeeded) |
If filterFinishedCallback is set, call it. More... | |
void | callStartCallback (const F &data, size_t filterNum) |
If filterStartCallback is set, call it. More... | |
void | updateActiveFilters () |
Update the contents of activeFilters with just the filters that have not been disabled. More... | |
Protected Attributes | |
::std::vector<::std::shared_ptr<::filters::FilterBase< F > > > | activeFilters |
A list of filters that should be treated as active and should act on the input data. More... | |
mutable ::std::mutex | activeFiltersMutex |
Mutex protecting activeFilters access. More... | |
F | buffer0 |
A temporary intermediate buffer. More... | |
F | buffer1 |
A temporary intermediate buffer. More... | |
::std::unordered_set<::std::string > | disabledFilters |
A set of filters that have been temporarily disabled. More... | |
FilterFinishedCallback | filterFinishedCallback |
The optional callback to call when a filter finishes its work. More... | |
FilterStartCallback | filterStartCallback |
The optional callback to call when a filter starts its work. More... | |
bool | initialized {false} |
Whether this filter chain has been initialized (gets set by first update() and cleared by clear() ). More... | |
Additional Inherited Members | |
Private Member Functions inherited from cras::HasLogger | |
::cras::LogHelperConstPtr | getCrasLogger () const |
This is the function picked up by CRAS_* logging macros. More... | |
HasLogger (const ::cras::LogHelperPtr &log) | |
Associate the logger with this interface. More... | |
void | setCrasLogger (const ::cras::LogHelperPtr &log) |
Set the logger to be used for logging. More... | |
Private Attributes inherited from cras::HasLogger | |
::cras::LogHelperPtr | log |
Log helper. More... | |
This filter chain implementation allows for selectively disabling/enabling filters during run time. It also adds a callback with the input and result of each filter run, so that you can e.g. publish the output of each filter.
F | Type of the filtered data. |
Definition at line 42 of file filter_chain.hpp.
typedef ::std::function< void(const F& data, const size_t filterNum, const ::std::string& name, const ::std::string& type, bool success)> cras::FilterChain< F >::FilterFinishedCallback |
Callback to be called after each filter processes the data.
[in] | data | The data after application of the filter. |
[in] | filterNum | The number of the filter in the filtering chain. |
[in] | name | Name of the filter that processed the data. |
[in] | type | Type of the filter that processed the data. |
[in] | success | Whether the filter succeeded (its update() function returned true). |
Definition at line 68 of file filter_chain.hpp.
typedef ::std::function< void(const F& data, const size_t filterNum, const ::std::string& name, const ::std::string& type)> cras::FilterChain< F >::FilterStartCallback |
Callback to be called before each filter processes the data.
[in] | data | The data before application of the filter. |
[in] | filterNum | The number of the filter in the filtering chain. |
[in] | name | Name of the filter that processed the data. |
[in] | type | Type of the filter that processed the data. |
Definition at line 55 of file filter_chain.hpp.
|
explicit |
Construct a filter chain.
[in] | dataType | Textual representation of the data type. |
[in] | filterFinishedCallback | Optional callback to be called after each filter finishes its work. |
[in] | filterStartCallback | Optional callback to be called before each filter starts its work. |
[in] | logHelper | The log helper used for printing console messages. |
|
protected |
If filterFinishedCallback is set, call it.
[in] | data | The filtered data to pass to the callback. |
[in] | filterNum | Number of the filter to pass to the callback. |
[in] | succeeded | Whether the filter succeeded (its update() function returned true). |
|
protected |
If filterStartCallback is set, call it.
[in] | data | The filtered data to pass to the callback. |
[in] | filterNum | Number of the filter to pass to the callback. |
bool cras::FilterChain< F >::clear | ( | ) |
Clear all filters from this chain. This function intentionally shadows filters::FilterChain::clear() which is non-virtual.
void cras::FilterChain< F >::disableFilter | ( | const ::std::string & | name | ) |
Temporarily disable the filter with the given name.
[in] | name | Name of the filter to disable. If the filter is not found, nothing happens. |
void cras::FilterChain< F >::enableFilter | ( | const ::std::string & | name | ) |
Enable the temporarily disabled filter with the given name.
[in] | name | Name of the filter to enable. If the filter is not found, nothing happens. |
::std::vector<::std::shared_ptr<::filters::FilterBase<F> > > cras::FilterChain< F >::getActiveFilters | ( | ) | const |
Get a copy of the list of active filters.
::std::unordered_set<::std::string> cras::FilterChain< F >::getDisabledFilters | ( | ) | const |
Get which filters are temporarily disabled.
void cras::FilterChain< F >::setDisabledFilters | ( | ::std::unordered_set<::std::string > | filters | ) |
Set which filters are temporarily disabled. This overrides any previous calls to disableFilter() and enableFilter().
[in] | filters | The filters to disable. |
void cras::FilterChain< F >::setFilterFinishedCallback | ( | const FilterFinishedCallback & | callback | ) |
Set the filter finished callback.
[in] | callback | The callback to set. |
void cras::FilterChain< F >::setFilterStartCallback | ( | const FilterStartCallback & | callback | ) |
Set the filter start callback.
[in] | callback | The callback to set. |
void cras::FilterChain< F >::setNodelet | ( | const ::nodelet::Nodelet * | nodelet | ) |
Inform this chain that it is running in the given nodelet, so that it can do appropriate optimizations. This should be done after the filters are configured.
[in] | nodelet | The nodelet this chain is running in. Setting to nullptr will inform the chain it is not running inside a nodelet. |
bool cras::FilterChain< F >::update | ( | const F & | data_in, |
F & | data_out | ||
) |
Do the filtering. This function intentionally shadows filters::FilterChain::update() which is non-virtual.
[in] | data_in | Input data. |
[out] | data_out | The filtered data. |
|
protected |
Update the contents of activeFilters with just the filters that have not been disabled.
|
protected |
A list of filters that should be treated as active and should act on the input data.
Definition at line 179 of file filter_chain.hpp.
|
protected |
Mutex protecting activeFilters access.
Definition at line 182 of file filter_chain.hpp.
|
protected |
A temporary intermediate buffer.
Definition at line 190 of file filter_chain.hpp.
|
protected |
A temporary intermediate buffer.
Definition at line 193 of file filter_chain.hpp.
|
protected |
A set of filters that have been temporarily disabled.
Definition at line 176 of file filter_chain.hpp.
|
protected |
The optional callback to call when a filter finishes its work.
Definition at line 173 of file filter_chain.hpp.
|
protected |
The optional callback to call when a filter starts its work.
Definition at line 170 of file filter_chain.hpp.
|
protected |
Whether this filter chain has been initialized (gets set by first update()
and cleared by clear()
).
Definition at line 185 of file filter_chain.hpp.