19 #include <Eigen/Geometry> 22 #include "ISM/utility/GeometryHelper.hpp" 27 IH::ObjectConverter::ObjectConverter(
const std::string& pBaseFrame,
const bool pIgnoreTypes,
const bool pIgnoreIds,
const int pEnableRotationMode,
const std::string pRotationFrame,
const std::string pRotationObjType,
const std::string pRotationObjId) : mBaseFrame(pBaseFrame),
28 mIgnoreTypes(pIgnoreTypes), mIgnoreIds(pIgnoreIds), mEnableRotationMode(pEnableRotationMode), mRotationFrame(pRotationFrame), mRotationObjType(pRotationObjType), mRotationObjId(pRotationObjId), mUseConfidenceFromMsg(false),
34 IH::ObjectConverter::ObjectConverter(
const std::string& pBaseFrame,
const bool pIgnoreTypes,
const bool pIgnoreIds,
const int pEnableRotationMode,
const std::string pRotationFrame,
const std::string pRotationObjType,
const std::string pRotationObjId,
const bool pUseConfidenceFromMsg)
43 Eigen::Quaterniond orientationRef;
44 Eigen::Vector3d yUnitVector;
47 for (ISM::ObjectPtr
object : objectSet->objects) {
59 yUnitVector = Eigen::Vector3d::UnitY();
65 orientationRef = Eigen::Quaterniond(1.0, 0, 0, 0);
66 yUnitVector = -Eigen::Vector3d::UnitZ();
68 orientationRef.normalize();
70 for (ISM::ObjectPtr
object : objectSet->objects) {
71 asr_object_database::ObjectMetaData objMetaData;
72 objMetaData.request.object_type =
object->type;
73 objMetaData.request.recognizer =
object->providedBy ==
"fake_data_publisher" ||
"fake_object_recognition" ?
"segmentable" :
object->providedBy;
75 if (objMetaData.response.is_rotation_invariant)
77 Eigen::Quaterniond orientation = ISM::GeometryHelper::quatToEigenQuat(object->pose->quat);
78 orientation.normalize();
79 Eigen::Vector3d objYAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientation), Eigen::Vector3d::UnitY());
80 Eigen::Vector3d refYAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientationRef), yUnitVector);
81 Eigen::AngleAxisd yTransform =
calculateTransform(objYAxis, refYAxis, Eigen::Vector3d::UnitX());
82 Eigen::Quaterniond yAlignedOrientation = (yTransform * orientation).normalized();
83 Eigen::Vector3d objXAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(yAlignedOrientation), Eigen::Vector3d::UnitX());
84 Eigen::Vector3d refXAxis = ISM::GeometryHelper::getAxisFromQuat(ISM::GeometryHelper::eigenQuatToQuat(orientationRef), Eigen::Vector3d::UnitX());
85 object->pose->quat->eigen = (yTransform.inverse() *
calculateTransform(objXAxis, refXAxis, Eigen::Vector3d::UnitY())).normalized() * yAlignedOrientation;
88 ROS_ERROR(
"Could not call the asr_object_database::ObjectMetaData service call");
94 double angle = ISM::GeometryHelper::getAngleBetweenAxes(referenceAxis, objectAxis);
95 Eigen::Vector3d rotationAxis = objectAxis.cross(referenceAxis);
96 rotationAxis.normalize();
100 return Eigen::AngleAxisd(0, unitAxis);
101 }
else if (fabs(angle - M_PI) < 0.001) {
102 return Eigen::AngleAxisd(M_PI, unitAxis);
104 return Eigen::AngleAxisd(angle, rotationAxis);
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
ISM::ObjectPtr mRotationRefObject
Current object pose, to which rotation invariant objects are normalized.
const bool mIgnoreTypes
Whether to take over object types from AsrObjects.
const std::string mRotationObjType
If normalizing to object: Which type of object to normalize to.
bool call(MReq &req, MRes &res)
std::string getName(void *handle)
const bool mUseConfidenceFromMsg
Whether to take over recognition confidences (into ism rating) from AsrObjects.
const int mEnableRotationMode
Normalize orientations of rotation invariant objects to either a coordinate frame or an not-rotation ...
Eigen::AngleAxisd calculateTransform(const Eigen::Vector3d &objectAxis, const Eigen::Vector3d &referenceAxis, const Eigen::Vector3d &unitAxis)
calculateTransform Caculate the transformation between two vectors.
void normalizeRotationInvariantObjects(ISM::ObjectSetPtr objectSet)
normalizeOrientation Normalizes the orientation of rotation invariance objects accroding to: ...
ros::ServiceClient objectMetaDataClient
ObjectConverter(const std::string &pBaseFrame, const bool pIgnoreTypes, const bool pIgnoreIds, const int pEnableRotationMode, const std::string pRotationFrame, const std::string pRotationObjType, const std::string pRotationObjId)
const std::string mRotationFrame
If normalizing to frame: Which frame to normalize to.
const std::string mBaseFrame
Frame to which incoming object messages are transformed.
#define ROS_INFO_STREAM(args)
ros::NodeHandle nodehandle
const int ROTATION_MODE_FRAME
const bool mIgnoreIds
Whether to take over object ids from AsrObjects.
const std::string mRotationObjId
If normalizing to object: Which id of object to normalize to.
const int ROTATION_MODE_OBJECT
const int ROTATION_MODE_DEACTIVATED