depth_map_preprocessing
ConverterBase.hpp
Go to the documentation of this file.
1 /* Generated from orogen/lib/orogen/templates/tasks/Task.hpp */
2 
3 #ifndef DEPTH_MAP_PREPROCESSING_CONVERTERBASE_TASK_HPP
4 #define DEPTH_MAP_PREPROCESSING_CONVERTERBASE_TASK_HPP
5 
6 #include "depth_map_preprocessing/ConverterBaseBase.hpp"
7 #include <depth_map_preprocessing/PointCloudConversion.hpp>
8 
9 #include <Eigen/StdVector>
10 
12 
27  class ConverterBase : public ConverterBaseBase
28  {
29  friend class ConverterBaseBase;
30  protected:
31 
33  {
34  base::Time sample_time_id;
35  PointCloudConversion::TransformationVector laser_in_odometry;
36 
37  SampleTransforms(const base::Time& sample_time_id) : sample_time_id(sample_time_id) {}
38 
39  void clear()
40  {
41  sample_time_id.microseconds = 0;
42  laser_in_odometry.clear();
43  }
44  };
45 
50  virtual void newSampleCallback(const base::Time &ts, const base::samples::DepthMap &depth_map_sample) = 0;
51 
55  virtual void depth_mapAcquisitionTimeTransformerCallback(const base::Time &ts, const base::Time &depth_map_sample_start);
56 
61  virtual void depth_mapTransformerCallback(const base::Time &ts, const base::samples::DepthMap &depth_map_sample);
62 
66  virtual void pullPorts();
67 
71  template<class T>
72  bool convertToPointCloud(const base::Time &ts, const base::samples::DepthMap &depth_map_sample,
73  std::vector<T>& pointcloud);
74 
80 
84  template<class ElementIterator>
85  void pushDepthMapTimestamps(ElementIterator it_first, ElementIterator it_last, const base::samples::DepthMap &depth_map_sample);
86 
87  protected:
88 
90  std::list<SampleTransforms> depth_map_acquisition_transforms;
91  MotionCompensation motion_compensation;
93 
94  public:
99  ConverterBase(std::string const& name = "depth_map_preprocessing::ConverterBase");
100 
106  ConverterBase(std::string const& name, RTT::ExecutionEngine* engine);
107 
110  ~ConverterBase();
111 
126  bool configureHook();
127 
133  bool startHook();
134 
149  void updateHook();
150 
157  void errorHook();
158 
162  void stopHook();
163 
168  void cleanupHook();
169  };
170 
171 
172 template<class T>
173 bool ConverterBase::convertToPointCloud(const base::Time &ts, const base::samples::DepthMap &depth_map_sample,
174  std::vector<T>& pointcloud)
175 {
176  if(motion_compensation == NoCompensation)
177  {
178  depth_map_sample.convertDepthMapToPointCloud(pointcloud, true);
179  return true;
180  }
181 
182  // drop older acquisition transforms sets
183  std::list<SampleTransforms>::iterator acquisition_transforms = depth_map_acquisition_transforms.begin();
184  while(acquisition_transforms->sample_time_id < depth_map_sample.time && depth_map_acquisition_transforms.size() > 1)
185  acquisition_transforms = depth_map_acquisition_transforms.erase(acquisition_transforms);
186 
187  // check if acquisition transforms are the right ones
188  if(acquisition_transforms->sample_time_id == depth_map_sample.time)
189  {
190  // convert scan to pointcloud with motion compensation
191  Eigen::Affine3d depth_map_end_transform;
192  if(_laser2odometry.get(ts, depth_map_end_transform, true))
193  {
194  acquisition_transforms->laser_in_odometry.push_back(depth_map_end_transform);
195  return PointCloudConversion::convertToPointCloud(depth_map_sample, acquisition_transforms->laser_in_odometry,
196  motion_compensation, pointcloud);
197  }
198  }
199  else
200  LOG_DEBUG_S << "No acquisition transforms for the current sample available!";
201 
202  LOG_ERROR_S << "Failed to convert depth map to point cloud, missing scan acquisition transformations!";
203  return false;
204 }
205 
206 template<class ElementIterator>
207 void ConverterBase::pushDepthMapTimestamps(ElementIterator it_first, ElementIterator it_last, const base::samples::DepthMap& depth_map_sample)
208 {
209  for(;it_first != it_last; it_first++)
210  _transformer.pushData(depth_map_acquisition_times_idx_tr, *it_first, depth_map_sample.time);
211  _transformer.pushData(depth_map_idx_tr, *it_last, depth_map_sample);
212 }
213 
214 }
215 
216 #endif
std::list< SampleTransforms > depth_map_acquisition_transforms
Definition: ConverterBase.hpp:90
void clear()
Definition: ConverterBase.hpp:39
PointCloudConversion::TransformationVector laser_in_odometry
Definition: ConverterBase.hpp:35
friend class ConverterBaseBase
Definition: ConverterBase.hpp:29
The task context provides and requires services. It uses an ExecutionEngine to perform its functions...
Definition: ConverterBase.hpp:27
MotionCompensation motion_compensation
Definition: ConverterBase.hpp:91
void updateHook()
Definition: ConverterBase.cpp:125
Definition: ConverterBase.hpp:11
void pushDepthMapTimestamps(ElementIterator it_first, ElementIterator it_last, const base::samples::DepthMap &depth_map_sample)
Definition: ConverterBase.hpp:207
virtual void newSampleCallback(const base::Time &ts, const base::samples::DepthMap &depth_map_sample)=0
bool startHook()
Definition: ConverterBase.cpp:118
~ConverterBase()
Definition: ConverterBase.cpp:17
void stopHook()
Definition: ConverterBase.cpp:133
base::Time sample_time_id
Definition: ConverterBase.hpp:34
void registerAcquisitionTimeStream()
Definition: ConverterBase.cpp:83
bool configureHook()
The following lines are template definitions for the various state machine.
Definition: ConverterBase.cpp:105
void cleanupHook()
Definition: ConverterBase.cpp:137
bool convertToPointCloud(const base::Time &ts, const base::samples::DepthMap &depth_map_sample, std::vector< T > &pointcloud)
Definition: ConverterBase.hpp:173
SampleTransforms(const base::Time &sample_time_id)
Definition: ConverterBase.hpp:37
virtual void pullPorts()
Definition: ConverterBase.cpp:46
void errorHook()
Definition: ConverterBase.cpp:129
virtual void depth_mapTransformerCallback(const base::Time &ts, const base::samples::DepthMap &depth_map_sample)
Definition: ConverterBase.cpp:41
unsigned acquisition_timestamps
Definition: ConverterBase.hpp:92
virtual void depth_mapAcquisitionTimeTransformerCallback(const base::Time &ts, const base::Time &depth_map_sample_start)
Definition: ConverterBase.cpp:21
int depth_map_acquisition_times_idx_tr
Definition: ConverterBase.hpp:89
ConverterBase(std::string const &name="depth_map_preprocessing::ConverterBase")
Definition: ConverterBase.cpp:7