nxLibHelpers.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "nxLib.h"
4 #include "pose_utilities.h"
5 
7 #include <boost/optional.hpp>
8 #include <string>
9 #include <vector>
10 
14 bool checkNxLibVersion(int major, int minor)
15 {
16  int nxLibMajor = NxLibItem()[itmVersion][itmMajor].asInt();
17  int nxLibMinor = NxLibItem()[itmVersion][itmMinor].asInt();
18  return (nxLibMajor > major) || (nxLibMajor == major && nxLibMinor >= minor);
19 }
20 
22 {
23 protected:
24  bool useOpenGL;
25 
26 public:
27  explicit RenderPointMapParams(bool _useOpenGl) : useOpenGL(_useOpenGl){};
28  virtual bool useOpenGl() const
29  {
30  return useOpenGL;
31  };
32 
33  virtual boost::optional<int> pixelScale() const
34  {
35  return {};
36  }
37 
38  virtual boost::optional<double> scaling() const
39  {
40  return {};
41  }
42 
43  virtual boost::optional<int> sizeWidth() const
44  {
45  return {};
46  }
47 
48  virtual boost::optional<int> sizeHeight() const
49  {
50  return {};
51  }
52 
53  virtual boost::optional<double> far() const
54  {
55  return {};
56  }
57 
58  virtual boost::optional<double> near() const
59  {
60  return {};
61  }
62 
63  virtual boost::optional<bool> withTexture() const
64  {
65  return {};
66  }
67 
68  virtual boost::optional<tf2::Transform const&> viewPose() const
69  {
70  return {};
71  }
72 };
73 
75 {
76 private:
78  double mScaling;
82 
83 public:
85  tf2::Transform const& viewPose)
86  : RenderPointMapParams(useOpenGl)
87  , mPixelScale(pixelScale)
88  , mScaling(scaling)
89  , mSizeWidth(sizeWidth)
90  , mSizeHeight(sizeHeight)
91  , mViewPose(viewPose){};
92 
93  boost::optional<int> pixelScale() const override
94  {
95  return mPixelScale;
96  }
97 
98  boost::optional<double> scaling() const override
99  {
100  return mScaling;
101  }
102 
103  boost::optional<int> sizeWidth() const override
104  {
105  return mSizeWidth;
106  }
107 
108  boost::optional<int> sizeHeight() const override
109  {
110  return mSizeHeight;
111  }
112 
113  boost::optional<tf2::Transform const&> viewPose() const override
114  {
115  if (!isValid(mViewPose))
116  {
117  return {};
118  }
119  return mViewPose;
120  }
121 };
122 
124 {
125 private:
126  double mFar, mNear;
128 
129 public:
131  : RenderPointMapParams(useOpenGL), mFar(far), mNear(near), mWithTexture(withTexture){};
132 
133  boost::optional<double> far() const override
134  {
135  return mFar;
136  }
137 
138  boost::optional<double> near() const override
139  {
140  return mNear;
141  }
142 
143  boost::optional<bool> withTexture() const override
144  {
145  return mWithTexture;
146  }
147 };
148 
149 void setRenderParams(NxLibItem const& paramItem, RenderPointMapParams const* params)
150 {
151  paramItem[itmUseOpenGL] = params->useOpenGl();
152  if (params->pixelScale())
153  {
154  paramItem[itmPixelSize] = *params->pixelScale();
155  }
156  if (params->scaling())
157  {
158  paramItem[itmScaling] = *params->scaling();
159  }
160  if (params->withTexture())
161  {
162  paramItem[itmTexture] = *params->withTexture();
163  }
164  if (params->sizeWidth())
165  {
166  paramItem[itmSize][0] = *params->sizeWidth();
167  }
168  if (params->sizeHeight())
169  {
170  paramItem[itmSize][1] = *params->sizeHeight();
171  }
172  if (params->viewPose())
173  {
174  writePoseToNxLib(*params->viewPose(), paramItem[itmViewPose]);
175  }
176 }
177 
178 inline void rosWarnOnceAboutDeprSDKVersion(std::string const& notSupportedMsg, VersionInfo const& version)
179 {
180  ROS_WARN_ONCE("This EnsensoSDK Version does not support: %s. Version used: %i.%i.%i", notSupportedMsg.c_str(),
181  version.majorV, version.minorV, version.buildV);
182 }
183 
184 pcl::PointCloud<pcl::PointXYZ>::Ptr retrieveRenderedPointCloud(NxLibItem const& cmdResult,
185  VersionInfo const& nxLibVersion,
186  std::string const& frame)
187 {
188  // Because the Ensenso SDK 2.2.x has its Rendered Point Maps in a global image node, we try to get the rendered point
189  // cloud from this image node. Of course this is NOT Multi Threading friendly.
190  if (nxLibVersion.majorV == 2 && nxLibVersion.minorV <= 2)
191  {
192  rosWarnOnceAboutDeprSDKVersion("Multi threaded Rendering of Point map", nxLibVersion);
193  auto const& globalResults = NxLibItem()[itmImages];
194  return pointCloudFromNxLib(globalResults[itmRenderPointMap], frame);
195  }
196 
197  return pointCloudFromNxLib(cmdResult[itmImages][itmRenderPointMap], frame);
198 }
199 
200 pcl::PointCloud<pcl::PointXYZRGB>::Ptr retrieveTexturedPointCloud(NxLibItem const& cmdResult,
201  VersionInfo const& nxLibVersion,
202  std::string const& targetFrame)
203 {
204  if (nxLibVersion.majorV == 2 && nxLibVersion.minorV <= 2)
205  {
206  rosWarnOnceAboutDeprSDKVersion("Multi threaded Rendering of Point map", nxLibVersion);
207  auto const& globalResults = NxLibItem()[itmImages];
208  return pointCloudTexturedFromNxLib(globalResults[itmRenderPointMapTexture], globalResults[itmRenderPointMap],
209  targetFrame);
210  }
211 
212  return pointCloudTexturedFromNxLib(cmdResult[itmImages][itmRenderPointMapTexture],
213  cmdResult[itmImages][itmRenderPointMap], targetFrame);
214 }
215 
216 NxLibItem retrieveResultPath(NxLibItem const& cmdResult, VersionInfo const& nxLibVersion)
217 {
218  if (nxLibVersion.majorV == 2 && nxLibVersion.minorV <= 2)
219  {
220  return NxLibItem()[itmImages][itmRenderPointMap];
221  }
222 
223  return cmdResult[itmImages][itmRenderPointMap];
224 }
225 
226 sensor_msgs::ImagePtr retrieveRenderedDepthMap(NxLibItem const& cmdResult, VersionInfo const& nxLibVersion,
227  std::string const& frame)
228 {
229  sensor_msgs::ImagePtr renderedImage;
230  if (nxLibVersion.majorV == 2 && nxLibVersion.minorV <= 2)
231  {
232  rosWarnOnceAboutDeprSDKVersion("Multi threaded Rendering of Point map", nxLibVersion);
233  auto const& globalResults = NxLibItem()[itmImages];
234  return depthImageFromNxLibNode(globalResults[itmRenderPointMap], frame);
235  }
236 
237  return depthImageFromNxLibNode(cmdResult[itmImages][itmRenderPointMap], frame);
238 }
239 
240 void setRenderParams(NxLibItem const& cmdParams, VersionInfo const& nxLibVersion, RenderPointMapParams const* params)
241 {
242  // Some Parameters are set in the global parameters node in 2.2.x. That is why we have to split the params
243  // correspondingly to the global and the command parameter node.
244  if (nxLibVersion.majorV == 2 && nxLibVersion.minorV <= 2)
245  {
246  rosWarnOnceAboutDeprSDKVersion("Multi threaded Rendering of Point map", nxLibVersion);
247  auto globalParams = NxLibItem()[itmParameters][itmRenderPointMap];
248  setRenderParams(globalParams, params);
249  }
250  else
251  {
252  setRenderParams(cmdParams, params);
253  }
254  // Some parameters are both in the cmd Parameters and the global parameter node
255  if (params->far())
256  {
257  cmdParams[itmFar] = *params->far();
258  }
259  if (params->near())
260  {
261  cmdParams[itmNear] = *params->near();
262  }
263 }
void rosWarnOnceAboutDeprSDKVersion(std::string const &notSupportedMsg, VersionInfo const &version)
Definition: nxLibHelpers.h:178
boost::optional< bool > withTexture() const override
Definition: nxLibHelpers.h:143
boost::optional< double > scaling() const override
Definition: nxLibHelpers.h:98
virtual boost::optional< int > sizeHeight() const
Definition: nxLibHelpers.h:48
sensor_msgs::ImagePtr retrieveRenderedDepthMap(NxLibItem const &cmdResult, VersionInfo const &nxLibVersion, std::string const &frame)
Definition: nxLibHelpers.h:226
boost::optional< double > near() const override
Definition: nxLibHelpers.h:138
RenderPointMapParams(bool _useOpenGl)
Definition: nxLibHelpers.h:27
pcl::PointCloud< pcl::PointXYZ >::Ptr pointCloudFromNxLib(NxLibItem const &node, std::string const &frame, PointCloudROI const *roi=nullptr)
pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointCloudTexturedFromNxLib(NxLibItem const &imageNode, NxLibItem const &pointsNode, std::string const &frame, PointCloudROI const *roi=nullptr)
virtual boost::optional< tf2::Transform const & > viewPose() const
Definition: nxLibHelpers.h:68
virtual boost::optional< bool > withTexture() const
Definition: nxLibHelpers.h:63
boost::optional< double > far() const override
Definition: nxLibHelpers.h:133
virtual bool useOpenGl() const
Definition: nxLibHelpers.h:28
void writePoseToNxLib(tf2::Transform const &pose, NxLibItem const &node)
boost::optional< int > sizeHeight() const override
Definition: nxLibHelpers.h:108
bool checkNxLibVersion(int major, int minor)
Definition: nxLibHelpers.h:14
virtual boost::optional< int > sizeWidth() const
Definition: nxLibHelpers.h:43
#define ROS_WARN_ONCE(...)
virtual boost::optional< int > pixelScale() const
Definition: nxLibHelpers.h:33
bool isValid(tf2::Transform const &pose)
pcl::PointCloud< pcl::PointXYZ >::Ptr retrieveRenderedPointCloud(NxLibItem const &cmdResult, VersionInfo const &nxLibVersion, std::string const &frame)
Definition: nxLibHelpers.h:184
virtual boost::optional< double > scaling() const
Definition: nxLibHelpers.h:38
boost::optional< tf2::Transform const & > viewPose() const override
Definition: nxLibHelpers.h:113
sensor_msgs::ImagePtr depthImageFromNxLibNode(NxLibItem const &node, std::string const &frame)
NxLibItem retrieveResultPath(NxLibItem const &cmdResult, VersionInfo const &nxLibVersion)
Definition: nxLibHelpers.h:216
void setRenderParams(NxLibItem const &paramItem, RenderPointMapParams const *params)
Definition: nxLibHelpers.h:149
boost::optional< int > pixelScale() const override
Definition: nxLibHelpers.h:93
virtual boost::optional< double > far() const
Definition: nxLibHelpers.h:53
RenderPointMapParamsTelecentric(bool useOpenGl, int pixelScale, double scaling, int sizeWidth, int sizeHeight, tf2::Transform const &viewPose)
Definition: nxLibHelpers.h:84
pcl::PointCloud< pcl::PointXYZRGB >::Ptr retrieveTexturedPointCloud(NxLibItem const &cmdResult, VersionInfo const &nxLibVersion, std::string const &targetFrame)
Definition: nxLibHelpers.h:200
RenderPointMapParamsProjection(bool useOpenGL, double far, double near, bool withTexture)
Definition: nxLibHelpers.h:130
virtual boost::optional< double > near() const
Definition: nxLibHelpers.h:58
boost::optional< int > sizeWidth() const override
Definition: nxLibHelpers.h:103


ensenso_camera
Author(s): Ensenso
autogenerated on Thu May 6 2021 02:50:06