ImFusion SDK 4.3
ImFusion::Geometry Namespace Reference

Classes to represent geometric primitives like lines or polygons, as well as functions dealing exclusively with such objects. More...

Detailed Description

Classes to represent geometric primitives like lines or polygons, as well as functions dealing exclusively with such objects.

Note
This namespace contains improved versions of what is in the original and now deprecated GeometryLegacy namespace.
See also
ImFusionGeometry

Classes

class  AlignedBox
 Class representing an axis aligned rectangular cuboid in 3D space. More...
 
class  AlignedRectangle2D
 Class representing an axis aligned rectangle in 2D space. More...
 
class  Circle
 Class representing a circle (actually a disk, so including the inner part) in 3D space. More...
 
class  Ellipse2D
 Class representing an ellipse in 2D space. More...
 
class  Line
 Class representing a full line, i.e. More...
 
class  LineBase
 Common interface of Line and LineSegment. More...
 
class  LineSegment
 Class representing a line segment, i.e. More...
 
class  Plane
 Class representing an oriented plane in 3D space defined by a base point and a normal direction. More...
 
class  Polygon2D
 Class representing a planar polygon. More...
 
class  Rectangle
 Arbitrary rectangle in 3D space. More...
 
struct  SpherePivotResult
 
class  Triangle
 Class representing a triangle in 3D space. More...
 

Functions

std::ostreamoperator<< (std::ostream &o, const AlignedBox &b)
 
int fitCircle (const std::vector< vec2 > &pts, vec2 &center, double &radius, bool fixed[3], double *res=0, bool outlierRejection=false)
 Fit circle to points, using the Levenberg-Marquardt algorithm.
 
double fitCircleRANSAC (const std::vector< vec2 > &pts, vec3 &circleOut, std::vector< vec2 > &inliersOut, double inlierThreshold=1.0, double diameter=-1)
 
double fitCircleLeastSquares (const std::vector< vec2 > &pts, vec2 &center, double &radius)
 Fit circle to points, using a linear least squares fit.
 
int fitCircle3D (const std::vector< vec3 > &pts, vec3 &outCenter, double &outRadius, mat3 &outR, double *outRes=0, bool rejectOutliers=false)
 Fit circle in 3D to points.
 
int fitSphere (const std::vector< vec3 > &pts, vec3 &center, double &radius, bool fixed[4], double *res=0)
 Fit sphere to points.
 
double fitSphereRANSAC (const std::vector< vec3 > &pts, vec4 &circleOut, std::vector< vec3 > &inliersOut, double inlierThreshold, double diameter=-1)
 
SpherePivotResult fitSpherePivotingPoses (const std::vector< mat4 > &pivotPoses)
 
int fitConic (const std::vector< vec2 > &pts, mat3 &C, double *res=0)
 Fit conic to points.
 
int fitCylinder (const std::vector< vec3 > &pts, vec3 &center, double &radius, mat3 &R, double *res=0)
 Fit cylinder to points.
 
int fitPlane (const std::vector< vec3 > &pts_, vec4 *plane, double *res=0, bool rejectOutliers=false)
 Fit plane to points.
 
double fitPlaneRANSAC (const std::vector< vec3 > &pts, vec4 &planeOut, std::vector< vec3 > &inliersOut, double inlierThreshold, int maxIter=100)
 
void fitAxesPCA (const std::vector< vec3 > &pts_, vec3 &outCentroid_, vec4(&outPlanes_)[3], bool scalePoints=true, vec3 *outEigenvalues=nullptr)
 Performs a PCA to fit the principal component axes to points.
 
int fitLine (const std::vector< vec2 > &pts_, vec3 *line, double *res=0)
 Fit line to points.
 
double fitLineRANSAC (const std::vector< vec2 > &pts, vec3 &lineOut, std::vector< vec2 > &inliersOut, double inlierThreshold)
 
double fitLineRANSAC (const std::vector< vec3 > &pts, vec3 &lineOutOrigin, vec3 &lineOutDir, std::vector< vec3 > &inliersOut, double inlierThreshold)
 Fit line to inlier points.
 
int fitLine (const std::vector< vec3 > &pts_, vec3 &lineOutOrigin, vec3 &lineOutDir, double *res=0)
 
std::optional< Geometry::Ellipse2DfitEllipse (const std::vector< vec2 > &pts)
 Fit ellipse to points using least squares.
 
std::vector< vec3 > uniformDistributedPointsOnSphere (const int N)
 Picks uniform distributed points on the sphere, i.e.
 
std::vector< vec2 > uniformDistributedPointsOnCircle (const int N)
 Picks uniform distributed points on the circle, i.e.
 

Find intersection points or overlapping parts

