00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #ifndef __pcl_ros__FEATURECONFIG_H__
00048 #define __pcl_ros__FEATURECONFIG_H__
00049
00050 #include <dynamic_reconfigure/config_tools.h>
00051 #include <limits>
00052 #include <ros/node_handle.h>
00053 #include <dynamic_reconfigure/ConfigDescription.h>
00054 #include <dynamic_reconfigure/ParamDescription.h>
00055 #include <dynamic_reconfigure/config_init_mutex.h>
00056
00057 namespace pcl_ros
00058 {
00059 class FeatureConfigStatics;
00060
00061 class FeatureConfig
00062 {
00063 public:
00064 class AbstractParamDescription : public dynamic_reconfigure::ParamDescription
00065 {
00066 public:
00067 AbstractParamDescription(std::string n, std::string t, uint32_t l,
00068 std::string d, std::string e)
00069 {
00070 name = n;
00071 type = t;
00072 level = l;
00073 description = d;
00074 edit_method = e;
00075 }
00076
00077 virtual void clamp(FeatureConfig &config, const FeatureConfig &max, const FeatureConfig &min) const = 0;
00078 virtual void calcLevel(uint32_t &level, const FeatureConfig &config1, const FeatureConfig &config2) const = 0;
00079 virtual void fromServer(const ros::NodeHandle &nh, FeatureConfig &config) const = 0;
00080 virtual void toServer(const ros::NodeHandle &nh, const FeatureConfig &config) const = 0;
00081 virtual bool fromMessage(const dynamic_reconfigure::Config &msg, FeatureConfig &config) const = 0;
00082 virtual void toMessage(dynamic_reconfigure::Config &msg, const FeatureConfig &config) const = 0;
00083 };
00084
00085 typedef boost::shared_ptr<AbstractParamDescription> AbstractParamDescriptionPtr;
00086 typedef boost::shared_ptr<const AbstractParamDescription> AbstractParamDescriptionConstPtr;
00087
00088 template <class T>
00089 class ParamDescription : public AbstractParamDescription
00090 {
00091 public:
00092 ParamDescription(std::string name, std::string type, uint32_t level,
00093 std::string description, std::string edit_method, T FeatureConfig::* f) :
00094 AbstractParamDescription(name, type, level, description, edit_method),
00095 field(f)
00096 {}
00097
00098 T (FeatureConfig::* field);
00099
00100 virtual void clamp(FeatureConfig &config, const FeatureConfig &max, const FeatureConfig &min) const
00101 {
00102 if (config.*field > max.*field)
00103 config.*field = max.*field;
00104
00105 if (config.*field < min.*field)
00106 config.*field = min.*field;
00107 }
00108
00109 virtual void calcLevel(uint32_t &comb_level, const FeatureConfig &config1, const FeatureConfig &config2) const
00110 {
00111 if (config1.*field != config2.*field)
00112 comb_level |= level;
00113 }
00114
00115 virtual void fromServer(const ros::NodeHandle &nh, FeatureConfig &config) const
00116 {
00117 nh.getParam(name, config.*field);
00118 }
00119
00120 virtual void toServer(const ros::NodeHandle &nh, const FeatureConfig &config) const
00121 {
00122 nh.setParam(name, config.*field);
00123 }
00124
00125 virtual bool fromMessage(const dynamic_reconfigure::Config &msg, FeatureConfig &config) const
00126 {
00127 return dynamic_reconfigure::ConfigTools::getParameter(msg, name, config.*field);
00128 }
00129
00130 virtual void toMessage(dynamic_reconfigure::Config &msg, const FeatureConfig &config) const
00131 {
00132 dynamic_reconfigure::ConfigTools::appendParameter(msg, name, config.*field);
00133 }
00134 };
00135
00136
00137 int k_search;
00138
00139 double radius_search;
00140
00141
00142 bool __fromMessage__(dynamic_reconfigure::Config &msg)
00143 {
00144 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00145 int count = 0;
00146 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00147 if ((*i)->fromMessage(msg, *this))
00148 count++;
00149 if (count != dynamic_reconfigure::ConfigTools::size(msg))
00150 {
00151 ROS_ERROR("FeatureConfig::__fromMessage__ called with an unexpected parameter.");
00152 ROS_ERROR("Booleans:");
00153 for (unsigned int i = 0; i < msg.bools.size(); i++)
00154 ROS_ERROR(" %s", msg.bools[i].name.c_str());
00155 ROS_ERROR("Integers:");
00156 for (unsigned int i = 0; i < msg.ints.size(); i++)
00157 ROS_ERROR(" %s", msg.ints[i].name.c_str());
00158 ROS_ERROR("Doubles:");
00159 for (unsigned int i = 0; i < msg.doubles.size(); i++)
00160 ROS_ERROR(" %s", msg.doubles[i].name.c_str());
00161 ROS_ERROR("Strings:");
00162 for (unsigned int i = 0; i < msg.strs.size(); i++)
00163 ROS_ERROR(" %s", msg.strs[i].name.c_str());
00164
00165
00166 return false;
00167 }
00168 return true;
00169 }
00170
00171
00172
00173 void __toMessage__(dynamic_reconfigure::Config &msg, const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__) const
00174 {
00175 dynamic_reconfigure::ConfigTools::clear(msg);
00176 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00177 (*i)->toMessage(msg, *this);
00178 }
00179
00180 void __toMessage__(dynamic_reconfigure::Config &msg) const
00181 {
00182 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00183 __toMessage__(msg, __param_descriptions__);
00184 }
00185
00186 void __toServer__(const ros::NodeHandle &nh) const
00187 {
00188 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00189 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00190 (*i)->toServer(nh, *this);
00191 }
00192
00193 void __fromServer__(const ros::NodeHandle &nh)
00194 {
00195 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00196 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00197 (*i)->fromServer(nh, *this);
00198 }
00199
00200 void __clamp__()
00201 {
00202 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00203 const FeatureConfig &__max__ = __getMax__();
00204 const FeatureConfig &__min__ = __getMin__();
00205 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00206 (*i)->clamp(*this, __max__, __min__);
00207 }
00208
00209 uint32_t __level__(const FeatureConfig &config) const
00210 {
00211 const std::vector<AbstractParamDescriptionConstPtr> &__param_descriptions__ = __getParamDescriptions__();
00212 uint32_t level = 0;
00213 for (std::vector<AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00214 (*i)->calcLevel(level, config, *this);
00215 return level;
00216 }
00217
00218 static const dynamic_reconfigure::ConfigDescription &__getDescriptionMessage__();
00219 static const FeatureConfig &__getDefault__();
00220 static const FeatureConfig &__getMax__();
00221 static const FeatureConfig &__getMin__();
00222 static const std::vector<AbstractParamDescriptionConstPtr> &__getParamDescriptions__();
00223
00224 private:
00225 static const FeatureConfigStatics *__get_statics__();
00226 };
00227
00228 template <>
00229 inline void FeatureConfig::ParamDescription<std::string>::clamp(FeatureConfig &config, const FeatureConfig &max, const FeatureConfig &min) const
00230 {
00231 return;
00232 }
00233
00234 class FeatureConfigStatics
00235 {
00236 friend class FeatureConfig;
00237
00238 FeatureConfigStatics()
00239 {
00240
00241 __min__.k_search = 0;
00242
00243 __max__.k_search = 1000;
00244
00245 __default__.k_search = 10;
00246
00247 __param_descriptions__.push_back(FeatureConfig::AbstractParamDescriptionConstPtr(new FeatureConfig::ParamDescription<int>("k_search", "int", 0, "Number of k-nearest neighbors to search for", "", &FeatureConfig::k_search)));
00248
00249 __min__.radius_search = 0.0;
00250
00251 __max__.radius_search = 0.5;
00252
00253 __default__.radius_search = 0.0;
00254
00255 __param_descriptions__.push_back(FeatureConfig::AbstractParamDescriptionConstPtr(new FeatureConfig::ParamDescription<double>("radius_search", "double", 0, "Sphere radius for nearest neighbor search", "", &FeatureConfig::radius_search)));
00256
00257
00258 for (std::vector<FeatureConfig::AbstractParamDescriptionConstPtr>::const_iterator i = __param_descriptions__.begin(); i != __param_descriptions__.end(); i++)
00259 __description_message__.parameters.push_back(**i);
00260 __max__.__toMessage__(__description_message__.max, __param_descriptions__);
00261 __min__.__toMessage__(__description_message__.min, __param_descriptions__);
00262 __default__.__toMessage__(__description_message__.dflt, __param_descriptions__);
00263 }
00264 std::vector<FeatureConfig::AbstractParamDescriptionConstPtr> __param_descriptions__;
00265 FeatureConfig __max__;
00266 FeatureConfig __min__;
00267 FeatureConfig __default__;
00268 dynamic_reconfigure::ConfigDescription __description_message__;
00269 static const FeatureConfigStatics *get_instance()
00270 {
00271
00272
00273
00274
00275 static FeatureConfigStatics instance;
00276 return &instance;
00277 }
00278 };
00279
00280 inline const dynamic_reconfigure::ConfigDescription &FeatureConfig::__getDescriptionMessage__()
00281 {
00282 return __get_statics__()->__description_message__;
00283 }
00284
00285 inline const FeatureConfig &FeatureConfig::__getDefault__()
00286 {
00287 return __get_statics__()->__default__;
00288 }
00289
00290 inline const FeatureConfig &FeatureConfig::__getMax__()
00291 {
00292 return __get_statics__()->__max__;
00293 }
00294
00295 inline const FeatureConfig &FeatureConfig::__getMin__()
00296 {
00297 return __get_statics__()->__min__;
00298 }
00299
00300 inline const std::vector<FeatureConfig::AbstractParamDescriptionConstPtr> &FeatureConfig::__getParamDescriptions__()
00301 {
00302 return __get_statics__()->__param_descriptions__;
00303 }
00304
00305 inline const FeatureConfigStatics *FeatureConfig::__get_statics__()
00306 {
00307 const static FeatureConfigStatics *statics;
00308
00309 if (statics)
00310 return statics;
00311
00312 boost::mutex::scoped_lock lock(dynamic_reconfigure::__init_mutex__);
00313
00314 if (statics)
00315 return statics;
00316
00317 statics = FeatureConfigStatics::get_instance();
00318
00319 return statics;
00320 }
00321
00322
00323 }
00324
00325 #endif // __FEATURERECONFIGURATOR_H__