fcl_marker_converter.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *   http://www.apache.org/licenses/LICENSE-2.0
00009 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 
00018 #ifndef FCL_MARKER_CONVERTER_HPP_
00019 #define FCL_MARKER_CONVERTER_HPP_
00020 
00021 #include <boost/scoped_ptr.hpp>
00022 #include <fcl/shape/geometric_shapes.h>
00023 #include <fcl/BVH/BVH_model.h>
00024 #include <fcl/shape/geometric_shape_to_BVH_model.h>
00025 
00026 
00027 #include "cob_obstacle_distance/marker_shapes/marker_shapes_interface.hpp"
00028 
00029 // the less the better performance for BVH generation and distance calculation
00030 // E.g. values == 100u then CPU% at 20 Hz is 65 %
00031 // E.g. values == 10u then CPU% at 20 Hz is 35 %
00032 #define SEGMENTS 10u
00033 #define RINGS 10u
00034 #define SEG_AXIS 10u
00035 #define SEG_CIRCLE 10u
00036 
00037 template <typename T>
00038 class FclMarkerConverter
00039 {
00040     private:
00041         FclMarkerConverter() {}
00042         FclMarkerConverter(T &t) {}
00043 };
00044 
00045 template<>
00046 class FclMarkerConverter<fcl::Box>
00047 {
00048     typedef boost::scoped_ptr<fcl::Box> sPtrBox;
00049 
00050     private:
00051         fcl::Box geo_shape_;
00052 
00053     public:
00054         FclMarkerConverter() : geo_shape_(fcl::Box(1.0, 1.0, 1.0)) {}
00055         FclMarkerConverter(fcl::Box& box) : geo_shape_(box) {}
00056 
00057         void assignValues(visualization_msgs::Marker& marker)
00058         {
00059             marker.scale.x = this->geo_shape_.side[0];
00060             marker.scale.y = this->geo_shape_.side[1];
00061             marker.scale.z = this->geo_shape_.side[2];
00062             marker.type = visualization_msgs::Marker::CUBE;
00063         }
00064 
00065         fcl::Box getGeoShape() const
00066         {
00067             return geo_shape_;
00068         }
00069 
00070         void getBvhModel(BVH_RSS_t& bvh) const
00071         {
00072             const fcl::Transform3f x;
00073             fcl::generateBVHModel(bvh, geo_shape_, x);
00074         }
00075 };
00076 
00077 template<>
00078 class FclMarkerConverter<fcl::Sphere>
00079 {
00080     typedef boost::scoped_ptr<fcl::Sphere> sPtrSphere;
00081 
00082     private:
00083         fcl::Sphere geo_shape_;
00084 
00085     public:
00086         FclMarkerConverter() : geo_shape_(fcl::Sphere(1.0)) {}
00087         FclMarkerConverter(fcl::Sphere &sphere) : geo_shape_(sphere) {}
00088 
00089         void assignValues(visualization_msgs::Marker &marker)
00090         {
00091             marker.scale.x = this->geo_shape_.radius * 2.0; // marker needs the diameter in x
00092             marker.scale.y = this->geo_shape_.radius * 2.0; // marker needs the diameter in y
00093             marker.scale.z = this->geo_shape_.radius * 2.0; // marker needs the diameter in z
00094             marker.type = visualization_msgs::Marker::SPHERE;
00095         }
00096 
00097         fcl::Sphere getGeoShape() const
00098         {
00099             return geo_shape_;
00100         }
00101 
00108         void getBvhModel(BVH_RSS_t& bvh) const
00109         {
00110             const fcl::Transform3f x;
00111             fcl::generateBVHModel(bvh, geo_shape_, x, SEGMENTS, RINGS);
00112         }
00113 };
00114 
00115 template<>
00116 class FclMarkerConverter<fcl::Cylinder>
00117 {
00118     typedef boost::scoped_ptr<fcl::Cylinder> sPtrCylinder;
00119 
00120     private:
00121         fcl::Cylinder geo_shape_;
00122 
00123     public:
00124         FclMarkerConverter() : geo_shape_(fcl::Cylinder(1.0, 1.0)) {}
00125         FclMarkerConverter(fcl::Cylinder &cyl) : geo_shape_(cyl) {}
00126 
00127         void assignValues(visualization_msgs::Marker &marker)
00128         {
00129             marker.scale.x = this->geo_shape_.radius * 2.0; // marker needs the diameter in x
00130             marker.scale.y = this->geo_shape_.radius * 2.0; // marker needs the diameter in y
00131             marker.scale.z = this->geo_shape_.lz;
00132             marker.type = visualization_msgs::Marker::CYLINDER;
00133         }
00134 
00135         fcl::Cylinder getGeoShape() const
00136         {
00137             return geo_shape_;
00138         }
00139 
00140         void getBvhModel(BVH_RSS_t& bvh) const
00141         {
00142             const fcl::Transform3f x;
00143             fcl::generateBVHModel(bvh, geo_shape_, x, SEG_CIRCLE, SEG_AXIS);
00144         }
00145 };
00146 
00147 #endif /* FCL_MARKER_CONVERTER_HPP_ */


cob_obstacle_distance
Author(s): Marco Bezzon
autogenerated on Thu Jun 6 2019 21:19:14