Skip to content

Commit

Permalink
RSDK-4602 - add extra params to camera (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcvella authored Jan 12, 2024
1 parent be3d245 commit 878449e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/src/components/camera/camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ abstract class Camera extends Resource {
static const Subtype subtype = Subtype(resourceNamespaceRDK, resourceTypeComponent, 'camera');

/// Get the next image from the camera.
Future<ViamImage> image({MimeType? mimeType});
Future<ViamImage> image({MimeType? mimeType, Map<String, dynamic>? extra});

/// Get the next point cloud from the camera.
Future<ViamImage> pointCloud();
Future<ViamImage> pointCloud({Map<String, dynamic>? extra});

/// Get the camera's intrinsic parameters and the camera's distortion parameters.
Future<CameraProperties> properties();
Expand Down
11 changes: 7 additions & 4 deletions lib/src/components/camera/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:grpc/grpc_connection_interface.dart';

import '../../gen/common/v1/common.pb.dart';
import '../../gen/component/camera/v1/camera.pbgrpc.dart';
import '../../gen/google/protobuf/struct.pb.dart';
import '../../media/image.dart';
import '../../resource/base.dart';
import '../../utils.dart';
Expand All @@ -21,20 +22,22 @@ class CameraClient extends Camera implements ResourceRPCClient {
CameraClient(this.name, this.channel);

@override
Future<ViamImage> image({MimeType? mimeType}) async {
Future<ViamImage> image({MimeType? mimeType, Map<String, dynamic>? extra}) async {
final request = GetImageRequest()
..name = name
..mimeType = mimeType?.name ?? '';
..mimeType = mimeType?.name ?? ''
..extra = extra?.toStruct() ?? Struct();
final response = await client.getImage(request);
final actualMimeType = MimeType.fromString(response.mimeType);
return ViamImage(response.image, actualMimeType);
}

@override
Future<ViamImage> pointCloud() async {
Future<ViamImage> pointCloud({Map<String, dynamic>? extra}) async {
final request = GetPointCloudRequest()
..name = name
..mimeType = MimeType.pcd.name;
..mimeType = MimeType.pcd.name
..extra = extra?.toStruct() ?? Struct();
final response = await client.getPointCloud(request);
final actualMimeType = MimeType.fromString(response.mimeType);
return ViamImage(response.pointCloud, actualMimeType);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/components/camera/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CameraService extends CameraServiceBase {
@override
Future<GetImageResponse> getImage(ServiceCall call, GetImageRequest request) async {
final camera = _fromManager(request.name);
final image = await camera.image(mimeType: MimeType.fromString(request.mimeType));
final image = await camera.image(mimeType: MimeType.fromString(request.mimeType), extra: request.extra.toMap());
return GetImageResponse()
..mimeType = image.mimeType.name
..image = image.raw;
Expand All @@ -41,7 +41,7 @@ class CameraService extends CameraServiceBase {
@override
Future<GetPointCloudResponse> getPointCloud(ServiceCall call, GetPointCloudRequest request) async {
final camera = _fromManager(request.name);
final image = await camera.pointCloud();
final image = await camera.pointCloud(extra: request.extra.toMap());
return GetPointCloudResponse()
..mimeType = image.mimeType.name
..pointCloud = image.raw;
Expand Down
25 changes: 23 additions & 2 deletions test/unit_test/components/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ class FakeCamera extends Camera {
}

@override
Future<ViamImage> image({MimeType? mimeType}) async {
Future<ViamImage> image({MimeType? mimeType, Map<String, dynamic>? extra}) async {
if (mimeType == null) {
throw const GrpcError.invalidArgument('invalid mimetype');
}
if (extra != null && extra['forcePng'] == true) {
mimeType = MimeType.png;
}

return ViamImage([0, 0, 0], mimeType);
}

@override
Future<ViamImage> pointCloud() async {
Future<ViamImage> pointCloud({Map<String, dynamic>? extra}) async {
return ViamImage([0, 0, 0], MimeType.pcd);
}

Expand Down Expand Up @@ -60,6 +64,10 @@ void main() {
final actualPng = await camera.image(mimeType: MimeType.png);
expect(actualPng.mimeType, MimeType.png);
expect(actualPng.raw, [0, 0, 0]);

final actualPngForce = await camera.image(mimeType: MimeType.jpeg, extra: {'forcePng': true});
expect(actualPngForce.mimeType, MimeType.png);
expect(actualPngForce.raw, [0, 0, 0]);
});

test('pointCloud', () async {
Expand Down Expand Up @@ -122,6 +130,15 @@ void main() {
final actualPng = await client.getImage(pngRequest);
expect(actualPng.mimeType, 'png');
expect(actualPng.image, [0, 0, 0]);

final forcePngRequest = GetImageRequest()
..name = name
..mimeType = 'jpeg'
..extra = {'forcePng': true}.toStruct();

final actualPngForce = await client.getImage(forcePngRequest);
expect(actualPngForce.mimeType, 'image/png');
expect(actualPngForce.image, [0, 0, 0]);
});

test('pointCloud', () async {
Expand Down Expand Up @@ -157,6 +174,10 @@ void main() {
final actualPng = await client.image(mimeType: MimeType.png);
expect(actualPng.mimeType, MimeType.png);
expect(actualPng.raw, [0, 0, 0]);

final actualPngForce = await client.image(mimeType: MimeType.jpeg, extra: {'forcePng': true});
expect(actualPngForce.mimeType, MimeType.png);
expect(actualPngForce.raw, [0, 0, 0]);
});

test('pointCloud', () async {
Expand Down

0 comments on commit 878449e

Please sign in to comment.