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 all commits
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, err
}
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, err
}
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
26 changes: 26 additions & 0 deletions pointcloud/pointcloud_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,29 @@ func StatisticalOutlierFilter(meanK int, stdDevThresh float64) (func(PointCloud)
}
return filterFunc, nil
}

// ToBasicOctree takes a pointcloud object and converts it into a basic octree.
func ToBasicOctree(cloud PointCloud) (*BasicOctree, error) {
if basicOctree, ok := cloud.(*BasicOctree); ok {
return basicOctree, nil
}

center := getCenterFromPcMetaData(cloud.MetaData())
maxSideLength := getMaxSideLengthFromPcMetaData(cloud.MetaData())
basicOctree, err := NewBasicOctree(center, maxSideLength)
if err != nil {
return nil, err
}
var iterateError error
biotinker 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
return false
}
return true
})
if iterateError != nil {
return nil, err
}
return basicOctree, nil
}
23 changes: 23 additions & 0 deletions pointcloud/pointcloud_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,26 @@ func TestPrune(t *testing.T) {
test.That(t, len(clouds), test.ShouldEqual, 1)
test.That(t, clouds[0].Size(), test.ShouldEqual, 5)
}

func TestToOctree(t *testing.T) {
pc := newBigPC()
tree, err := ToBasicOctree(pc)
test.That(t, err, test.ShouldBeNil)
pc.Iterate(0, 0, func(p r3.Vector, d Data) bool {
treeData, b := tree.At(p.X, p.Y, p.Z)
test.That(t, b, test.ShouldBeTrue)
test.ShouldResemble(t, treeData, d)
return true
})

basicTree, err := createPopulatedOctree(1)
test.That(t, err, test.ShouldBeNil)
tree, err = ToBasicOctree(basicTree)
test.That(t, err, test.ShouldBeNil)
basicTree.Iterate(0, 0, func(p r3.Vector, d Data) bool {
treeData, b := tree.At(p.X, p.Y, p.Z)
test.That(t, b, test.ShouldBeTrue)
test.ShouldResemble(t, treeData, d)
return true
})
}
Loading