If the result has the same type as one of the arguments, it is a copy of the first such argument. In all other cases, the choice of variables that do not change the represented object (e.g. sign of normal) is arbitrary. Objects involving NAN or infinity will never intersect.
Utils::Variant< Line, vec3, std::nullptr_tintersection (const Line &l1, const Line &l2)
 Compute the intersection between two Lines or LineSegments.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Line &l1, const LineSegment &l2)
 Compute the intersection between two Lines or LineSegments.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const LineSegment &l1, const Line &l2)
 Compute the intersection between two Lines or LineSegments.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const LineSegment &l1, const LineSegment &l2)
 Compute the intersection between two Lines or LineSegments.
 
Utils::Variant< Line, vec3, std::nullptr_tintersection (const Line &l, const Plane &p)
 Compute the intersection between a Line or LineSegment and a Plane.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const LineSegment &l, const Plane &p)
 Compute the intersection between a Line or LineSegment and a Plane.
 
Utils::Variant< Line, vec3, std::nullptr_tintersection (const Plane &p, const Line &l)
 Compute the intersection between a Line or LineSegment and a Plane.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Plane &p, const LineSegment &l)
 Compute the intersection between a Line or LineSegment and a Plane.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Line &l, const Triangle &p)
 Compute the intersection between a Line or LineSegment and a Triangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const LineSegment &l, const Triangle &p)
 Compute the intersection between a Line or LineSegment and a Triangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Triangle &t, const Line &l)
 Compute the intersection between a Line or LineSegment and a Triangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Triangle &t, const LineSegment &l)
 Compute the intersection between a Line or LineSegment and a Triangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Line &l, const AlignedBox &c)
 Compute the intersection between a Line or LineSegment and a AlignedBox.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const LineSegment &l, const AlignedBox &c)
 Compute the intersection between a Line or LineSegment and a AlignedBox.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const AlignedBox &c, const Line &l)
 Compute the intersection between a Line or LineSegment and a AlignedBox.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const AlignedBox &c, const LineSegment &l)
 Compute the intersection between a Line or LineSegment and a AlignedBox.
 
std::vector< vec3 > intersection (const AlignedBox &cuboid, const Plane &plane)
 Compute the intersection between a AlignedBox and a Plane.
 
std::vector< vec3 > intersection (const Plane &plane, const AlignedBox &cuboid)
 Compute the intersection between a AlignedBox and a Plane.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Rectangle &p, const LineSegment &l)
 Compute the intersection between a LineSegment and a Rectangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const LineSegment &l, const Rectangle &p)
 Compute the intersection between a LineSegment and a Rectangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Rectangle &p, const Line &l)
 Compute the intersection between a Line and a Rectangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersection (const Line &l, const Rectangle &p)
 Compute the intersection between a Line and a Rectangle.
 
Utils::Variant< std::vector< vec3 >, LineSegment, vec3, std::nullptr_tintersection (const Rectangle &l, const Rectangle &p)
 Compute the intersection between two Rectangles.
 
Utils::Variant< AlignedBox, LineSegment, vec3, std::nullptr_tintersection (const AlignedBox &c, const AlignedBox &c2)
 Returns intersection between 2 boxes or nullptr in case of no intersection.
 
Utils::Variant< Plane, Line, std::nullptr_tintersection (const Plane &p1, const Plane &p2)
 Compute the intersection between multiple planes.
 
Utils::Variant< Plane, Line, vec3, std::nullptr_tintersection (const Plane &p1, const Plane &p2, const Plane &p3)
 Compute the intersection between multiple planes.
 
Utils::Variant< Triangle, LineSegment, vec3, std::nullptr_tintersection (const Plane &p, const Triangle &t)
 Compute the intersection between a Plane and a Triangle.
 
Utils::Variant< Triangle, LineSegment, vec3, std::nullptr_tintersection (const Triangle &t, const Plane &p)
 Compute the intersection between a Plane and a Triangle.
 
Utils::Variant< AlignedRectangle2D, vec3, std::nullptr_tintersection (const AlignedRectangle2D &r1, const AlignedRectangle2D &r2)
 Returns the intersection of 2 rectangles.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersectionFast (const Line &l, const Triangle &t)
 Compute the intersection between a Line and a Triangle.
 
Utils::Variant< LineSegment, vec3, std::nullptr_tintersectionFast (const Triangle &t, const Line &l)
 Compute the intersection between a Line and a Triangle.
 

Check if, but not how, a pair of objects intersects

Touching at a single point counts as intersection for the purpose of these functions. These are faster than computing the full intersection. Objects involving NAN or infinity will never intersect.
bool intersects (const AlignedRectangle2D &r1, const AlignedRectangle2D &r2)
 Checks if the two rectangles intersect.
 
bool intersects (const AlignedBox &c, const Triangle &t)
 Checks if the box and triangle intersect.
 
bool intersects (const AlignedBox &c, const AlignedBox &c2)
 Checks if the two boxes intersect.
 
bool intersects (const AlignedBox &cub, const Plane &plane)
 Checks if the box and plane intersect.
 

Function Documentation

◆ fitCircle()

int fitCircle ( const std::vector< vec2 > & pts,
vec2 & center,
double & radius,
bool fixed[3],
double * res = 0,
bool outlierRejection = false )

