YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
depthimage_to_vectorTest.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026-2026 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
7#include <yarp/os/Network.h>
8#include <yarp/os/LogStream.h>
9#include <yarp/os/Time.h>
11#include <yarp/sig/Image.h>
12#include <yarp/sig/Vector.h>
13
15
16#include <array>
17#include <thread>
18#include <cmath>
19
20#include <catch2/catch_amalgamated.hpp>
21#include <harness.h>
22
23TEST_CASE("pm::depthimage_to_vectorTest", "[yarp::pm]")
24{
25 YARP_REQUIRE_PLUGIN("depthimage_to_vector", "portmonitor")
26
28
31
32 struct TestCase {
33 std::string carrier;
34 bool should_convert;
35 };
36
37 auto tc = GENERATE(
38 TestCase {"fast_tcp", false},
39 TestCase {"fast_tcp+recv.portmonitor+file.depthimage_to_vector+type.dll", true}
40 );
41
42 SECTION("Test depth image to vector conversion with portmonitor: " + tc.carrier)
43 {
45 yarp::os::Port receiver;
46
47 sender.open("/send");
48 receiver.open("/recv");
49
50 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
51 REQUIRE(b);
52
53 // Create a test depth image (4x4 pixels = 16 total values for easy verification)
54 constexpr int width = 4;
55 constexpr int height = 4;
56 constexpr int total_pixels = width * height;
57
59 depthImg.resize(width, height);
60
61 // Fill with test data - sequential values for easy verification
62 for (int y = 0; y < height; y++)
63 {
64 for (int x = 0; x < width; x++)
65 {
66 float depth_value = static_cast<float>(x + y * width) + 0.5f;
67 depthImg.pixel(x, y) = depth_value;
68 }
69 }
70
71 sender.write();
72
74
75 if (tc.should_convert)
76 {
77 // When converted, expect a Vector
78 yarp::sig::Vector receivedVec;
79 receiver.read(receivedVec);
80
81 // Verify size
82 CHECK(receivedVec.size() == total_pixels);
83
84 // Verify the values match the input
85 for (int i = 0; i < total_pixels; i++)
86 {
87 float expected_value = static_cast<float>(i) + 0.5f;
88 CHECK(receivedVec[i] == expected_value);
89 }
90 }
91 else
92 {
93 // Without conversion, should still be an image
95 receiver.read(receivedImg);
96
97 CHECK(receivedImg.width() == width);
98 CHECK(receivedImg.height() == height);
99 }
100
101 receiver.close();
102 sender.close();
103 }
104
106}
contains the definition of a Vector type
A mini-server for performing network communication in the background.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:751
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1118
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition Network.h:718
A mini-server for network communication.
Definition Port.h:46
bool read(PortReader &reader, bool willReply=false) override
Read an object from the port.
Definition Port.cpp:440
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
Typed image class.
Definition Image.h:603
T & pixel(size_t x, size_t y)
Definition Image.h:619
size_t width() const
Gets width of image in pixels.
Definition Image.h:171
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
Definition Image.cpp:387
size_t height() const
Gets height of image in pixels.
Definition Image.h:177
size_t size() const
Definition Vector.h:351
TEST_CASE("pm::depthimage_to_vectorTest", "[yarp::pm]")
void delay(double seconds)
Wait for a certain number of seconds.
Definition Time.cpp:111
@ YARP_CLOCK_SYSTEM
Definition Time.h:28
The main, catch-all namespace for YARP.
Definition dirs.h:16