-
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
Changes from 8 commits
35d243c
58bea5e
a109126
167e93b
1b1dac5
ed9e15d
6c2e826
c67adc6
18ab6c6
16abc5b
3353dac
c0b21cf
e1662b3
1037ceb
6fd968a
daaed79
e33470f
e9432ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| "context" | ||
| "sync" | ||
|
|
||
| commonpb "go.viam.com/api/common/v1" | ||
|
Check failure on line 8 in components/arm/client.go
|
||
| pb "go.viam.com/api/component/arm/v1" | ||
| "go.viam.com/utils/protoutils" | ||
| "go.viam.com/utils/rpc" | ||
|
|
@@ -218,7 +218,7 @@ | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return spatialmath.NewGeometriesFromProto(resp.GetGeometries()) | ||
| return referenceframe.NewGeometriesFromProto(resp.GetGeometries()) | ||
| } | ||
|
|
||
| // warnKinematicsUnsafe is a helper function to warn the user that no kinematics have been supplied for the conversion between | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ | |
|
|
||
| "github.com/golang/geo/r3" | ||
| "github.com/pkg/errors" | ||
| packagespb "go.viam.com/api/app/packages/v1" | ||
|
Check failure on line 10 in config/proto_conversions.go
|
||
| pb "go.viam.com/api/app/v1" | ||
| "go.viam.com/utils" | ||
| "go.viam.com/utils/pexec" | ||
|
|
@@ -519,7 +519,7 @@ | |
| } | ||
|
|
||
| if proto.GetGeometry() != nil { | ||
| geom, err := spatial.NewGeometryFromProto(proto.GetGeometry()) | ||
| geom, err := referenceframe.NewGeometryFromProto(proto.GetGeometry()) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| 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 | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.