semio_ros  0.10.6
humanoid_source_adapter.cpp
Go to the documentation of this file.
2 
8 
9 semio::ros::HumanoidSourceAdapter::HumanoidSourceAdapter( ::ros::NodeHandle const & nh_rel, std::string const & default_source )
10 :
11  _nh_rel( nh_rel ),
12  _default_source( default_source )
13 {
14  //
15 }
16 
18 {
19  std::string const & source_type( source == "param" ? _nh_rel.param( std::string( "humanoid_source/type" ), _default_source ) : source );
20 
22 
23  // apply smoothing filter if specified via params
24  std::shared_ptr<semio::HumanoidSmoothingFilter> smoothing_filter_ptr;
25  {
26  typedef std::function<void(std::string const &)> _ParamFunc;
27  typedef std::pair<std::string, _ParamFunc> _ParamOp;
28 
29  for( auto const & param_op : {
30  _ParamOp(
31  "humanoid_source/filter/smoothing/add",
32  []( std::string const & param_name ){} ),
33  _ParamOp(
34  "humanoid_source/filter/smoothing/position",
35  [this,&smoothing_filter_ptr]( std::string const & param_name ){
36  smoothing_filter_ptr->setPositionSmoothing( semio::HumanoidSmoothingFilter::getSmoothing( 0.75, this->_nh_rel.param<double>( param_name, 0 ) ) );
37  } ),
38  _ParamOp(
39  "humanoid_source/filter/smoothing/orientation",
40  [this,&smoothing_filter_ptr]( std::string const & param_name ){
41  smoothing_filter_ptr->setOrientationSmoothing( semio::HumanoidSmoothingFilter::getSmoothing( 0.75, this->_nh_rel.param<double>( param_name, 0 ) ) );
42  } ),
43  _ParamOp(
44  "humanoid_source/filter/smoothing/confidence",
45  [this,&smoothing_filter_ptr]( std::string const & param_name ){
46  smoothing_filter_ptr->setConfidenceSmoothing( semio::HumanoidSmoothingFilter::getSmoothing( 0.75, this->_nh_rel.param<double>( param_name, 0 ) ) );
47  } ),
48  _ParamOp(
49  "humanoid_source/filter/smoothing/window",
50  [this,&smoothing_filter_ptr]( std::string const & param_name ){
51  smoothing_filter_ptr->setSmoothingWindow( this->_nh_rel.param<double>( param_name, 0 ) );
52  } ) } )
53  {
54  auto const & param_name( param_op.first );
55 
56  if( _nh_rel.hasParam( param_name ) )
57  {
58  if( !smoothing_filter_ptr ) smoothing_filter_ptr = std::make_shared<semio::HumanoidSmoothingFilter>();
59 
60  param_op.second( param_name );
61  }
62  }
63  }
64 
65  if( source_type == "nite" ) result = std::make_shared<semio::HumanoidSourceNiTE>();
66  else if( source_type == "openface" ) result = std::make_shared<semio::HumanoidSourceOpenFace>();
67  else if( source_type == "fullbody" )
68  {
69  auto local_result( std::make_shared<semio::HumanoidSourceFullBody>() );
70  local_result->show_cropped_image_ = _nh_rel.param<bool>( std::string( "humanoid_source/fullbody/show_cropped_image" ), false );
71  result = local_result;
72  }
73  else if( source_type == "ros" )
74  {
75  result = std::make_shared<semio::ros::HumanoidSourceROS>( _nh_rel );
76  }
77  else if( source_type == "virtual" ) result = std::make_shared<HumanoidSourceVirtual>();
78  else return std::make_shared<semio::ros::HumanoidSourceROS>( ::ros::NodeHandle( _nh_rel, "/null" ) );
79 
80  // add a smoothing filter and a basic state filter (to remove untracked smoothed humanoids)
81  if( smoothing_filter_ptr )
82  {
83  auto & result_filter( result->getFilter() );
84  result_filter.addFilter( smoothing_filter_ptr );
85  result_filter.addFilter( std::make_shared<semio::HumanoidStateFilter>( semio::HumanoidStateFilter::getStandardFilterHumanoid() ) );
86  }
87 
88  return result;
89 }
static double getSmoothing(double const &factor, double const &duration)
HumanoidSourceAdapter(::ros::NodeHandle const &nh_rel, std::string const &default_source="fullbody")
::ros::NodeHandle _nh_rel
NodeHandle copy for interfacing with ROS.
std::string _default_source
The type of source to use by default if param mode is selected and the ROS param _humanoid_source/typ...
decltype(std::make_shared< HumanoidSource >()) typedef Ptr
HumanoidSource::Ptr getHumanoidSource(std::string const &source="param")
Create a semio::HumanoidSource.
static _FilterFuncArray const & getStandardFilterHumanoid()