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/os/Carriers.h>
12#include <yarp/sig/Image.h>
13#include <yarp/sig/Vector.h>
14
16
17#include <array>
18#include <thread>
19#include <cmath>
20
21#include <catch2/catch_amalgamated.hpp>
22#include <harness.h>
23
24TEST_CASE("pm::depthimage_to_vectorTest", "[yarp::pm]")
25{
26 YARP_REQUIRE_PLUGIN("depthimage_to_vector", "portmonitor")
27
29
31
32 REQUIRE(yarp::os::Carriers::getCarrierTemplate("portmonitor") != nullptr);
33
35
36 struct TestCase {
37 std::string carrier;
38 bool should_convert;
39 };
40
41 auto tc = GENERATE(
42 TestCase {"fast_tcp", false},
43 TestCase {"fast_tcp+recv.portmonitor+file.depthimage_to_vector+type.dll", true}
44 );
45
46 SECTION("Test depth image to vector conversion with portmonitor: " + tc.carrier)
47 {
49 yarp::os::Port receiver;
50
51 sender.open("/send");
52 receiver.open("/recv");
53
54 bool b = yarp::os::Network::connect("/send", "/recv", tc.carrier);
55 REQUIRE(b);
56
57 // Create a test depth image (4x4 pixels = 16 total values for easy verification)
58 constexpr int width = 4;
59 constexpr int height = 4;
60 constexpr int total_pixels = width * height;
61
63 depthImg.resize(width, height);
64
65 // Fill with test data - sequential values for easy verification
66 for (int y = 0; y < height; y++)
67 {
68 for (int x = 0; x < width; x++)
69 {
70 float depth_value = static_cast<float>(x + y * width) + 0.5f;
71 depthImg.pixel(x, y) = depth_value;
72 }
73 }
74
75 sender.write();
76
78
79 if (tc.should_convert)
80 {
81 // When converted, expect a Vector
82 yarp::sig::Vector receivedVec;
83 receiver.read(receivedVec);
84
85 // Verify size
86 CHECK(receivedVec.size() == total_pixels);
87
88 // Verify the values match the input
89 for (int i = 0; i < total_pixels; i++)
90 {
91 float expected_value = static_cast<float>(i) + 0.5f;
92 CHECK(receivedVec[i] == expected_value);
93 }
94 }
95 else
96 {
97 // Without conversion, should still be an image
99 receiver.read(receivedImg);
100
101 CHECK(receivedImg.width() == width);
102 CHECK(receivedImg.height() == height);
103 }
104
105 receiver.close();
106 sender.close();
107 }
108
110}
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 Carrier * getCarrierTemplate(const std::string &name)
Get template for carrier.
Definition Carriers.cpp:238
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:784
static bool setLocalMode(bool flag)
Chooses whether communication is process-local.
Definition Network.cpp:1137
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
Returns the number of elements in the vector.
Definition VectorBase.h:167
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