util.cpp
Go to the documentation of this file.
1 /**
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @author Fabian Reister ( fabian dot reister at kit dot edu )
17  * @date 2022
18  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19  * GNU General Public License
20  */
21 
22 #include "util.h"
23 
24 #include <string>
25 
26 #include <Eigen/Geometry>
27 
28 #include <VirtualRobot/ManipulationObject.h>
29 #include <VirtualRobot/SceneObjectSet.h>
30 
32 
33 namespace armarx::objpose
34 {
35 
37  filterObjects(objpose::ObjectPoseSeq objects, const std::vector<std::string>& datasetBlocklist)
38  {
39  const auto isBlacklisted = [&datasetBlocklist](const objpose::ObjectPose& objectPose)
40  {
41  const auto dataset = objectPose.objectID.dataset();
42 
43  return std::find(datasetBlocklist.begin(), datasetBlocklist.end(), dataset) !=
44  datasetBlocklist.end();
45  };
46 
47  objects.erase(std::remove_if(objects.begin(), objects.end(), isBlacklisted), objects.end());
48  return objects;
49  }
50 
51 
52  VirtualRobot::ManipulationObjectPtr
54  {
55  ObjectFinder finder;
56 
57  VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
58  if (auto obstacle = finder.loadManipulationObject(objectPose))
59  {
60  obstacle->setGlobalPose(objectPose.objectPoseGlobal);
61  return obstacle;
62  }
63 
64  ARMARX_WARNING << "Failed to load scene object `" << objectPose.objectID << "`";
65  return nullptr;
66  }
67 
68 
69  VirtualRobot::SceneObjectSetPtr
71  {
72  ObjectFinder finder;
73 
74  VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
75  for (const auto& objectPose : objectPoses)
76  {
77  if (auto obstacle = finder.loadManipulationObject(objectPose))
78  {
79  obstacle->setGlobalPose(objectPose.objectPoseGlobal);
80  sceneObjects->addSceneObject(obstacle);
81  }
82  }
83 
84  return sceneObjects;
85  }
86 
87 
88 } // namespace armarx::objpose
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
armarx::objpose::filterObjects
objpose::ObjectPoseSeq filterObjects(objpose::ObjectPoseSeq objects, const std::vector< std::string > &datasetBlocklist)
Definition: util.cpp:37
armarx::objpose::asSceneObjects
VirtualRobot::SceneObjectSetPtr asSceneObjects(const objpose::ObjectPoseSeq &objectPoses)
Definition: util.cpp:70
util.h
armarx::ObjectFinder::loadManipulationObject
static VirtualRobot::ManipulationObjectPtr loadManipulationObject(const std::optional< ObjectInfo > &ts)
Definition: ObjectFinder.cpp:298
armarx::ObjectFinder
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
Definition: ObjectFinder.h:23
armarx::objpose
This file is part of ArmarX.
Definition: objpose.h:7
armarx::objpose::ObjectPose::objectID
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition: ObjectPose.h:58
armarx::objpose::ObjectPose::objectPoseGlobal
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition: ObjectPose.h:73
armarx::objpose::asManipulationObject
VirtualRobot::ManipulationObjectPtr asManipulationObject(const objpose::ObjectPose &objectPose)
Definition: util.cpp:53
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:36
ObjectFinder.h