articulated_objects.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 Niklas Arlt ( niklas dot arlt at kit dot edu )
17 * @date 2026
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#include "articulated_objects.h"
23
24#include <set>
25#include <sstream>
26
27#include <VirtualRobot/Robot.h>
28
32
34
36{
37
38 std::string
40 {
41 std::stringstream ss;
42 for (const auto& objectID : missing)
43 {
44 if (ss.tellp() > 0)
45 {
46 ss << ", ";
47 }
48 ss << objectID.str();
49 }
50 return ss.str();
51 }
52
55 const objpose::ObjectPoseSeq& articulatedObjectPoses,
56 VirtualRobot::RobotIO::RobotDescription loadMode)
57 {
59
60 for (const auto& objectPose : articulatedObjectPoses)
61 {
62 const armarx::ObjectID& objectID = objectPose.objectID;
63
64 ARMARX_VERBOSE << "Loading articulated object: " << objectID;
65
66 VirtualRobot::RobotPtr articulatedObject;
67 try
68 {
69 // The reader has no non-throwing overload: it throws if the object's description
70 // or its instance state is not (yet) in the object memory.
71 articulatedObject = reader.getArticulatedObject(objectID.getClassID().str(),
73 std::nullopt,
74 objectID.instanceName(),
75 loadMode);
76 }
77 catch (const armarx::LocalException&)
78 {
79 ARMARX_WARNING << "Could not load articulated object `" << objectID
80 << "`: " << GetHandledExceptionString();
81 result.missing.push_back(objectID);
82 continue;
83 }
84
85 if (articulatedObject == nullptr)
86 {
87 ARMARX_WARNING << "Could not load articulated object `" << objectID
88 << "`: the robot model could not be loaded.";
89 result.missing.push_back(objectID);
90 continue;
91 }
92
93 if (not reader.synchronizeArticulatedObject(
94 *articulatedObject, armarx::Clock::Now(), std::nullopt))
95 {
96 ARMARX_WARNING << "Could not synchronize articulated object `" << objectID
97 << "`: no state available.";
98 result.missing.push_back(objectID);
99 continue;
100 }
101
102 if (articulatedObject->getCollisionModels().empty())
103 {
104 ARMARX_VERBOSE << "The articulated object `" << articulatedObject->getType() << "/"
105 << articulatedObject->getName()
106 << "` does not have a collision model. Using primitive model "
107 "instead.";
108
109 std::set<std::string> primitiveIDs;
110 articulatedObject->getPrimitiveApproximationIDs(primitiveIDs);
111
112 // use all primitive ids
113 // TODO: refine selection?
114 const std::vector<std::string> usedPrimitiveModelIDs(primitiveIDs.begin(),
115 primitiveIDs.end());
116 articulatedObject->setPrimitiveApproximationModel(usedPrimitiveModelIDs);
117 }
118
119 result.objects.push_back(articulatedObject);
120 }
121
122 return result;
123 }
124
125} // namespace armarx::navigation::util
static DateTime Now()
Current time on the virtual clock.
Definition Clock.cpp:93
A known object ID of the form "Dataset/ClassName" or "Dataset/ClassName/InstanceName".
Definition ObjectID.h:11
ObjectID getClassID() const
Return just the class ID without an intance name.
Definition ObjectID.cpp:71
std::string instanceName() const
Definition ObjectID.h:36
std::string str() const
Return "dataset/className" or "dataset/className/instanceName".
Definition ObjectID.cpp:60
VirtualRobot::RobotPtr getArticulatedObject(const std::string &typeName, const armem::Time &timestamp, const std::optional< std::string > &providerName, const std::string &instanceName="", VirtualRobot::RobotIO::RobotDescription loadMode=VirtualRobot::RobotIO::eStructure)
bool synchronizeArticulatedObject(VirtualRobot::Robot &object, const armem::Time &timestamp, const std::optional< std::string > &providerName)
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:191
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:185
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file is part of ArmarX.
ArticulatedObjectsResult loadArticulatedObjects(armem::articulated_object::ArticulatedObjectReader &reader, const objpose::ObjectPoseSeq &articulatedObjectPoses, VirtualRobot::RobotIO::RobotDescription loadMode)
Loads the articulated objects for the given (already filtered) articulated object poses.
std::vector< ObjectPose > ObjectPoseSeq
std::string GetHandledExceptionString()
std::vector< armarx::ObjectID > missing
Objects whose description or state was not (yet) available in the object memory.
std::string missingToString() const
The missing object IDs, for logging.
std::vector< VirtualRobot::RobotPtr > objects