nerian_stereo_node_base.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2019 Nerian Vision GmbH
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *******************************************************************************/
14 
15 #ifndef __NERIAN_STEREO_NODE_H__
16 #define __NERIAN_STEREO_NODE_H__
17 
18 #include <ros/ros.h>
19 #include <visiontransfer/asynctransfer.h>
20 #include <visiontransfer/reconstruct3d.h>
21 #include <sensor_msgs/PointCloud2.h>
22 #include <sensor_msgs/Image.h>
23 #include <opencv2/opencv.hpp>
24 #include <cv_bridge/cv_bridge.h>
25 #include <iostream>
26 #include <iomanip>
27 #include <nerian_stereo/StereoCameraInfo.h>
28 #include <boost/smart_ptr.hpp>
29 #include <colorcoder.h>
30 
31 #include <dynamic_reconfigure/server.h>
32 #include <nerian_stereo/NerianStereoConfig.h>
33 #include <visiontransfer/scenescanparameters.h>
34 #include <visiontransfer/exceptions.h>
35 
36 using namespace std;
37 using namespace visiontransfer;
38 
59 namespace nerian_stereo {
60 
62 public:
63  StereoNodeBase(): initialConfigReceived(false), frameNum(0) {
64  }
65 
67  }
68 
72  void init();
73 
74  /*
75  * \brief Initialize and publish configuration with a dynamic_reconfigure server
76  */
77  void initDynamicReconfigure();
78 
82  void prepareAsyncTransfer();
83 
84  /*
85  * \brief Collect and process a single image pair (or return after timeout if none are available)
86  */
87  void processOneImagePair();
88 
89 private:
94  NONE
95  };
96 
97  virtual ros::NodeHandle& getNH() = 0;
98  virtual ros::NodeHandle& getPrivateNH() = 0;
99 
100  //
101  boost::scoped_ptr<ros::Publisher> cloudPublisher;
102  boost::scoped_ptr<ros::Publisher> disparityPublisher;
103  boost::scoped_ptr<ros::Publisher> leftImagePublisher;
104  boost::scoped_ptr<ros::Publisher> rightImagePublisher;
105  boost::scoped_ptr<ros::Publisher> cameraInfoPublisher;
106 
107  // ROS dynamic_reconfigure
108  boost::scoped_ptr<dynamic_reconfigure::Server<nerian_stereo::NerianStereoConfig>> dynReconfServer;
109  nerian_stereo::NerianStereoConfig lastKnownConfig;
111 
112  // Connection to parameter server on device
113  boost::scoped_ptr<SceneScanParameters> sceneScanParameters;
114 
115  // Parameters
116  bool useTcp;
117  std::string colorCodeDispMap;
121  std::string remotePort;
122  std::string frame;
123  std::string remoteHost;
124  std::string calibFile;
125  double execDelay;
126  double maxDepth;
129 
130  // Other members
131  int frameNum;
132  boost::scoped_ptr<Reconstruct3D> recon3d;
133  boost::scoped_ptr<ColorCoder> colCoder;
134  cv::Mat_<cv::Vec3b> colDispMap;
135  sensor_msgs::PointCloud2Ptr pointCloudMsg;
136  cv::FileStorage calibStorage;
137  nerian_stereo::StereoCameraInfoPtr camInfoMsg;
139 
140  boost::scoped_ptr<AsyncTransfer> asyncTransfer;
142  int lastLogFrames = 0;
143 
147  void loadCameraCalibration();
148 
153  void publishImageMsg(const ImagePair& imagePair, int imageIndex, ros::Time stamp, bool allowColorCode,
154  ros::Publisher* publisher);
155 
160  void qMatrixToRosCoords(const float* src, float* dst);
161 
166  void publishPointCloudMsg(ImagePair& imagePair, ros::Time stamp);
167 
171  template <PointCloudColorMode colorMode> void copyPointCloudIntensity(ImagePair& imagePair);
172 
177  template <int coord> void copyPointCloudClamped(float* src, float* dst, int size);
178 
183  void initPointCloud();
184 
188  void publishCameraInfo(ros::Time stamp, const ImagePair& imagePair);
189 
193  template<class T> void readCalibrationArray(const char* key, T& dest);
194 
195  /*
196  * \brief Callback that receives an updated configuration from ROS; internally uses autogen_dynamicReconfigureCallback
197  */
198  void dynamicReconfigureCallback(nerian_stereo::NerianStereoConfig &config, uint32_t level);
199 
200  /*
201  * \brief Forward parameters from the device as initial values to the ROS parameter server; internally uses autogen_updateParameterServerFromDevice
202  */
203  void updateParameterServerFromDevice(std::map<std::string, ParameterInfo>& cfg);
204 
205  /*
206  * \brief Uses parameters from the device as a run-time override for limits and defaults in the dynamic_reconfigure node; internally uses autogen_updateDynamicReconfigureFromDevice
207  */
208  void updateDynamicReconfigureFromDevice(std::map<std::string, ParameterInfo>& cfg);
209 
210 
211  // The following three implementations are autogenerated by generate_nerian_config_cpp.py
212  // by parsing cfg/NerianStereo.cfg (which is also used by dynamic_reconfigure)
216  void autogen_dynamicReconfigureCallback(nerian_stereo::NerianStereoConfig &config, uint32_t level);
220  void autogen_updateParameterServerFromDevice(std::map<std::string, ParameterInfo>& cfg);
224  void autogen_updateDynamicReconfigureFromDevice(std::map<std::string, ParameterInfo>& cfg);
225 
226 };
227 
228 } // namespace
229 
230 #endif
231 
sensor_msgs::PointCloud2Ptr pointCloudMsg
boost::scoped_ptr< dynamic_reconfigure::Server< nerian_stereo::NerianStereoConfig > > dynReconfServer
boost::scoped_ptr< ColorCoder > colCoder
nerian_stereo::StereoCameraInfoPtr camInfoMsg
boost::scoped_ptr< ros::Publisher > rightImagePublisher
boost::scoped_ptr< SceneScanParameters > sceneScanParameters
boost::scoped_ptr< Reconstruct3D > recon3d
boost::scoped_ptr< ros::Publisher > cloudPublisher
boost::scoped_ptr< ros::Publisher > disparityPublisher
A driver node that receives data from SceneScan/SP1 and forwards it to ROS.
boost::scoped_ptr< ros::Publisher > leftImagePublisher
boost::scoped_ptr< ros::Publisher > cameraInfoPublisher
nerian_stereo::NerianStereoConfig lastKnownConfig
boost::scoped_ptr< AsyncTransfer > asyncTransfer


nerian_stereo
Author(s): Nerian Vision Technologies
autogenerated on Thu Jun 20 2019 19:12:46