Skip to content
Snippets Groups Projects

Draft: Resolve "Implementation of new nodes creation"

Open Joan Vallvé Navarro requested to merge 454-implementation-of-new-nodes-creation into devel
9 files
+ 830
555
Compare changes
  • Side-by-side
  • Inline
Files
9
@@ -69,27 +69,21 @@ namespace wolf
* Sensor creators have the following API:
*
* \code
* static SensorBasePtr create(const std::string& _name, Eigen::VectorXd& _params_extrinsics, ParamsSensorBasePtr _params_sensor);
* static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const ParamsServer& _server);
* \endcode
*
* They follow the general implementation shown below:
*
* \code
* static SensorBasePtr create(const std::string& _unique_name, Eigen::VectorXd& _params_extrinsics, ParamsSensorBasePtr _params_sensor)
* static SensorBasePtr create(const std::string& _unique_name, SizeEigen _dim, const ParamsServer& _server)
* {
* // check extrinsics vector --- example: 3D pose
* assert(_params_extrinsics.size() == 7 && "Bad extrinsics vector length. Should be 7 for 3d.");
*
* // cast sensor parameters to good type --- example: ParamsSensorCamera
* auto intrinsics_ptr = std::static_pointer_cast<ParamsSensorCamera>(_params_sensor);
*
* // Do create the Sensor Parameters --- example: ParamsSensorCamera
* auto params = std::make_shared<ParamsSensorCamera>(_unique_name, _server);
*
* // Do create the Sensor object --- example: SensorCamera
* auto sen_ptr = std::make_shared<SensorCamera>(_extrinsics_pq, intrinsics_ptr);
*
* // Complete the sensor setup with a unique name identifying the sensor
* sen_ptr->setName(_unique_name);
*
* return sen_ptr;
* auto sensor = std::make_shared<SensorCamera>(_unique_name, _dim, params, _server);
*
* return sensor;
* }
* \endcode
*
@@ -97,42 +91,27 @@ namespace wolf
* Note: Prior to invoking the creation of a sensor of a particular type,
* you must register the creator for this type into the factory.
*
* To create e.g. a SensorCamera, you type:
* To create e.g. a SensorCamera in 3D, you type:
*
* \code
* auto camera_ptr = FactorySensor::create("SensorCamera", "Front-left camera", params_extrinsics, params_camera);
* auto camera_ptr = FactorySensor::create("SensorCamera", "Front-left camera", 3, param_server);
* \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!
*
* #### See also
* - FactoryParamsSensor: to create intrinsic structs deriving from ParamsSensorBase directly from YAML files.
* - FactoryProcessor: to create processors that will be bound to sensors.
* - Problem::installSensor() : to install sensors in WOLF Problem.
*
* #### Example 1: writing a SensorCamera creator
* Here is an example of SensorCamera::create() extracted from sensor_camera.cpp:
*
* We RECOMMEND using the macro WOLF_SENSOR_CREATE(SensorClass, ParamsSensorClass) to automatically add the sensor creator, provided in 'sensor_base.h'.
*
* To do so, you should implement a constructor with the API:
*
* \code
* static SensorBasePtr create(const std::string& _unique_name, Eigen::VectorXd& _extrinsics_pq, ParamsSensorBasePtr _intrinsics)
* {
* // check extrinsics vector
* assert(_extrinsics_pq.size() == 7 && "Bad extrinsics vector length. Should be 7 for 3d.");
*
* // cast instrinsics to good type
* auto intrinsics_ptr = std::static_pointer_cast<ParamsSensorCamera>(_intrinsics);
*
* // Do create the SensorCamera object, and complete its setup
* auto sen_ptr = std::make_shared<SensorCamera>(_extrinsics_pq, intrinsics_ptr);
*
* sen_ptr->setName(_unique_name);
*
* return sen_ptr;
* }
* SensorDerived(const std::string& _unique_name,
* SizeEigen _dim,
* ParamsSensorDummyPtr _params,
* const ParamsServer& _server)
* \endcode
*
* #### Example 2: registering a sensor creator into the factory
* #### Registering sensor creator into the factory
* Registration can be done manually or automatically. It involves the call to static functions.
* It is advisable to put these calls within unnamed namespaces.
*
@@ -159,7 +138,7 @@ namespace wolf
* const bool registered_camera = FactorySensor::registerCreator("SensorCamera", SensorCamera::create);
* }
* \endcode
* Automatic registration is recommended in wolf, and implemented in the classes shipped with it.
* Automatic registration is recommended in wolf, and implemented in the classes shipped with it using the macro WOLF_REGISTER_SENSOR(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
@@ -177,15 +156,8 @@ namespace wolf
* // To create a camera, provide:
* // a type = "SensorCamera",
* // a name = "Front-left camera",
* // an extrinsics vector, and
* // a pointer to the intrinsics struct:
*
* Eigen::VectorXd extrinsics_1(7); // give it some values...
*
* // Create a pointer to the struct of sensor parameters stored in a YAML file ( see FactoryParamsSensor )
* ParamsSensorCameraPtr intrinsics_1 =
* FactoryParamsSensor::create("ParamsSensorCamera",
* camera_1.yaml);
* // the problem dimension dim = 3, and
* // the parameter server or a yaml file
*
* SensorBasePtr camera_1_ptr =
* FactorySensor::create ( "SensorCamera" ,
@@ -211,47 +183,34 @@ namespace wolf
* }
* \endcode
*
* #### See also
* - FactoryProcessor: to create processors that will be bound to sensors.
* - Problem::installSensor() : to install sensors in WOLF Problem.
*/
typedef Factory<SensorBase,
const std::string&,
const Eigen::VectorXd&,
const ParamsSensorBasePtr> FactorySensor;
template<>
inline std::string FactorySensor::getClass() const
{
return "FactorySensor";
}
// ParamsSensor factory
struct ParamsSensorBase;
typedef Factory<ParamsSensorBase,
const std::string&> FactoryParamsSensor;
template<>
inline std::string FactoryParamsSensor::getClass() const
{
return "FactoryParamsSensor";
}
#define WOLF_REGISTER_SENSOR(SensorType) \
namespace{ const bool WOLF_UNUSED SensorType##Registered = \
FactorySensor::registerCreator(#SensorType, SensorType::create); } \
SizeEigen,
const ParamsServer&> FactorySensor;
typedef Factory<SensorBase,
const std::string&,
const ParamsServer&> AutoConfFactorySensor;
SizeEigen,
const std::string&> FactorySensorYaml;
template<>
inline std::string AutoConfFactorySensor::getClass() const
inline std::string FactorySensor::getClass() const
{
return "AutoConfFactorySensor";
return "FactorySensor";
}
#define WOLF_REGISTER_SENSOR_AUTO(SensorType) \
namespace{ const bool WOLF_UNUSED SensorType##AutoConfRegistered = \
AutoConfFactorySensor::registerCreator(#SensorType, SensorType::create); } \
#define WOLF_REGISTER_SENSOR(SensorType) \
namespace{ const bool WOLF_UNUSED SensorType##Registered = \
FactorySensor::registerCreator(#SensorType, SensorType::create); } \
#define WOLF_REGISTER_SENSOR_YAML(SensorType) \
namespace{ const bool WOLF_UNUSED SensorType##YamlRegistered = \
FactorySensorYaml::registerCreator(#SensorType, SensorType::create); } \
} /* namespace wolf */
Loading