-
Notifications
You must be signed in to change notification settings - Fork 126
APP-8776 Move geometry proto conversions to reference frame #5149
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
Merged
DTCurrie
merged 18 commits into
viamrobotics:main
from
DTCurrie:APP-8776-move-pointcloud-to-spatialmath
Aug 28, 2025
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
35d243c
move proto to/from conversions to referenceframe
DTCurrie 58bea5e
remove point proto
DTCurrie a109126
cleanup
DTCurrie 167e93b
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie 1b1dac5
cleanup
DTCurrie ed9e15d
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie 6c2e826
pr comments
DTCurrie c67adc6
fixture cleanup
DTCurrie 18ab6c6
fix linting issue in test files
DTCurrie 16abc5b
fix test
DTCurrie 3353dac
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie c0b21cf
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie e1662b3
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie 1037ceb
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie 6fd968a
undo breaking changes from API and simplify
DTCurrie daaed79
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie e33470f
bump api
DTCurrie e9432ae
Merge branch 'main' of ssh://github.com/viamrobotics/rdk into APP-877…
DTCurrie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,90 @@ | ||
| package referenceframe | ||
|
|
||
| import ( | ||
| "github.com/golang/geo/r3" | ||
| geo "github.com/kellydunn/golang-geo" | ||
| "github.com/pkg/errors" | ||
| commonpb "go.viam.com/api/common/v1" | ||
|
|
||
| "go.viam.com/rdk/pointcloud" | ||
| "go.viam.com/rdk/spatialmath" | ||
| ) | ||
|
|
||
| // NewGeometryFromProto instantiates a new Geometry from a protobuf Geometry message. | ||
| func NewGeometryFromProto(geometry *commonpb.Geometry) (spatialmath.Geometry, error) { | ||
| if geometry.Center == nil { | ||
| return nil, errors.New("cannot have nil pose for geometry") | ||
| } | ||
| pose := spatialmath.NewPoseFromProtobuf(geometry.Center) | ||
| if box := geometry.GetBox().GetDimsMm(); box != nil { | ||
| return spatialmath.NewBox(pose, r3.Vector{X: box.X, Y: box.Y, Z: box.Z}, geometry.Label) | ||
| } | ||
| if capsule := geometry.GetCapsule(); capsule != nil { | ||
| return spatialmath.NewCapsule(pose, capsule.RadiusMm, capsule.LengthMm, geometry.Label) | ||
| } | ||
| if sphere := geometry.GetSphere(); sphere != nil { | ||
| // Fallback to point if radius is 0 | ||
| if sphere.RadiusMm == 0 { | ||
| return spatialmath.NewPoint(pose.Point(), geometry.Label), nil | ||
| } | ||
| return spatialmath.NewSphere(pose, sphere.RadiusMm, geometry.Label) | ||
| } | ||
| if mesh := geometry.GetMesh(); mesh != nil { | ||
| return spatialmath.NewMeshFromProto(pose, mesh, geometry.Label) | ||
| } | ||
| if pointCloud := geometry.GetPointcloud(); pointCloud != nil { | ||
| return pointcloud.NewPointCloudFromProto(pointCloud, geometry.Label) | ||
| } | ||
| return nil, errGeometryTypeUnsupported | ||
| } | ||
|
|
||
| // NewGeometriesFromProto converts a list of Geometries from protobuf. | ||
| func NewGeometriesFromProto(proto []*commonpb.Geometry) ([]spatialmath.Geometry, error) { | ||
| if proto == nil { | ||
| return nil, nil | ||
| } | ||
| geometries := []spatialmath.Geometry{} | ||
| for _, geometry := range proto { | ||
| g, err := NewGeometryFromProto(geometry) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| geometries = append(geometries, g) | ||
| } | ||
| return geometries, nil | ||
| } | ||
|
|
||
| // NewGeometriesToProto converts a list of Geometries to profobuf. | ||
| func NewGeometriesToProto(geometries []spatialmath.Geometry) []*commonpb.Geometry { | ||
| var proto []*commonpb.Geometry | ||
| for _, geometry := range geometries { | ||
| proto = append(proto, geometry.ToProtobuf()) | ||
| } | ||
| return proto | ||
| } | ||
|
|
||
| // GeoGeometryToProtobuf converts the GeoGeometry struct into an equivalent Protobuf message. | ||
| func GeoGeometryToProtobuf(geoObst *spatialmath.GeoGeometry) *commonpb.GeoGeometry { | ||
| var convGeoms []*commonpb.Geometry | ||
| for _, geometry := range geoObst.Geometries() { | ||
| convGeoms = append(convGeoms, geometry.ToProtobuf()) | ||
| } | ||
| return &commonpb.GeoGeometry{ | ||
| Location: &commonpb.GeoPoint{Latitude: geoObst.Location().Lat(), Longitude: geoObst.Location().Lng()}, | ||
| Geometries: convGeoms, | ||
| } | ||
| } | ||
|
|
||
| // GeoGeometryFromProtobuf takes a Protobuf representation of a GeoGeometry and converts back into a Go struct. | ||
| func GeoGeometryFromProtobuf(protoGeoObst *commonpb.GeoGeometry) (*spatialmath.GeoGeometry, error) { | ||
| convPoint := geo.NewPoint(protoGeoObst.GetLocation().GetLatitude(), protoGeoObst.GetLocation().GetLongitude()) | ||
| convGeoms := []spatialmath.Geometry{} | ||
| for _, protoGeom := range protoGeoObst.GetGeometries() { | ||
| newGeom, err := NewGeometryFromProto(protoGeom) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| convGeoms = append(convGeoms, newGeom) | ||
| } | ||
| return spatialmath.NewGeoGeometry(convPoint, convGeoms), nil | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.