Fit circle to points, using the Levenberg-Marquardt algorithm.

Parameters
ptsinput points
centerestimated center
radiusestimated radius
fixedfixed parameters (center x, y, radius)
resresidual
Returns
0 if successful

◆ fitCircleLeastSquares()

double fitCircleLeastSquares ( const std::vector< vec2 > & pts,
vec2 & center,
double & radius )

Fit circle to points, using a linear least squares fit.

Parameters
ptsinput points
centerestimated center
radiusestimated radius
Returns
The residual
Note
See https://dtcenter.org/met/users/docs/write_ups/circle_fit.pdf for technical details.

◆ fitCircle3D()

int fitCircle3D ( const std::vector< vec3 > & pts,
vec3 & outCenter,
double & outRadius,
mat3 & outR,
double * outRes = 0,
bool rejectOutliers = false )

Fit circle in 3D to points.

Parameters
ptsinput points
outCenterestimated center
outRadiusestimated radius
outRestimated rotation matrix which transforms the circle normal to the z unit vector
outResresidual
Returns
0 if successful, -1 otherwise

◆ fitSphere()

int fitSphere ( const std::vector< vec3 > & pts,
vec3 & center,
double & radius,
bool fixed[4],
double * res = 0 )

Fit sphere to points.

Parameters
ptsinput points
centerestimated center and initial guess
radiusestimated radius and initial guess
fixedfixed parameters (center x, y, z, radius)
resresidual
Returns
0 if successful

◆ fitConic()

int fitConic ( const std::vector< vec2 > & pts,
mat3 & C,
double * res = 0 )

Fit conic to points.

Parameters
ptsinput points
Cconic
resresidual
Returns
0 if successful

◆ fitCylinder()

int fitCylinder ( const std::vector< vec3 > & pts,
vec3 & center,
double & radius,
mat3 & R,
double * res = 0 )

Fit cylinder to points.

Parameters
ptsinput points
centerestimated center
radiusestimated radius
Rrotation matrix
resresidual
Returns
0 if successful

◆ fitPlane()

int fitPlane ( const std::vector< vec3 > & pts_,
vec4 * plane,
double * res = 0,
bool rejectOutliers = false )

Fit plane to points.

Parameters
pts_input points
planeestimated plane
resresidual
Returns
0 if successful

For any point pt on the plane, plane.dot(pt.homogeneous()) == 0.0 holds, i.e. plane[3] is -d from the Hesse normal form

◆ fitAxesPCA()

void fitAxesPCA ( const std::vector< vec3 > & pts_,
vec3 & outCentroid_,
vec4(&) outPlanes_[3],
bool scalePoints = true,
vec3 * outEigenvalues = nullptr )

Performs a PCA to fit the principal component axes to points.

Parameters
pts_input points
outCentroid_estimated centroid
outPlanes_estimated planes in homogeneous convenion (see fitPlane())
scalePointswhether to scale the points
outEigenvaluesestimated eigenvalues

The first three components of each estimated plane contain the normal vector, i.e. the principal component axis. fitPlane() returns the last of these planes.

◆ fitLine()

int fitLine ( const std::vector< vec2 > & pts_,
vec3 * line,
double * res = 0 )

Fit line to points.

Parameters
pts_input points
lineestimated line in general form: a*x + b*y + c = 0
resresidual
Returns
0 if successful

◆ fitLineRANSAC()

double fitLineRANSAC ( const std::vector< vec3 > & pts,
vec3 & lineOutOrigin,
vec3 & lineOutDir,
std::vector< vec3 > & inliersOut,
double inlierThreshold )

Fit line to inlier points.

Parameters
ptsinput points
lineOutOriginpoint belonging to the line
lineOutDirdirection of the line, thus any point on the line can be estimated as: <x, y, z> = lineOutOrigin + t*lineOutDir
inliersOutinput points that lie within inlierThreshold distance from the estimated line
inlierThresholdthreshold for distance between an inlier point and an estimated line
Returns
average distance between inlier point and the line

◆ fitEllipse()

std::optional< Geometry::Ellipse2D > fitEllipse ( const std::vector< vec2 > & pts)

Fit ellipse to points using least squares.

Parameters
ptsinput points
ellipseoutput fitted ellipse
Returns
true if successful, false otherwise

◆ uniformDistributedPointsOnSphere()

std::vector< vec3 > uniformDistributedPointsOnSphere ( const int N)

Picks uniform distributed points on the sphere, i.e.

unit vectors in 3D

Parameters
Nnumber of points to be picked
Returns
Vector of N uniform distributed unit vectors

◆ uniformDistributedPointsOnCircle()

std::vector< vec2 > uniformDistributedPointsOnCircle ( const int N)

Picks uniform distributed points on the circle, i.e.

unit vectors in 2D

Parameters
Nnumber of points to be picked
Returns
Vector of N uniform distributed unit vectors
Search Tab / S to search, Esc to close