Skip to content

Commit

Permalink
Merge pull request #33 from cserteGT3/cst-updates
Browse files Browse the repository at this point in the history
StaticArrays.jl compatibility has been updated to the 1.0 releases
progress is shown with the help of ProgressMeter.jl
documentation is updated to use the new RANSACVisualizer package with Makie recipes
handling the negative sqrt error
  • Loading branch information
cserteGT3 authored Nov 24, 2021
2 parents b846a64 + 3fc8155 commit 28b594d
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 deletions.
6 changes: 4 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ ExtractMacro = "f86d3d12-fd5b-522c-99e9-61577282a1e9"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RegionTrees = "dee08c22-ab7f-5625-9660-a9af2021b33f"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
ExtractMacro = "^1"
JSON = "0.20, 0.21"
ProgressMeter = "1.7"
RegionTrees = "^0.3"
StaticArrays = "0.11, 0.12"
StaticArrays = "0.11,0.12,1.0,1.1,1.2"
YAML = "0.4"
ExtractMacro = "^1"
julia = "^1"

[extras]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ Follow the [detailed example](https://csertegt3.github.io/RANSAC.jl/stable/examp

Here's an example with a point cloud and the detected primitives colored according to their type.
![RANSAC example](img/ransac_example.png)

## Related projects

* The [RANSACVisualizer.jl](https://github.com/cserteGT3/RANSACVisualizer.jl) package implements Makie.jl recipes to visualize results from this package.
* There are other RANSAC implementations in Julia, for example:
* [ImageProjectiveGeometry.jl](https://github.com/peterkovesi/ImageProjectiveGeometry.jl/blob/master/doc/ransac.md): fits planes and lines to 3d points using RANSAC.
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"

[compat]
Documenter = "0.24,0.25"
Documenter = "0.24,0.25,0.25,0.26,0.27"
31 changes: 13 additions & 18 deletions docs/src/example.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,34 +69,29 @@ julia> extr, _ = ransac(pc, p, true, reset_rand=true);

## See the results

The [RANSACVisualizer](https://csertegt3.github.io/RANSACVisualizer.jl/stable/) package provides a few utility functions to check the results (check the docs for function signatures).

### Check the input

The `showgeometry()` function shows a mesh and its normal vectors:
The [RANSACVisualizer](https://csertegt3.github.io/RANSACVisualizer.jl/stable/) package provides Makie recipes to check the results (check the docs for function signatures).
To use them, install the package, and a Makie backend as well, for example:

```julia
julia> showgeometry(m, arrow=0.3; show_axis = false)
]add GLMakie
add https://github.com/cserteGT3/RANSACVisualizer.jl.git
using RANSACVisualizer, GLMakie
```

![](img/showgeometry.png)

### Results colored randomly
### Check the input

The `showshapes()` function provides this functionality.
The `meshschatter`, `mesh` or `wireframe` functions (from Makie.jl) can be used to inspect a mesh:

```julia
julia> showshapes(pc, extr; show_axis = false)
julia> mesh(m)
```

![](img/showshapes.png)

### Results colored according to their type
### See the coloured result

The `showbytype()` function provides this functionality.
The `visualize()` function (from RANSACVisualizer.jl) plots one `ExtractedShape`.
It can be coloured by type or randomly.
(See the [docs](https://csertegt3.github.io/RANSACVisualizer.jl/stable/) for details.)

```julia
julia> showbytype(pc, extr; show_axis = false)
julia> visualize(extr[1],pc, pointsize=0.5, coloringtype=:bytype)
```

![](img/bytype.png)
5 changes: 5 additions & 0 deletions src/RANSAC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using RegionTrees
using ExtractMacro
import JSON
import YAML
using ProgressMeter

import RegionTrees: AbstractRefinery, needs_refinement, refine_data
import Base: show, length, deleteat!
Expand Down Expand Up @@ -81,6 +82,10 @@ include("iterations.jl")
include("logging.jl")
include("orientedbox_.jl")
include("json-yaml.jl")
# functions and tools unrelated to RANSAC,
# but using the same methods
# these are not exported
include("unrelated.jl")

"""
`const DEFAULT_PARAMETERS =
Expand Down
5 changes: 4 additions & 1 deletion src/confidenceintervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ Standard deviation of the hypergeometric distribution.
Just copied from the article (Efficient RANSAC).
"""
function hypergeomdev(N, x, n)
sq = sqrt((x*n*(N-x)*(N-n))/(N-1))
sq_ = (x*n*(N-x)*(N-n))/(N-1)
# handle floating point errors:
# small negative numbers, that should be zero
sq = sq_ < 0 ? zero(sq_) : sqrt(sq_)
(min=(x*n+sq)/N, max=(x*n-sq)/N)
end

Expand Down
2 changes: 2 additions & 0 deletions src/iterations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function ransac(pc, params; reset_rand = false)
countcandidates = [0, 0, 0]

# iterate begin
progbar = Progress(itermax; desc = "Running iteration...", dt=1, barglyphs=BarGlyphs("[=> ]"))
for k in 1:itermax
if count(pc.isenabled) < τ
@logmsg IterInf "Break at $k iteration, because left less points, then τ"
Expand Down Expand Up @@ -153,6 +154,7 @@ function ransac(pc, params; reset_rand = false)
@logmsg IterInf "Break, at this point all shapes should be extracted: $k. iteration."
break
end
next!(progbar)
end # iterate end
fint = trunc((time_ns() - start_time)/1_000_000_000, digits=2)
@logmsg IterInf "Iteration finished in $fint seconds with $(length(extracted)) extracted and $(length(scoredshapes)) scored shapes."
Expand Down
5 changes: 5 additions & 0 deletions src/unrelated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function testshape(shape, vertices, normals, epsilon, alpha)
# compatiblesCylinder(cylinder, points, normals, params)
rpars = ransacparameters([FittedCylinder], cylinder==epsilon, α=alpha,))
compatiblesCylinder(shape, vertices, normals, rpars)
end

0 comments on commit 28b594d

Please sign in to comment.