ed_sensor_integration
fitter.h
Go to the documentation of this file.
1 #ifndef ED_SENSOR_INTEGRATION_FITTER_PLUGIN_H_
2 #define ED_SENSOR_INTEGRATION_FITTER_PLUGIN_H_
3 
4 #include <exception>
5 
6 #include <ed/plugin.h>
7 #include <ed/types.h>
8 
9 #include <geolib/datatypes.h>
10 
11 #include <rgbd/types.h>
12 #include <image_geometry/pinhole_camera_model.h>
13 
14 #include "beam_model.h"
15 
16 // Model loading
17 #include <ed/models/model_loader.h>
18 
19 #include <map>
20 #include <vector>
21 
23 
27 class Candidate;
28 class OptimalFit;
29 struct YawRange;
30 
31 // ----------------------------------------------------------------------------------------------------
32 
37 {
38 public:
40 
41  virtual const char* what() const throw ()
42  {
43  return error_message_.c_str();
44  }
45 private:
47 };
48 
49 // ----------------------------------------------------------------------------------------------------
50 
56 {
57  unsigned int shape_revision;
59 };
60 
61 // ----------------------------------------------------------------------------------------------------
62 
68 struct FitterData
69 {
71  float fx;
75 };
76 
77 // ----------------------------------------------------------------------------------------------------
78 
86 {
93 };
94 
95 // ----------------------------------------------------------------------------------------------------
96 
100 class Fitter
101 {
102 
103 public:
104 
108  Fitter();
109 
115  Fitter(unsigned int nr_data_points, float fx);
116 
121  Fitter(const image_geometry::PinholeCameraModel& cammodel) { configureBeamModel(cammodel); }
122 
123  ~Fitter();
124 
125  inline bool isConfigured() { return configured_; };
126 
134  void processSensorData(const rgbd::Image& image, const geo::Pose3D& sensor_pose, FitterData& data) const;
135 
147  bool estimateEntityPose(const FitterData& data, const ed::WorldModel& world, const ed::UUID& id,
148  const geo::Pose3D& expected_pose, geo::Pose3D& fitted_pose, double max_yaw_change = M_PI) const;
149 
157  std::unique_ptr<OptimalFit> findOptimum(const EstimationInputData& input_data, const YawRange& yaw_range) const;
158 
166 
171  void configureBeamModel(const image_geometry::PinholeCameraModel& cammodel);
172 
173 private:
174 
185  void renderEntity(const ed::EntityConstPtr& e, const geo::Pose3D& sensor_pose_xya, int identifier,
186  std::vector<double>& model_ranges, std::vector<int>& identifiers) const;
187 
200  bool estimateEntityPoseImp(const FitterData& data, const ed::WorldModel& world, const ed::UUID& id,
201  const geo::Pose3D& expected_pose, geo::Pose3D& fitted_pose, double max_yaw_change) const;
202 
213  EstimationInputData preProcessInputData(const ed::WorldModel &world, const ed::UUID &id, const geo::Pose3D &expected_pose, const FitterData &data) const;
214 
220  Shape2D get2DShape(ed::EntityConstPtr entity_ptr) const;
221 
231  void renderWorldModel2D(const ed::WorldModel& world, const geo::Pose3D& sensor_pose_xya, const ed::UUID& skip_id,
232  std::vector<double>& model_ranges, std::vector<int>& identifiers) const;
233 
243  const geo::Pose3D &sensor_pose_xya, const int expected_center_beam) const;
244 
252  bool evaluateCandidate(const EstimationInputData& static_data, Candidate& candidate) const;
253 
254  // Fitting
256 
257  // 2D Entity shapes
259 
260  // Models
262 
264  bool configured_ = false;
265 
266 };
267 
268 #endif
datatypes.h
Fitter::renderEntity
void renderEntity(const ed::EntityConstPtr &e, const geo::Pose3D &sensor_pose_xya, int identifier, std::vector< double > &model_ranges, std::vector< int > &identifiers) const
renderEntity renders the entity in 2D using the beam model with the provided (2D) sensor pose....
Definition: fitter.cpp:548
std::string
Fitter::preProcessInputData
EstimationInputData preProcessInputData(const ed::WorldModel &world, const ed::UUID &id, const geo::Pose3D &expected_pose, const FitterData &data) const
preProcessInputData pre-processes the inputs for the fitting algorithm, i.e., gets the shape of the e...
Definition: fitter.cpp:307
EstimationInputData::shape_center
geo::Vec2 shape_center
Definition: fitter.h:89
exception
Shape2D
std::vector< std::vector< geo::Vec2 > > Shape2D
Definition: fitter.h:22
Fitter::beam_model_
BeamModel beam_model_
Definition: fitter.h:255
vector
FitterData::fx
float fx
Definition: fitter.h:71
EstimationInputData::entity
ed::EntityConstPtr entity
Definition: fitter.h:87
FitterError::FitterError
FitterError(const std::string &msg)
Definition: fitter.h:39
Fitter::~Fitter
~Fitter()
Definition: fitter.cpp:252
EstimationInputData::sensor_ranges
std::vector< double > sensor_ranges
Definition: fitter.h:92
FitterData::sensor_pose_xya
geo::Pose3D sensor_pose_xya
Definition: fitter.h:73
ed::models::ModelLoader
FitterData::sensor_pose
geo::Pose3D sensor_pose
Definition: fitter.h:72
Fitter::nr_data_points_
uint nr_data_points_
Definition: fitter.h:263
FitterError
The FitterError class exception is thrown in case of errors in the fitter algorithm.
Definition: fitter.h:36
EntityRepresentation2D::shape_2d
Shape2D shape_2d
Definition: fitter.h:58
geo::Transform3T
Fitter::estimateEntityPose
bool estimateEntityPose(const FitterData &data, const ed::WorldModel &world, const ed::UUID &id, const geo::Pose3D &expected_pose, geo::Pose3D &fitted_pose, double max_yaw_change=M_PI) const
estimateEntityPose performs the entity pose estimation. Basically, tries to call estimateEntityPoseIm...
Definition: fitter.cpp:258
FitterData
The FitterData struct contains the downprojected (hence 2D) sensor readings as well as the sensor pos...
Definition: fitter.h:68
EntityRepresentation2D
The EntityRepresentation2D struct contains the (downprojected) shape that is used for the fitting.
Definition: fitter.h:55
Fitter::configured_
bool configured_
Definition: fitter.h:264
YawRange
Definition: fitter.cpp:34
EstimationInputData
The EstimationInputData struct contains processed data from the world model (entity,...
Definition: fitter.h:85
Fitter::entity_shapes_
std::map< ed::UUID, EntityRepresentation2D > entity_shapes_
Definition: fitter.h:258
Fitter::checkExpectedBeamThroughEntity
void checkExpectedBeamThroughEntity(const std::vector< double > &model_ranges, ed::EntityConstPtr entity, const geo::Pose3D &sensor_pose_xya, const int expected_center_beam) const
checkExpectedBeamThroughEntity checks if the expected center beam passes through the entity....
Definition: fitter.cpp:458
ed::EntityConstPtr
shared_ptr< const Entity > EntityConstPtr
EntityRepresentation2D::shape_revision
unsigned int shape_revision
Definition: fitter.h:57
Candidate
Definition: fitter.cpp:147
rgbd::Image
Fitter::GetOrCreateEntity2D
EntityRepresentation2D GetOrCreateEntity2D(const ed::EntityConstPtr &e) const
GetOrCreateEntity2D returns the downprojected shape of the entity. If it's already in the cache,...
Definition: fitter.cpp:528
std::string::c_str
T c_str(T... args)
OptimalFit
Definition: fitter.cpp:123
ed::UUID
Fitter::Fitter
Fitter(const image_geometry::PinholeCameraModel &cammodel)
Fitter constructor.
Definition: fitter.h:121
Fitter::findOptimum
std::unique_ptr< OptimalFit > findOptimum(const EstimationInputData &input_data, const YawRange &yaw_range) const
findOptimum finds the 'optimal' fit by evaluating candidates over all beams and over the entire yaw r...
Definition: fitter.cpp:347
map
Fitter::isConfigured
bool isConfigured()
Definition: fitter.h:125
ed::WorldModel
EstimationInputData::model_ranges
std::vector< double > model_ranges
Definition: fitter.h:91
Fitter::get2DShape
Shape2D get2DShape(ed::EntityConstPtr entity_ptr) const
get2DShape gets the downprojected, 2D shape from an entity
Definition: fitter.cpp:417
FitterError::error_message_
std::string error_message_
Definition: fitter.h:46
plugin.h
Fitter::model_loader_
ed::models::ModelLoader model_loader_
Definition: fitter.h:261
beam_model.h
Fitter::configureBeamModel
void configureBeamModel(const image_geometry::PinholeCameraModel &cammodel)
configure the beam model (nr of data points and focal length) according to the camera you are using.
Definition: fitter.cpp:475
Fitter::estimateEntityPoseImp
bool estimateEntityPoseImp(const FitterData &data, const ed::WorldModel &world, const ed::UUID &id, const geo::Pose3D &expected_pose, geo::Pose3D &fitted_pose, double max_yaw_change) const
estimateEntityPoseImp actual implementation of the entity pose estimation. Preprocess input data iter...
Definition: fitter.cpp:274
Fitter::evaluateCandidate
bool evaluateCandidate(const EstimationInputData &static_data, Candidate &candidate) const
evaluateCandidate renders the model, transform the model along the beam direction to get this distanc...
Definition: fitter.cpp:388
EstimationInputData::shape2d_transformed
Shape2D shape2d_transformed
Definition: fitter.h:88
Fitter::processSensorData
void processSensorData(const rgbd::Image &image, const geo::Pose3D &sensor_pose, FitterData &data) const
processSensorData pre-processes sensor data, i.e., performs a downprojection of the input depth image...
Definition: fitter.cpp:486
Fitter
The Fitter class contains the algorithm to do the 2D fit of an entity.
Definition: fitter.h:100
FitterData::sensor_pose_zrp
geo::Pose3D sensor_pose_zrp
Definition: fitter.h:74
FitterError::what
virtual const char * what() const
Definition: fitter.h:41
EstimationInputData::expected_center_beam
int expected_center_beam
Definition: fitter.h:90
Fitter::renderWorldModel2D
void renderWorldModel2D(const ed::WorldModel &world, const geo::Pose3D &sensor_pose_xya, const ed::UUID &skip_id, std::vector< double > &model_ranges, std::vector< int > &identifiers) const
renderWorldModel2D renders all world model entities
Definition: fitter.cpp:431
types.h
std::unique_ptr
model_loader.h
geo::Vec2T
Fitter::Fitter
Fitter()
Fitter default constructor, must be configured later.
Definition: fitter.cpp:235
FitterData::sensor_ranges
std::vector< double > sensor_ranges
Definition: fitter.h:70
BeamModel
Definition: beam_model.h:8