NextBestViewCalculator.hpp
Go to the documentation of this file.
1 
20 #pragma once
21 
22 #include "typedef.hpp"
23 #include <vector>
24 #include <map>
25 #include <chrono>
26 
27 #include <boost/foreach.hpp>
28 #include <boost/range/algorithm_ext/iota.hpp>
29 #include <boost/lexical_cast.hpp>
30 #include <boost/range/irange.hpp>
31 
33 #include <robot_model_services/robot_model/RobotModel.hpp>
42 #include "asr_msgs/AsrAttributedPointCloud.h"
43 #include "asr_msgs/AsrAttributedPoint.h"
48 
49 namespace next_best_view {
51 private:
53  // this is basically unused, but "might" be used to remove objects from mPointCloudPtr
56  std::map<std::string, std::string> objectsResources;
57 
58  // modules
62  robot_model_services::RobotModelPtr mRobotModelPtr;
66 
69 
71  float mEpsilon;
75 
78 
80 
82  std::vector<CameraModelFilterPtr> mThreadCameraModels;
83  std::vector<RatingModulePtr> mThreadRatingModules;
84 
85  double mMinUtility;
87 
88 public:
89 
91  const MapHelperPtr &mapHelperPtr = MapHelperPtr(),
92  const SpaceSamplerPtr &spaceSamplerPtr = SpaceSamplerPtr(),
93  const robot_model_services::RobotModelPtr &robotModelPtr = robot_model_services::RobotModelPtr(),
94  const CameraModelFilterPtr &cameraModelFilterPtr = CameraModelFilterPtr(),
95  const RatingModulePtr &ratingModulePtr = RatingModulePtr())
96  : objectsResources(),
97  mUnitSphereSamplerPtr(unitSphereSamplerPtr),
98  mMapHelperPtr(mapHelperPtr),
99  mSpaceSamplerPtr(spaceSamplerPtr),
100  mRobotModelPtr(robotModelPtr),
101  mCameraModelFilterPtr(cameraModelFilterPtr),
102  mRatingModulePtr(ratingModulePtr),
103  mEpsilon(10E-3),
104  mNumberOfThreads(boost::thread::hardware_concurrency()),
105  mThreadCameraModels(mNumberOfThreads),
106  mThreadRatingModules(mNumberOfThreads) {
107 
108  setMapHelper(mapHelperPtr);
109  mDebugHelperPtr = DebugHelper::getInstance();
110  }
111 
115  bool calculateNextBestView(const ViewportPoint &currentCameraViewport, ViewportPoint &resultViewport) {
116  auto begin = std::chrono::high_resolution_clock::now();
117  mDebugHelperPtr->writeNoticeably("STARTING CALCULATE-NEXT-BEST-VIEW METHOD", DebugHelper::CALCULATION);
118 
119  //Calculate robot configuration corresponding to current camera viewport of robot.
120  initializeRobotState(currentCameraViewport);
121 
122  mDebugHelperPtr->write("Calculate discrete set of view orientations on unit sphere",
124  //Get discretized set of camera orientations (pan, tilt) that are to be considered at each robot position considered during iterative optimization.
125  SimpleQuaternionCollectionPtr feasibleOrientationsCollectionPtr = generateOrientationSamples();
126 
127  // create the next best view point cloud
128  bool success = this->doIteration(currentCameraViewport, feasibleOrientationsCollectionPtr, resultViewport);
129 
130  auto finish = std::chrono::high_resolution_clock::now();
131  // cast timediff to flaot in seconds
132  ROS_INFO_STREAM("Iteration took " << std::chrono::duration<float>(finish-begin).count() << " seconds.");
133  mDebugHelperPtr->writeNoticeably("ENDING CALCULATE-NEXT-BEST-VIEW METHOD", DebugHelper::CALCULATION);
134  return success;
135  }
136 
141  void initializeRobotState(const ViewportPoint &currentCameraViewport) {
142  robot_model_services::RobotStatePtr currentState = mRobotModelPtr->calculateRobotState(currentCameraViewport.getPosition(), currentCameraViewport.getSimpleQuaternion());
143  //Save it.
144  mRobotModelPtr->setCurrentRobotState(currentState);
145  mRatingModulePtr->setRobotState(currentState);
146  for (int i : boost::irange(0, mNumberOfThreads)) {
147  mThreadRatingModules[i]->setRobotState(currentState);
148  }
149  }
150 
151  void getFeasibleSamplePoints(const SamplePointCloudPtr &sampledSpacePointCloudPtr, IndicesPtr &resultIndicesPtr) {
152  resultIndicesPtr = IndicesPtr(new Indices());
153  //Go through all
154  for(std::size_t index = 0; index < sampledSpacePointCloudPtr->size(); index++) {
155  // get the point
156  SamplePoint &spaceSamplePoint = sampledSpacePointCloudPtr->at(index);
157 
158 
159  IndicesPtr childIndicesPtr;
160  if (getFeasibleHypothesis(spaceSamplePoint.getSimpleVector3(), childIndicesPtr)) {
161  // set the indices
162  spaceSamplePoint.child_indices = childIndicesPtr;
163 
164  // add the index to active indices.
165  resultIndicesPtr->push_back(index);
166  }
167  }
168  }
169 
175  void getFeasibleViewports(const ViewportPointCloudPtr &sampleViewportsPtr, IndicesPtr &resultIndicesPtr) {
176  resultIndicesPtr = IndicesPtr(new Indices());
177  //Go through all
178  for(std::size_t index = 0; index < sampleViewportsPtr->size(); index++) {
179  // get the point
180  ViewportPoint &spaceViewport = sampleViewportsPtr->at(index);
181 
182  IndicesPtr childIndicesPtr;
183  if (getFeasibleHypothesis(spaceViewport.getPosition(), childIndicesPtr)) {
184  // set the indices
185  spaceViewport.child_indices = childIndicesPtr;
186 
187  // add the index to active indices.
188  resultIndicesPtr->push_back(index);
189  }
190  }
191  }
192 
193 
200  bool getFeasibleHypothesis(SimpleVector3 samplePoint, IndicesPtr &resultIndicesPtr) {
201  // get max radius by far clipping plane of camera. this marks the limit for the visible object distance.
202  double radius = mCameraModelFilterPtr->getFarClippingPlane();
203 
204  ObjectPoint comparablePoint(samplePoint);
205 
206  // the resulting child indices will be written in here
207  IndicesPtr childIndicesPtr(new Indices());
208  // we don't need distances, but distances are written in here
209  SquaredDistances dismissDistances;
210 
211  // this is a radius search - which reduces the complexity level for frustum culling.
212  int k = mKdTreePtr->radiusSearch(comparablePoint, radius, *childIndicesPtr, dismissDistances);
213 
214  // if there is no result of neighboured points, no need to add this point.
215  if (k == 0) {
216  return false;
217  }
218 
219  // set the indices
220  resultIndicesPtr = childIndicesPtr;
221  return true;
222  }
223 
232  bool rateViewports(const ViewportPointCloudPtr &sampleNextBestViewportsPtr, const ViewportPoint &currentCameraViewport, ViewportPoint &resultViewport, bool objectTypeSetIsKnown = false) {
233  ViewportPointCloudPtr ratedNextBestViewportsPtr = ViewportPointCloudPtr(new ViewportPointCloud());
234  return rateViewportsInternal(sampleNextBestViewportsPtr, currentCameraViewport, ratedNextBestViewportsPtr, resultViewport, objectTypeSetIsKnown);
235  }
236 
245  bool rateViewports(const ViewportPointCloudPtr &sampleNextBestViewports, const ViewportPoint &currentCameraViewport, ViewportPointCloudPtr &ratedNextBestViewportsPtr, bool objectTypeSetIsKnown = false) {
246  ratedNextBestViewportsPtr = ViewportPointCloudPtr(new ViewportPointCloud());
247  ViewportPoint resultViewport;
248  return rateViewportsInternal(sampleNextBestViewports, currentCameraViewport, ratedNextBestViewportsPtr, resultViewport, objectTypeSetIsKnown);
249  }
250 
251 private:
252 
262  bool rateViewportsInternal(const ViewportPointCloudPtr &sampleNextBestViewports, const ViewportPoint &currentCameraViewport,
263  ViewportPointCloudPtr &ratedNextBestViewports, ViewportPoint &resultViewport, bool objectTypeSetIsKnown) {
264  // start threads
265  boost::thread_group threadGroup;
266  boost::mutex mutex;
267  for (int i : boost::irange(0, mNumberOfThreads)) {
268  threadGroup.add_thread(new boost::thread(&NextBestViewCalculator::ratingThread, this, i, boost::ref(mutex),
269  boost::ref(sampleNextBestViewports),
270  boost::ref(currentCameraViewport),
271  boost::ref(ratedNextBestViewports),
272  objectTypeSetIsKnown));
273  }
274  threadGroup.join_all();
275 
276  mDebugHelperPtr->write("Sorted list of all viewports (each best for pos & orient combi) in this iteration step.",
278  return mRatingModulePtr->getBestViewport(ratedNextBestViewports, resultViewport);
279  }
280 
290  void ratingThread(int threadId, boost::mutex &mutex,
291  const ViewportPointCloudPtr &sampleNextBestViewports,
292  const ViewportPoint &currentCameraViewport,
293  const ViewportPointCloudPtr &ratedNextBestViewports,
294  bool objectTypeSetIsKnown) {
295  unsigned int nViewportSamples = sampleNextBestViewports->size();
296  double startFactor = (double) threadId / mNumberOfThreads;
297  double endFactor = (threadId + 1.0) / mNumberOfThreads;
298  unsigned int startIdx = (int) (startFactor * nViewportSamples);
299  unsigned int endIdx = (int) (endFactor * nViewportSamples);
300  //Go through all interesting space sample points for one iteration step to create candidate viewports.
301  for (int i : boost::irange(startIdx, endIdx)) {
302  ViewportPoint fullViewportPoint = sampleNextBestViewports->at(i);
303  //Calculate which object points lie within frustum for given viewport.
304  if (!this->doFrustumCulling(mThreadCameraModels[threadId], fullViewportPoint)) {
305  //Skip viewport if no object point is within frustum.
306  continue;
307  }
308 
309  //For given viewport(combination of robot position and camera viewing direction)
310  // get combination of objects (all present in frustum) to search for and the corresponding score for viewport, given that combination.
311  mDebugHelperPtr->write("Getting viewport with optimal object constellation for given position & orientation combination.",
313  if (objectTypeSetIsKnown) {
314  if (!rateSingleViewportFixedObjectTypes(mThreadRatingModules[threadId], currentCameraViewport, fullViewportPoint))
315  continue;
316  } else {
317  if (!rateSingleViewportOptimizeObjectTypes(mThreadRatingModules[threadId], currentCameraViewport, fullViewportPoint))
318  continue;
319  }
320  //Keep viewport with optimal subset of objects within frustum to search for.
321  mutex.lock();
322  ratedNextBestViewports->push_back(fullViewportPoint);
323  mutex.unlock();
324  }
325  }
326 
334  bool rateSingleViewportOptimizeObjectTypes(const RatingModulePtr &ratingModulePtr, const ViewportPoint &currentCameraViewport, ViewportPoint &fullViewportPoint) {
335  mDebugHelperPtr->write("Getting viewport with optimal object constellation for given position & orientation combination.",
337  return ratingModulePtr->setBestScoreContainer(currentCameraViewport, fullViewportPoint);
338  }
339 
347  bool rateSingleViewportFixedObjectTypes(const RatingModulePtr &ratingModulePtr, const ViewportPoint &currentCameraViewport, ViewportPoint &fullViewportPoint) {
348  ratingModulePtr->resetCache();
349  return ratingModulePtr->setSingleScoreContainer(currentCameraViewport, fullViewportPoint);
350  }
351 
352  bool doIteration(const ViewportPoint &currentCameraViewport, const SimpleQuaternionCollectionPtr &sampledOrientationsPtr, ViewportPoint &resultViewport) {
353  mDebugHelperPtr->writeNoticeably("STARTING DO-ITERATION METHOD", DebugHelper::CALCULATION);
354 
355  int iterationStep = 0;
356  //Best viewport at the end of each iteration step and starting point for optimization (grid alignment) for each following step.
357  ViewportPoint currentBestViewport = currentCameraViewport;
358  float currentBestRating = 0;
359 
360  //Enables to interrupt iterating if it takes too long.
361  while (ros::ok()) {
362  ViewportPoint intermediateResultViewport;
363 
364  //Contractor is always divided by two.
365  if (!this->doIterationStep(currentCameraViewport, currentBestViewport,
366  sampledOrientationsPtr, 1.0 / pow(2.0, iterationStep),
367  intermediateResultViewport, iterationStep)) {
368  //Happens, when no valid viewport is found in that iteration step (including current viewport). E.g. when all normals are invalidated.
369  mDebugHelperPtr->writeNoticeably("ENDING DO-ITERATION METHOD", DebugHelper::CALCULATION);
370  return false;
371  }
372 
373  //Iteration step must be increased before the following check.
374  iterationStep ++;
375  float rating = mRatingModulePtr->getRating(intermediateResultViewport.score);
376  mDebugHelperPtr->write("THIS IS THE BEST VIEWPORT IN THE GIVEN ITERATION STEP.",
378  mDebugHelperPtr->write(std::stringstream() << intermediateResultViewport, DebugHelper::CALCULATION);
379  mDebugHelperPtr->write(std::stringstream() << "rating: " << rating, DebugHelper::CALCULATION);
380  mDebugHelperPtr->write(std::stringstream() << "IterationStep: " << iterationStep, DebugHelper::CALCULATION);
381 
382  //First condition is runtime optimization to not iterate around current pose. Second is general abort criterion.
383  if (std::abs(rating - currentBestRating) <= this->getEpsilon() || iterationStep >= mMaxIterationSteps) {
384  //Stop once position displacement (resp. differing view at sufficient space sampling resolution) is small enough.
385  resultViewport = intermediateResultViewport;
386  ROS_INFO_STREAM ("Next-best-view estimation SUCCEEDED. Took " << iterationStep << " iterations");
387  mDebugHelperPtr->write("THIS IS THE BEST VIEWPORT FOR ALL ITERATION STEPS.",
389  mDebugHelperPtr->write(std::stringstream() << resultViewport, DebugHelper::CALCULATION);
390  mDebugHelperPtr->write(std::stringstream() << "rating: " << rating, DebugHelper::CALCULATION);
391  mDebugHelperPtr->write(std::stringstream() << "IterationStep: " << iterationStep,
393  mDebugHelperPtr->writeNoticeably("ENDING DO-ITERATION METHOD", DebugHelper::CALCULATION);
394  return true;
395  }
396 
397  currentBestViewport = intermediateResultViewport;
398  currentBestRating = rating;
399 
400  }
401  mDebugHelperPtr->writeNoticeably("ENDING DO-ITERATION METHOD", DebugHelper::CALCULATION);
402  //Only reached when iteration fails or is interrupted.
403  return false;
404  }
405 
406  bool doIterationStep(const ViewportPoint &currentCameraViewport, const ViewportPoint &currentBestViewport,
407  const SimpleQuaternionCollectionPtr &sampledOrientationsPtr, float contractor,
408  ViewportPoint &resultViewport, int iterationStep) {
409  mDebugHelperPtr->writeNoticeably("STARTING DO-ITERATION-STEP METHOD", DebugHelper::CALCULATION);
410 
411  // current camera position
412  SimpleVector3 currentBestPosition = currentBestViewport.getPosition();
413 
414  //Calculate grid for resolution given in this iteration step.
415  SamplePointCloudPtr sampledSpacePointCloudPtr = generateSpaceSamples(currentBestPosition, contractor, currentBestPosition[2]);
416 
417  //Skip rating all orientations (further code here) if we can only consider our current best robot position and increase sampling resolution
418  if (sampledSpacePointCloudPtr->size() == 1 && this->getEpsilon() < contractor) {
419  mDebugHelperPtr->write("No RViz visualization for this iteration step, since no new next-best-view found for that resolution.",
421  bool success = doIterationStep(currentCameraViewport, currentBestViewport, sampledOrientationsPtr, contractor * .5, resultViewport, iterationStep);
422  mDebugHelperPtr->writeNoticeably("ENDING DO-ITERATION-STEP METHOD", DebugHelper::CALCULATION);
423  return success;
424  }
425 
426  //Create list of all view ports that are checked during this iteration step.
427  ViewportPointCloudPtr sampleNextBestViewports = combineSamples(sampledSpacePointCloudPtr, sampledOrientationsPtr);
428 
429  // rate
430  ViewportPointCloudPtr ratedNextBestViewportsPtr;
431  if (!rateViewports(sampleNextBestViewports, currentCameraViewport, ratedNextBestViewportsPtr)) {
432  mDebugHelperPtr->writeNoticeably("ENDING DO-ITERATION-STEP METHOD", DebugHelper::CALCULATION);
433  return false;
434  }
435 
436  // sort
437  // ascending -> last element hast best rating
438  auto sortFunction = [this](const ViewportPoint &a, const ViewportPoint &b) {
439  // a < b
440  return mRatingModulePtr->compareViewports(a, b);
441  };
442  std::sort(ratedNextBestViewportsPtr->begin(), ratedNextBestViewportsPtr->end(), sortFunction);
443 
444  if (mRequireMinUtility) {
445  bool foundUtility = false;
446  BOOST_REVERSE_FOREACH (ViewportPoint &ratedViewport, *ratedNextBestViewportsPtr) {
447  if (ratedViewport.score->getUnweightedUnnormalizedUtility() > mMinUtility) {
448  resultViewport = ratedViewport;
449  foundUtility = true;
450  break;
451  }
452  }
453  if (!foundUtility) {
454  ROS_WARN_STREAM("every nbv has too little utility");
455  resultViewport = ratedNextBestViewportsPtr->back();
456  }
457  } else {
458  resultViewport = ratedNextBestViewportsPtr->back();
459  }
460 
461 // mVisHelperPtr->triggerSamplingVisualization(ratedNextBestViewportsPtr, Color(1, 0, 0, 1), "ratedViewports");
462 
463  //Visualize iteration step and its result.
464  mVisHelperPtr->triggerIterationVisualization(iterationStep, sampledOrientationsPtr, resultViewport,
465  sampledSpacePointCloudPtr, mSpaceSamplerPtr);
466 
467  mDebugHelperPtr->writeNoticeably("ENDING DO-ITERATION-STEP METHOD", DebugHelper::CALCULATION);
468  return true;
469  }
470 
471 public:
472  void setHeight(SamplePointCloudPtr pointCloudPtr, double height) {
473  for (unsigned int i = 0; i < pointCloudPtr->size(); i++) {
474  pointCloudPtr->at(i).z = height;
475  }
476  }
477 
486  bool doFrustumCulling(const SimpleVector3 &position, const SimpleQuaternion &orientation, const IndicesPtr &indices, ViewportPoint &viewportPoint) {
487  return doFrustumCulling(mCameraModelFilterPtr, position, orientation, indices, viewportPoint);
488  }
489 
499  bool doFrustumCulling(const CameraModelFilterPtr &cameraModelFilterPtr, const SimpleVector3 &position, const SimpleQuaternion &orientation, const IndicesPtr &indices, ViewportPoint &resultViewport) {
500  resultViewport = ViewportPoint(position, orientation);
501  resultViewport.child_indices = indices;
502  return doFrustumCulling(cameraModelFilterPtr, resultViewport);
503  }
504 
510  bool doFrustumCulling(ViewportPoint &resultViewportPoint) {
511  return doFrustumCulling(mCameraModelFilterPtr, resultViewportPoint);
512  }
513 
520  bool doFrustumCulling(const CameraModelFilterPtr &cameraModelFilterPtr, ViewportPoint &resultViewportPoint) {
521  cameraModelFilterPtr->setIndices(resultViewportPoint.child_indices);
522  cameraModelFilterPtr->setPivotPointPose(resultViewportPoint.getPosition(), resultViewportPoint.getSimpleQuaternion());
523 
524  // do the frustum culling
525  IndicesPtr frustumIndicesPtr;
526  //Call wrapper (with next-best-view data structures) for PCL frustum culling call.
527  cameraModelFilterPtr->filter(frustumIndicesPtr);
528 
529  resultViewportPoint.child_indices = frustumIndicesPtr;
530  resultViewportPoint.child_point_cloud = cameraModelFilterPtr->getInputCloud();
531  resultViewportPoint.point_cloud = mPointCloudPtr;
532 
533  if (frustumIndicesPtr->size() == 0) {
534  return false;
535  }
536 
537  return true;
538  }
539 
545  void updateFromExternalViewportPointList(const std::vector<ViewportPoint> &viewportPointList) {
546  mDebugHelperPtr->writeNoticeably("STARTING UPDATE-FROM-EXTERNAL-OBJECT-POINT-LIST", DebugHelper::CALCULATION);
547 
548  mDebugHelperPtr->write(std::stringstream() << "Number of viewports: " << viewportPointList.size(), DebugHelper::CALCULATION);
549 
550  for (unsigned int i = 0; i < viewportPointList.size(); i++) {
551  ViewportPoint viewportPoint = viewportPointList.at(i);
552 
553  mDebugHelperPtr->write(std::stringstream() << "THIS IS VIEWPORT NR. " << i+1 << " IN THE LIST OF EXTERNAL VIEWPORTS.",
555  mDebugHelperPtr->write(std::stringstream() << viewportPoint, DebugHelper::CALCULATION);
556 
557  ViewportPoint culledViewportPoint;
558  if (!this->doFrustumCulling(viewportPoint.getPosition(), viewportPoint.getSimpleQuaternion(), this->getActiveIndices(), culledViewportPoint)) {
559  mDebugHelperPtr->write("Viewpoint SKIPPED by Culling", DebugHelper::CALCULATION);
560  continue;
561  }
562 
563  ViewportPoint resultingViewportPoint;
564  if (!culledViewportPoint.filterObjectPointCloudByTypes(viewportPoint.object_type_set, resultingViewportPoint)) {
565  mDebugHelperPtr->write("Viewpoint SKIPPED by NameFiltering", DebugHelper::CALCULATION);
566  continue;
567  }
568 
569  mDebugHelperPtr->write(std::stringstream() << "Viewpoint TAKEN",
571 
572  this->updateObjectPointCloud(mObjectTypeSetPtr, resultingViewportPoint);
573  }
574 
575  mDebugHelperPtr->writeNoticeably("ENDING UPDATE-FROM-EXTERNAL-OBJECT-POINT-LIST", DebugHelper::CALCULATION);
576  }
577 
584  unsigned int updateObjectPointCloud(const ObjectTypeSetPtr &objectTypeSetPtr, const ViewportPoint &viewportPoint) {
585 
586  mDebugHelperPtr->write(std::stringstream() << "Number of active normals before update: " << getNumberActiveNormals(),
588 
589  unsigned int deactivatedNormals = mHypothesisUpdaterPtr->update(objectTypeSetPtr, viewportPoint);
590 
591  mDebugHelperPtr->write(std::stringstream() << "Deactivated normals in viewport: " << deactivatedNormals, DebugHelper::CALCULATION);
592 
593  mDebugHelperPtr->write(std::stringstream() << "Number of active normals after update: " << getNumberActiveNormals(),
595 
596  return deactivatedNormals;
597 
598  }
599 
602  // GETTER AND SETTER
605 
610  bool setPointCloudFromMessage(const asr_msgs::AsrAttributedPointCloud &msg) {
611  // create a new point cloud
612  ObjectPointCloudPtr originalPointCloudPtr = ObjectPointCloudPtr(new ObjectPointCloud());
613 
614  ObjectHelper objectHelper;
615 
616  // empty object name set
617  mObjectTypeSetPtr = ObjectTypeSetPtr(new ObjectTypeSet);
618 
619  // put each element into the point cloud
620  BOOST_FOREACH(asr_msgs::AsrAttributedPoint element, msg.elements) {
621  // Create a new point with pose and set object type
622  ObjectPoint pointCloudPoint(element.pose);
623  pointCloudPoint.color.r = 0;
624  pointCloudPoint.color.g = 255;
625  pointCloudPoint.color.b = 0;
626  pointCloudPoint.type = element.type;
627  pointCloudPoint.identifier = element.identifier;
628 
629  // add type name to list if not already inserted
630  if (mObjectTypeSetPtr->find(element.type) == mObjectTypeSetPtr->end())
631  mObjectTypeSetPtr->insert(element.type);
632 
633 
634  // translating from std::vector<geometry_msgs::Point> to std::vector<SimpleVector3>
635  if (!mEnableCropBoxFiltering) {
636  if (!setNormals(pointCloudPoint)) {
637  return false;
638  }
639  }
640 
641  //Insert color
642  std_msgs::ColorRGBA colorByID = VisualizationHelper::getMeshColor(element.identifier);
643  pointCloudPoint.color = colorByID;
644 
645  if(mEnableIntermediateObjectWeighting)
646  {
647  //get the weight for the object from world model
648  IntermediateObjectWeightResponsePtr responsePtr_Intermediate = objectHelper.getIntermediateObjectValue(pointCloudPoint.type);
649 
650  if(responsePtr_Intermediate)
651  {
652  pointCloudPoint.intermediate_object_weight = responsePtr_Intermediate->value;
653  //ROS_ERROR_STREAM("Set input cloud " << responsePtr_Intermediate->value);
654  }
655  else
656  {
657  ROS_ERROR("Invalid object name %s or world model service call failed. Point Cloud not set!", pointCloudPoint.type.c_str());
658  return false;
659  }
660  }
661  else
662  {
663  pointCloudPoint.intermediate_object_weight = 1;
664  }
665 
666  // add point to array
667  originalPointCloudPtr->push_back(pointCloudPoint);
668  }
669 
670  ObjectPointCloudPtr outputPointCloudPtr;
671  if(mEnableCropBoxFiltering)
672  {
673  IndicesPtr filteredObjectIndices = IndicesPtr(new Indices());
674  mCropBoxFilterPtr->setInputCloud(originalPointCloudPtr);
675  mCropBoxFilterPtr->filter(filteredObjectIndices);
676 
677  mDebugHelperPtr->write("setPointCloudFromMessage::Filtering point cloud finished.",
679 
680  mVisHelperPtr->triggerCropBoxVisualization(mCropBoxFilterPtr->getCropBoxWrapperPtrList());
681 
682  outputPointCloudPtr = ObjectPointCloudPtr(new ObjectPointCloud(*originalPointCloudPtr, *filteredObjectIndices));
683 
684  // we have to set now the object hypothesis normals
685  for (ObjectPoint& pointCloudPoint : *outputPointCloudPtr) {
686  if (!setNormalsInCropBoxMode(pointCloudPoint)) {
687  return false;
688  }
689  }
690  }
691  else
692  {
693  outputPointCloudPtr = originalPointCloudPtr;
694  }
695 
696  //If point cloud is empty, getting the indices lead to an Error.
697  if(outputPointCloudPtr->size() > 0)
698  {
699  // the active indices.
700  IndicesPtr activeIndicesPtr = IndicesPtr(new Indices(outputPointCloudPtr->size()));
701  boost::range::iota(boost::iterator_range<Indices::iterator>(activeIndicesPtr->begin(), activeIndicesPtr->end()), 0);
702 
703 
704  // set the point cloud
705  this->setActiveIndices(activeIndicesPtr);
706  }
707  else
708  {
709  mDebugHelperPtr->write("setPointCloudFromMessage::output point cloud is empty.",
711  }
712 
713  this->setPointCloudPtr(outputPointCloudPtr);
714 
715  return true;
716  }
717 
718 private:
719 
727  ViewportPointCloudPtr generateSampleViewports(SimpleVector3 spaceSampleStartVector, double contractor, double pointCloudHeight) {
728  SimpleQuaternionCollectionPtr feasibleOrientationsCollectionPtr = generateOrientationSamples();
729 
730  SamplePointCloudPtr sampledSpacePointCloudPtr = generateSpaceSamples(spaceSampleStartVector, contractor, pointCloudHeight);
731  ROS_INFO_STREAM("sampledSpacePointCloudPtr->size: " << sampledSpacePointCloudPtr->size());
732 
733  ViewportPointCloudPtr sampleNextBestViewports = combineSamples(sampledSpacePointCloudPtr, feasibleOrientationsCollectionPtr);
734 
735  return sampleNextBestViewports;
736  }
737 
743  SimpleQuaternionCollectionPtr sampledOrientationsPtr = mUnitSphereSamplerPtr->getSampledUnitSphere();
744  SimpleQuaternionCollectionPtr feasibleOrientationsCollectionPtr(new SimpleQuaternionCollection());
745 
746  BOOST_FOREACH(SimpleQuaternion q, *sampledOrientationsPtr) {
747  if (mRobotModelPtr->isPoseReachable(robot_model_services::SimpleVector3(0, 0, 0), q)) {
748  feasibleOrientationsCollectionPtr->push_back(q);
749  }
750  }
751 
752  return feasibleOrientationsCollectionPtr;
753  }
754 
762  SamplePointCloudPtr generateSpaceSamples(SimpleVector3 spaceSampleStartVector, double contractor, double pointCloudHeight) {
763  SamplePointCloudPtr sampledSpacePointCloudPtr = mSpaceSamplerPtr->getSampledSpacePointCloud(spaceSampleStartVector, contractor);
764 
765  //Set height of sample points as it is set to zero by space sampler
766  this->setHeight(sampledSpacePointCloudPtr, pointCloudHeight);
767 
768  IndicesPtr feasibleIndicesPtr;
769  //Prune space sample points in that iteration step by checking whether there are any surrounding object points (within constant far-clipping plane).
770  this->getFeasibleSamplePoints(sampledSpacePointCloudPtr, feasibleIndicesPtr);
771 
772  return SamplePointCloudPtr(new SamplePointCloud(*sampledSpacePointCloudPtr, *feasibleIndicesPtr));
773  }
774 
782  ViewportPointCloudPtr combineSamples(SamplePointCloudPtr sampledSpacePointCloudPtr, SimpleQuaternionCollectionPtr sampledOrientationsPtr) {
783  ViewportPointCloudPtr sampleNextBestViewports = ViewportPointCloudPtr(new ViewportPointCloud());
784 
785  // convert space sampling combined with sphere sampling to viewport sampling
786  for (SamplePoint &samplePoint : (*sampledSpacePointCloudPtr)) {
787  SimpleVector3 samplePointCoords = samplePoint.getSimpleVector3();
788  IndicesPtr samplePointChildIndices = samplePoint.child_indices;
789 
790  //For each space sample point: Go through all interesting orientations.
791  mDebugHelperPtr->write("Iterating over all orientations for a given robot position.",
793  BOOST_FOREACH(SimpleQuaternion orientation, *sampledOrientationsPtr) {
794  // get the corresponding viewport
795  ViewportPoint sampleViewport(samplePointCoords, orientation);
796  // nearby object hypothesis for good estimation of possible hypothesis in frustum
797  sampleViewport.child_indices = samplePointChildIndices;
798  sampleViewport.object_type_set = mObjectTypeSetPtr;
799  sampleNextBestViewports->push_back(sampleViewport);
800  }
801  }
802  return sampleNextBestViewports;
803  }
804 
805  bool setNormals(const ObjectPoint& pointCloudPoint) {
806  ObjectHelper objectHelper;
807  // get object type information
808  ObjectMetaDataResponsePtr responsePtr_ObjectData = objectHelper.getObjectMetaData(pointCloudPoint.type);
809  if (responsePtr_ObjectData) {
810  // Get the rotation matrix to translate the normal vectors of the object.
811  SimpleMatrix3 rotationMatrix = pointCloudPoint.getSimpleQuaternion().toRotationMatrix();
812  int normalVectorCount = 0;
813  for (geometry_msgs::Point point : responsePtr_ObjectData->normal_vectors) {
814  SimpleVector3 normal(point.x, point.y, point.z);
815  normal = rotationMatrix * normal;
816  pointCloudPoint.active_normal_vectors->push_back(normalVectorCount);
817  pointCloudPoint.normal_vectors->push_back(normal);
818  ++normalVectorCount;
819  }
820  } else {
821  ROS_ERROR("Invalid object name '%s' in point cloud or object_database node not started. Point Cloud not set!", pointCloudPoint.type.c_str());
822  return false;
823  }
824  //Insert the meshpath
825  objectsResources[pointCloudPoint.type] = responsePtr_ObjectData->object_mesh_resource;
826  return true;
827  }
828 
829  bool setNormalsInCropBoxMode(const ObjectPoint& pointCloudPoint) {
830  SimpleMatrix3 rotationMatrix = pointCloudPoint.getSimpleQuaternion().toRotationMatrix();
831  // in cropbox filtering we don't use the normals of the point clouds. Instead we use the ones defined in the xml
832  auto cropBoxPtrList = mCropBoxFilterPtr->getCropBoxWrapperPtrList();
833  int normalVectorCount = 0;
834  bool foundNormals = false;
835  bool isInCropbox = false;
836  for (CropBoxWrapperPtr cropBoxWrapper : *cropBoxPtrList) {
837  CropBoxPtr cropBoxPtr = cropBoxWrapper->getCropBox();
838  Eigen::Vector4f max = cropBoxPtr->getMax();
839  Eigen::Vector3f translation = cropBoxPtr->getTranslation();
840  // check if pointCloudPoint is in the cropbox
841  if (isPointInCropbox(pointCloudPoint.getPosition(), translation, max))
842  {
843  isInCropbox = true;
844  if (!cropBoxWrapper->getCropBoxNormalsList()->empty()) {
845  foundNormals = true;
846  for (SimpleVector3 normal : *cropBoxWrapper->getCropBoxNormalsList()) {
847  pointCloudPoint.active_normal_vectors->push_back(normalVectorCount);
848  SimpleVector3 rotatedNormal = rotationMatrix * normal;
849  pointCloudPoint.normal_vectors->push_back(rotatedNormal);
850  ++normalVectorCount;
851  }
852  }
853  }
854  }
855  if (isInCropbox && !foundNormals) {
856  if (!setNormals(pointCloudPoint)) {
857  return false;
858  }
859  } else {
860  //Insert the meshpath
861  objectsResources[pointCloudPoint.type] = "package://asr_next_best_view/rsc/sphere.dae";
862  }
863  return true;
864  }
865 
866  bool isPointInCropbox(const SimpleVector3& position, const Eigen::Vector3f& translation, const Eigen::Vector4f& max) const {
867  return isPointInRange(position(0,0), translation(0,0), max(0,0)) &&
868  isPointInRange(position(1,0), translation(1,0), max(1,0)) &&
869  isPointInRange(position(2,0), translation(2,0), max(2,0));
870  }
871 
872  bool isPointInRange(float point, float min, float lenght) const {
873  return point >= min && point <= (min + lenght);
874  }
875 
876 public:
880  std::string getMeshPathByName(std::string objectType)
881  {
882  if(this->objectsResources.find(objectType) != this->objectsResources.end())
883  {
884  return this->objectsResources[objectType];
885  }
886  else
887  {
888  return "-2";
889  }
890  }
891 
892 
896  void setPointCloudPtr(const ObjectPointCloudPtr &pointCloudPtr) {
897  mPointCloudPtr = pointCloudPtr;
898 
899  mKdTreePtr = KdTreePtr(new KdTree());
900  mKdTreePtr->setInputCloud(mPointCloudPtr);
901  mRatingModulePtr->setInputCloud(mPointCloudPtr);
902  mCameraModelFilterPtr->setInputCloud(mPointCloudPtr);
903  for (int i : boost::irange(0, mNumberOfThreads)) {
904  mThreadRatingModules[i]->setInputCloud(mPointCloudPtr);
905  mThreadCameraModels[i]->setInputCloud(mPointCloudPtr);
906  }
907  mSpaceSamplerPtr->setInputCloud(mPointCloudPtr);
908  }
909 
910  void loadCropBoxListFromFile(const std::string mCropBoxListFilePath)
911  {
912  this->mCropBoxFilterPtr = CropBoxFilterPtr(new CropBoxFilter(mCropBoxListFilePath));
913  }
914 
915  void setEnableCropBoxFiltering(const bool mEnableCropBoxFiltering)
916  {
917  this->mEnableCropBoxFiltering = mEnableCropBoxFiltering;
918  }
919 
920  void setEnableIntermediateObjectWeighting(const bool mEnableIntermediateObjectWeighting)
921  {
922  this->mEnableIntermediateObjectWeighting = mEnableIntermediateObjectWeighting;
923  }
924 
929  return mPointCloudPtr;
930  }
931 
935  void setActiveIndices(const IndicesPtr &activeIndicesPtr) {
936  mActiveIndicesPtr = activeIndicesPtr;
937  }
938 
943  return mActiveIndicesPtr;
944  }
945 
947  int result = 0;
948 
950  for (ObjectPoint &objPoint : objectPointCloud) {
951  result += objPoint.active_normal_vectors->size();
952  }
953 
954  return result;
955  }
956 
957  unsigned int getNumberTotalNormals(std::string type, std::string identifier) {
958  int result = 0;
959 
961  for (ObjectPoint &objPoint : objectPointCloud) {
962  if (objPoint.identifier.compare(identifier) != 0 || objPoint.type.compare(type) != 0)
963  continue;
964  result += objPoint.normal_vectors->size();
965  }
966 
967  return result;
968  }
969 
970  unsigned int getNumberActiveNormals(std::string type, std::string identifier) {
971  int result = 0;
972 
974  for (ObjectPoint &objPoint : objectPointCloud) {
975  if (objPoint.identifier.compare(identifier) != 0 || objPoint.type.compare(type) != 0)
976  continue;
977  result += objPoint.active_normal_vectors->size();
978  }
979 
980  return result;
981  }
982 
983  std::vector<std::pair<std::string, std::string>> getTypeAndIds() {
984  std::vector<std::pair<std::string, std::string>> result;
986  std::set<std::string> foundObjectTypeAndIds;
987  for (ObjectPoint &objPoint : objectPointCloud) {
988  std::string currentObjTypeAndId = objPoint.type + objPoint.identifier;
989  if (foundObjectTypeAndIds.find(currentObjTypeAndId) == foundObjectTypeAndIds.end()) {
990  foundObjectTypeAndIds.insert(currentObjTypeAndId);
991  result.push_back(std::make_pair(objPoint.type, objPoint.identifier));
992  }
993  }
994  return result;
995  }
996 
997  bool removeObjects(std::string type, std::string identifier) {
998  auto it = mPointCloudPtr->begin();
999  while (it != mPointCloudPtr->end()) {
1000  ObjectPoint objPoint = *it;
1001  if (objPoint.identifier.compare(identifier) != 0 || objPoint.type.compare(type) != 0) {
1002  it ++;
1003  } else {
1004  it = mPointCloudPtr->erase(it);
1005  }
1006  }
1007  if (mPointCloudPtr->empty()) {
1008  return false;
1009  }
1010  // the active indices.
1011  IndicesPtr activeIndicesPtr = IndicesPtr(new Indices(mPointCloudPtr->size()));
1012  boost::range::iota(boost::iterator_range<Indices::iterator>(activeIndicesPtr->begin(), activeIndicesPtr->end()), 0);
1013 
1014  // set the point cloud
1015  this->setActiveIndices(activeIndicesPtr);
1016  setPointCloudPtr(mPointCloudPtr);
1017  return true;
1018  }
1019 
1024  return mKdTreePtr;
1025  }
1026 
1031  void setUnitSphereSampler(const UnitSphereSamplerPtr &unitSphereSamplerPtr) {
1032  mUnitSphereSamplerPtr = unitSphereSamplerPtr;
1033  }
1034 
1039  return mUnitSphereSamplerPtr;
1040  }
1041 
1046  void setSpaceSampler(const SpaceSamplerPtr &spaceSamplerPtr) {
1047  mSpaceSamplerPtr = spaceSamplerPtr;
1048  }
1049 
1054  return mSpaceSamplerPtr;
1055  }
1056 
1061  void setRobotModel(const robot_model_services::RobotModelPtr &robotModelPtr) {
1062  mRobotModelPtr = robotModelPtr;
1063  }
1064 
1068  robot_model_services::RobotModelPtr getRobotModel() {
1069  return mRobotModelPtr;
1070  }
1071 
1076  void setCameraModelFilter(const CameraModelFilterPtr &cameraModelFilterPtr) {
1077  mCameraModelFilterPtr = cameraModelFilterPtr;
1078  }
1079 
1084  return mCameraModelFilterPtr;
1085  }
1086 
1091  void setRatingModule(const RatingModulePtr &ratingModulePtr) {
1092  mRatingModulePtr = ratingModulePtr;
1093  }
1094 
1099  return mRatingModulePtr;
1100  }
1101 
1106  void setMapHelper(const MapHelperPtr &mapHelperPtr) {
1107  mMapHelperPtr = mapHelperPtr;
1108  mVisHelperPtr = VisualizationHelperPtr(new VisualizationHelper(mMapHelperPtr));
1109  }
1110 
1115  return mMapHelperPtr;
1116  }
1117 
1118  void setHypothesisUpdater(const HypothesisUpdaterPtr &hypothesisUpdaterPtr) {
1119  mHypothesisUpdaterPtr = hypothesisUpdaterPtr;
1120  }
1121 
1123  return mHypothesisUpdaterPtr;
1124  }
1125 
1129  void setEpsilon(float epsilon) {
1130  mEpsilon = epsilon;
1131  }
1132 
1136  float getEpsilon() {
1137  return mEpsilon;
1138  }
1139 
1144  void setMaxIterationSteps(int maxIterationSteps)
1145  {
1146  mMaxIterationSteps = maxIterationSteps;
1147  }
1148 
1153  void setRatingModuleAbstractFactoryPtr(const RatingModuleAbstractFactoryPtr &ratingModuleAbstractFactoryPtr) {
1154  mRatingModuleAbstractFactoryPtr = ratingModuleAbstractFactoryPtr;
1155  for (int i : boost::irange(0, mNumberOfThreads)) {
1156  if (mThreadRatingModules[i]) {
1157  mThreadRatingModules[i].reset();
1158  }
1159  mThreadRatingModules[i] = mRatingModuleAbstractFactoryPtr->createRatingModule();
1160  }
1161  }
1162 
1169  }
1170 
1175  void setCameraModelFilterAbstractFactoryPtr(const CameraModelFilterAbstractFactoryPtr &cameraModelFilterAbstractFactoryPtr) {
1176  mCameraModelFilterAbstractFactoryPtr = cameraModelFilterAbstractFactoryPtr;
1177  for (int i : boost::irange(0, mNumberOfThreads)) {
1178  if (mThreadCameraModels[i]) {
1179  mThreadCameraModels[i].reset();
1180  }
1181  mThreadCameraModels[i] = mCameraModelFilterAbstractFactoryPtr->createCameraModelFilter();
1182  }
1183  }
1184 
1191  }
1192 
1197  int getNumberOfThreads() const {
1198  return mNumberOfThreads;
1199  }
1200 
1205  void setNumberOfThreads(int value) {
1206  if (value < 0) {
1207  mNumberOfThreads = boost::thread::hardware_concurrency();
1208  } else {
1209  mNumberOfThreads = value;
1210  }
1211  // reinitialize camera modules and rating modules per thread
1212  mThreadCameraModels.clear();
1213  mThreadRatingModules.clear();
1214  mThreadCameraModels.resize(mNumberOfThreads);
1215  mThreadRatingModules.resize(mNumberOfThreads);
1216  for (int i : boost::irange(0, mNumberOfThreads)) {
1217  // set RatingModule per thread
1218  if (mThreadRatingModules[i]) {
1219  mThreadRatingModules[i].reset();
1220  }
1221  mThreadRatingModules[i] = mRatingModuleAbstractFactoryPtr->createRatingModule();
1222  mThreadRatingModules[i]->setInputCloud(mPointCloudPtr);
1223 
1224  // set CameraModule per thread
1225  if (mThreadCameraModels[i]) {
1226  mThreadCameraModels[i].reset();
1227  }
1228  mThreadCameraModels[i] = mCameraModelFilterAbstractFactoryPtr->createCameraModelFilter();
1229  mThreadCameraModels[i]->setInputCloud(mPointCloudPtr);
1230  }
1231  }
1232 
1233  double getMinUtility() const {
1234  return mMinUtility;
1235  }
1236 
1237  void setMinUtility(double minUtility) {
1238  mMinUtility = minUtility;
1239  }
1240 
1241  bool getRequireMinUtility() const {
1242  return mRequireMinUtility;
1243  }
1244 
1245  void setRequireMinUtility(bool requireMinUtility) {
1246  mRequireMinUtility = requireMinUtility;
1247  }
1248 };
1249 
1250 }
bool rateViewports(const ViewportPointCloudPtr &sampleNextBestViewportsPtr, const ViewportPoint &currentCameraViewport, ViewportPoint &resultViewport, bool objectTypeSetIsKnown=false)
rates given viewports, which must contain child_indices
bool getFeasibleHypothesis(SimpleVector3 samplePoint, IndicesPtr &resultIndicesPtr)
getFeasibleHypothesis finds object hypothesis near samplePoint
void getFeasibleSamplePoints(const SamplePointCloudPtr &sampledSpacePointCloudPtr, IndicesPtr &resultIndicesPtr)
SimpleVector3 getSimpleVector3() const
void setHypothesisUpdater(const HypothesisUpdaterPtr &hypothesisUpdaterPtr)
unsigned int getNumberTotalNormals(std::string type, std::string identifier)
pcl::PointCloud< ObjectPoint > ObjectPointCloud
Definition: typedef.hpp:85
void setEnableIntermediateObjectWeighting(const bool mEnableIntermediateObjectWeighting)
void ratingThread(int threadId, boost::mutex &mutex, const ViewportPointCloudPtr &sampleNextBestViewports, const ViewportPoint &currentCameraViewport, const ViewportPointCloudPtr &ratedNextBestViewports, bool objectTypeSetIsKnown)
ratingThread
bool doFrustumCulling(const SimpleVector3 &position, const SimpleQuaternion &orientation, const IndicesPtr &indices, ViewportPoint &viewportPoint)
creates a new camera viewport with the given data
void setHeight(SamplePointCloudPtr pointCloudPtr, double height)
void setCameraModelFilter(const CameraModelFilterPtr &cameraModelFilterPtr)
bool setNormalsInCropBoxMode(const ObjectPoint &pointCloudPoint)
bool rateViewportsInternal(const ViewportPointCloudPtr &sampleNextBestViewports, const ViewportPoint &currentCameraViewport, ViewportPointCloudPtr &ratedNextBestViewports, ViewportPoint &resultViewport, bool objectTypeSetIsKnown)
rates viewports and returns vector with rated wiewports and the best rated viewport ...
CameraModelFilterAbstractFactoryPtr mCameraModelFilterAbstractFactoryPtr
bool isPointInCropbox(const SimpleVector3 &position, const Eigen::Vector3f &translation, const Eigen::Vector4f &max) const
unsigned int getNumberActiveNormals(std::string type, std::string identifier)
std::string getMeshPathByName(std::string objectType)
bool doIteration(const ViewportPoint &currentCameraViewport, const SimpleQuaternionCollectionPtr &sampledOrientationsPtr, ViewportPoint &resultViewport)
bool setNormals(const ObjectPoint &pointCloudPoint)
SimpleVector3CollectionPtr normal_vectors
bool isPointInRange(float point, float min, float lenght) const
IntermediateObjectWeightResponse::Ptr IntermediateObjectWeightResponsePtr
Definition: ObjectHelper.h:33
void setCameraModelFilterAbstractFactoryPtr(const CameraModelFilterAbstractFactoryPtr &cameraModelFilterAbstractFactoryPtr)
setCameraModelFilterAbstractFactoryPtr used to generate camera models per thread. ...
ViewportPointCloud::Ptr ViewportPointCloudPtr
Definition: typedef.hpp:97
Eigen::Matrix< Precision, 3, 1 > SimpleVector3
Definition: typedef.hpp:53
void initializeRobotState(const ViewportPoint &currentCameraViewport)
initializeRobotState initializes the robotstate to the given viewport
bool doFrustumCulling(const CameraModelFilterPtr &cameraModelFilterPtr, ViewportPoint &resultViewportPoint)
creates a new camera viewport with the given data
bool setPointCloudFromMessage(const asr_msgs::AsrAttributedPointCloud &msg)
///
bool doFrustumCulling(const CameraModelFilterPtr &cameraModelFilterPtr, const SimpleVector3 &position, const SimpleQuaternion &orientation, const IndicesPtr &indices, ViewportPoint &resultViewport)
creates a new camera viewport with the given data
bool doIterationStep(const ViewportPoint &currentCameraViewport, const ViewportPoint &currentBestViewport, const SimpleQuaternionCollectionPtr &sampledOrientationsPtr, float contractor, ViewportPoint &resultViewport, int iterationStep)
std::vector< SimpleQuaternion, Eigen::aligned_allocator< SimpleQuaternion > > SimpleQuaternionCollection
Definition: typedef.hpp:70
ViewportPointCloudPtr combineSamples(SamplePointCloudPtr sampledSpacePointCloudPtr, SimpleQuaternionCollectionPtr sampledOrientationsPtr)
combines space samples and orientation samples to viewport samples
std::map< std::string, std::string > objectsResources
void setNumberOfThreads(int value)
sets number of threads used to rate samples, negative numbers use boost::thread::hardware_concurrency...
std::vector< CameraModelFilterPtr > mThreadCameraModels
std::set< std::string > ObjectTypeSet
Definition: typedef.hpp:124
std::vector< int > Indices
Definition: typedef.hpp:117
unsigned int updateObjectPointCloud(const ObjectTypeSetPtr &objectTypeSetPtr, const ViewportPoint &viewportPoint)
Updates the point cloud under the assumption that the given viewport was chosen.
bool rateViewports(const ViewportPointCloudPtr &sampleNextBestViewports, const ViewportPoint &currentCameraViewport, ViewportPointCloudPtr &ratedNextBestViewportsPtr, bool objectTypeSetIsKnown=false)
rates given viewports, which must contain child_indices
SamplePointCloud::Ptr SamplePointCloudPtr
Definition: typedef.hpp:93
pcl::PointCloud< SamplePoint > SamplePointCloud
Definition: typedef.hpp:92
SimpleQuaternion getSimpleQuaternion() const
IntermediateObjectWeightResponsePtr getIntermediateObjectValue(std::string objectTypeName)
Definition: ObjectHelper.h:117
std::vector< float > SquaredDistances
Definition: typedef.hpp:114
The CropBoxFilter class, used to filter objects in crop boxes.
SamplePointCloudPtr generateSpaceSamples(SimpleVector3 spaceSampleStartVector, double contractor, double pointCloudHeight)
generateSpaceSamples
boost::shared_ptr< RatingModule > RatingModulePtr
Definition for the shared pointer type of the class.
void setSpaceSampler(const SpaceSamplerPtr &spaceSamplerPtr)
bool rateSingleViewportFixedObjectTypes(const RatingModulePtr &ratingModulePtr, const ViewportPoint &currentCameraViewport, ViewportPoint &fullViewportPoint)
uses setSingleScoreContainer to use object_type_set of fullViewportPoint to rate. ...
this namespace contains all generally usable classes.
void setRatingModuleAbstractFactoryPtr(const RatingModuleAbstractFactoryPtr &ratingModuleAbstractFactoryPtr)
setRatingModuleAbstractFactoryPtr used to generate rating modules per thread.
boost::shared_ptr< CropBoxFilter > CropBoxFilterPtr
CropBoxFilterPtr typedef for consistency/less code to create boost::shared_ptr to CropBoxFilter...
ObjectMetaDataResponsePtr getObjectMetaData(std::string objectTypeName)
Definition: ObjectHelper.h:73
void setPointCloudPtr(const ObjectPointCloudPtr &pointCloudPtr)
void setMapHelper(const MapHelperPtr &mapHelperPtr)
pcl::KdTreeFLANN< ObjectPoint > KdTree
Definition: typedef.hpp:109
NextBestViewCalculator(const UnitSphereSamplerPtr &unitSphereSamplerPtr=UnitSphereSamplerPtr(), const MapHelperPtr &mapHelperPtr=MapHelperPtr(), const SpaceSamplerPtr &spaceSamplerPtr=SpaceSamplerPtr(), const robot_model_services::RobotModelPtr &robotModelPtr=robot_model_services::RobotModelPtr(), const CameraModelFilterPtr &cameraModelFilterPtr=CameraModelFilterPtr(), const RatingModulePtr &ratingModulePtr=RatingModulePtr())
pcl::PointCloud< ViewportPoint > ViewportPointCloud
Definition: typedef.hpp:96
robot_model_services::RobotModelPtr mRobotModelPtr
RatingModuleAbstractFactoryPtr mRatingModuleAbstractFactoryPtr
void setActiveIndices(const IndicesPtr &activeIndicesPtr)
sets the active indices.
void loadCropBoxListFromFile(const std::string mCropBoxListFilePath)
static boost::shared_ptr< DebugHelper > getInstance()
Definition: DebugHelper.cpp:29
ROSCPP_DECL bool ok()
void updateFromExternalViewportPointList(const std::vector< ViewportPoint > &viewportPointList)
updates point cloud with external viewport point list
CropBox::Ptr CropBoxPtr
Definition: typedef.hpp:106
boost::shared_ptr< Indices > IndicesPtr
Definition: typedef.hpp:118
bool filterObjectPointCloudByTypes(const ObjectTypeSetPtr &objectTypeSetPtr, ViewportPoint &viewportPoint)
filters all the objects in this viewport with one of the given types and puts them in a new viewport...
bool rateSingleViewportOptimizeObjectTypes(const RatingModulePtr &ratingModulePtr, const ViewportPoint &currentCameraViewport, ViewportPoint &fullViewportPoint)
uses setBestScoreContainer to optimize which objects should be recognized
void setUnitSphereSampler(const UnitSphereSamplerPtr &unitSphereSamplerPtr)
#define ROS_WARN_STREAM(args)
boost::shared_ptr< ObjectTypeSet > ObjectTypeSetPtr
Definition: typedef.hpp:125
KdTree::Ptr KdTreePtr
Definition: typedef.hpp:110
DefaultViewportPoint ViewportPoint
Definition: typedef.hpp:81
boost::shared_ptr< VisualizationHelper > VisualizationHelperPtr
static std_msgs::ColorRGBA getMeshColor(std::string observedId)
CameraModelFilterAbstractFactoryPtr getCameraModelFilterAbstractFactoryPtr()
getCameraModelFilterAbstractFactoryPtr
robot_model_services::RobotModelPtr getRobotModel()
void setEnableCropBoxFiltering(const bool mEnableCropBoxFiltering)
SimpleVector3 getPosition() const
int getNumberOfThreads() const
getNumberOfThreads
RatingModuleAbstractFactoryPtr getRatingModuleAbstractFactoryPtr()
getRatingModuleAbstractFactoryPtr
void setRequireMinUtility(bool requireMinUtility)
std::vector< std::pair< std::string, std::string > > getTypeAndIds()
ObjectPointCloud::Ptr ObjectPointCloudPtr
Definition: typedef.hpp:86
bool removeObjects(std::string type, std::string identifier)
#define ROS_INFO_STREAM(args)
void setRobotModel(const robot_model_services::RobotModelPtr &robotModelPtr)
boost::shared_ptr< CameraModelFilter > CameraModelFilterPtr
Definition for the shared pointer type of the class.
ViewportPointCloudPtr generateSampleViewports(SimpleVector3 spaceSampleStartVector, double contractor, double pointCloudHeight)
generateSampleViewports
std::vector< RatingModulePtr > mThreadRatingModules
boost::shared_ptr< UnitSphereSampler > UnitSphereSamplerPtr
Definition for the shared pointer type of the class.
bool calculateNextBestView(const ViewportPoint &currentCameraViewport, ViewportPoint &resultViewport)
ObjectMetaDataResponse::Ptr ObjectMetaDataResponsePtr
Definition: ObjectHelper.h:31
Eigen::Quaternion< Precision > SimpleQuaternion
Definition: typedef.hpp:67
Eigen::Matrix< Precision, 3, 3 > SimpleMatrix3
Definition: typedef.hpp:40
#define ROS_ERROR(...)
SimpleQuaternion getSimpleQuaternion() const
void getFeasibleViewports(const ViewportPointCloudPtr &sampleViewportsPtr, IndicesPtr &resultIndicesPtr)
getFeasibleViewports returns a vector of indices/sampleViewports which contain nearby (hypothesis) ...
void setRatingModule(const RatingModulePtr &ratingModulePtr)
boost::shared_ptr< SpaceSampler > SpaceSamplerPtr
Definition for the shared pointer type of the class.
boost::shared_ptr< MapHelper > MapHelperPtr
Definition: MapHelper.hpp:424
SimpleQuaternionCollectionPtr generateOrientationSamples()
generateOrientationSamples
bool doFrustumCulling(ViewportPoint &resultViewportPoint)
creates a new camera viewport with the given data


asr_next_best_view
Author(s): Aumann Florian, Borella Jocelyn, Heller Florian, Meißner Pascal, Schleicher Ralf, Stöckle Patrick, Stroh Daniel, Trautmann Jeremias, Walter Milena, Wittenbeck Valerij
autogenerated on Thu Jan 9 2020 07:20:18