54 const std::vector<TPolygon3D>& oldPolys,
55 std::vector<TPolygonWithPlane>& newPolys);
70 bool intersect(
const TSegment3D& s1,
const TSegment3D& s2, TObject3D&
obj);
80 bool intersect(
const TSegment3D& s1,
const TPlane& p2, TObject3D&
obj);
90 bool intersect(
const TSegment3D& s1,
const TLine3D& r2, TObject3D&
obj);
111 bool intersect(
const TPlane& p1,
const TPlane& p2, TObject3D&
obj);
121 bool intersect(
const TPlane& p1,
const TLine3D& p2, TObject3D&
obj);
158 bool intersect(
const TLine3D& r1,
const TLine3D& r2, TObject3D&
obj);
169 bool intersect(
const TLine2D& r1,
const TLine2D& r2, TObject2D&
obj);
179 bool intersect(
const TLine2D& r1,
const TSegment2D& s2, TObject2D&
obj);
202 bool intersect(
const TSegment2D& s1,
const TSegment2D& s2, TObject2D&
obj);
214 double getAngle(
const TPlane& p1,
const TPlane& p2);
219 double getAngle(
const TPlane& p1,
const TLine3D& r2);
232 double getAngle(
const TLine3D& r1,
const TLine3D& r2);
237 double getAngle(
const TLine2D& r1,
const TLine2D& r2);
287 const TPose2D&
p,
const double (&vector)[2], TLine2D&
r);
338 point.
x, point.
y, point.
z, newPoint.
x, newPoint.
y, newPoint.
z);
360 TPolygon3D& newPolygon);
364 TObject3D& newObject);
395 std::vector<T>& newObjs)
397 size_t N = objs.size();
399 for (
size_t i = 0; i < N; i++)
project3D(objs[i], newXYpose, newObjs[i]);
423 TPolygon2D& newPolygon);
427 TObject2D& newObject);
434 template <
class T,
class CPOSE2D>
447 template <
class T,
class CPOSE2D>
460 std::vector<T>& newObjs)
462 size_t N = objs.size();
464 for (
size_t i = 0; i < N; i++)
project2D(objs[i], newXpose, newObjs[i]);
475 bool intersect(
const TPolygon2D& p1,
const TSegment2D& s2, TObject2D&
obj);
477 bool intersect(
const TPolygon2D& p1,
const TLine2D& r2, TObject2D&
obj);
479 bool intersect(
const TPolygon2D& p1,
const TPolygon2D& p2, TObject2D&
obj);
494 bool intersect(
const TPolygon3D& p1,
const TSegment3D& s2, TObject3D&
obj);
496 bool intersect(
const TPolygon3D& p1,
const TLine3D& r2, TObject3D&
obj);
498 bool intersect(
const TPolygon3D& p1,
const TPlane& p2, TObject3D&
obj);
500 bool intersect(
const TPolygon3D& p1,
const TPolygon3D& p2, TObject3D&
obj);
524 const std::vector<TPolygon3D>&
v1,
const std::vector<TPolygon3D>&
v2,
525 CSparseMatrixTemplate<TObject3D>& objs);
531 const std::vector<TPolygon3D>&
v1,
const std::vector<TPolygon3D>&
v2,
532 std::vector<TObject3D>& objs);
542 template <
class T,
class U,
class O>
544 const std::vector<T>&
v1,
const std::vector<U>&
v2,
547 size_t M =
v1.size(), N =
v2.size();
551 for (
size_t i = 0; i < M; i++)
552 for (
size_t j = 0; j < M; j++)
560 template <
class T,
class U,
class O>
562 const std::vector<T>&
v1,
const std::vector<U>&
v2, std::vector<O> objs)
567 it1 !=
v1.end(); ++it1)
569 const T& elem1 = *it1;
571 it2 !=
v2.end(); ++it2)
578 bool intersect(
const TObject2D& o1,
const TObject2D& o2, TObject2D&
obj);
580 bool intersect(
const TObject3D& o1,
const TObject3D& o2, TObject3D&
obj);
588 double distance(
const TPoint2D& p1,
const TPoint2D& p2);
590 double distance(
const TPoint3D& p1,
const TPoint3D& p2);
592 double distance(
const TLine2D& r1,
const TLine2D& r2);
594 double distance(
const TLine3D& r1,
const TLine3D& r2);
597 double distance(
const TPlane& p1,
const TPlane& p2);
599 double distance(
const TPolygon2D& p1,
const TPolygon2D& p2);
601 double distance(
const TPolygon2D& p1,
const TSegment2D& s2);
608 double distance(
const TPolygon2D& p1,
const TLine2D& l2);
614 double distance(
const TPolygon3D& p1,
const TPolygon3D& p2);
616 double distance(
const TPolygon3D& p1,
const TSegment3D& s2);
623 double distance(
const TPolygon3D& p1,
const TLine3D& l2);
630 double distance(
const TPolygon3D& po,
const TPlane& pl);
644 const std::vector<TPoint2D>& poly, TPoint2D& pMin, TPoint2D& pMax);
647 const std::vector<TPoint3D>& poly, TPoint3D& pMin, TPoint3D& pMax);
718 const std::vector<TSegment3D>& segms, std::vector<TPolygon3D>& polys);
724 const std::vector<TSegment3D>& segms, std::vector<TPolygon3D>& polys,
725 std::vector<TSegment3D>& remainder);
731 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys);
737 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys,
738 std::vector<TObject3D>& remainder);
744 const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys,
745 std::vector<TSegment3D>& remainder1, std::vector<TObject3D>& remainder2);
761 const TPolygon2D& poly, std::vector<TPolygon2D>&
components);
767 const TPolygon3D& poly, std::vector<TPolygon3D>&
components);
804 std::vector<TPolygonWithPlane> pwp;
821 template <
class T,
class U,
class V>
824 vOut[0] =
v0[1] *
v1[2] -
v0[2] *
v1[1];
825 vOut[1] =
v0[2] *
v1[0] -
v0[0] *
v1[2];
826 vOut[2] =
v0[0] *
v1[1] -
v0[1] *
v1[0];
832 const std::vector<T>&
v0,
const std::vector<T>&
v1, std::vector<T>& v_out)
837 v_out[0] =
v0[1] *
v1[2] -
v0[2] *
v1[1];
838 v_out[1] = -
v0[0] *
v1[2] +
v0[2] *
v1[0];
839 v_out[2] =
v0[0] *
v1[1] -
v0[1] *
v1[0];
843 template <
class VEC1,
class VEC2>
845 const VEC1&
v0,
const VEC2&
v1)
847 Eigen::Matrix<double, 3, 1> vOut;
848 vOut[0] =
v0[1] *
v1[2] -
v0[2] *
v1[1];
849 vOut[1] =
v0[2] *
v1[0] -
v0[0] *
v1[2];
850 vOut[2] =
v0[0] *
v1[1] -
v0[1] *
v1[0];
863 template <
class VECTOR,
class MATRIX>
868 M.set_unsafe(0, 0, 0);
869 M.set_unsafe(0, 1, -
v[2]);
870 M.set_unsafe(0, 2,
v[1]);
871 M.set_unsafe(1, 0,
v[2]);
872 M.set_unsafe(1, 1, 0);
873 M.set_unsafe(1, 2, -
v[0]);
874 M.set_unsafe(2, 0, -
v[1]);
875 M.set_unsafe(2, 1,
v[0]);
876 M.set_unsafe(2, 2, 0);
879 template <
class VECTOR>
897 template <
class VECTOR,
class MATRIX>
902 M.set_unsafe(0, 0, 0);
903 M.set_unsafe(0, 1,
v[2]);
904 M.set_unsafe(0, 2, -
v[1]);
905 M.set_unsafe(1, 0, -
v[2]);
906 M.set_unsafe(1, 1, 0);
907 M.set_unsafe(1, 2,
v[0]);
908 M.set_unsafe(2, 0,
v[1]);
909 M.set_unsafe(2, 1, -
v[0]);
910 M.set_unsafe(2, 2, 0);
913 template <
class VECTOR>
925 template <
class T,
class U>
935 template <
class T,
class U>
947 const double& Px,
const double& Py,
const double& x1,
const double& y1,
948 const double& x2,
const double& y2,
double& out_x,
double& out_y);
954 const double& Px,
const double& Py,
const double& x1,
const double& y1,
955 const double& x2,
const double& y2,
double& out_x,
double& out_y);
960 const double& Px,
const double& Py,
const double& x1,
const double& y1,
961 const double& x2,
const double& y2);
964 template <
typename T>
971 template <
typename T>
973 const T x1,
const T y1,
const T
z1,
const T x2,
const T y2,
const T
z2)
979 template <
typename T>
986 template <
typename T>
988 const T x1,
const T y1,
const T
z1,
const T x2,
const T y2,
const T
z2)
996 template <
typename T>
998 const double Px,
const double Py,
const double x1,
const double y1,
999 const double x2,
const double y2, T& out_x, T& out_y)
1003 out_x =
static_cast<T
>(ox);
1004 out_y =
static_cast<T
>(oy);
1011 const double x1,
const double y1,
const double x2,
const double y2,
1012 const double x3,
const double y3,
const double x4,
const double y4,
1013 double& ix,
double& iy);
1018 const double x1,
const double y1,
const double x2,
const double y2,
1019 const double x3,
const double y3,
const double x4,
const double y4,
1020 float& ix,
float& iy);
1026 const double& px,
const double& py,
unsigned int polyEdges,
1027 const double* poly_xs,
const double* poly_ys);
1032 template <
typename T>
1034 T
x, T
y, T v1x, T v1y, T v2x, T v2y, T v3x, T v3y, T v4x, T v4y)
1038 const T
a1 = atan2(v1y -
y, v1x -
x);
1039 const T
a2 = atan2(v2y -
y, v2x -
x);
1040 const T
a3 = atan2(v3y -
y, v3x -
x);
1041 const T a4 = atan2(v4y -
y, v4x -
x);
1047 if (
sign(da1) !=
sign(da2))
return false;
1050 if (
sign(da2) !=
sign(da3))
return false;
1060 const double& px,
const double& py,
unsigned int polyEdges,
1061 const double* poly_xs,
const double* poly_ys);
1073 const double& p1_x,
const double& p1_y,
const double& p1_z,
1074 const double& p2_x,
const double& p2_y,
const double& p2_z,
1075 const double& p3_x,
const double& p3_y,
const double& p3_z,
1076 const double& p4_x,
const double& p4_y,
const double& p4_z,
double&
x,
1077 double&
y,
double&
z,
double& dist);
1089 const double& R1_x_min,
const double& R1_x_max,
const double& R1_y_min,
1090 const double& R1_y_max,
const double& R2_x_min,
const double& R2_x_max,
1091 const double& R2_y_min,
const double& R2_y_max,
const double& R2_pose_x,
1092 const double& R2_pose_y,
const double& R2_pose_phi);
1136 if (dx == 0 && dy == 0 && dz == 0)
1143 T
n = sqrt(n_xy +
square(dz));
1150 if (fabs(dx) > 1e-4 || fabs(dy) > 1e-4)
1152 P(0, 1) = -dy / n_xy;
1153 P(1, 1) = dx / n_xy;
A matrix of dynamic size.
A sparse matrix container (with cells of any type), with iterators.
size_t getNonNullElements() const
Gets the amount of non-null elements inside the matrix.
void clear()
Completely removes all elements, although maintaining the matrix's size.
void resize(size_t nRows, size_t nCols)
Changes the size of the matrix.
2D polygon, inheriting from std::vector<TPoint2D>.
3D polygon, inheriting from std::vector<TPoint3D>
Slightly heavyweight type to speed-up calculations with polygons in 3D.
TPolygon3D poly
Actual polygon.
TPolygonWithPlane()
Basic constructor.
TPolygon2D poly2D
Polygon, after being projected to the plane using inversePose.
mrpt::poses::CPose3D pose
Plane's pose.
static void getPlanes(const std::vector< TPolygon3D > &oldPolys, std::vector< TPolygonWithPlane > &newPolys)
Static method for vectors.
TPlane plane
Plane containing the polygon.
mrpt::poses::CPose3D inversePose
Plane's inverse pose.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::math::CMatrixFixedNumeric< double, 3, 3 > *out_jacobian_df_dpoint=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dpose=nullptr, mrpt::math::CMatrixFixedNumeric< double, 3, 6 > *out_jacobian_df_dse3=nullptr, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
const Scalar * const_iterator
GLsizei GLsizei GLuint * obj
GLenum GLenum GLuint components
GLfloat GLfloat GLfloat v2
GLdouble GLdouble GLdouble r
GLsizei const GLfloat * points
T wrapToPi(T a)
Modifies the given angle to translate it into the ]-pi,pi] range.
bool vectorsAreParallel2D(const T &v1, const U &v2)
Returns true if two 2D vectors are parallel.
bool areAligned(const std::vector< TPoint2D > &points)
Checks whether this set of points acceptably fits a 2D line.
bool splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components.
void createPlaneFromPoseYZ(const mrpt::poses::CPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its X vector.
void skew_symmetric3(const VECTOR &v, MATRIX &M)
Computes the 3x3 skew symmetric matrix from a 3-vector or 3-array:
void createPlaneFromPoseAndNormal(const mrpt::poses::CPose3D &pose, const double(&normal)[3], TPlane &plane)
Given a pose and any vector, creates a plane orthogonal to that vector in the pose's coordinates.
void getRectangleBounds(const std::vector< TPoint2D > &poly, TPoint2D &pMin, TPoint2D &pMax)
Gets the rectangular bounds of a 2D polygon or set of 2D points.
void createFromPoseX(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the X axis in a given pose.
double closestSquareDistanceFromPointToLine(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2)
Returns the square distance from a point to a line.
T distanceSqrBetweenPoints(const T x1, const T y1, const T x2, const T y2)
Returns the square distance between 2 points in 2D.
void project2D(const TPoint2D &point, const mrpt::poses::CPose2D &newXpose, TPoint2D &newPoint)
Uses the given pose 2D to project a point into a new base.
void createFromPoseY(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the Y axis in a given pose.
void closestFromPointToLine(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
Computes the closest point from a given point to a (infinite) line.
void createPlaneFromPoseXY(const mrpt::poses::CPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its Z vector.
bool traceRay(const std::vector< TPolygonWithPlane > &vec, const mrpt::poses::CPose3D &pose, double &dist)
Fast ray tracing method using polygons' properties.
bool SegmentsIntersection(const double x1, const double y1, const double x2, const double y2, const double x3, const double y3, const double x4, const double y4, double &ix, double &iy)
Returns the intersection point, and if it exists, between two segments.
bool pointIntoPolygon2D(const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
Returns true if the 2D point (px,py) falls INTO the given polygon.
void getAngleBisector(const TLine2D &l1, const TLine2D &l2, TLine2D &bis)
Gets the bisector of two lines or segments (implicit constructor will be used if necessary)
bool minDistBetweenLines(const double &p1_x, const double &p1_y, const double &p1_z, const double &p2_x, const double &p2_y, const double &p2_z, const double &p3_x, const double &p3_y, const double &p3_z, const double &p4_x, const double &p4_y, const double &p4_z, double &x, double &y, double &z, double &dist)
Calculates the minimum distance between a pair of lines.
double distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
void setEpsilon(double nE)
Changes the value of the geometric epsilon (default = 1e-5)
void project3D(const TPoint3D &point, const mrpt::poses::CPose3D &newXYpose, TPoint3D &newPoint)
Uses the given pose 3D to project a point into a new base.
bool pointIntoQuadrangle(T x, T y, T v1x, T v1y, T v2x, T v2y, T v3x, T v3y, T v4x, T v4y)
Specialized method to check whether a point (x,y) falls into a quadrangle.
double getRegressionLine(const std::vector< TPoint2D > &points, TLine2D &line)
Using eigenvalues, gets the best fitting line for a set of 2D points.
bool vectorsAreParallel3D(const T &v1, const U &v2)
Returns true if two 3D vectors are parallel.
void getPrismBounds(const std::vector< TPoint3D > &poly, TPoint3D &pMin, TPoint3D &pMax)
Gets the prism bounds of a 3D polygon or set of 3D points.
bool RectanglesIntersection(const double &R1_x_min, const double &R1_x_max, const double &R1_y_min, const double &R1_y_max, const double &R2_x_min, const double &R2_x_max, const double &R2_y_min, const double &R2_y_max, const double &R2_pose_x, const double &R2_pose_y, const double &R2_pose_phi)
Returns whether two rotated rectangles intersect.
double distancePointToPolygon2D(const double &px, const double &py, unsigned int polyEdges, const double *poly_xs, const double *poly_ys)
Returns the closest distance of a given 2D point to a polygon, or "0" if the point is INTO the polygo...
void skew_symmetric3_neg(const VECTOR &v, MATRIX &M)
Computes the negative version of a 3x3 skew symmetric matrix from a 3-vector or 3-array:
T distanceBetweenPoints(const T x1, const T y1, const T x2, const T y2)
Returns the distance between 2 points in 2D.
double getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
CMatrixTemplateNumeric< T > generateAxisBaseFromDirection(T dx, T dy, T dz)
Computes an axis base (a set of three 3D normal vectors) with the given vector being the first of the...
bool intersect(const TSegment3D &s1, const TSegment3D &s2, TObject3D &obj)
Gets the intersection between two 3D segments.
double minimumDistanceFromPointToSegment(const double Px, const double Py, const double x1, const double y1, const double x2, const double y2, T &out_x, T &out_y)
Computes the closest point from a given point to a segment, and returns that minimum distance.
bool conformAPlane(const std::vector< TPoint3D > &points)
Checks whether this polygon or set of points acceptably fits a plane.
void generateAxisBaseFromDirectionAndAxis(const double(&vec)[3], char coord, CMatrixDouble &matrix)
Creates a homogeneus matrix (4x4) such that the coordinate given (0 for x, 1 for y,...
void crossProduct3D(const T &v0, const U &v1, V &vOut)
Computes the cross product of two 3D vectors, returning a vector normal to both.
void getSegmentBisector(const TSegment2D &sgm, TLine2D &bis)
Gets the bisector of a 2D segment.
void closestFromPointToSegment(const double &Px, const double &Py, const double &x1, const double &y1, const double &x2, const double &y2, double &out_x, double &out_y)
Computes the closest point from a given point to a segment.
double getRegressionPlane(const std::vector< TPoint3D > &points, TPlane &plane)
Using eigenvalues, gets the best fitting plane for a set of 3D points.
double getAngle(const TPlane &p1, const TPlane &p2)
Computes the angle between two planes.
void assemblePolygons(const std::vector< TSegment3D > &segms, std::vector< TPolygon3D > &polys)
Tries to assemble a set of segments into a set of closed polygons.
void createFromPoseAndVector(const mrpt::poses::CPose3D &p, const double(&vector)[3], TLine3D &r)
Gets a 3D line corresponding to any arbitrary vector, in the base given by the pose.
void createPlaneFromPoseXZ(const mrpt::poses::CPose3D &pose, TPlane &plane)
Given a pose, creates a plane orthogonal to its Y vector.
void createFromPoseZ(const mrpt::poses::CPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the Z axis in a given pose.
#define THROW_EXCEPTION(msg)
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
T square(const T x)
Inline function for the square of a number.
int sign(T x)
Returns the sign of X as "1" or "-1".
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
2D line without bounds, represented by its equation .
void getAsPose2D(mrpt::poses::CPose2D &outPose) const
Get a pose2D whose X axis corresponds to the line.
void getAsPose2DForcingOrigin(const TPoint2D &origin, mrpt::poses::CPose2D &outPose) const
Get a pose2D whose X axis corresponds to the line, forcing the base point to one given.
3D line, represented by a base point and a director vector.
Standard type for storing any lightweight 2D type.
Standard object for storing any 3D lightweight object.
3D Plane, represented by its equation
void getAsPose3D(mrpt::poses::CPose3D &outPose)
Gets a pose whose XY plane corresponds to this plane.
double x
X,Y,Z coordinates.
2D segment, consisting of two points.
TPoint2D point2
Destiny point.
TPoint2D point1
Origin point.
3D segment, consisting of two points.
TPoint3D point1
Origin point.
TPoint3D point2
Destiny point.