YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
DepthImageVec.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "DepthImageVec.h"
7
8#include <algorithm>
9#include <cmath>
10
12#include <yarp/sig/Image.h>
13
14using namespace yarp::os;
15using namespace yarp::sig;
16
17namespace {
19 "yarp.carrier.portmonitor.depthimage_to_vector",
23 nullptr)
24}
25
27{
28 return true;
29}
30
34
36{
37 return false;
38}
39
41{
42 return false;
43}
44
46{
47 auto* img = thing.cast_as<Image>();
48 if(img == nullptr) {
49 yCError(DEPTHIMAGE, "Expected type FlexImage but got wrong data type!");
50 return false;
51 }
52
53 if( img->getPixelCode() == VOCAB_PIXEL_MONO_FLOAT)
54 {
55 return true;
56 }
57
59 "Expected %s, got %s, not doing any conversion!",
61 yarp::os::Vocab32::decode(img->getPixelCode()).c_str() );
62 return false;
63}
64
66{
67 auto* img = thing.cast_as<Image>();
68
69 outVec.resize(img->width()* img->height());
70
71 auto* inPixels = reinterpret_cast<float *> (img->getRawImage());
72 std::copy(inPixels, inPixels + outVec.size(), outVec.begin());
73
74 th.setPortWriter(&outVec);
75 return th;
76}
@ VOCAB_PIXEL_MONO_FLOAT
Definition Image.h:53
bool getparam(yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are requested via YARP admin port.
bool accept(yarp::os::Things &thing) override
This will be called when the data reach the portmonitor object.
bool setparam(const yarp::os::Property &params) override
This will be called when the portmonitor carrier parameters are set via YARP admin port.
yarp::os::Things & update(yarp::os::Things &thing) override
After data get accpeted in the accept() callback, an instance of that is given to the update function...
bool create(const yarp::os::Property &options) override
This will be called when the dll is properly loaded by the portmonitor carrier.
void destroy() override
This will be called when the portmonitor object destroyes.
A mini-server for performing network communication in the background.
static LogCallback printCallback()
Get current print callback.
Definition Log.cpp:873
static LogType minimumPrintLevel()
Get current minimum print level.
Definition Log.cpp:833
@ LogTypeReserved
Definition Log.h:98
A class for storing options and configuration information.
Definition Property.h:33
Base class for generic things.
Definition Things.h:18
T * cast_as()
Definition Things.h:53
void setPortWriter(yarp::os::PortWriter *writer)
Set the reference to a PortWriter object.
Definition Things.cpp:26
Base class for storing images.
Definition Image.h:79
void resize(size_t size) override
Resize the vector.
Definition Vector.h:221
size_t size() const
Definition Vector.h:341
iterator begin() noexcept
Returns an iterator to the beginning of the VectorOf.
Definition Vector.h:473
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition Vocab.cpp:33
An interface to the operating system, including Port based communication.