-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #931 from JuliaRobotics/22Q4/fix/boundingbox
obj bounding box improvements
- Loading branch information
Showing
7 changed files
with
389 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
abstract type AbstractBoundingBox end | ||
|
||
Base.@kwdef struct AxisAlignedBoundingBox <: AbstractBoundingBox | ||
""" axis aligned bounding box, leveraging GeometryBasics.Rect3 (towards GoeB.HyperRectangle) """ | ||
hr::GeoB.Rect3{<:Any} = GeoB.Rect3(GeoB.Point(0,0,0.), GeoB.Point(1,1,1.)) | ||
end | ||
|
||
function AxisAlignedBoundingBox( | ||
org::Union{<:AbstractVector{<:Real}, <:GeoB.Point}, | ||
wdt::Union{<:AbstractVector{<:Real}, <:GeoB.Point}, | ||
) | ||
AxisAlignedBoundingBox( | ||
hr = GeoB.Rect3( | ||
GeoB.Point(org...), | ||
GeoB.Point(wdt...) | ||
) | ||
) | ||
end | ||
|
||
function Base.getproperty(aabb::AxisAlignedBoundingBox, f::Symbol) | ||
if f == :hr | ||
getfield(aabb, f) | ||
elseif f == :origin | ||
aabb.hr.origin | ||
elseif f == :widths | ||
aabb.hr.widths | ||
else | ||
error("AxisAlignedBoundingBox has no field $f") | ||
end | ||
end | ||
|
||
|
||
Base.@kwdef struct OrientedBoundingBox <: AbstractBoundingBox | ||
""" axis aligned bounding box, leveraging GeometryBasics.Rect3 (towards GoeB.HyperRectangle) """ | ||
hr::GeoB.Rect3{<:Any} = GeoB.Rect3(GeoB.Point(0,0,0.), GeoB.Point(1,1,1.)) | ||
""" Inverse homography which goes from some reference frame r to the bounding box frame """ | ||
bb_H_r::typeof(SMatrix{4,4}(diagm(ones(4)))) = SMatrix{4,4}(diagm(ones(4))) | ||
end | ||
|
||
function OrientedBoundingBox( | ||
org::Union{<:AbstractVector{<:Real}, <:GeoB.Point}, | ||
wdt::Union{<:AbstractVector{<:Real}, <:GeoB.Point}, | ||
position::Union{<:AbstractVector{<:Real}, <:GeoB.Point}, | ||
rotation::AbstractMatrix{<:Real} | ||
) | ||
r_H_bb = affine_matrix(SpecialEuclidean(3), ArrayPartition(position, rotation)) | ||
OrientedBoundingBox(; | ||
hr = GeoB.Rect3(GeoB.Point(org...), GeoB.Point(wdt...)), | ||
bb_H_r = inv(SMatrix{4,4}(r_H_bb)) | ||
) | ||
end | ||
|
||
function Base.getproperty(obb::OrientedBoundingBox, f::Symbol) | ||
if f == :hr | ||
getfield(obb, f) | ||
elseif f == :bb_H_r | ||
getfield(obb, f) | ||
elseif f == :origin | ||
obb.hr.origin | ||
elseif f == :widths | ||
obb.hr.widths | ||
elseif f == :position | ||
inv(obb.bb_H_r)[1:end-1, end] | ||
elseif f == :rotation | ||
inv(obb.bb_H_r)[1:end-1,1:end-1] | ||
else | ||
error("OrientedBoundingBox has no field $f") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.