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.PointCloudType
mutable 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.

source
RANSAC.PointCloudMethod
PointCloud(vertices, normals, subsets)

Construct a PointCloud, filling it's other fields.

size=length(vertices), levelweight=[1.0], levelscore=[1.0], isenabled=trues(length(vertices))

source
RANSAC.PointCloudMethod
PointCloud(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]

source
RANSAC.PointCloudMethod
PointCloud(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.
source

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:

Primitives

RANSAC.FittedPlaneType
struct FittedPlane{A<:AbstractArray} <: FittedShape

Plane primitive, defined by one of its point, and its normalvector.

source
RANSAC.FittedSphereType
struct FittedSphere{A<:AbstractArray, R<:Real} <: FittedShape

Sphere primitive, defined by its center and radius. Also stored, if the normals point outwards of the shape.

source
RANSAC.FittedCylinderType
struct 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.

source
RANSAC.FittedConeType
struct 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.

source

Iteration

The ransac() function does the iteration.

RANSAC.ransacFunction
ransac(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: if true: set every point to enabled.
  • reset_rand::Bool=false: if true, resets the random seed with Random.seed!(1234)
source
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: if true, resets the random seed with Random.seed!(1234)
source