Skip to content

Commit

Permalink
Add a progress meter option in find_visiblefacets!
Browse files Browse the repository at this point in the history
  • Loading branch information
MasanoriKanamaru committed Jan 25, 2024
1 parent 921b036 commit 1d37645
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
29 changes: 23 additions & 6 deletions src/facet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,31 @@ raycast(A::StaticVector{3}, B::StaticVector{3}, C::StaticVector{3}, R::StaticVec


"""
find_visiblefacets!(obs::Facet, facets)
find_visiblefacets!(shape::ShapeModel; show_progress=true)
Find facets that is visible from the facet where the observer is located.
# Parameters
- `obs` : Facet where the observer stands
- `facets` : Array of `Facet`
# Arguments
- `shape` : Shape model of an asteroid
# Keyword arguments
- `show_progress` : Switch to show a progress meter
"""
function find_visiblefacets!(shape::ShapeModel)
function find_visiblefacets!(shape::ShapeModel; show_progress=true)
nodes = shape.nodes
faces = shape.faces
face_centers = shape.face_centers
face_normals = shape.face_normals
face_areas = shape.face_areas
visiblefacets = shape.visiblefacets

@showprogress 1 "Searching for visible faces..." for i in eachindex(faces)
## `ProgressMeter` setting
if show_progress
p = Progress(length(faces); dt=1, desc="Searching for visible faces...", showspeed=true)
ProgressMeter.ijulia_behavior(:clear)
end

for i in eachindex(faces)
cᵢ = face_centers[i]
n̂ᵢ = face_normals[i]
aᵢ = face_areas[i]
Expand Down Expand Up @@ -141,6 +149,15 @@ function find_visiblefacets!(shape::ShapeModel)
push!(visiblefacets[i], VisibleFacet(j, view_factor(cᵢ, cⱼ, n̂ᵢ, n̂ⱼ, aⱼ)...)) # i -> j
push!(visiblefacets[j], VisibleFacet(i, view_factor(cⱼ, cᵢ, n̂ⱼ, n̂ᵢ, aᵢ)...)) # j -> i
end

## Update the progress meter
if show_progress
showvalues = [
("Face ID ", i),
("Visible faces ", length(visiblefacets[i])),
]
ProgressMeter.next!(p; showvalues)
end
end
end

Expand Down
17 changes: 15 additions & 2 deletions src/shape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,20 @@ function Base.show(io::IO, shape::ShapeModel)
print(io, msg)
end

function load_shape_obj(shapepath; scale = 1.0, find_visible_facets = false)
"""
load_shape_obj(shapepath; scale=1.0, find_visible_facets=false; show_progress=true)
Load a shape model from a Wavefront OBJ file.
# Arguments
- `shapepath` : Path to a Wavefront OBJ file
# Keyword arguments
- `scale` : Scale factor of the shape model
- `find_visible_facets` : Switch to find visible facets
- `show_progress` : Switch to show a progress meter
"""
function load_shape_obj(shapepath; scale=1.0, find_visible_facets=false, show_progress=true)
# TODO: use MeshIO.jl
nodes, faces = loadobj(shapepath; scale = scale, message = false)

Expand All @@ -66,7 +79,7 @@ function load_shape_obj(shapepath; scale = 1.0, find_visible_facets = false)
visiblefacets = [VisibleFacet[] for _ in faces]

shape = ShapeModel(nodes, faces, face_centers, face_normals, face_areas, visiblefacets)
find_visible_facets && find_visiblefacets!(shape)
find_visible_facets && find_visiblefacets!(shape; show_progress)

return shape
end
Expand Down

0 comments on commit 1d37645

Please sign in to comment.