Public API
Note, that not all exported functions are considered as part of the public API. The private API is not mature yet, expect it to change.
Representing a point cloud
RANSAC.PointCloud
— Typemutable struct PointCloud{A<:AbstractArray, B<:AbstractArray, C<:AbstractArray}
A struct to wrap a point cloud. Stores the vertices, the normals, the subsets (as an array of arrays of vertice indexes), an array to indicate if a point is part of an already extracted primitive, the size of the point cloud (number of vertices), the weight of each octree level (populated during the construction of the octree, by copying the given element), an array to store the sum of the score of already extracted primitives for each octree level.
RANSAC.PointCloud
— MethodPointCloud(vertices, normals, subsets)
Construct a PointCloud
, filling it's other fields.
size=length(vertices)
, levelweight=[1.0]
, levelscore=[1.0]
, isenabled=trues(length(vertices))
RANSAC.PointCloud
— MethodPointCloud(vertices, normals, subsets, isenabled)
Construct a PointCloud
with filling it's size
, isenabled
and levelweight
fields.
size=length(vertices)
, levelweight=[1.0]
, levelscore=[1.0]
RANSAC.PointCloud
— MethodPointCloud(vertices, normals, subsets, isenabled, size, levelweight, levelscore)
Constructor that converts vertices and normals to array of SVector{3,Float64}
.
Arguments
vertices::AbstractArray
: an array of vertices.normals::AbstractArray
: an array of surface normals.subsets::AbstractArray
: an array consisting of index-arrays, that describe which point is in which subset.isenabled::BitArray{1}
: an array indicating if the given point is enabled (true
) or already has been extracted (false
).size::Int
: number of points in the cloud.levelweight::Vector{Float}
: the weight of every octree level.levelscore::Vector{Float}
: for every octree level, store the sum of the scores of primitives that have been extracted.
Parameters
With the help of Parameters.jl it's easy to parameterize the algorithm. The RANSACParameters
type collects all the parameters, though its fields are subject to change, the current fields and default values are listed below.
@with_kw struct RANSACParameters{R<:Real} @deftype R
ϵ_plane = 0.3
α_plane = deg2rad(5)
ϵ_sphere = 0.3
α_sphere = deg2rad(5)
ϵ_cylinder = 0.3
α_cylinder = deg2rad(5)
ϵ_cone = 0.3
α_cone = deg2rad(5)
# filter those cones, whose opening angle is less than `minconeopang` radians
minconeopang = deg2rad(2)
ϵ_torus = 0.3
α_torus = deg2rad(5)
# number of points to be sampled (length of a minimal subset)
drawN::Int = 3; @assert drawN>2
# number of minimal sets sampled in one iteration
minsubsetN::Int = 15; @assert minsubsetN>0
# probability of detection
prob_det = 0.9
# minimal shape size
τ::Int = 900
# maximum number of iteration
itermax::Int = 1000
# if the number of enabled points fall under `leftover`,
# the iteration terminates
leftovers::Int = 1
# threshold of two vectors being parallel (in degrees)
parallelthrdeg = 1
# threshold of points being collinear
collin_threshold = 0.2
# parameter in sphere fitting
sphere_par = 0.02
# shapes that are fitted to the point cloud
shape_types::Array{Symbol,1} = [:sphere, :plane, :cylinder, :cone]
end
You can use the following functions to set every $\alpha$ or $\epsilon$ parameters to a certain value:
RANSAC.setalphas
— Functionsetalphas(p::RANSACParameters, α)
Set all α_*
fields to α
RANSAC.setepsilons
— Functionsetepsilons(p::RANSACParameters, ϵ)
Set all ϵ_*
fields to ϵ
.
Primitives
RANSAC.FittedShape
— TypeAn abstract type that supertypes all the fitted shapes.
RANSAC.FittedPlane
— Typestruct FittedPlane{A<:AbstractArray} <: FittedShape
Plane primitive, defined by one of its point, and its normalvector.
RANSAC.FittedSphere
— Typestruct FittedSphere{A<:AbstractArray, R<:Real} <: FittedShape
Sphere primitive, defined by its center and radius. Also stored, if the normals point outwards of the shape.
RANSAC.FittedCylinder
— Typestruct FittedCylinder{A<:AbstractArray, R<:Real} <: FittedShape
Cylinder primitive, defined by its axis direction, a point that lies on its axis, and its radius. Also stored, if the normals point outwards of the shape.
RANSAC.FittedCone
— Typestruct FittedCone{A<:AbstractArray, R<:Real} <: FittedShape
Cone primitive, defined by its apex, its axis (that points from the apex towards the opening), and its opening angle in radians. Also stored, if the normals point outwards of the shape.
Iteration
The ransac()
function does the iteration.
RANSAC.ransac
— Functionransac(pc, params, setenabled; reset_rand = false)
Run the RANSAC algorithm on a pointcloud with the given parameters.
Returns the candidates (as they are at the end of the iteration), the extracted primitives and the time it took to run the algorithm (in seconds).
Arguments
pc::PointCloud
: the point cloud.params::RANSACParameters
: parameters.setenabled::Bool
: iftrue
: set every point to enabled.reset_rand::Bool=false
: iftrue
, resets the random seed withRandom.seed!(1234)
ransac(pc, params; reset_rand = false)
Run the RANSAC algorithm on a pointcloud with the given parameters.
Returns the candidates (as they are at the end of the iteration), the extracted primitives and the time it took to run the algorithm (in seconds).
Arguments
pc::PointCloud
: the point cloud.params::RANSACParameters
: parameters.reset_rand::Bool=false
: iftrue
, resets the random seed withRandom.seed!(1234)