ZMQPreviewPublisher: Add spots to preview message + allow for frame number management within the ZMQPreviewPublisher
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "../common/ZMQPreviewPublisher.h"
|
||||
#include "../common/jsonToGrpc.h"
|
||||
|
||||
TEST_CASE("ZMQPreviewPublisher","[ZSTD]") {
|
||||
TEST_CASE("ZMQPreviewPublisher","[ZMQ]") {
|
||||
ZMQContext context;
|
||||
ZMQPreviewPublisher publisher(context, "inproc://#5");
|
||||
|
||||
@@ -26,7 +26,12 @@ TEST_CASE("ZMQPreviewPublisher","[ZSTD]") {
|
||||
for (auto &i: image)
|
||||
i = distribution(g1);
|
||||
|
||||
publisher.Publish(experiment, image.data(), 546);
|
||||
std::vector<SpotToSave> spots;
|
||||
spots.push_back(SpotToSave{.x = 7, .y = 8, .intensity = 34, .indexed = false});
|
||||
spots.push_back(SpotToSave{.x = 37, .y = 48, .intensity = 123, .indexed = true});
|
||||
|
||||
DataMessage message{.number = 564, .spots = spots};
|
||||
publisher.Publish(experiment, image.data(), message);
|
||||
|
||||
std::string s;
|
||||
|
||||
@@ -43,14 +48,70 @@ TEST_CASE("ZMQPreviewPublisher","[ZSTD]") {
|
||||
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
|
||||
|
||||
REQUIRE(frame.pixel_depth() == 2);
|
||||
REQUIRE(frame.image_number() == 546);
|
||||
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);
|
||||
REQUIRE(frame.spots_size() == 2);
|
||||
REQUIRE(frame.spots(0).x() == 7);
|
||||
REQUIRE(!frame.spots(0).indexed());
|
||||
REQUIRE(frame.spots(1).y() == 48);
|
||||
REQUIRE(frame.spots(1).indexed());
|
||||
|
||||
REQUIRE(socket.Receive(s, false) < 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ZMQPreviewPublisher_GetPreviewImage","[ZSTD]") {
|
||||
TEST_CASE("ZMQPreviewPublisher_FrameNumbers","[ZMQ]") {
|
||||
ZMQContext context;
|
||||
ZMQPreviewPublisher publisher(context, "inproc://#5");
|
||||
|
||||
ZMQSocket socket(context, ZMQSocketType::Sub);
|
||||
socket.Connect("inproc://#5");
|
||||
socket.SubscribeAll();
|
||||
|
||||
DiffractionExperiment experiment(DetectorGeometry(1, 1, 0, 0, false));
|
||||
experiment.PreviewPeriod(std::chrono::milliseconds(10)).ImageTimeUs(std::chrono::milliseconds(1));
|
||||
REQUIRE(experiment.GetPreviewStride() == 10);
|
||||
|
||||
JFCalibration calibration(experiment);
|
||||
publisher.Start(experiment, calibration);
|
||||
|
||||
std::vector<int16_t> image(experiment.GetPixelsNum());
|
||||
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 0});
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 9});
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 12});
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 10});
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 25});
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 20});
|
||||
publisher.Publish(experiment, image.data(), DataMessage{.number = 18});
|
||||
|
||||
std::string s;
|
||||
JFJochProtoBuf::PreviewFrame frame;
|
||||
|
||||
// Pixel mask
|
||||
REQUIRE(socket.Receive(s, false) > 0);
|
||||
|
||||
// Frame
|
||||
REQUIRE(socket.Receive(s, false) > 0);
|
||||
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
|
||||
REQUIRE(frame.image_number() == 0);
|
||||
std::vector<char> image_out = {frame.data().begin(), frame.data().end()};
|
||||
|
||||
REQUIRE(socket.Receive(s, false) > 0);
|
||||
|
||||
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
|
||||
REQUIRE(frame.image_number() == 12);
|
||||
|
||||
REQUIRE(socket.Receive(s, false) > 0);
|
||||
|
||||
REQUIRE_NOTHROW(frame = jsonToGrpc<JFJochProtoBuf::PreviewFrame>(s));
|
||||
REQUIRE(frame.image_number() == 25);
|
||||
|
||||
REQUIRE(socket.Receive(s, false) < 0);
|
||||
}
|
||||
|
||||
TEST_CASE("ZMQPreviewPublisher_GetPreviewImage","") {
|
||||
ZMQContext context;
|
||||
ZMQPreviewPublisher publisher(context, "inproc://#5");
|
||||
|
||||
@@ -67,12 +128,13 @@ TEST_CASE("ZMQPreviewPublisher_GetPreviewImage","[ZSTD]") {
|
||||
for (auto &i: image)
|
||||
i = distribution(g1);
|
||||
|
||||
publisher.Publish(experiment, image.data(), 546);
|
||||
DataMessage message{.number = 564};
|
||||
publisher.Publish(experiment, image.data(), message);
|
||||
|
||||
JFJochProtoBuf::PreviewFrame frame = publisher.GetPreviewImage();
|
||||
|
||||
REQUIRE(frame.pixel_depth() == 2);
|
||||
REQUIRE(frame.image_number() == 546);
|
||||
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