Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #define BOOST_PARAMETER_MAX_ARITY 7
00037
00038 #include "jsk_recognition_utils/geo/segment.h"
00039 #include "jsk_recognition_utils/geo_util.h"
00040 namespace jsk_recognition_utils
00041 {
00042 Segment::Segment(const Eigen::Vector3f& from, const Eigen::Vector3f to):
00043 Line(from - to, from), from_(from), to_(to)
00044 {
00045
00046 }
00047
00048 double Segment::dividingRatio(const Eigen::Vector3f& point) const
00049 {
00050 if (to_[0] != from_[0]) {
00051 return (point[0] - from_[0]) / (to_[0] - from_[0]);
00052 }
00053 else if (to_[1] != from_[1]) {
00054 return (point[1] - from_[1]) / (to_[1] - from_[1]);
00055 }
00056 else {
00057 return (point[2] - from_[2]) / (to_[2] - from_[2]);
00058 }
00059 }
00060
00061 void Segment::foot(const Eigen::Vector3f& from, Eigen::Vector3f& output) const
00062 {
00063 Eigen::Vector3f foot_point;
00064 Line::foot(from, foot_point);
00065 double r = dividingRatio(foot_point);
00066 if (r < 0.0) {
00067 output = from_;
00068 }
00069 else if (r > 1.0) {
00070 output = to_;
00071 }
00072 else {
00073 output = foot_point;
00074 }
00075 }
00076
00077 double Segment::distance(const Eigen::Vector3f& point) const
00078 {
00079 Eigen::Vector3f foot_point;
00080 return distance(point, foot_point);
00081 }
00082
00083 double Segment::distance(const Eigen::Vector3f& point,
00084 Eigen::Vector3f& foot_point) const
00085 {
00086 foot(point, foot_point);
00087 return (foot_point - point).norm();
00088 }
00089
00090 bool Segment::intersect(Plane& plane, Eigen::Vector3f& point) const
00091 {
00092 double x = - (plane.getNormal().dot(origin_) + plane.getD()) / (plane.getNormal().dot(direction_));
00093 point = direction_ * x + origin_;
00094 double r = dividingRatio(point);
00095 return 0 <= r && r <= 1.0;
00096 }
00097
00098 std::ostream& operator<<(std::ostream& os, const Segment& seg)
00099 {
00100 os << "[" << seg.from_[0] << ", " << seg.from_[1] << ", " << seg.from_[2] << "] -- "
00101 << "[" << seg.to_[0] << ", " << seg.to_[1] << ", " << seg.to_[2] << "]";
00102 }
00103
00104 }