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