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

RSDK-1072 Read PCD to Octree #1768

Merged
14 commits merged into from Jan 25, 2023
Merged

RSDK-1072 Read PCD to Octree #1768

14 commits merged into from Jan 25, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jan 13, 2023

This PR implements the ReadPCDToOctree function which allows the creation of an octree from a pcd file/buffer. It also adds octrees to the pointcloud package, as the rescoping of map representation removed the formerly required Marshaler function allowing octrees to implement the pointcloud interface exactly. This change over also allows us to take advantage of the pcd reader functions where are unexposed.

The ReadPCDToBasicOctree current is implemented by creating a basic pointcloud which allows us to obtain the requried metadata for an octree (center and sideLength from the max and min X,Y and Z values and then converting this pointcloud to a basicOctree. This results in a call to ReadPCD as well as a call to the new ConvertPointCloudToOctree function. The ConvertPointCloudToOctree returns a Pointcloud interface that can be cast into a BasicOctree and any other implementation of octree that should be created in the future, while ReadPCDToBasicOctree returns the specific BasicOctree struct

Several changes were made, including but not limited to:

  • Removing the context and logger from BasicOctrees
  • Renaming certain functions such as New to NewBasicOctree to reduce confusion as New already exists in the pointcloud package
  • Exposing the BasicOctree (basicOctree -> BasicOctree)

Additional information can be found in the comment below

JIRA Ticket: RSDK-1072

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Jan 13, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 13, 2023
@ghost ghost requested review from bhaney, kkufieta, nicksanford and tessavitabile January 17, 2023 19:38
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/pointcloud_file.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 17, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 17, 2023
pointcloud/basic_octree.go Outdated Show resolved Hide resolved
pointcloud/basic_octree.go Show resolved Hide resolved
pointcloud/basic_octree.go Show resolved Hide resolved
pointcloud/basic_octree.go Outdated Show resolved Hide resolved
pointcloud/basic_octree.go Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 17, 2023

basicOct, err := ReadPCDToBasicOctree(strings.NewReader(gotPCD))
test.That(t, err, test.ShouldBeNil)
test.That(t, basicOct.Size(), test.ShouldEqual, 3)
Copy link
Member

@nicksanford nicksanford Jan 18, 2023

Choose a reason for hiding this comment

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

Also, do we want to have any more comprehensive testing that the conversion from PCD to Octree is lossless?

Would it be possible to write a test that confirms that (at a high level):

  1. ToPCD(ToOctree(PCD)) == PCD
  2. ToPointcloud(PCD)'s methods behave in the exact same way as ToOctree(PCD)? for a given PCD

Copy link
Author

Choose a reason for hiding this comment

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

I have a note on line 174 in basic_octree_utils.go to do so once we decide which way to go (one way doesnt require this function to exist)

Copy link
Member

Choose a reason for hiding this comment

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

If I were implementing this, I'd like to have tests that prove 1 & 2 in the PR that adds the functionality to go between PCD & Octree to ensure they are correct.

Could we add them before merging this PR?

Copy link
Member

@nicksanford nicksanford Jan 25, 2023

Choose a reason for hiding this comment

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

Can we please get tests for the behavior of https://github.com/viamrobotics/rdk/pull/1768/files#diff-e01dea69a2aaa9209cb5deeb1c4569f99ef8c51262c69799a0cec3a79d7434ebR543 ?
PCDAscii and PCDCompressed and an unexpected type?

Copy link
Member

Choose a reason for hiding this comment

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

Never mind, I now see that these cases are covered in testASCIIRoundTrip & testBinaryRoundTrip

pointcloud/basic_octree.go Outdated Show resolved Hide resolved
pointcloud/basic_octree.go Show resolved Hide resolved
pointcloud/basic_octree_test.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_test.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
bOct.logger.Infof("%v %e %e %e - %v | Children: %v Side: %v Size: %v\n", s,
func printBasicOctree(bOct *BasicOctree, s string) {
//nolint:forbidigo
fmt.Printf("%v %e %e %e - %v | Children: %v Side: %v Size: %v\n", s,
Copy link
Member

Choose a reason for hiding this comment

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

why is this Printf needed, is there no global logger? also, why the//nolint:unsued there?

pointcloud/pointcloud_file_test.go Show resolved Hide resolved
}

return ok
}

// ConvertPointCloudToBasicOctree converts a pointcloud into a octree pointcloud representation.
func ConvertPointCloudToBasicOctree(cloud PointCloud) (PointCloud, error) {
Copy link
Member

Choose a reason for hiding this comment

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

I think if we end up having multiple octree types, we could just create another function which returns a that octree type. If the caller has opinions on which octree representation to use, they can call the function which gives them that flavor of octree.

Returning a PointCloud implies to me that returning anything that implements the PointCloud interface would be equally valid, which I don't think is the case for this function.


basicOct, err := ReadPCDToBasicOctree(strings.NewReader(gotPCD))
test.That(t, err, test.ShouldBeNil)
test.That(t, basicOct.Size(), test.ShouldEqual, 3)
Copy link
Member

Choose a reason for hiding this comment

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

If I were implementing this, I'd like to have tests that prove 1 & 2 in the PR that adds the functionality to go between PCD & Octree to ensure they are correct.

Could we add them before merging this PR?

@ghost ghost marked this pull request as ready for review January 19, 2023 20:03
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 19, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 24, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 24, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 24, 2023
@ghost ghost requested review from nicksanford and removed request for kkufieta January 24, 2023 21:51
@ghost ghost assigned JohnN193 Jan 24, 2023
@nicksanford
Copy link
Member

only blocking feedback remaining is test cases for all the different PCD formats ReadPCDToOctree supports & doesn't support, so we can have at least high level tests of all the new code paths which are being added.

Copy link
Member

@nicksanford nicksanford left a comment

Choose a reason for hiding this comment

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

LGTM!

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 25, 2023
Copy link
Member

@bhaney bhaney left a comment

Choose a reason for hiding this comment

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

Things are looking good, just some optional cosmetic changes

pointcloud/basic_octree_utils.go Outdated Show resolved Hide resolved
Comment on lines 176 to 178
X: meta.MinX + (meta.MaxX-meta.MinX)/2,
Y: meta.MinY + (meta.MaxY-meta.MinY)/2,
Z: meta.MinZ + (meta.MaxZ-meta.MinZ)/2,
Copy link
Member

Choose a reason for hiding this comment

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

[opt] This can also be expressed as (meta.MinX + meta.MaxX)/2 but it's not like an extra operation makes a big difference.

Comment on lines 549 to 559
switch header.data {
case PCDAscii:
meta, err = getPCDMetaDataASCII(*in, header)
case PCDBinary:
meta, err = getPCDMetaDataBinary(*in, header)
case PCDCompressed:
// return readPCDCompressed(in, header)
return nil, errors.New("compressed pcd not yet supported")
default:
return nil, fmt.Errorf("unsupported pcd data type %v", header.data)
}
Copy link
Member

Choose a reason for hiding this comment

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

It feels like this switch statement could be within the function more general called getPCDMetaData

Comment on lines 682 to 693
func getPCDMetaDataBinary(in bufio.Reader, header pcdHeader) (MetaData, error) {
meta := NewMetaData()
for i := 0; i < int(header.points); i++ {
pd, err := extractPCDPointBinary(&in, header)
if err != nil {
return MetaData{}, err
}

meta.Merge(pd.P, pd.D)
}
return meta, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

yes, I think combining the getPCDMetaData functions into one will make all right sense

@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 25, 2023
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Jan 25, 2023
@github-actions
Copy link
Contributor

Code Coverage

Package Line Rate Delta Health
go.viam.com/rdk/components/arm 56% 0.00%
go.viam.com/rdk/components/arm/universalrobots 41% 0.00%
go.viam.com/rdk/components/arm/xarm 2% 0.00%
go.viam.com/rdk/components/arm/yahboom 7% 0.00%
go.viam.com/rdk/components/audioinput 55% -0.34%
go.viam.com/rdk/components/base 63% 0.00%
go.viam.com/rdk/components/base/agilex 62% 0.00%
go.viam.com/rdk/components/base/boat 41% 0.00%
go.viam.com/rdk/components/base/wheeled 65% 0.00%
go.viam.com/rdk/components/board 66% 0.00%
go.viam.com/rdk/components/board/arduino 10% 0.00%
go.viam.com/rdk/components/board/commonsysfs 48% 0.00%
go.viam.com/rdk/components/board/fake 38% 0.00%
go.viam.com/rdk/components/board/numato 19% 0.00%
go.viam.com/rdk/components/board/pi 50% 0.00%
go.viam.com/rdk/components/camera 63% 0.00%
go.viam.com/rdk/components/camera/align 64% +0.48%
go.viam.com/rdk/components/camera/fake 64% 0.00%
go.viam.com/rdk/components/camera/ffmpeg 77% 0.00%
go.viam.com/rdk/components/camera/transformpipeline 79% +0.31%
go.viam.com/rdk/components/camera/videosource 46% 0.00%
go.viam.com/rdk/components/encoder 4% 0.00%
go.viam.com/rdk/components/encoder/fake 76% 0.00%
go.viam.com/rdk/components/gantry 60% 0.00%
go.viam.com/rdk/components/gantry/multiaxis 84% 0.00%
go.viam.com/rdk/components/gantry/oneaxis 86% 0.00%
go.viam.com/rdk/components/generic 83% 0.00%
go.viam.com/rdk/components/gripper 68% 0.00%
go.viam.com/rdk/components/input 87% 0.00%
go.viam.com/rdk/components/input/gpio 84% 0.00%
go.viam.com/rdk/components/motor 77% 0.00%
go.viam.com/rdk/components/motor/dimensionengineering 63% 0.00%
go.viam.com/rdk/components/motor/dmc4000 69% 0.00%
go.viam.com/rdk/components/motor/fake 57% 0.00%
go.viam.com/rdk/components/motor/gpio 64% 0.00%
go.viam.com/rdk/components/motor/gpiostepper 57% 0.00%
go.viam.com/rdk/components/motor/tmcstepper 62% 0.00%
go.viam.com/rdk/components/movementsensor 75% 0.00%
go.viam.com/rdk/components/movementsensor/cameramono 46% 0.00%
go.viam.com/rdk/components/movementsensor/gpsnmea 36% 0.00%
go.viam.com/rdk/components/movementsensor/gpsrtk 28% 0.00%
go.viam.com/rdk/components/posetracker 86% 0.00%
go.viam.com/rdk/components/sensor 86% 0.00%
go.viam.com/rdk/components/sensor/ultrasonic 26% 0.00%
go.viam.com/rdk/components/servo 68% 0.00%
go.viam.com/rdk/components/servo/gpio 71% 0.00%
go.viam.com/rdk/config 75% 0.00%
go.viam.com/rdk/control 57% 0.00%
go.viam.com/rdk/data 79% 0.00%
go.viam.com/rdk/examples/customresources/demos/complexmodule 0% 0.00%
go.viam.com/rdk/examples/customresources/demos/remoteserver 0% 0.00%
go.viam.com/rdk/grpc 25% 0.00%
go.viam.com/rdk/ml 67% 0.00%
go.viam.com/rdk/ml/inference 70% 0.00%
go.viam.com/rdk/module 64% 0.00%
go.viam.com/rdk/module/modmanager 79% 0.00%
go.viam.com/rdk/motionplan 59% +0.10%
go.viam.com/rdk/operation 82% 0.00%
go.viam.com/rdk/pointcloud 73% +1.60%
go.viam.com/rdk/protoutils 59% 0.00%
go.viam.com/rdk/referenceframe 71% 0.00%
go.viam.com/rdk/registry 89% 0.00%
go.viam.com/rdk/resource 84% 0.00%
go.viam.com/rdk/rimage 78% 0.00%
go.viam.com/rdk/rimage/depthadapter 94% 0.00%
go.viam.com/rdk/rimage/transform 74% 0.00%
go.viam.com/rdk/rimage/transform/cmd/extrinsic_calibration 67% 0.00%
go.viam.com/rdk/robot 85% -0.95%
go.viam.com/rdk/robot/client 81% 0.00%
go.viam.com/rdk/robot/framesystem 65% 0.00%
go.viam.com/rdk/robot/impl 80% 0.00%
go.viam.com/rdk/robot/server 55% 0.00%
go.viam.com/rdk/robot/web 61% 0.00%
go.viam.com/rdk/robot/web/stream 87% 0.00%
go.viam.com/rdk/services/armremotecontrol 71% 0.00%
go.viam.com/rdk/services/armremotecontrol/builtin 52% 0.00%
go.viam.com/rdk/services/baseremotecontrol 71% 0.00%
go.viam.com/rdk/services/baseremotecontrol/builtin 79% 0.00%
go.viam.com/rdk/services/datamanager 79% 0.00%
go.viam.com/rdk/services/datamanager/builtin 78% 0.00%
go.viam.com/rdk/services/datamanager/datacapture 70% 0.00%
go.viam.com/rdk/services/datamanager/datasync 0% 0.00%
go.viam.com/rdk/services/motion 63% 0.00%
go.viam.com/rdk/services/motion/builtin 88% 0.00%
go.viam.com/rdk/services/navigation 53% 0.00%
go.viam.com/rdk/services/sensors 77% 0.00%
go.viam.com/rdk/services/sensors/builtin 97% 0.00%
go.viam.com/rdk/services/shell 14% 0.00%
go.viam.com/rdk/services/slam 84% 0.00%
go.viam.com/rdk/services/slam/builtin 70% 0.00%
go.viam.com/rdk/services/vision 80% 0.00%
go.viam.com/rdk/services/vision/builtin 74% 0.00%
go.viam.com/rdk/session 97% 0.00%
go.viam.com/rdk/spatialmath 82% 0.00%
go.viam.com/rdk/subtype 92% 0.00%
go.viam.com/rdk/utils 72% +0.18%
go.viam.com/rdk/vision 26% 0.00%
go.viam.com/rdk/vision/chess 80% 0.00%
go.viam.com/rdk/vision/delaunay 87% 0.00%
go.viam.com/rdk/vision/keypoints 92% 0.00%
go.viam.com/rdk/vision/objectdetection 82% 0.00%
go.viam.com/rdk/vision/odometry 60% 0.00%
go.viam.com/rdk/vision/odometry/cmd 0% 0.00%
go.viam.com/rdk/vision/segmentation 49% 0.00%
go.viam.com/rdk/web/server 25% 0.00%
Summary 65% (21335 / 32986) 0.00%

@ghost ghost merged commit c1fc222 into viamrobotics:main Jan 25, 2023
@ghost ghost deleted the RSDK-1072_ReadPCDforOctree branch February 1, 2023 19:50
randhid pushed a commit to randhid/rdk that referenced this pull request Feb 25, 2023
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
safe to test This pull request is marked safe to test from a trusted zone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants