Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method which converts a pointcloud into an octree. #4608

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 24 additions & 27 deletions pointcloud/basic_octree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,24 +633,33 @@ func testPCDToBasicOctree(t *testing.T, artifactPath string) {
validateBasicOctree(t, basicOct, basicOct.center, basicOct.sideLength)
}

func TestCachedMaxProbability(t *testing.T) {
func createPopulatedOctree(sign int) (*BasicOctree, error) {
center := r3.Vector{X: 0, Y: 0, Z: 0}
side := 2.0
octree, err := createNewOctree(center, side)
if err != nil {
return nil, nil
}
pointsAndData := []PointAndData{
{P: r3.Vector{X: 0, Y: 0, Z: 0}, D: NewValueData(2 * sign)},
{P: r3.Vector{X: .5, Y: 0, Z: 0}, D: NewValueData(3 * sign)},
{P: r3.Vector{X: .5, Y: 0, Z: .5}, D: NewValueData(10 * sign)},
{P: r3.Vector{X: .5, Y: .5, Z: 0}, D: NewValueData(1 * sign)},
{P: r3.Vector{X: .55, Y: .55, Z: 0}, D: NewValueData(4 * sign)},
{P: r3.Vector{X: -.55, Y: -.55, Z: 0}, D: NewValueData(5 * sign)},
{P: r3.Vector{X: .755, Y: .755, Z: 0}, D: NewValueData(6 * sign)},
}

t.Run("get the max val from an octree", func(t *testing.T) {
octree, err := createNewOctree(center, side)
test.That(t, err, test.ShouldBeNil)
pointsAndData := []PointAndData{
{P: r3.Vector{X: 0, Y: 0, Z: 0}, D: NewValueData(2)},
{P: r3.Vector{X: .5, Y: 0, Z: 0}, D: NewValueData(3)},
{P: r3.Vector{X: .5, Y: 0, Z: .5}, D: NewValueData(10)},
{P: r3.Vector{X: .5, Y: .5, Z: 0}, D: NewValueData(1)},
{P: r3.Vector{X: .55, Y: .55, Z: 0}, D: NewValueData(4)},
{P: r3.Vector{X: -.55, Y: -.55, Z: 0}, D: NewValueData(5)},
{P: r3.Vector{X: .755, Y: .755, Z: 0}, D: NewValueData(6)},
}
err = addPoints(octree, pointsAndData)
if err != nil {
return nil, nil
}
return octree, nil
}

err = addPoints(octree, pointsAndData)
func TestCachedMaxProbability(t *testing.T) {
t.Run("get the max val from an octree", func(t *testing.T) {
octree, err := createPopulatedOctree(1)
test.That(t, err, test.ShouldBeNil)

validateBasicOctree(t, octree, octree.center, octree.sideLength)
Expand All @@ -675,19 +684,7 @@ func TestCachedMaxProbability(t *testing.T) {
})

t.Run("setting negative values", func(t *testing.T) {
octree, err := createNewOctree(center, side)
test.That(t, err, test.ShouldBeNil)
pointsAndData := []PointAndData{
{P: r3.Vector{X: 0, Y: 0, Z: 0}, D: NewValueData(-2)},
{P: r3.Vector{X: .5, Y: 0, Z: 0}, D: NewValueData(-3)},
{P: r3.Vector{X: .5, Y: 0, Z: .5}, D: NewValueData(-10)},
{P: r3.Vector{X: .5, Y: .5, Z: 0}, D: NewValueData(-1)},
{P: r3.Vector{X: .55, Y: .55, Z: 0}, D: NewValueData(-4)},
{P: r3.Vector{X: -.55, Y: -.55, Z: 0}, D: NewValueData(-5)},
{P: r3.Vector{X: .755, Y: .755, Z: 0}, D: NewValueData(-6)},
}

err = addPoints(octree, pointsAndData)
octree, err := createPopulatedOctree(-1)
test.That(t, err, test.ShouldBeNil)

validateBasicOctree(t, octree, octree.center, octree.sideLength)
Expand Down
10 changes: 5 additions & 5 deletions pointcloud/pointcloud_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ func ToBasicOctree(cloud PointCloud) (*BasicOctree, error) {
if err != nil {
return &BasicOctree{}, err
nfranczak marked this conversation as resolved.
Show resolved Hide resolved
}
var iterateError error
// var iterateError error
nfranczak marked this conversation as resolved.
Show resolved Hide resolved
cloud.Iterate(0, 0, func(p r3.Vector, d Data) bool {
biotinker marked this conversation as resolved.
Show resolved Hide resolved
if err = basicOctree.Set(p, d); err != nil {
iterateError = err
// iterateError = err
return false
}
return true
})
if iterateError != nil {
return &BasicOctree{}, iterateError
}
// if iterateError != nil {
// return &BasicOctree{}, iterateError
// }
return basicOctree, nil
}
14 changes: 1 addition & 13 deletions pointcloud/pointcloud_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,7 @@ func TestToOctree(t *testing.T) {
return true
})

basicTree, err := createNewOctree(r3.Vector{0, 0, 0}, 2)
test.That(t, err, test.ShouldBeNil)
pointsAndData := []PointAndData{
{P: r3.Vector{X: 0, Y: 0, Z: 0}, D: NewValueData(2)},
{P: r3.Vector{X: .5, Y: 0, Z: 0}, D: NewValueData(3)},
{P: r3.Vector{X: .5, Y: 0, Z: .5}, D: NewValueData(10)},
{P: r3.Vector{X: .5, Y: .5, Z: 0}, D: NewValueData(1)},
{P: r3.Vector{X: .55, Y: .55, Z: 0}, D: NewValueData(4)},
{P: r3.Vector{X: -.55, Y: -.55, Z: 0}, D: NewValueData(5)},
{P: r3.Vector{X: .755, Y: .755, Z: 0}, D: NewValueData(6)},
}

err = addPoints(basicTree, pointsAndData)
basicTree, err := createPopulatedOctree(1)
test.That(t, err, test.ShouldBeNil)
tree, err = ToBasicOctree(basicTree)
test.That(t, err, test.ShouldBeNil)
Expand Down
Loading