/* * PluginBase * * Author: Andrew Salamon * * Copyright (c) 2008 Machine Perception Laboratory * University of California San Diego. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #ifndef __CERT_PLUGINBASE_H__ #define __CERT_PLUGINBASE_H__ #include #include #include #include namespace CERT { class ConfigItem; typedef std::string PluginStep; typedef std::vector< double > PluginResultsType; /** Base class for all plugin types. * Provides access to standard config items like id, name, plugin step, etc. * Also provides a basic interface for CERT and other plugins to use. * There will probably be one sub-class for each of the PluginSteps in order to provide * more specific interface items for that type of plugin. */ class PluginBase { public: PluginBase( ConfigItem *_config ); virtual ~PluginBase(); virtual PluginBase *copy(); virtual std::string id() const; ///< An ID unique among plugins. Usually reverse DNS plus a plugin name. virtual std::string name() const; ///< Plugin name used in all output. virtual std::string internalName() const; ///< This can be used any way the plugin needs. E.g. SVM plugins use the internal name as a prefix for the names of the SVM data files. virtual PluginStep step() const; ///< Basically what type of plugin this is. Different types of plugins are used during different steps of the CERT process. See PluginController, specifically namespace PluginSteps for a list of current plugin types. virtual bool isEnabled() const; ///< Is this plugin enabled. virtual void setEnabled( bool _enabled ); virtual bool shouldDisplay() const; ///< Should this plugin display any output. Sometimes it's useful to have a plugin run even though you don't need it's output. For example, if all you're interested in is the AU outputs you might want to suppress feature detector outputs even though they still need to be enabled. virtual bool areResultsValid(); virtual PluginResultsType getResults() const; virtual void clearResults(); ///< Clear previous results. virtual std::vector getLabels() const; virtual std::string invalidResultsString() const; ///< Usually returns a string of tab separated "NaN" of the same length as the normal results. protected: ConfigItem *config; PluginResultsType results; }; namespace PluginExceptions { /** An exception that all plugins should use to signal an error in their config entry. * If a non-standard property is missing for example, or if the number of labels doesn't match * the number of outputs. * This class should probably be moved to the Plugins namespace, getting rid of PluginExceptions. */ class configError : public std::runtime_error { public: configError( const std::string &msg ) : std::runtime_error(msg) { } }; } namespace Plugins { /** Plugin Clear functor. * This class can be used to clear the results from all plugins in an STL container. * This would normally be done just before processing a new image to make sure that * any values from previous images are removed. * e.g. std::for_each( pluginVector.begin(), pluginVector.end(), CERT::Plugins::Clear() ); */ class Clear { public: Clear() {} template void operator()( T &a ) { a->clearResults(); } }; } } // end namespace CERT #endif // __CERT_PLUGINBASE_H__