diff --git a/include/core/sensor/factory_sensor.h b/include/core/sensor/factory_sensor.h index d51b407e3e33ba37ab087bd12373c68bba6f51a3..13968e370e83326135ef5958e3abcd9e457a92b3 100644 --- a/include/core/sensor/factory_sensor.h +++ b/include/core/sensor/factory_sensor.h @@ -70,9 +70,10 @@ namespace wolf * * \code * static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const ParamsServer& _server); + * static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const std::string& _yaml_filepath); * \endcode * - * They follow the general implementation shown below: + * They follow the general implementations shown below: * * \code * static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const ParamsServer& _server) @@ -85,6 +86,22 @@ namespace wolf * * return sensor; * } + * static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const std::string& _yaml_filepath) + * { + * // parse the yaml file + * auto parser = ParserYaml(_yaml_filepath, "", true); + * + * // load the parameters + * auto server = ParamsServer(parser.getParams()); + * + * // Do create the Sensor Parameters --- example: ParamsSensorCamera + * auto params = std::make_shared<ParamsSensorCamera>(_unique_name, server); + * + * // Do create the Sensor object --- example: SensorCamera + * auto sensor = std::make_shared<SensorCamera>(_unique_name, _dim, params, server); + * + * return sensor; + * } * \endcode * * #### Creating sensors @@ -97,6 +114,12 @@ namespace wolf * auto camera_ptr = FactorySensor::create("SensorCamera", "Front-left camera", 3, param_server); * \endcode * + * or: + * + * \code + * auto camera_ptr = FactorySensorYaml::create("SensorCamera", "Front-left camera", 3, yaml_filepath); + * \endcode + * * where ABSOLUTELY ALL input parameters are important. In particular, the sensor name "Front-left camera" will be used to identify this camera * and to assign it the appropriate processors. DO NOT USE IT WITH DUMMY PARAMETERS! * @@ -121,12 +144,16 @@ namespace wolf * namespace { * const bool registered_camera = FactorySensor::registerCreator("SensorCamera", SensorCamera::create); * } + * namespace { + * const bool registered_camera_yaml = FactorySensorYaml::registerCreator("SensorCamera", SensorCamera::create); + * } * main () { ... } * \endcode * or inside your main(), where a direct call is possible: * \code * main () { * FactorySensor::registerCreator("SensorCamera", SensorCamera::create); + * FactorySensor::registerCreatorYaml("SensorCamera", SensorCamera::create); * ... * } * \endcode @@ -136,9 +163,11 @@ namespace wolf * \code * namespace { * const bool registered_camera = FactorySensor::registerCreator("SensorCamera", SensorCamera::create); + * const bool registered_camera_yaml = FactorySensorYaml::registerCreator("SensorCamera", SensorCamera::create); * } * \endcode - * Automatic registration is recommended in wolf, and implemented in the classes shipped with it using the macro WOLF_REGISTER_SENSOR(SensorType). + * Automatic registration is recommended in wolf, and implemented in the classes shipped with it using the macros + * WOLF_REGISTER_SENSOR(SensorType) and WOLF_REGISTER_SENSOR_YAML(SensorType). * You are free to comment out these lines and place them wherever you consider it more convenient for your design. * * #### Example 2: creating sensors @@ -160,24 +189,18 @@ namespace wolf * // the parameter server or a yaml file * * SensorBasePtr camera_1_ptr = - * FactorySensor::create ( "SensorCamera" , - * "Front-left camera" , - * extrinsics_1 , - * intrinsics_1 ); + * FactorySensor::create ( "SensorCamera", + * "Front-left camera" , + * 3 , + * parameter_server ); * * // A second camera... with a different name! * - * Eigen::VectorXd extrinsics_2(7); - * - * ParamsSensorCameraPtr intrinsics_2 = - * FactoryParamsSensor::create("ParamsSensorCamera", - * camera_2.yaml); - * * SensorBasePtr camera_2_ptr = * FactorySensor::create( "SensorCamera" , - * "Front-right camera" , - * extrinsics_2 , - * intrinsics_2 ); + * "Front-right camera" , + * 3 , + * yaml_filename ); * * return 0; * } diff --git a/include/core/sensor/sensor_base.h b/include/core/sensor/sensor_base.h index cf693f57c9b8b3fa8de09299d01c7b69ddbe968c..c43d61d1553d74b3eae74cf7f95fa73ca05d1f71 100644 --- a/include/core/sensor/sensor_base.h +++ b/include/core/sensor/sensor_base.h @@ -58,27 +58,27 @@ namespace wolf { * ParamsSensorClassPtr _params) * */ -#define WOLF_SENSOR_CREATE(SensorClass, ParamsSensorClass) \ -static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const ParamsServer& _server) \ -{ \ - auto params = std::make_shared<ParamsSensorClass>(_unique_name, _server); \ - \ - auto sensor = std::make_shared<SensorClass>(_unique_name, _dim, params, _server); \ - \ - return sensor; \ -} \ -static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const std::string& _yaml_file) \ -{ \ - auto parser = ParserYaml(_yaml_file, "", true); \ - \ - auto server = ParamsServer(parser.getParams()); \ - \ - auto params = std::make_shared<ParamsSensorClass>(_unique_name, server); \ - \ - auto sensor = std::make_shared<SensorClass>(_unique_name, _dim, params, server); \ - \ - return sensor; \ -} \ +#define WOLF_SENSOR_CREATE(SensorClass, ParamsSensorClass) \ +static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const ParamsServer& _server) \ +{ \ + auto params = std::make_shared<ParamsSensorClass>(_unique_name, _server); \ + \ + auto sensor = std::make_shared<SensorClass>(_unique_name, _dim, params, _server); \ + \ + return sensor; \ +} \ +static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const std::string& _yaml_filepath) \ +{ \ + auto parser = ParserYaml(_yaml_filepath, "", true); \ + \ + auto server = ParamsServer(parser.getParams()); \ + \ + auto params = std::make_shared<ParamsSensorClass>(_unique_name, server); \ + \ + auto sensor = std::make_shared<SensorClass>(_unique_name, _dim, params, server); \ + \ + return sensor; \ +} \ /** \brief base struct for intrinsic sensor parameters *