21 #include <ISM/utility/GeometryHelper.hpp> 22 #include <ISM/common_type/Pose.hpp> 23 #include <ISM/common_type/Object.hpp> 24 #include <ISM/common_type/RecognitionResult.hpp> 50 ISM::PosePtr
id = ISM::PosePtr(
new ISM::Pose(
new ISM::Point(),
new ISM::Quaternion()));
51 std::vector<ISM::PosePtr> poses;
54 id->quat = (ISM::GeometryHelper::getQuatFromRPY(id->quat, 0, 0, 180));
68 if (result->referencePose ==
nullptr)
73 std::vector<ISM::RecognitionResultPtr> ism_tree =
traverseTree(result, 0);
76 max_depth = std::max(max_depth, ism_to_depth_map_iter.second);
82 std::stringstream ns_stream;
83 ns_stream <<
"ism_" << result->patternName <<
"_" <<
scene_iterator_ <<
"";
84 std::string marker_namespace = ns_stream.str();
88 for(ISM::RecognitionResultPtr leaf : ism_tree) {
89 std::string leaf_pattern_name = leaf->patternName;
90 int inverse_depth = max_depth - ism_to_depth_map_[leaf_pattern_name];
92 ISM::PosePtr from_pose_ptr =
getAdjustedPose(leaf->referencePose, inverse_depth,
false);
93 ISM::PointPtr from_point_ptr = from_pose_ptr->point;
96 ret_markers.markers.push_back(temp_marker);
102 ret_markers.markers.push_back(temp_marker);
114 std::vector<ISM::PosePtr> to_poses;
116 for(ISM::ObjectPtr
object : leaf->recognizedSet->objects){
118 to_poses.push_back(
getAdjustedPose(object->pose, inverse_depth,
true));
120 if(ism_to_depth_map_.find(object->type) != ism_to_depth_map_.end()){
124 if(ism_to_depth_map_.find(object->type + object->observedId) == ism_to_depth_map_.end()){
125 ISM::PosePtr adjusted_pose_ptr =
getAdjustedPose(object->pose, inverse_depth,
true);
129 if(!object->ressourcePath.empty()){
133 mesh_marker.scale.x = 0.0001;
134 mesh_marker.scale.y = 0.0001;
135 mesh_marker.scale.z = 0.0001;
136 ret_markers.markers.push_back(mesh_marker);
140 double height =
use_z_max_ ? std::abs(object->pose->point->eigen.z() - std::max(adjusted_pose_ptr->point->eigen.z(),
z_offset_)) : std::abs(
z_offset_ - std::min(object->pose->point->eigen.z(), adjusted_pose_ptr->point->eigen.z()));
142 ISM::PosePtr cylinder_pose_ptr =
calculateCylinderPose(object->pose, adjusted_pose_ptr->point, height);
146 cylinder_map_.insert(std::make_pair(object->type + object->observedId, std::make_pair(cylinder_pose_ptr, height)));
148 if(
cylinder_map_[object->type + object->observedId].second < height){
149 cylinder_map_[
object->type +
object->observedId] = std::make_pair(cylinder_pose_ptr, height);
154 adjusted_pose_ptr->quat =(
calculateOrientation(adjusted_pose_ptr->point, from_point_ptr,
true));
157 ret_markers.markers.insert(ret_markers.markers.end(), cube_markers.markers.begin(), cube_markers.markers.end());
163 ret_markers.markers.push_back(temp_marker);
175 ret_markers.markers.push_back(cylinder_marker);
182 ISM::PosePtr ret_pose_ptr = ISM::PosePtr(
new ISM::Pose());
185 ret_pose_ptr->point->eigen.z() =(std::min(
z_offset_, from_pose_ptr->point->eigen.z()) + height / 2);
186 ret_pose_ptr->point->eigen.y() = (from_pose_ptr->point->eigen.y());
187 ret_pose_ptr->point->eigen.x() = (from_pose_ptr->point->eigen.x());
196 pose_relative =
false;
198 double x = from_point_ptr->eigen.x() - to_point_ptr->eigen.x();
199 double y = from_point_ptr->eigen.y() - to_point_ptr->eigen.y();
200 double z = from_point_ptr->eigen.z() - to_point_ptr->eigen.z();
202 double az = atan2(-x, -z);
203 double alt = atan2(y, sqrt(x*x + z*z));
210 az = az < -M_PI / 2 || az > M_PI / 2 ? M_PI - az : az;
211 alt = alt < -M_PI / 2 || alt > M_PI / 2 ? M_PI - alt : alt;
214 Eigen::AngleAxisd rY(-az, Eigen::Vector3d::UnitY());
215 Eigen::AngleAxisd rX(-alt, Eigen::Vector3d::UnitX());
217 return ISM::GeometryHelper::eigenQuatToQuat(rY * rX);
222 std::vector<ISM::RecognitionResultPtr> ism_tree;
223 ism_tree.push_back(result);
226 for(ISM::ObjectPtr
object : result->recognizedSet->objects){
231 for(ISM::RecognitionResultPtr subPattern : result->subPatterns) {
234 std::vector<ISM::RecognitionResultPtr> childTrees =
traverseTree(subPattern, depth);
235 ism_tree.insert(ism_tree.end(), childTrees.begin(), childTrees.end());
243 ISM::PosePtr ret_pose = ISM::PosePtr(
new ISM::Pose());
244 ret_pose->quat =ISM::QuaternionPtr(pose->quat);
249 Eigen::Quaternion<double> rotation = ISM::GeometryHelper::quatToEigenQuat(
ref_pose_->quat);
250 rotation.normalize();
251 Eigen::Vector3d translation(0.0, 0.0, (-depth *
tree_depth_size_) - delta_offset);
252 Eigen::Vector3d offset = rotation._transformVector(translation);
254 const ISM::PointPtr ret_point_ptr = ISM::PointPtr(
new ISM::Point(
255 pose->point->eigen.x() + offset[0],
256 pose->point->eigen.y() + offset[1] ,
257 pose->point->eigen.z() + offset[2]));
258 ret_pose->point = ret_point_ptr;
260 const ISM::PointPtr ret_point_ptr = ISM::PointPtr(
new ISM::Point(
261 pose->point->eigen.x(),
262 pose->point->eigen.y(),
264 ret_pose->point = ret_point_ptr;
void addVisualization(const ISM::RecognitionResultPtr recognition_result)
static Marker createCylinderMarker(ISM::PosePtr pose, std::string baseFrame, std::string markerNamespace, int id, float radius, float height, ColorRGBA color, double markerLifetime)
void publishCollectedMarkers()
static ColorRGBA hsvToRGBA(double hue, double saturation, double value)
static MarkerArray createCubeArrow(ISM::PosePtr pose, std::string baseFrame, std::string markerNamespace, int &id, float scale, ColorRGBA cubeColor, ColorRGBA arrowColor, double markerLifetime)
static MarkerArray createCoordinateMarkerWithAngle(ISM::PosePtr pose, std::string baseFrame, std::string markerNamespace, int id, float length, float openAngle, double markerLifetime)
visualization_msgs::MarkerArray genTestMarker()
static ColorRGBA getColorOfObject(const ISM::Object &object)
static Marker createConeMarker(ISM::PosePtr pose, std::string baseFrame, std::string markerNamespace, int id, float radius, ColorRGBA color, double markerLifetime)
visualization_msgs::Marker Marker
std::map< std::string, ISM::PosePtr > ism_to_parent_ism_map_
TFSIMD_FORCE_INLINE const tfScalar & y() const
std::vector< ISM::RecognitionResultPtr > traverseTree(ISM::RecognitionResultPtr result, int depth)
static Marker createSphereMarker(ISM::PointPtr point, std::string baseFrame, std::string markerNamespace, int id, float radius, ColorRGBA color, double markerLifetime)
static ColorRGBA createColorRGBA(float red, float green, float blue, float alpha)
std_msgs::ColorRGBA ColorRGBA
TFSIMD_FORCE_INLINE const tfScalar & x() const
visualization_msgs::MarkerArray MarkerArray
TFSIMD_FORCE_INLINE const tfScalar & z() const
void addMarker(visualization_msgs::Marker marker)
static Marker createMeshMarker(ISM::PosePtr pose, std::string baseFrame, std::string markerNamespace, int id, ColorRGBA color, double markerLifetime, std::string resourcePath)
ISM::PosePtr getAdjustedPose(ISM::PosePtr pose, int depth, bool is_child)
Helper method to translate a point. So we can see the tree depth objects residing in trough their cor...
ISM::PointPtr last_ref_pose_
ISM::QuaternionPtr calculateOrientation(ISM::PointPtr from_point_ptr, ISM::PointPtr to_point_ptr, bool pose_relative=false)
std::map< std::string, int > ism_to_depth_map_
std::map< std::string, VIZ::ColorRGBA > ism_to_color_map_
static Marker createLineArrow(ISM::PointPtr fromPoint, std::vector< ISM::PosePtr > toPoses, std::string baseFrame, std::string markerNamespace, int &id, float arrowScale, ColorRGBA color, double markerLifetime)
static ColorRGBA confidenceToColor(double confidence)
visualization_msgs::MarkerArray getMarkersFromResult(const ISM::RecognitionResultPtr result)
std::map< std::string, std::pair< ISM::PosePtr, double > > cylinder_map_
ISM::PosePtr calculateCylinderPose(const ISM::PosePtr from_pose_ptr, const ISM::PointPtr to_point_ptr, double height)