JFJochReceiver: No access to preview frame via gRPC
This commit is contained in:
@@ -58,11 +58,6 @@ grpc::Status JFJochBroker::GetRadialIntegrationProfiles(grpc::ServerContext *con
|
||||
GRPC_RUN( *response = state_machine.GetRadialIntegrationProfiles() );
|
||||
}
|
||||
|
||||
grpc::Status JFJochBroker::GetPreview(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::PreviewFrame *response) {
|
||||
GRPC_RUN( *response = services.GetPreviewFrame() );
|
||||
}
|
||||
|
||||
grpc::Status JFJochBroker::GetPedestalG0(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::Image *response) {
|
||||
GRPC_RUN( *response = state_machine.GetPedestalG0() );
|
||||
|
||||
@@ -46,9 +46,6 @@ public:
|
||||
grpc::Status GetRadialIntegrationProfiles(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::RadialIntegrationProfiles *response) override;
|
||||
|
||||
grpc::Status GetPreview(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::PreviewFrame *response) override;
|
||||
|
||||
grpc::Status GetPedestalG0(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::Image *response) override;
|
||||
|
||||
|
||||
@@ -162,10 +162,6 @@ void JFJochServices::SetDataProcessingSettings(const JFJochProtoBuf::DataProcess
|
||||
receiver.SetDataProcessingSettings(settings);
|
||||
}
|
||||
|
||||
JFJochProtoBuf::PreviewFrame JFJochServices::GetPreviewFrame() {
|
||||
return receiver.GetPreviewFrame();
|
||||
}
|
||||
|
||||
void JFJochServices::Trigger() {
|
||||
detector.Trigger();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ public:
|
||||
void Trigger();
|
||||
|
||||
JFJochProtoBuf::ReceiverStatus GetReceiverStatus();
|
||||
JFJochProtoBuf::PreviewFrame GetPreviewFrame();
|
||||
JFJochProtoBuf::Plot GetPlots(const JFJochProtoBuf::PlotRequest &request);
|
||||
JFJochProtoBuf::RadialIntegrationProfiles GetRadialIntegrationProfiles();
|
||||
|
||||
|
||||
@@ -60,16 +60,5 @@ void ZMQPreviewPublisher::Publish(const DiffractionExperiment& experiment, const
|
||||
fr->set_indexed(s.indexed);
|
||||
}
|
||||
|
||||
SetPreviewImage(frame);
|
||||
socket.Send(grpcToJson(frame));
|
||||
}
|
||||
|
||||
void ZMQPreviewPublisher::SetPreviewImage(const JFJochProtoBuf::PreviewFrame &frame) {
|
||||
std::unique_lock<std::mutex> ul(frame_mutex);
|
||||
saved_frame = frame;
|
||||
}
|
||||
|
||||
JFJochProtoBuf::PreviewFrame ZMQPreviewPublisher::GetPreviewImage() const {
|
||||
std::unique_lock<std::mutex> ul(frame_mutex);
|
||||
return saved_frame;
|
||||
}
|
||||
|
||||
@@ -17,15 +17,11 @@ class ZMQPreviewPublisher {
|
||||
int64_t current_part;
|
||||
|
||||
mutable std::mutex m;
|
||||
mutable std::mutex frame_mutex;
|
||||
JFJochProtoBuf::PreviewFrame saved_frame;
|
||||
void SetPreviewImage(const JFJochProtoBuf::PreviewFrame &frame);
|
||||
public:
|
||||
ZMQPreviewPublisher(ZMQContext& context, const std::string& addr);
|
||||
void Start(const DiffractionExperiment& experiment, const JFCalibration &calibration);
|
||||
void Publish(const DiffractionExperiment& experiment, const void* image_data, const DataMessage &message);
|
||||
void Stop(const DiffractionExperiment& experiment);
|
||||
JFJochProtoBuf::PreviewFrame GetPreviewImage() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -85,28 +85,6 @@ void JFJochReceiverClient::SetDataProcessingSettings(const JFJochProtoBuf::DataP
|
||||
}
|
||||
}
|
||||
|
||||
JFJochProtoBuf::PreviewFrame JFJochReceiverClient::GetPreviewFrame() {
|
||||
JFJochProtoBuf::PreviewFrame ret;
|
||||
if (_stub) {
|
||||
grpc::ClientContext context;
|
||||
JFJochProtoBuf::Empty empty;
|
||||
auto status = _stub->GetPreviewFrame(&context, empty, &ret);
|
||||
if (!status.ok()) throw JFJochException(JFJochExceptionCategory::gRPCError,
|
||||
"JFJochReceiver: " + status.error_message());
|
||||
} else {
|
||||
std::vector<uint16_t> fake_image(640*480);
|
||||
for (int i = 0; i < 640 * 480; i++)
|
||||
fake_image[i] = i % 65536;
|
||||
|
||||
ret.set_image_number(0);
|
||||
ret.set_width(640);
|
||||
ret.set_height(480);
|
||||
ret.set_pixel_depth(2);
|
||||
ret.set_data(fake_image.data(), fake_image.size() * sizeof(uint16_t));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
JFJochProtoBuf::ReceiverNetworkConfig JFJochReceiverClient::GetNetworkConfig() {
|
||||
JFJochProtoBuf::ReceiverNetworkConfig ret;
|
||||
if (_stub) {
|
||||
|
||||
@@ -21,7 +21,6 @@ public:
|
||||
void SetDataProcessingSettings(const JFJochProtoBuf::DataProcessingSettings& settings);
|
||||
JFJochProtoBuf::ReceiverOutput Stop();
|
||||
JFJochProtoBuf::ReceiverStatus GetStatus();
|
||||
JFJochProtoBuf::PreviewFrame GetPreviewFrame();
|
||||
JFJochProtoBuf::ReceiverNetworkConfig GetNetworkConfig();
|
||||
JFJochProtoBuf::Plot GetPlots(const JFJochProtoBuf::PlotRequest& request);
|
||||
JFJochProtoBuf::RadialIntegrationProfiles GetRadialIntegrationProfiles();
|
||||
|
||||
@@ -520,7 +520,6 @@ service gRPC_JFJochReceiver {
|
||||
rpc SetDataProcessingSettings(DataProcessingSettings) returns (Empty) {}
|
||||
rpc GetDataProcessingPlots(PlotRequest) returns (Plot) {}
|
||||
rpc GetRadialIntegrationProfiles(Empty) returns (RadialIntegrationProfiles) {}
|
||||
rpc GetPreviewFrame (Empty) returns (PreviewFrame) {}
|
||||
rpc GetNetworkConfig (Empty) returns (ReceiverNetworkConfig) {}
|
||||
}
|
||||
|
||||
@@ -558,7 +557,6 @@ service gRPC_JFJochBroker {
|
||||
rpc GetPlots (PlotRequest) returns (Plot) {}
|
||||
rpc GetRadialIntegrationProfiles(Empty) returns (RadialIntegrationProfiles) {}
|
||||
|
||||
rpc GetPreview (Empty) returns (PreviewFrame) {}
|
||||
rpc GetPedestalG0 (Empty) returns (Image) {}
|
||||
rpc GetPedestalG1 (Empty) returns (Image) {}
|
||||
rpc GetPedestalG2 (Empty) returns (Image) {}
|
||||
|
||||
@@ -245,26 +245,6 @@ async def put_detector_selection(request: Request):
|
||||
raise HTTPException(status_code=400, detail=e.details())
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/55873174/how-do-i-return-an-image-in-fastapi
|
||||
@app.get(
|
||||
"/image/preview.tiff",
|
||||
responses={200: {"content": {"image/tiff": {}}}},
|
||||
response_class=Response,
|
||||
)
|
||||
async def get_preview():
|
||||
try:
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
pbuf = stub.GetPreview(jfjoch_pb2.Empty())
|
||||
image_array = numpy.frombuffer(pbuf.data, numpy.int16)
|
||||
image_array = numpy.where(image_array < 0, -1, image_array)
|
||||
image_array = numpy.reshape(image_array, (pbuf.height, pbuf.width))
|
||||
b = BytesIO()
|
||||
imwrite(b, image_array)
|
||||
return Response(content=b.getvalue(), media_type="image/tiff")
|
||||
except grpc.RpcError as e:
|
||||
raise HTTPException(status_code=400, detail=e.details())
|
||||
|
||||
|
||||
def calib_to_tiff(im: jfjoch_pb2.Image) -> bytes:
|
||||
if im.pixel_depth == 2:
|
||||
image_array = numpy.frombuffer(im.data, numpy.uint16)
|
||||
@@ -276,29 +256,6 @@ def calib_to_tiff(im: jfjoch_pb2.Image) -> bytes:
|
||||
return bytes(b.getvalue())
|
||||
|
||||
|
||||
@app.get(
|
||||
"/image/preview_dioptas.tiff",
|
||||
responses={200: {"content": {"image/tiff": {}}}},
|
||||
response_class=Response,
|
||||
)
|
||||
async def get_preview_dioptas():
|
||||
try:
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
pbuf = stub.GetPreview(jfjoch_pb2.Empty())
|
||||
if pbuf.pixel_depth == 2:
|
||||
image_array = numpy.frombuffer(pbuf.data, numpy.int16)
|
||||
else:
|
||||
image_array = numpy.frombuffer(pbuf.data, numpy.int32)
|
||||
image_array = numpy.where(image_array < 0, 32767, image_array)
|
||||
image_array = numpy.reshape(image_array, (pbuf.height, pbuf.width))
|
||||
image_array = numpy.flipud(image_array)
|
||||
b = BytesIO()
|
||||
imwrite(b, image_array)
|
||||
return Response(content=b.getvalue(), media_type="image/tiff")
|
||||
except grpc.RpcError as e:
|
||||
raise HTTPException(status_code=400, detail=e.details())
|
||||
|
||||
|
||||
@app.get(
|
||||
"/image/pedestalG0.tiff",
|
||||
responses={200: {"content": {"image/tiff": {}}}},
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -54,11 +54,6 @@ class gRPC_JFJochReceiverStub(object):
|
||||
request_serializer=jfjoch__pb2.Empty.SerializeToString,
|
||||
response_deserializer=jfjoch__pb2.RadialIntegrationProfiles.FromString,
|
||||
)
|
||||
self.GetPreviewFrame = channel.unary_unary(
|
||||
'/JFJochProtoBuf.gRPC_JFJochReceiver/GetPreviewFrame',
|
||||
request_serializer=jfjoch__pb2.Empty.SerializeToString,
|
||||
response_deserializer=jfjoch__pb2.PreviewFrame.FromString,
|
||||
)
|
||||
self.GetNetworkConfig = channel.unary_unary(
|
||||
'/JFJochProtoBuf.gRPC_JFJochReceiver/GetNetworkConfig',
|
||||
request_serializer=jfjoch__pb2.Empty.SerializeToString,
|
||||
@@ -117,12 +112,6 @@ class gRPC_JFJochReceiverServicer(object):
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
def GetPreviewFrame(self, request, context):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
def GetNetworkConfig(self, request, context):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
@@ -172,11 +161,6 @@ def add_gRPC_JFJochReceiverServicer_to_server(servicer, server):
|
||||
request_deserializer=jfjoch__pb2.Empty.FromString,
|
||||
response_serializer=jfjoch__pb2.RadialIntegrationProfiles.SerializeToString,
|
||||
),
|
||||
'GetPreviewFrame': grpc.unary_unary_rpc_method_handler(
|
||||
servicer.GetPreviewFrame,
|
||||
request_deserializer=jfjoch__pb2.Empty.FromString,
|
||||
response_serializer=jfjoch__pb2.PreviewFrame.SerializeToString,
|
||||
),
|
||||
'GetNetworkConfig': grpc.unary_unary_rpc_method_handler(
|
||||
servicer.GetNetworkConfig,
|
||||
request_deserializer=jfjoch__pb2.Empty.FromString,
|
||||
@@ -328,23 +312,6 @@ class gRPC_JFJochReceiver(object):
|
||||
options, channel_credentials,
|
||||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
|
||||
|
||||
@staticmethod
|
||||
def GetPreviewFrame(request,
|
||||
target,
|
||||
options=(),
|
||||
channel_credentials=None,
|
||||
call_credentials=None,
|
||||
insecure=False,
|
||||
compression=None,
|
||||
wait_for_ready=None,
|
||||
timeout=None,
|
||||
metadata=None):
|
||||
return grpc.experimental.unary_unary(request, target, '/JFJochProtoBuf.gRPC_JFJochReceiver/GetPreviewFrame',
|
||||
jfjoch__pb2.Empty.SerializeToString,
|
||||
jfjoch__pb2.PreviewFrame.FromString,
|
||||
options, channel_credentials,
|
||||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
|
||||
|
||||
@staticmethod
|
||||
def GetNetworkConfig(request,
|
||||
target,
|
||||
@@ -805,11 +772,6 @@ class gRPC_JFJochBrokerStub(object):
|
||||
request_serializer=jfjoch__pb2.Empty.SerializeToString,
|
||||
response_deserializer=jfjoch__pb2.RadialIntegrationProfiles.FromString,
|
||||
)
|
||||
self.GetPreview = channel.unary_unary(
|
||||
'/JFJochProtoBuf.gRPC_JFJochBroker/GetPreview',
|
||||
request_serializer=jfjoch__pb2.Empty.SerializeToString,
|
||||
response_deserializer=jfjoch__pb2.PreviewFrame.FromString,
|
||||
)
|
||||
self.GetPedestalG0 = channel.unary_unary(
|
||||
'/JFJochProtoBuf.gRPC_JFJochBroker/GetPedestalG0',
|
||||
request_serializer=jfjoch__pb2.Empty.SerializeToString,
|
||||
@@ -941,12 +903,6 @@ class gRPC_JFJochBrokerServicer(object):
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
def GetPreview(self, request, context):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
context.set_details('Method not implemented!')
|
||||
raise NotImplementedError('Method not implemented!')
|
||||
|
||||
def GetPedestalG0(self, request, context):
|
||||
"""Missing associated documentation comment in .proto file."""
|
||||
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
|
||||
@@ -1066,11 +1022,6 @@ def add_gRPC_JFJochBrokerServicer_to_server(servicer, server):
|
||||
request_deserializer=jfjoch__pb2.Empty.FromString,
|
||||
response_serializer=jfjoch__pb2.RadialIntegrationProfiles.SerializeToString,
|
||||
),
|
||||
'GetPreview': grpc.unary_unary_rpc_method_handler(
|
||||
servicer.GetPreview,
|
||||
request_deserializer=jfjoch__pb2.Empty.FromString,
|
||||
response_serializer=jfjoch__pb2.PreviewFrame.SerializeToString,
|
||||
),
|
||||
'GetPedestalG0': grpc.unary_unary_rpc_method_handler(
|
||||
servicer.GetPedestalG0,
|
||||
request_deserializer=jfjoch__pb2.Empty.FromString,
|
||||
@@ -1383,23 +1334,6 @@ class gRPC_JFJochBroker(object):
|
||||
options, channel_credentials,
|
||||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
|
||||
|
||||
@staticmethod
|
||||
def GetPreview(request,
|
||||
target,
|
||||
options=(),
|
||||
channel_credentials=None,
|
||||
call_credentials=None,
|
||||
insecure=False,
|
||||
compression=None,
|
||||
wait_for_ready=None,
|
||||
timeout=None,
|
||||
metadata=None):
|
||||
return grpc.experimental.unary_unary(request, target, '/JFJochProtoBuf.gRPC_JFJochBroker/GetPreview',
|
||||
jfjoch__pb2.Empty.SerializeToString,
|
||||
jfjoch__pb2.PreviewFrame.FromString,
|
||||
options, channel_credentials,
|
||||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
|
||||
|
||||
@staticmethod
|
||||
def GetPedestalG0(request,
|
||||
target,
|
||||
|
||||
@@ -182,15 +182,6 @@ grpc::Status JFJochReceiverService::SetDataProcessingSettings(grpc::ServerContex
|
||||
}
|
||||
}
|
||||
|
||||
grpc::Status JFJochReceiverService::GetPreviewFrame(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::PreviewFrame *response) {
|
||||
if (preview_publisher != nullptr) {
|
||||
*response = preview_publisher->GetPreviewImage();
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
return {grpc::StatusCode::NOT_FOUND, "Preview publisher not running"};
|
||||
}
|
||||
|
||||
grpc::Status JFJochReceiverService::GetNetworkConfig(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::ReceiverNetworkConfig *response) {
|
||||
for (const auto &aq: aq_devices) {
|
||||
|
||||
@@ -51,8 +51,6 @@ public:
|
||||
JFJochProtoBuf::ReceiverStatus *response) override;
|
||||
grpc::Status SetDataProcessingSettings(grpc::ServerContext *context, const JFJochProtoBuf::DataProcessingSettings *request,
|
||||
JFJochProtoBuf::Empty *response) override;
|
||||
grpc::Status GetPreviewFrame(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::PreviewFrame *response) override;
|
||||
grpc::Status GetNetworkConfig(grpc::ServerContext *context, const JFJochProtoBuf::Empty *request,
|
||||
JFJochProtoBuf::ReceiverNetworkConfig *response) override;
|
||||
grpc::Status GetDataProcessingPlots(grpc::ServerContext *context, const JFJochProtoBuf::PlotRequest *request,
|
||||
|
||||
@@ -109,32 +109,3 @@ TEST_CASE("ZMQPreviewPublisher_FrameNumbers","[ZMQ]") {
|
||||
|
||||
REQUIRE(socket.Receive(s, false) < 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ZMQPreviewPublisher_GetPreviewImage","") {
|
||||
ZMQContext context;
|
||||
ZMQPreviewPublisher publisher(context, "inproc://#5");
|
||||
|
||||
DiffractionExperiment experiment(DetectorGeometry(1, 1, 0, 0, false));
|
||||
|
||||
JFCalibration calibration(experiment);
|
||||
publisher.Start(experiment, calibration);
|
||||
|
||||
std::vector<int16_t> image(experiment.GetPixelsNum());
|
||||
|
||||
// Predictable random number generator
|
||||
std::mt19937 g1(19876);
|
||||
std::uniform_int_distribution<int16_t> distribution(-200,25000);
|
||||
for (auto &i: image)
|
||||
i = distribution(g1);
|
||||
|
||||
DataMessage message{.number = 564};
|
||||
publisher.Publish(experiment, image.data(), message);
|
||||
|
||||
JFJochProtoBuf::PreviewFrame frame = publisher.GetPreviewImage();
|
||||
|
||||
REQUIRE(frame.pixel_depth() == 2);
|
||||
REQUIRE(frame.image_number() == 564);
|
||||
std::vector<char> image_out = {frame.data().begin(), frame.data().end()};
|
||||
|
||||
REQUIRE(memcmp(image.data(), image_out.data(), experiment.GetPixelsNum() * experiment.GetPixelDepth()) == 0);
|
||||
}
|
||||
Reference in New Issue
Block a user