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.
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,
76  const armem::Time& timestamp,
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
90  const armem::Time& timestamp,
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
armarx::armem::articulated_object::ArticulatedObjectWriter::storeArticulatedObjectWithObjectClass
bool storeArticulatedObjectWithObjectClass(const VirtualRobot::RobotPtr &articulatedObject, const armem::Time &timestamp, bool isStatic=false)
Stores the articulated object.
Definition: ArticulatedObjectWriter.cpp:74
armarx::armem::robot_state::Robot
Definition: types.h:126
armarx::CMakePackageFinder::FindAllArmarXSourcePackages
static std::vector< std::string > FindAllArmarXSourcePackages()
Definition: CMakePackageFinder.cpp:461
armarx::armem::server::ltm::mongodb::util::convert
void convert(const mongocxx::database &db, armem::wm::Memory &m)
Definition: operations.cpp:186
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::ArmarXDataPath::getProject
static std::string getProject(const std::vector< std::string > &projects, const std::string &relativeFilename)
Definition: ArmarXDataPath.cpp:299
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
armarx::armem::articulated_object::Writer::storeInstance
bool storeInstance(const ArticulatedObject &obj, bool isStatic) const
Definition: Writer.cpp:163
armarx::armem::articulated_object::Writer::store
bool store(const ArticulatedObject &obj, bool isStatic) const override
Definition: Writer.cpp:241
armarx::armem::human::Robot
@ Robot
Definition: util.h:17
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::armem::articulated_object::ArticulatedObject
armarx::armem::robot_state::Robot ArticulatedObject
Definition: types.h:140
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
ExpressionException.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
CMakePackageFinder.h
armarx::armem::robot_state::description::RobotDescription::name
std::string name
Definition: types.h:48
armarx::armem::articulated_object
Definition: ArticulatedObjectReader.cpp:26
Logging.h
ArmarXDataPath.h
armarx::armem::articulated_object::ArticulatedObjectWriter::storeArticulatedObject
bool storeArticulatedObject(const VirtualRobot::RobotPtr &articulatedObject, const armem::Time &timestamp, bool isStatic=false)
Stores the articulated object in the memory.
Definition: ArticulatedObjectWriter.cpp:89
armarx::armem::robot_state::Robot::description
description::RobotDescription description
Definition: types.h:128
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19
ArticulatedObjectWriter.h