ArticulatedObjectWriter.cpp
Go to the documentation of this file.
2
3#include <Eigen/Core>
4#include <Eigen/Geometry>
5
6#include <SimoxUtility/algorithm/string/string_tools.h>
7#include <VirtualRobot/Nodes/RobotNode.h>
8#include <VirtualRobot/Robot.h>
9
14
16{
17
18 // Slow version with filesystem access. It runs CMake for each project / environment variable.
20 convert(const VirtualRobot::Robot& obj, const armem::Time& timestamp)
21 {
22 ARMARX_DEBUG << "Filename is " << obj.getFilename();
23
24 // this is very inefficient. It runs CMake for each project
25 const std::vector<std::string> packages =
27 const std::string package = armarx::ArmarXDataPath::getProject(packages, obj.getFilename());
28
29 // make sure that the relative path is without the 'package/' prefix
30 const std::string fileRelPath = [&obj, &package]() -> std::string
31 {
32 if (simox::alg::starts_with(obj.getFilename(), package))
33 {
34 // remove "package" + "/"
35 const std::string fixedFilename = obj.getFilename().substr(package.size() + 1, -1);
36 return fixedFilename;
37 }
38
39 return obj.getFilename();
40 }();
41
43 .description = {.name = obj.getType(),
44 .xml = PackagePath(
45 armarx::ArmarXDataPath::getProject({package}, fileRelPath),
46 obj.getFilename()),
47 .visualization = {},
48 .info = {}},
49 .instance = obj.getName(),
50 .config = {.timestamp = timestamp,
51 .globalPose = Eigen::Isometry3f(obj.getRootNode()->getGlobalPose()),
52 .jointMap = obj.getJointValues(),
53 .proprioception = std::nullopt},
54 .timestamp = timestamp};
55 }
56
57 // fast version without filesystem (CMake) access
59 convertWithoutPackagePath(const VirtualRobot::Robot& obj, const armem::Time& timestamp)
60 {
61 ARMARX_DEBUG << "Filename is " << obj.getFilename();
62
64 .description = {.name = obj.getType(), .xml = {}, .visualization = {}, .info = {}},
65 .instance = obj.getName(),
66 .config = {.timestamp = timestamp,
67 .globalPose = Eigen::Isometry3f(obj.getRootNode()->getGlobalPose()),
68 .jointMap = obj.getJointValues(),
69 .proprioception = std::nullopt},
70 .timestamp = timestamp};
71 }
72
73 bool
75 const VirtualRobot::RobotPtr& articulatedObject,
77 const bool isStatic)
78 {
79
80 ARMARX_CHECK_NOT_NULL(articulatedObject);
81
83 convert(*articulatedObject, timestamp);
84
85 return store(armemArticulatedObject, isStatic);
86 }
87
88 bool
91 const bool isStatic)
92 {
93
94 ARMARX_CHECK_NOT_NULL(articulatedObject);
95
97 convertWithoutPackagePath(*articulatedObject, timestamp);
98
99 return storeInstance(armemArticulatedObject, isStatic);
100 }
101
102} // namespace armarx::armem::articulated_object
std::string timestamp()
static std::string getProject(const std::vector< std::string > &projects, const std::string &relativeFilename)
static std::vector< std::string > FindAllArmarXSourcePackages()
bool storeArticulatedObject(const VirtualRobot::RobotPtr &articulatedObject, const armem::Time &timestamp, bool isStatic=false)
Stores the articulated object in the memory.
bool storeArticulatedObjectWithObjectClass(const VirtualRobot::RobotPtr &articulatedObject, const armem::Time &timestamp, bool isStatic=false)
Stores the articulated object.
bool store(const ArticulatedObject &obj, bool isStatic) const override
Definition Writer.cpp:242
bool storeInstance(const ArticulatedObject &obj, bool isStatic) const
Definition Writer.cpp:163
#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...
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
armarx::armem::robot_state::Robot ArticulatedObject
Definition types.h:140
armarx::core::time::DateTime Time