DepthImageProviderDynamicSimulation.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2013-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author Raphael Grimm
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
26 
27 #include <Eigen/Geometry>
28 
29 #include <pcl/common/transforms.h>
30 #include <pcl/compression/organized_pointcloud_conversion.h>
31 
32 #include <SimoxUtility/math/convert/deg_to_rad.h>
33 #include <VirtualRobot/Nodes/RobotNode.h>
34 #include <VirtualRobot/Visualization/CoinVisualization/CoinVisualizationFactory.h>
35 
37 
40 
41 #include <Inventor/SoInteraction.h>
42 #include <Inventor/actions/SoGLRenderAction.h>
43 
44 namespace armarx
45 {
46 
49  visionx::CapturingPointCloudProviderPropertyDefinitions(prefix)
50  {
51  defineOptionalProperty<bool>(
52  "FloatImageMode", false, "Whether to provide a CFloatImage or the standard CByteImage");
53  defineOptionalProperty<float>("Noise",
54  0.0f,
55  "Noise of the point cloud position results as standard "
56  "deviation of the normal distribution (in mm)")
57  .setMin(0);
58  defineOptionalProperty<float>("DistanceZNear",
59  20.0f,
60  "Distance of the near clipping plain. (If set too small "
61  "the agent's model's inside may be visible")
62  .setMin(1e-8);
63  defineOptionalProperty<float>(
64  "DistanceZFar",
65  5000.0f,
66  "Distance of the far clipping plain. (DistanceZFar-DistanceZNear should be "
67  "minimal, DistanceZFar > DistanceZNear)")
68  .setMin(1e-8);
69  defineOptionalProperty<float>(
70  "FieldOfView", 90, "Vertical field of view (FOV) in degrees.");
71  defineOptionalProperty<float>(
72  "BaseLine", 0.075, "The value returned from getBaseline(). It has no other effect.");
73  defineOptionalProperty<float>("NanValue",
74  std::nan(""),
75  "Value of points that are farther away than DistanceZFar. "
76  "Most cameras return NaN here.");
77 
78  defineOptionalProperty<visionx::ImageDimension>(
79  "ImageSize",
80  visionx::ImageDimension(640, 480),
81  "Target resolution of the images. Captured images will be converted to this size.")
82  .setCaseInsensitive(true)
83  .map("200x200", visionx::ImageDimension(200, 200))
84  .map("320x240", visionx::ImageDimension(320, 240))
85  .map("640x480", visionx::ImageDimension(640, 480))
86  .map("800x600", visionx::ImageDimension(800, 600))
87  .map("768x576", visionx::ImageDimension(768, 576))
88  .map("1024x768", visionx::ImageDimension(1024, 768))
89  .map("1280x960", visionx::ImageDimension(1280, 960))
90  .map("1600x1200", visionx::ImageDimension(1600, 1200))
91  .map("1920x1080", visionx::ImageDimension(1920, 1080))
92  .map("none", visionx::ImageDimension(0, 0));
93  defineOptionalProperty<std::string>("RobotName", "Armar3", "The robot's name.");
94  defineOptionalProperty<std::string>(
95  "RobotNodeCamera", "DepthCameraSim", "The coordinate system of the used camera");
96 
97  //used to draw the cloud to the simulator
98  defineOptionalProperty<bool>(
99  "DrawPointCloud",
100  false,
101  "Whether the point cloud is drawn to the given DebugDrawerTopic");
102  defineOptionalProperty<std::string>("DrawPointCloud_DebugDrawerTopic",
103  "DebugDrawerUpdates",
104  "Name of the DebugDrawerTopic");
105  defineOptionalProperty<unsigned int>(
106  "DrawPointCloud_DrawDelay",
107  1000,
108  "The time between updates of the drawn point cloud (in ms)");
109  defineOptionalProperty<float>("DrawPointCloud_PointSize", 4, "The size of a point.");
110  defineOptionalProperty<std::size_t>(
111  "DrawPointCloud_PointSkip",
112  3,
113  "Only draw every n'th point in x and y direction (n=DrawPointCloud_PointSkip). "
114  "Increase this whenever the ice buffer size is to small to transmitt the cloud "
115  "size. (>0)");
116 
117  defineOptionalProperty<bool>(
118  "DrawPointCloud_ClipPoints",
119  true,
120  "Whether to clip the point cloud drawn to the given DebugDrawerTopic");
121 
122  defineOptionalProperty<float>(
123  "DrawPointCloud_ClipXHi", 25000, "Skip points with x higher than this limit.");
124  defineOptionalProperty<float>(
125  "DrawPointCloud_ClipYHi", 25000, "Skip points with y higher than this limit.");
126  defineOptionalProperty<float>(
127  "DrawPointCloud_ClipZHi", 25000, "Skip points with z higher than this limit.");
128 
129  defineOptionalProperty<float>(
130  "DrawPointCloud_ClipXLo", -25000, "Skip points with x lower than this limit.");
131  defineOptionalProperty<float>(
132  "DrawPointCloud_ClipYLo", -25000, "Skip points with y lower than this limit.");
133  defineOptionalProperty<float>(
134  "DrawPointCloud_ClipZLo", -25000, "Skip points with z lower than this limit.");
135  }
136 
137  void
139  {
140  ARMARX_TRACE;
141  ARMARX_VERBOSE_S << "DepthImageProviderDynamicSimulation::onInitComponent";
142  baseline = getProperty<float>("BaseLine").getValue();
143  robotName = getProperty<std::string>("RobotName").getValue();
144  camNodeName = getProperty<std::string>("RobotNodeCamera").getValue();
145 
146  zNear = getProperty<float>("DistanceZNear").getValue();
147  zFar = getProperty<float>("DistanceZFar").getValue();
148  vertFov = simox::math::deg_to_rad(getProperty<float>("FieldOfView").getValue());
149  nanValue = getProperty<float>("NanValue").getValue();
150 
151  floatImageMode = getProperty<bool>("FloatImageMode").getValue();
152 
153  drawPointCloud = getProperty<bool>("DrawPointCloud").getValue();
154  if (drawPointCloud)
155  {
156  lastUpdate = std::chrono::high_resolution_clock::now() -
157  std::chrono::seconds{pointCloudDrawDelay};
159  getProperty<std::string>("DrawPointCloud_DebugDrawerTopic").getValue();
161  pointCloudDrawDelay = getProperty<unsigned int>("DrawPointCloud_DrawDelay").getValue();
162  pointCloudPointSize = getProperty<float>("DrawPointCloud_PointSize").getValue();
163 
164  pointSkip = getProperty<std::size_t>("DrawPointCloud_PointSkip").getValue();
165 
166  clipDrawnCloudXLo = getProperty<float>("DrawPointCloud_ClipXLo").getValue();
167  clipDrawnCloudYLo = getProperty<float>("DrawPointCloud_ClipYLo").getValue();
168  clipDrawnCloudZLo = getProperty<float>("DrawPointCloud_ClipZLo").getValue();
169 
170  clipDrawnCloudXHi = getProperty<float>("DrawPointCloud_ClipXHi").getValue();
171  clipDrawnCloudYHi = getProperty<float>("DrawPointCloud_ClipYHi").getValue();
172  clipDrawnCloudZHi = getProperty<float>("DrawPointCloud_ClipZHi").getValue();
173 
174  clipPointCloud = getProperty<bool>("DrawPointCloud_ClipPoints").getValue();
175  }
176  noise = getProperty<float>("Noise").getValue();
177  if (noise > 0)
178  {
179  distribution = std::normal_distribution<double>(0, noise);
180  randValues.resize(1000, 0);
181  for (float& val : randValues)
182  {
183  val = distribution(generator);
184  }
185  }
186 
187  ImageProvider::onInitComponent();
188  CapturingPointCloudProvider::onInitComponent();
189  ARMARX_VERBOSE_S << "done DepthImageProviderDynamicSimulation::onInitComponent";
190  }
191 
192  void
194  {
195  ARMARX_TRACE;
196  ARMARX_VERBOSE_S << "DepthImageProviderDynamicSimulation::onConnectComponent";
197 
198  if (drawPointCloud)
199  {
200  debugDrawer = getTopic<DebugDrawerInterfacePrx>(debugDrawerTopicName);
201  }
202 
203  ImageProvider::onConnectComponent();
204  CapturingPointCloudProvider::onConnectComponent();
205  ARMARX_VERBOSE_S << "done DepthImageProviderDynamicSimulation::onConnectComponent";
206  }
207 
208  void
210  {
211  ARMARX_VERBOSE_S << "DepthImageProviderDynamicSimulation::onExitComponent";
212  CapturingPointCloudProvider::onExitComponent();
213  ImageProvider::onExitComponent();
214  ARMARX_VERBOSE_S << "done DepthImageProviderDynamicSimulation::onExitComponent";
215  }
216 
217  void
219  {
220  ARMARX_TRACE;
221  ARMARX_INFO << "DepthImageProviderDynamicSimulation::onStartCapture";
222  // ensure that all data is loaded
223  while (!simVisu || !simVisu->getRobot(robotName))
224  {
225  if (simVisu)
226  {
227  ARMARX_TRACE;
228  simVisu->synchronizeVisualizationData();
229  }
230  usleep(100000);
231  ARMARX_INFO << deactivateSpam(3) << "Waiting for visu";
232  }
233  syncVisu();
234  ARMARX_INFO << "Got visu";
235 
236  ARMARX_TRACE;
237  std::unique_lock lock(captureMutex);
238  auto l = simVisu->getScopedLock();
239 
240  // some checks...
241  ARMARX_TRACE;
242  offscreenRenderer.reset(
243  VirtualRobot::CoinVisualizationFactory::createOffscreenRenderer(width, height));
244  ARMARX_INFO << "done DepthImageProviderDynamicSimulation::onStartCapture";
245  }
246 
247  void
249  {
250  }
251 
253  {
254  }
255 
256  std::string
258  {
259  return "DynamicSimulationDepthImageProvider";
260  }
261 
262  bool
264  {
265  return true;
266  }
267 
268  visionx::StereoCalibration
270  {
271  visionx::StereoCalibration stereoCalibration;
272 
273  float r = static_cast<float>(width) / static_cast<float>(height);
274 
275  visionx::CameraParameters RGBCameraIntrinsics;
276  RGBCameraIntrinsics.distortion = {0, 0, 0, 0};
277  RGBCameraIntrinsics.focalLength = {
278  static_cast<float>(width) / (2 * std::tan((vertFov * r) / 2)),
279  static_cast<float>(height) / (2 * std::tan(vertFov / 2))};
280  RGBCameraIntrinsics.height = height;
281  RGBCameraIntrinsics.principalPoint = {width / 2.0f, height / 2.0f};
282  RGBCameraIntrinsics.rotation =
284  RGBCameraIntrinsics.translation =
285  visionx::tools::convertEigenVecToVisionX(Eigen::Vector3f::Zero());
286  RGBCameraIntrinsics.width = width;
287 
288  visionx::CameraParameters DepthCameraIntrinsics;
289  DepthCameraIntrinsics.distortion = {0, 0, 0, 0};
290  DepthCameraIntrinsics.focalLength = {
291  static_cast<float>(width) / (2 * std::tan((vertFov * r) / 2)),
292  static_cast<float>(height) / (2 * std::tan(vertFov / 2))};
293  DepthCameraIntrinsics.height = height;
294  DepthCameraIntrinsics.principalPoint = {width / 2.0f, height / 2.0f};
295  DepthCameraIntrinsics.rotation =
297  DepthCameraIntrinsics.translation = {0.075, 0, 0};
298  DepthCameraIntrinsics.width = width;
299 
300 
301  stereoCalibration.calibrationLeft = visionx::tools::createDefaultMonocularCalibration();
302  stereoCalibration.calibrationRight = visionx::tools::createDefaultMonocularCalibration();
303  stereoCalibration.calibrationLeft.cameraParam = RGBCameraIntrinsics;
304  stereoCalibration.calibrationRight.cameraParam = DepthCameraIntrinsics;
305  stereoCalibration.rectificationHomographyLeft =
306  visionx::tools::convertEigenMatToVisionX(Eigen::Matrix3f::Zero());
307  stereoCalibration.rectificationHomographyRight =
308  visionx::tools::convertEigenMatToVisionX(Eigen::Matrix3f::Zero());
309 
310 
311  return stereoCalibration;
312  }
313 
314  bool
316  {
317  return true;
318  }
319 
320  std::string
322  {
323  return getProperty<std::string>("RobotNodeCamera");
324  }
325 
326  void
328  {
329  }
330 
331  void
333  {
334  ARMARX_TRACE;
335  rgbImage.reset();
336  dImage.reset();
337  dFloatImage.reset();
338  imgPtr[0] = nullptr;
339  imgPtr[1] = nullptr;
340  imgPtrFlt[0] = nullptr;
341 
342  if (simVisu)
343  {
344  simVisu->releaseResources();
345  getArmarXManager()->removeObjectBlocking(simVisu);
346  }
347  simVisu = nullptr;
348  cameraNode = nullptr;
349  visualization = nullptr;
350 
351  offscreenRenderer.reset();
352 
353  SoDB::finish();
354  }
355 
356  void
358  {
359  ARMARX_TRACE;
360  ARMARX_VERBOSE_S << "DepthImageProviderDynamicSimulation::onInitImageProvider";
361 
362  const auto imgSz = getProperty<visionx::ImageDimension>("ImageSize").getValue();
363  height = imgSz.height;
364  width = imgSz.width;
365 
366  if (!floatImageMode)
367  {
368  setImageFormat(visionx::ImageDimension(imgSz), visionx::eRgb);
369  setNumberImages(2);
370 
371  rgbImage.reset(new CByteImage{
372  static_cast<int>(width), static_cast<int>(height), CByteImage::eRGB24});
373  dImage.reset(new CByteImage{
374  static_cast<int>(width), static_cast<int>(height), CByteImage::eRGB24});
375  imgPtr[0] = rgbImage.get();
376  imgPtr[1] = dImage.get();
377  }
378  else
379  {
380  setImageFormat(visionx::ImageDimension(imgSz), visionx::eFloat1Channel);
381  setNumberImages(1);
382 
383  dFloatImage.reset(
384  new CFloatImage{static_cast<int>(width), static_cast<int>(height), 1});
385  imgPtrFlt[0] = dFloatImage.get();
386  }
387 
388 
389  pointcloud.reset(new pcl::PointCloud<PointT>{static_cast<unsigned int>(width),
390  static_cast<unsigned int>(height)});
391 
392  rgbBuffer.resize(width * height);
393  depthBuffer.resize(width * height);
394  pointCloudBuffer.resize(width * height);
395 
396  // init SoDB / Coin3D
397  SoDB::init();
398 
399  VirtualRobot::init(getName());
400 
401  // needed for SoSelection
402  SoInteraction::init();
403 
404  std::stringstream svName;
405  svName << getName() << "_PhysicsWorldVisualization";
406  simVisu = Component::create<ArmarXPhysicsWorldVisualization>(
407  getIceProperties(), getName() + "_PhysicsWorldVisualization");
408  getArmarXManager()->addObject(simVisu);
409  ARMARX_VERBOSE_S << "done DepthImageProviderDynamicSimulation::onInitImageProvider";
410 
411  renderTimesCount = 0;
412  sumRenderTimes = 0;
414  }
415 
416  void
418  {
419  ARMARX_TRACE;
420  ImageProvider::onDisconnectComponent();
421  CapturingPointCloudProvider::onDisconnectComponent();
422  }
423 
424  void
426  {
427  }
428 
431  {
433  }
434 
435  bool
437  {
438  ARMARX_TRACE;
439  bool succeeded = true;
440  Ice::Long timestamp;
441  try
442  {
443  timestamp = TimeUtil::HasTimeServer() ? simVisu->getSyncTimestamp()
444  : IceUtil::Time::now().toMicroSeconds();
445  syncVisu();
446  if (!visualization || !visualization)
447  {
448  return false;
449  }
450  succeeded = render();
451  }
452  catch (...)
453  {
455  succeeded = false;
456  }
457 
458  if (succeeded)
459  {
461  // rotate to conform to ArmarX standards
462  rotate.block(0, 0, 3, 3) =
463  Eigen::AngleAxis<float>(M_PI_2, Eigen::Vector3f::UnitZ()).toRotationMatrix();
464  pcl::PointCloud<PointT>::Ptr cloudTransformedPtr(new pcl::PointCloud<PointT>());
465  pcl::transformPointCloud(*pointcloud, *cloudTransformedPtr, rotate);
466  cloudTransformedPtr->header.stamp = timestamp;
467  providePointCloud(cloudTransformedPtr);
468 
469  updateTimestamp(timestamp);
470  if (!floatImageMode)
471  {
473  }
474  else
475  {
477  }
478 
479  if (drawPointCloud && (std::chrono::high_resolution_clock::now() - lastUpdate >
480  std::chrono::milliseconds{pointCloudDrawDelay}))
481  {
482  lastUpdate = std::chrono::high_resolution_clock::now();
483  DebugDrawer24BitColoredPointCloud dbgPcl;
484  dbgPcl.points.reserve(cloudTransformedPtr->size());
485 
486  dbgPcl.pointSize = pointCloudPointSize;
487 
488  const auto pointCloudBaseNode =
489  simVisu->getRobot(robotName)->getRobotNode(camNodeName);
490 
491  if (!pointCloudBaseNode)
492  {
493  ARMARX_ERROR_S << deactivateSpam() << robotName << " has no node "
494  << camNodeName
495  << "\nthe point cloud will be attached to (0,0,0)";
496  }
497 
499  // rotate.block(0, 0, 3, 3) = Eigen::AngleAxis<float>(M_PI_2, Eigen::Vector3f::UnitZ()). toRotationMatrix();
500  Eigen::Matrix4f transformCamToWorld =
501  (pointCloudBaseNode ? pointCloudBaseNode->getGlobalPose()
503  rotate;
504 
505 
506  assert(static_cast<std::size_t>(width) == pointcloud->width);
507  assert(static_cast<std::size_t>(height) == pointcloud->height);
508  for (std::size_t x = 0; x < static_cast<std::size_t>(width); x += pointSkip)
509  {
510  for (std::size_t y = 0; y < static_cast<std::size_t>(height); y += pointSkip)
511  {
512  const auto& pclPoint = cloudTransformedPtr->at(x, y);
513 
514  //transform to point in world coord
515  const Eigen::Vector4f pointFromPcl{pclPoint.x, pclPoint.y, pclPoint.z, 1};
516 
517  const Eigen::Vector4f pointInWorld = transformCamToWorld * pointFromPcl;
518  const Eigen::Vector4f pointInWorldNormalizedW =
519  pointInWorld / pointInWorld(3);
520 
521  DebugDrawer24BitColoredPointCloudElement dbgPoint;
522 
523  dbgPoint.x = pointInWorldNormalizedW(0);
524  dbgPoint.y = pointInWorldNormalizedW(1);
525  dbgPoint.z = pointInWorldNormalizedW(2);
526 
527  //clip to space
528  if (clipPointCloud &&
529  (dbgPoint.x < clipDrawnCloudXLo || dbgPoint.x > clipDrawnCloudXHi ||
530  dbgPoint.y < clipDrawnCloudYLo || dbgPoint.y > clipDrawnCloudYHi ||
531  dbgPoint.z < clipDrawnCloudZLo || dbgPoint.z > clipDrawnCloudZHi))
532  {
533  continue;
534  }
535 
536  dbgPoint.color.r = pclPoint.r;
537  dbgPoint.color.g = pclPoint.g;
538  dbgPoint.color.b = pclPoint.b;
539 
540  dbgPcl.points.emplace_back(dbgPoint);
541  }
542  }
543 
544  debugDrawer->set24BitColoredPointCloudVisu(
545  "PointClouds", getName() + "::PointCloud", dbgPcl);
546  // debugDrawer->setPoseVisu("PointClouds", getName() + "::PointCloudBaseNode", new Pose { (pointCloudBaseNode ? pointCloudBaseNode->getGlobalPose() : Eigen::Matrix4f::Identity()) });
547  }
548  }
549  return succeeded;
550  }
551 
552  bool
554  {
555  ARMARX_TRACE;
556  //render images
557  if (!cameraNode)
558  {
559  ARMARX_ERROR << deactivateSpam() << "No camera node:" << camNodeName;
560  return false;
561  }
562 
563  bool renderOK = false;
564  {
565  auto l = simVisu->getScopedLock();
566  auto start = IceUtil::Time::now();
567 
568  ARMARX_TRACE;
569  renderOK = VirtualRobot::CoinVisualizationFactory::renderOffscreenRgbDepthPointcloud(
570  offscreenRenderer.get(),
571  cameraNode,
573  width,
574  height,
575  true,
576  rgbBuffer,
577  true,
578  depthBuffer,
579  true,
581  zNear,
582  zFar,
583  vertFov,
584  nanValue);
585 
586  ARMARX_DEBUG << deactivateSpam(1) << "Offscreen rendering took: "
587  << (IceUtil::Time::now() - start).toMilliSecondsDouble() << " ms";
588  }
589  if (renderOK)
590  {
591  ARMARX_TRACE;
592  //get images + cloud
593  std::unique_lock lock(captureMutex);
594 
595  auto start = std::chrono::high_resolution_clock::now();
596 
597  auto randValuesSize = randValues.size();
598  int noiseOffset = noise > 0 ? rand() % randValuesSize : 0;
599 
600  float* depthBufferEndOfRow = depthBuffer.data() + width - 1;
601  if (floatImageMode)
602  {
603  float* dFloatImageRow = dFloatImage->pixels;
604  for (int y = 0; y < height; y++)
605  {
606  for (int x = 0; x < width; x++)
607  {
608  float value = depthBufferEndOfRow[-x];
609  value = std::max(value, 0.0f);
610  value = std::min(value, static_cast<float>(0xffffff));
611  dFloatImageRow[x] = value;
612  }
613  dFloatImageRow += width;
614  depthBufferEndOfRow += width;
615  }
616  }
617  else
618  {
619  ARMARX_TRACE;
620  std::uint8_t* rgbImageRow = rgbImage->pixels;
621  std::uint8_t* rgbBufferEndOfRow = rgbBuffer.data() + (width - 1) * 3;
622  std::uint8_t* dImageRow = dImage->pixels;
623  for (int y = 0; y < height; ++y)
624  {
625  for (int x = 0; x < width; ++x)
626  {
627  memcpy(static_cast<void*>(&(rgbImageRow[x * 3])), //dest
628  static_cast<const void*>(&(rgbBufferEndOfRow[-x * 3])), //src
629  3 //count
630  );
631  float valueF = depthBufferEndOfRow[-x];
632  valueF = std::max(0.0f, valueF);
633  valueF = std::min(valueF, static_cast<float>(0xffffff));
634  std::uint32_t value = static_cast<std::uint32_t>(valueF);
635  memcpy(static_cast<void*>(&(dImageRow[x * 3])), //dest
636  static_cast<const void*>(&value), //src
637  3 //count
638  );
639  }
640  rgbImageRow += width * 3;
641  rgbBufferEndOfRow += width * 3;
642  dImageRow += width * 3;
643  depthBufferEndOfRow += width;
644  }
645  }
646 
647  ARMARX_TRACE;
648  float* randValuesData = randValues.data();
649  std::uint8_t* rgbBufferEntry = rgbBuffer.data();
650  Eigen::Vector3f* inputRow = pointCloudBuffer.data();
651  PointT* outputEndOfRow = pointcloud->points.data() + (width - 1);
652  for (int y = 0; y < height; ++y)
653  {
654  ARMARX_TRACE;
655  for (int x = 0; x < width; ++x)
656  {
657  PointT& point = outputEndOfRow[-x];
658  Eigen::Vector3f pointCloudBufferPoint = inputRow[x];
659 
660  int noiseIndex = (y * width + x) + noiseOffset;
661  float noiseX =
662  noise > 0.0f ? randValuesData[(noiseIndex) % randValuesSize] : 0.0f;
663  float noiseY =
664  noise > 0.0f ? randValuesData[(noiseIndex + 1) % randValuesSize] : 0.0f;
665  float noiseZ =
666  noise > 0.0f ? randValuesData[(noiseIndex + 2) % randValuesSize] : 0.0f;
667 
668  point.x = pointCloudBufferPoint[0] + noiseX;
669  point.y = pointCloudBufferPoint[1] + noiseY;
670  point.z = pointCloudBufferPoint[2] + noiseZ;
671  point.r = rgbBufferEntry[0];
672  point.g = rgbBufferEntry[1];
673  point.b = rgbBufferEntry[2];
674 
675  rgbBufferEntry += 3;
676  }
677  inputRow += width;
678  outputEndOfRow += width;
679  }
680 
681  auto end = std::chrono::high_resolution_clock::now();
682  std::int64_t timeDiff =
683  std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
684  sumRenderTimes += timeDiff;
685  sumRenderTimesSquared += timeDiff * timeDiff;
686  renderTimesCount += 1;
687 
688  if (renderTimesCount > 256)
689  {
690  ARMARX_TRACE;
691  double averageTime = sumRenderTimes * 1.0e-3 / renderTimesCount;
692  double averageSquaredTime = sumRenderTimesSquared * 1.0e-6 / renderTimesCount;
693  double stddevTime = std::sqrt(averageSquaredTime - averageTime * averageTime);
694 
695  ARMARX_DEBUG << "Copying depth buffer data took: " << averageTime << "ms +- "
696  << stddevTime << "ms";
697 
698  renderTimesCount = 0;
699  sumRenderTimes = 0;
701  renderTimesCount = 0;
702  }
703  }
704  return renderOK;
705  }
706 
707  void
709  {
710  ARMARX_TRACE;
711  if (simVisu)
712  {
713  ARMARX_TRACE;
714  simVisu->synchronizeVisualizationData();
715  if (simVisu->getRobot(robotName))
716  {
717  ARMARX_TRACE;
718  cameraNode = simVisu->getRobot(robotName)->getRobotNode(camNodeName);
719  }
720  visualization = simVisu->getVisualization();
721  if (!cameraNode)
722  {
723  ARMARX_WARNING << "The camera node is not in the scene";
724  }
725  if (!visualization)
726  {
727  ARMARX_WARNING << "No physics visualization scene";
728  }
729  }
730  }
731 
732 } // namespace armarx
armarx::DepthImageProviderDynamicSimulation::drawPointCloud
bool drawPointCloud
Definition: DepthImageProviderDynamicSimulation.h:133
armarx::DepthImageProviderDynamicSimulation::imgPtr
CByteImage * imgPtr[2]
Definition: DepthImageProviderDynamicSimulation.h:117
armarx::DepthImageProviderDynamicSimulation::nanValue
float nanValue
Definition: DepthImageProviderDynamicSimulation.h:127
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
armarx::DepthImageProviderDynamicSimulationPropertyDefinitions
Definition: DepthImageProviderDynamicSimulation.h:48
armarx::DepthImageProviderDynamicSimulation::rgbImage
std::unique_ptr< CByteImage > rgbImage
Definition: DepthImageProviderDynamicSimulation.h:114
armarx::DepthImageProviderDynamicSimulation::clipDrawnCloudZHi
float clipDrawnCloudZHi
Definition: DepthImageProviderDynamicSimulation.h:148
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::DepthImageProviderDynamicSimulation::imgPtrFlt
CFloatImage * imgPtrFlt[1]
Definition: DepthImageProviderDynamicSimulation.h:118
armarx::ManagedIceObject::getArmarXManager
ArmarXManagerPtr getArmarXManager() const
Returns the ArmarX manager used to add and remove components.
Definition: ManagedIceObject.cpp:360
trace.h
armarx::DepthImageProviderDynamicSimulation::dFloatImage
std::unique_ptr< CFloatImage > dFloatImage
Definition: DepthImageProviderDynamicSimulation.h:116
armarx::DepthImageProviderDynamicSimulation::height
short height
Definition: DepthImageProviderDynamicSimulation.h:101
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
armarx::DepthImageProviderDynamicSimulation::baseline
float baseline
Definition: DepthImageProviderDynamicSimulation.h:103
armarx::DepthImageProviderDynamicSimulation::onExitCapturingPointCloudProvider
void onExitCapturingPointCloudProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: DepthImageProviderDynamicSimulation.cpp:332
visionx::ImageProvider::setImageFormat
void setImageFormat(ImageDimension imageDimension, ImageType imageType, BayerPatternType bayerPatternType=visionx::eBayerPatternRg)
Sets the image basic format data.
Definition: ImageProvider.cpp:305
armarx::DepthImageProviderDynamicSimulation::onStopCapture
void onStopCapture() override
This is called when the point cloud provider capturing has been stopped.
Definition: DepthImageProviderDynamicSimulation.cpp:248
armarx::DepthImageProviderDynamicSimulation::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: DepthImageProviderDynamicSimulation.cpp:257
armarx::DepthImageProviderDynamicSimulation::camNodeName
std::string camNodeName
Definition: DepthImageProviderDynamicSimulation.h:108
armarx::DepthImageProviderDynamicSimulation::zNear
float zNear
Definition: DepthImageProviderDynamicSimulation.h:123
visionx::ImageProvider::start
void start(const Ice::Current &c) override
Definition: ImageProvider.h:217
armarx::DepthImageProviderDynamicSimulation::dImage
std::unique_ptr< CByteImage > dImage
Definition: DepthImageProviderDynamicSimulation.h:115
visionx::ImageProvider::updateTimestamp
void updateTimestamp(Ice::Long timestamp, bool threadSafe=true)
Updates the timestamp of the currently captured image.
Definition: ImageProvider.cpp:175
armarx::DepthImageProviderDynamicSimulation::~DepthImageProviderDynamicSimulation
~DepthImageProviderDynamicSimulation() override
Definition: DepthImageProviderDynamicSimulation.cpp:252
armarx::DepthImageProviderDynamicSimulation::distribution
std::normal_distribution< double > distribution
Definition: DepthImageProviderDynamicSimulation.h:154
armarx::DepthImageProviderDynamicSimulation::onConnectComponent
void onConnectComponent() override
Definition: DepthImageProviderDynamicSimulation.cpp:193
armarx::DepthImageProviderDynamicSimulation::pointcloud
pcl::PointCloud< PointT >::Ptr pointcloud
Definition: DepthImageProviderDynamicSimulation.h:130
armarx::DepthImageProviderDynamicSimulation::clipPointCloud
bool clipPointCloud
Definition: DepthImageProviderDynamicSimulation.h:140
ARMARX_TRACE
#define ARMARX_TRACE
Definition: trace.h:77
GfxTL::Identity
void Identity(MatrixXX< N, N, T > *a)
Definition: MatrixXX.h:570
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::DepthImageProviderDynamicSimulation::onExitComponent
void onExitComponent() override
Definition: DepthImageProviderDynamicSimulation.cpp:209
visionx::tools::convertEigenVecToVisionX
visionx::types::Vec convertEigenVecToVisionX(Eigen::VectorXf v)
Definition: TypeMapping.cpp:662
armarx::DepthImageProviderDynamicSimulation::clipDrawnCloudYHi
float clipDrawnCloudYHi
Definition: DepthImageProviderDynamicSimulation.h:147
armarx::DepthImageProviderDynamicSimulation::generator
std::default_random_engine generator
Definition: DepthImageProviderDynamicSimulation.h:155
armarx::DepthImageProviderDynamicSimulation::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: DepthImageProviderDynamicSimulation.cpp:321
armarx::TimeUtil::HasTimeServer
static bool HasTimeServer()
check if we have been initialized with a Timeserver
Definition: TimeUtil.cpp:124
armarx::DepthImageProviderDynamicSimulation::vertFov
float vertFov
Definition: DepthImageProviderDynamicSimulation.h:125
armarx::DepthImageProviderDynamicSimulation::simVisu
ArmarXPhysicsWorldVisualizationPtr simVisu
Definition: DepthImageProviderDynamicSimulation.h:105
ARMARX_ERROR_S
#define ARMARX_ERROR_S
Definition: Logging.h:216
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::DepthImageProviderDynamicSimulation::zFar
float zFar
Definition: DepthImageProviderDynamicSimulation.h:124
armarx::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:918
armarx::DepthImageProviderDynamicSimulation::onExitImageProvider
void onExitImageProvider() override
This is called when the Component::onExitComponent() setup is called.
Definition: DepthImageProviderDynamicSimulation.cpp:425
armarx::DepthImageProviderDynamicSimulation::noise
float noise
Definition: DepthImageProviderDynamicSimulation.h:152
max
T max(T t1, T t2)
Definition: gdiam.h:51
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
armarx::DepthImageProviderDynamicSimulation::width
short width
Definition: DepthImageProviderDynamicSimulation.h:100
visionx::ImageProvider::provideImages
void provideImages(void **inputBuffers, const IceUtil::Time &imageTimestamp=IceUtil::Time())
send images raw.
Definition: ImageProvider.cpp:351
armarx::DepthImageProviderDynamicSimulation::rgbBuffer
std::vector< unsigned char > rgbBuffer
Definition: DepthImageProviderDynamicSimulation.h:119
armarx::DepthImageProviderDynamicSimulation::lastUpdate
std::chrono::high_resolution_clock::time_point lastUpdate
Definition: DepthImageProviderDynamicSimulation.h:137
armarx::DepthImageProviderDynamicSimulation::clipDrawnCloudXHi
float clipDrawnCloudXHi
Definition: DepthImageProviderDynamicSimulation.h:146
visionx::ImageProvider::setNumberImages
void setNumberImages(int numberImages)
Sets the number of images on each capture.
Definition: ImageProvider.cpp:344
armarx::DepthImageProviderDynamicSimulation::pointCloudDrawDelay
unsigned int pointCloudDrawDelay
Definition: DepthImageProviderDynamicSimulation.h:136
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:704
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
armarx::DepthImageProviderDynamicSimulation::clipDrawnCloudYLo
float clipDrawnCloudYLo
Definition: DepthImageProviderDynamicSimulation.h:143
armarx::DepthImageProviderDynamicSimulation::onInitCapturingPointCloudProvider
void onInitCapturingPointCloudProvider() override
This is called when the Component::onInitComponent() is called.
Definition: DepthImageProviderDynamicSimulation.cpp:327
armarx::DepthImageProviderDynamicSimulation::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: DepthImageProviderDynamicSimulation.cpp:417
armarx::DepthImageProviderDynamicSimulation::onInitImageProvider
void onInitImageProvider() override
This is called when the Component::onInitComponent() is called.
Definition: DepthImageProviderDynamicSimulation.cpp:357
visionx::PointCloudProvider::providePointCloud
void providePointCloud(PointCloudPtrT pointCloudPtr)
offer the new point cloud.
Definition: PointCloudProvider.h:122
armarx::DepthImageProviderDynamicSimulation::robotName
std::string robotName
Definition: DepthImageProviderDynamicSimulation.h:107
armarx::DepthImageProviderDynamicSimulation::clipDrawnCloudXLo
float clipDrawnCloudXLo
Definition: DepthImageProviderDynamicSimulation.h:142
armarx::DepthImageProviderDynamicSimulation::onInitComponent
void onInitComponent() override
Definition: DepthImageProviderDynamicSimulation.cpp:138
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:181
armarx::DepthImageProviderDynamicSimulation::sumRenderTimes
std::int64_t sumRenderTimes
Definition: DepthImageProviderDynamicSimulation.h:158
armarx::DepthImageProviderDynamicSimulation::pointCloudPointSize
std::size_t pointCloudPointSize
Definition: DepthImageProviderDynamicSimulation.h:138
armarx::DepthImageProviderDynamicSimulation::clipDrawnCloudZLo
float clipDrawnCloudZLo
Definition: DepthImageProviderDynamicSimulation.h:144
armarx::ManagedIceObject::offeringTopic
void offeringTopic(const std::string &name)
Registers a topic for retrival after initialization.
Definition: ManagedIceObject.cpp:300
IceUtil::Handle
Definition: forward_declarations.h:30
visionx::tools::convertEigenMatToVisionX
visionx::types::Mat convertEigenMatToVisionX(Eigen::MatrixXf m)
Definition: TypeMapping.cpp:686
armarx::DepthImageProviderDynamicSimulation::doCapture
bool doCapture() override
Main capturing function.
Definition: DepthImageProviderDynamicSimulation.cpp:436
armarx::DepthImageProviderDynamicSimulation::render
bool render()
Definition: DepthImageProviderDynamicSimulation.cpp:553
DepthImageProviderDynamicSimulation.h
armarx::DepthImageProviderDynamicSimulation::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Definition: DepthImageProviderDynamicSimulation.cpp:269
armarx::DepthImageProviderDynamicSimulation::visualization
SoSeparator * visualization
Definition: DepthImageProviderDynamicSimulation.h:110
ImageUtil.h
armarx::DepthImageProviderDynamicSimulation::depthBuffer
std::vector< float > depthBuffer
Definition: DepthImageProviderDynamicSimulation.h:120
armarx::DepthImageProviderDynamicSimulationPropertyDefinitions::DepthImageProviderDynamicSimulationPropertyDefinitions
DepthImageProviderDynamicSimulationPropertyDefinitions(std::string prefix)
Definition: DepthImageProviderDynamicSimulation.cpp:48
armarx::DepthImageProviderDynamicSimulation::PointT
pcl::PointXYZRGBA PointT
Definition: DepthImageProviderDynamicSimulation.h:129
armarx::DepthImageProviderDynamicSimulation::pointCloudBuffer
std::vector< Eigen::Vector3f > pointCloudBuffer
Definition: DepthImageProviderDynamicSimulation.h:121
ARMARX_VERBOSE_S
#define ARMARX_VERBOSE_S
Definition: Logging.h:207
armarx::Logging::deactivateSpam
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
Definition: Logging.cpp:99
armarx::ManagedIceObject::getName
std::string getName() const
Retrieve name of object.
Definition: ManagedIceObject.cpp:108
TypeMapping.h
armarx::DepthImageProviderDynamicSimulation::debugDrawerTopicName
std::string debugDrawerTopicName
Definition: DepthImageProviderDynamicSimulation.h:134
armarx::DepthImageProviderDynamicSimulation::offscreenRenderer
std::shared_ptr< SoOffscreenRenderer > offscreenRenderer
Definition: DepthImageProviderDynamicSimulation.h:156
armarx::PropertyUser::getIceProperties
Ice::PropertiesPtr getIceProperties() const
Returns the set of Ice properties.
Definition: PropertyUser.cpp:221
armarx::DepthImageProviderDynamicSimulation::syncVisu
void syncVisu()
Definition: DepthImageProviderDynamicSimulation.cpp:708
armarx::DepthImageProviderDynamicSimulation::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Definition: DepthImageProviderDynamicSimulation.cpp:315
armarx::DepthImageProviderDynamicSimulation::debugDrawer
DebugDrawerInterfacePrx debugDrawer
Definition: DepthImageProviderDynamicSimulation.h:135
armarx::DepthImageProviderDynamicSimulation::randValues
std::vector< float > randValues
Definition: DepthImageProviderDynamicSimulation.h:153
min
T min(T t1, T t2)
Definition: gdiam.h:44
armarx::handleExceptions
void handleExceptions()
Definition: Exception.cpp:157
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::DepthImageProviderDynamicSimulation::onStartCapture
void onStartCapture(float frameRate) override
This is called when the point cloud provider capturing has been started.
Definition: DepthImageProviderDynamicSimulation.cpp:218
armarx::DepthImageProviderDynamicSimulation::hasSharedMemorySupport
bool hasSharedMemorySupport(const Ice::Current &c=Ice::emptyCurrent) override
Definition: DepthImageProviderDynamicSimulation.cpp:263
armarx::DepthImageProviderDynamicSimulation::pointSkip
std::size_t pointSkip
Definition: DepthImageProviderDynamicSimulation.h:150
visionx::tools::createDefaultMonocularCalibration
MonocularCalibration createDefaultMonocularCalibration()
Creates a MonocularCalibration with all parameters set to a neutral value.
Definition: ImageUtil.cpp:265
armarx::DepthImageProviderDynamicSimulation::captureMutex
std::mutex captureMutex
Definition: DepthImageProviderDynamicSimulation.h:98
armarx::DepthImageProviderDynamicSimulation::floatImageMode
bool floatImageMode
Definition: DepthImageProviderDynamicSimulation.h:112
armarx::DepthImageProviderDynamicSimulation::cameraNode
VirtualRobot::RobotNodePtr cameraNode
Definition: DepthImageProviderDynamicSimulation.h:109
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::DepthImageProviderDynamicSimulation::renderTimesCount
std::int32_t renderTimesCount
Definition: DepthImageProviderDynamicSimulation.h:160
armarx::DepthImageProviderDynamicSimulation::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: DepthImageProviderDynamicSimulation.cpp:430
armarx::DepthImageProviderDynamicSimulation::sumRenderTimesSquared
std::int64_t sumRenderTimesSquared
Definition: DepthImageProviderDynamicSimulation.h:159