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 
34 {
35 
38  const std::vector<std::string>& datasetDisableList)
39  {
40  const auto isInDisableList = [&datasetDisableList](const objpose::ObjectPose& objectPose)
41  {
42  const auto dataset = objectPose.objectID.dataset();
43 
44  return std::find(datasetDisableList.begin(), datasetDisableList.end(), dataset) !=
45  datasetDisableList.end();
46  };
47 
48  objects.erase(std::remove_if(objects.begin(), objects.end(), isInDisableList),
49  objects.end());
50  return objects;
51  }
52 
55  {
56  const auto isDynamic = [](const objpose::ObjectPose& objectPose)
57  { return not objectPose.isStatic; };
58 
59  objects.erase(std::remove_if(objects.begin(), objects.end(), isDynamic), objects.end());
60  return objects;
61  }
62 
65  {
66  ObjectFinder finder;
67  finder.setLogObjectDiscoveryError(false);
68 
69  const auto isArticulated = [&finder](const objpose::ObjectPose& objectPose)
70  {
71  const auto objInfo = finder.findObject(objectPose.objectID);
72  ARMARX_CHECK_NOT_NULL(objInfo) << objectPose.objectID;
73  const bool hasArticulatedModel = objInfo->getArticulatedModel().has_value();
74  return hasArticulatedModel;
75  };
76 
77  objects.erase(std::remove_if(objects.begin(), objects.end(), isArticulated), objects.end());
78  return objects;
79  }
80 
83  {
84  ObjectFinder finder;
85  finder.setLogObjectDiscoveryError(false);
86 
87  const auto isNonArticulated = [&finder](const objpose::ObjectPose& objectPose)
88  {
89  const auto objInfo = finder.findObject(objectPose.objectID);
90  ARMARX_CHECK_NOT_NULL(objInfo) << objectPose.objectID;
91  const bool hasArticulatedModel = objInfo->getArticulatedModel().has_value();
92  return not hasArticulatedModel;
93  };
94 
95  objects.erase(std::remove_if(objects.begin(), objects.end(), isNonArticulated),
96  objects.end());
97  return objects;
98  }
99 
100  std::optional<objpose::ObjectPose>
101  findObject(const objpose::ObjectPoseSeq& objectPoses, const armarx::ObjectID& objectID)
102  {
103  const auto matchesId = [&objectID](const objpose::ObjectPose& objectPose) -> bool
104  { return objectPose.objectID == objectID; };
105 
106  const auto it = std::find_if(objectPoses.begin(), objectPoses.end(), matchesId);
107  if (it != objectPoses.end())
108  {
109  return *it;
110  }
111 
112  return std::nullopt;
113  }
114 
115  VirtualRobot::ManipulationObjectPtr
117  {
118  ObjectFinder finder;
119  finder.setLogObjectDiscoveryError(false);
120 
121  VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
122  if (auto obstacle = finder.loadManipulationObject(objectPose))
123  {
124  obstacle->setGlobalPose(objectPose.objectPoseGlobal);
125  return obstacle;
126  }
127 
128  ARMARX_WARNING << "Failed to load scene object `" << objectPose.objectID << "`";
129  return nullptr;
130  }
131 
132  VirtualRobot::SceneObjectSetPtr
134  {
135  ObjectFinder finder;
136  finder.setLogObjectDiscoveryError(false);
137 
138  VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
139  for (const auto& objectPose : objectPoses)
140  {
141  ARMARX_VERBOSE << "Loading object `" << objectPose.objectID << "`";
142  if (auto obstacle = finder.loadManipulationObject(objectPose))
143  {
144  obstacle->setGlobalPose(objectPose.objectPoseGlobal);
145  sceneObjects->addSceneObject(obstacle);
146  }
147  }
148 
149  return sceneObjects;
150  }
151 
154  {
155  ObjectFinder finder;
156  finder.setLogObjectDiscoveryError(false);
157 
158  VirtualRobot::SceneObjectSetPtr sceneObjects(new VirtualRobot::SceneObjectSet);
159  if (auto obstacle = finder.loadManipulationObject(objectPose))
160  {
161  obstacle->setGlobalPose(objectPose.objectPoseGlobal);
162  return obstacle;
163  }
164  return nullptr;
165  }
166 
167 
168 } // namespace armarx::objpose
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
armarx::ObjectID
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition: ObjectID.h:10
armarx::objpose::util::filterObjects
objpose::ObjectPoseSeq filterObjects(objpose::ObjectPoseSeq objects, const std::vector< std::string > &datasetDisableList)
Definition: util.cpp:37
armarx::objpose::ObjectPoseSeq
std::vector< ObjectPose > ObjectPoseSeq
Definition: forward_declarations.h:20
armarx::objpose::util::findObject
std::optional< objpose::ObjectPose > findObject(const objpose::ObjectPoseSeq &objectPoses, const armarx::ObjectID &objectID)
Definition: util.cpp:101
ARMARX_CHECK_NOT_NULL
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
Definition: ExpressionException.h:206
armarx::objpose::util::articulatedObjects
objpose::ObjectPoseSeq articulatedObjects(objpose::ObjectPoseSeq objects)
Definition: util.cpp:82
armarx::objpose::util::asSceneObject
VirtualRobot::SceneObjectPtr asSceneObject(const objpose::ObjectPose &objectPose)
Definition: util.cpp:153
util.h
armarx::ObjectFinder::loadManipulationObject
static VirtualRobot::ManipulationObjectPtr loadManipulationObject(const std::optional< ObjectInfo > &ts)
Definition: ObjectFinder.cpp:310
armarx::ObjectFinder::setLogObjectDiscoveryError
void setLogObjectDiscoveryError(bool logEnabled)
Definition: ObjectFinder.cpp:397
armarx::ObjectFinder
Used to find objects in the ArmarX objects repository [1] (formerly [2]).
Definition: ObjectFinder.h:22
armarx::objpose::util::staticObjects
objpose::ObjectPoseSeq staticObjects(objpose::ObjectPoseSeq objects)
Definition: util.cpp:54
armarx::objpose::ObjectPose::objectID
armarx::ObjectID objectID
The object ID, i.e. dataset, class name and instance name.
Definition: ObjectPose.h:56
armarx::objpose::util::nonArticulatedObjects
objpose::ObjectPoseSeq nonArticulatedObjects(objpose::ObjectPoseSeq objects)
Definition: util.cpp:64
armarx::objpose::util::asManipulationObject
VirtualRobot::ManipulationObjectPtr asManipulationObject(const objpose::ObjectPose &objectPose)
Definition: util.cpp:116
armarx::objpose::ObjectPose::objectPoseGlobal
Eigen::Matrix4f objectPoseGlobal
The object pose in the global frame.
Definition: ObjectPose.h:71
armarx::objpose::util::asSceneObjects
VirtualRobot::SceneObjectSetPtr asSceneObjects(const objpose::ObjectPoseSeq &objectPoses)
Definition: util.cpp:133
armarx::objpose::util
This file is part of ArmarX.
Definition: util.cpp:33
armarx::ObjectFinder::findObject
std::optional< ObjectInfo > findObject(const std::string &dataset, const std::string &name) const
Definition: ObjectFinder.cpp:64
scene3D::SceneObjectPtr
boost::intrusive_ptr< SceneObject > SceneObjectPtr
Definition: PointerDefinitions.h:40
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::objpose::ObjectPose
An object pose as stored by the ObjectPoseStorage.
Definition: ObjectPose.h:33
ObjectFinder.h