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

// PointCloudToBasicOctree takes a pointcloud object and converts it into an octree.
func PointCloudToBasicOctree(cloud PointCloud) (*BasicOctree, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If cloud is already a BasicOctree, we should return that directly instead of copying

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems that is is not.

return utils.AssertType[*BasicOctree](cloud)

gives error

expected *pointcloud.BasicOctree but got *pointcloud.basicPointCloud

Unless, I am completely mis-understanding this comment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

octrees still satify the pointcloud interface iirc, so a user could call this function with something thats already an octree.

if we realize that we have an octree already, then we should just return it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be because you passed in a basicPointCloud.

You should not be returning AssertType directly, only if the err is nil.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PointCloud is an interface type -- there are many structs that fulfill the PointCloud interface. You should do a type assertion to see if the cloud passed is already of the BasicOctree Type, and return it if it is.

This isn't just for your use case, but a check so that all future users can ensure they're not accidently passing in a pointcloud that already an OctTree type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if octTree, ok := cloud.(*BasicOctree); ok {
   return octTree, nil
}

https://yourbasic.org/golang/type-assertion-switch/

center := getCenterFromPcMetaData(cloud.MetaData())
maxSideLength := getMaxSideLengthFromPcMetaData(cloud.MetaData())

basicOct, err := NewBasicOctree(center, maxSideLength)
if err != nil {
return &BasicOctree{}, err
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 = basicOct.Set(p, d); err != nil {
return false
}
return true
})
return basicOct, nil
}
Loading