23 const Eigen::Vector3d& direction,
25 :
Eigen::ParametrizedLine<double, 3>(
origin, direction), line_type_(
type) {
33 x_inv_ = 1. / direction.x();
34 y_inv_ = 1. / direction.y();
35 z_inv_ = 1. / direction.z();
59 double t_min = std::min(t_x0, t_x1);
60 double t_max = std::max(t_x0, t_x1);
66 t_min = std::max(t_min, std::min(t_y0, t_y1));
67 t_max = std::min(t_max, std::max(t_y0, t_y1));
73 t_min = std::max(t_min, std::min(t_z0, t_z1));
74 t_max = std::min(t_max, std::max(t_z0, t_z1));
76 return {t_min, t_max};
90 using namespace Eigen;
102 using plane_t = Eigen::Hyperplane<double, 3>;
103 std::array<plane_t, 6> planes{{{{-1, 0, 0}, box.
GetMinBound()},
111 std::vector<double> parameters;
112 std::vector<Eigen::Vector3d>
points;
113 parameters.reserve(7);
117 parameters.push_back(0);
121 for (std::size_t i = 0; i < 6; ++i) {
124 parameters.push_back(t.value());
125 auto p = pointAt(t.value());
131 auto contained_indices = b_tol.GetPointIndicesWithinBoundingBox(
points);
132 if (contained_indices.empty())
return {};
135 double minimum = parameters[contained_indices[0]];
136 for (
auto i : contained_indices) {
137 minimum = std::min(minimum, parameters[i]);
151 double t_min = std::get<0>(t);
152 double t_max = std::get<1>(t);
154 if (t_max >= t_min)
return t_min;
159 const Eigen::Hyperplane<double, 3>& plane)
const {
160 double value = intersectionParameter(plane);
161 if (std::isinf(value)) {
223 double D =
a * c - b * b;
231 tc = b > c ? d / b :
e / c;
233 sc = (b *
e - c * d) / D;
234 tc = (
a *
e - b * d) / D;
266 const Line3D& other)
const {
280 return (std::get<0>(pair) - std::get<1>(pair)).norm();
300 double t_min = std::get<0>(t);
301 double t_max = std::get<1>(t);
303 t_min = std::max(0., t_min);
305 if (t_max >= t_min)
return t_min;
310 const Eigen::Hyperplane<double, 3>& plane)
const {
313 auto result =
Line().intersectionParameter(plane);
324 const Eigen::Vector3d& end_point)
326 (end_point - start_point).normalized(),
328 end_point_(end_point),
329 length_((start_point - end_point_).norm()) {}
336 end_point_ = t * end_point_;
352 double t_min = std::get<0>(t);
353 double t_max = std::get<1>(t);
355 t_min = std::max(0., t_min);
357 if (t_max >= t_min && t_min <= length_)
return t_min;
371 Eigen::Vector3d min{std::min(
origin().
x(), end_point_.x()),
372 std::min(
origin().
y(), end_point_.y()),
373 std::min(
origin().
z(), end_point_.z())};
375 Eigen::Vector3d max{std::max(
origin().
x(), end_point_.x()),
376 std::max(
origin().
y(), end_point_.y()),
377 std::max(
origin().
z(), end_point_.z())};
382 const Eigen::Hyperplane<double, 3>& plane)
const {
385 auto result =
Line().intersectionParameter(plane);
virtual Eigen::Vector3d GetMaxBound() const override
Returns max bounds for geometry coordinates.
virtual Eigen::Vector3d GetMinBound() const override
Returns min bounds for geometry coordinates.
const Vector3Tpl< T > & maxCorner() const
Returns max corner (const)
const Vector3Tpl< T > & minCorner() const
Returns min corner (const)
Line3D is a class which derives from Eigen::ParametrizedLine<double, 3> in order to capture the seman...
virtual void Transform(const Eigen::Transform< double, 3, Eigen::Affine > &t)
Transform the Line3D by the given matrix.
virtual Eigen::Vector3d Projection(const Eigen::Vector3d &point) const
Calculates a point projected onto the line, taking into account special semantics.
const Eigen::Vector3d & Direction() const
Gets the line's direction vector.
double DistanceTo(const Line3D &other) const
Gets the closest distance between two Line3D objects, including derived types Ray3D and Segment3D,...
LineType
Specifies different semantic interpretations of 3d lines.
std::pair< Eigen::Vector3d, Eigen::Vector3d > ClosestPoints(const Line3D &other) const
Computes the two closest points between this Line3D object and the other, including of derived types ...
std::pair< double, double > ClosestParameters(const Line3D &other) const
Computes the two corresponding parameters of the closest distance between two Line3D objects,...
virtual cloudViewer::utility::optional< double > SlabAABB(const ccBBox &box) const
Returns the lower intersection parameter for a line with an axis aligned bounding box or empty if no ...
std::pair< double, double > SlabAABBBase(const ccBBox &box) const
Calculates the common t_min and t_max values of the slab AABB intersection method....
double ProjectionParameter(const Eigen::Vector3d &point) const
Calculates the parameter of a point projected onto the line taking into account special semantics.
const Eigen::ParametrizedLine< double, 3 > & Line() const
Returns a const reference to the underlying Eigen::ParametrizedLine object.
virtual bool IsParameterValid(double parameter) const
Verifies that a given parameter value is valid for the semantics of the line object....
virtual cloudViewer::utility::optional< double > IntersectionParameter(const Eigen::Hyperplane< double, 3 > &plane) const
Calculates the intersection parameter between the line and a plane taking into account line semantics...
const Eigen::Vector3d & Origin() const
Gets the line's origin point.
virtual double ClampParameter(double parameter) const
Clamps/bounds a parameter value to the closest valid place where the entity exists....
Line3D(const Eigen::Vector3d &origin, const Eigen::Vector3d &direction)
Default user constructor.
virtual cloudViewer::utility::optional< double > ExactAABB(const ccBBox &box) const
Returns the lower intersection parameter for a line with an axis aligned bounding box or empty if no ...
cloudViewer::utility::optional< double > IntersectionParameter(const Eigen::Hyperplane< double, 3 > &plane) const override
Calculates the intersection parameter between the line and a plane taking into account ray semantics....
cloudViewer::utility::optional< double > SlabAABB(const ccBBox &box) const override
Returns the lower intersection parameter for a ray with an axis aligned bounding box or empty if no i...
Ray3D(const Eigen::Vector3d &origin, const Eigen::Vector3d &direction)
Default constructor, requires point and direction.
A segment is a semantic interpretation of Eigen::ParametrizedLine which has an origin and an endpoint...
cloudViewer::utility::optional< double > SlabAABB(const ccBBox &box) const override
Returns the lower intersection parameter for a segment with an axis aligned bounding box or empty if ...
cloudViewer::utility::optional< double > IntersectionParameter(const Eigen::Hyperplane< double, 3 > &plane) const override
Calculates the intersection parameter between the line and a plane taking into account segment semant...
Segment3D(const Eigen::Vector3d &start_point, const Eigen::Vector3d &end_point)
Default constructor for Segment3D takes the start and end points of the segment.
void Transform(const Eigen::Transform< double, 3, Eigen::Affine > &t) override
Transform the segment by the given matrix.
cloudViewer::utility::optional< double > ExactAABB(const ccBBox &box) const override
Returns the lower intersection parameter for a segment with an axis aligned bounding box or empty if ...
ccBBox GetBoundingBox() const
Get an axis-aligned bounding box representing the enclosed volume of the line segment.
Generic file read and write utility for python interface.