YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
PointCloud.h
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#ifndef YARP_SIG_POINTCLOUD_H
7#define YARP_SIG_POINTCLOUD_H
8
9#include <yarp/sig/Vector.h>
13
14namespace yarp::sig {
15
16template <class T>
21{
22 static_assert(std::is_same<T, DataXY>::value ||
23 std::is_same<T, DataXYZ>::value ||
24 std::is_same<T, DataNormal>::value ||
25 std::is_same<T, DataXYZRGBA>::value ||
26 std::is_same<T, DataXYZI>::value ||
27 std::is_same<T, DataInterestPointXYZ>::value ||
28 std::is_same<T, DataXYZNormal>::value ||
29 std::is_same<T, DataXYZNormalRGBA>::value, "yarp::sig::PointCloud<T>: T chosen is not supported");
30
31private:
32
33 static bool compZ(const T& a, const T& b);
34
35public:
36
41 {
42 m_storage.clear();
43 setPointType();
44 }
45
51 template <class T1>
53 {
54 setPointType();
55 copy<T1>(alt);
56 }
57
63 virtual void resize(size_t width, size_t height);
64
72 virtual void resize(size_t width);
73
74 const char* getRawData() const override
75 {
76 return m_storage.getMemoryBlock();
77 }
78
84 size_t wireSizeBytes() const override
85 {
86 return sizeof(header) + dataSizeBytes();
87 }
88
94 size_t dataSizeBytes() const override
95 {
96 return header.width * header.height * (sizeof(T));
97 }
98
99 size_t size() const override
100 {
101 return m_storage.size();
102 }
103
110 inline T& operator()(size_t u, size_t v)
111 {
112 return m_storage[u + v * width()];
113 }
114
121 inline const T& operator()(size_t u, size_t v) const
122 {
123 return m_storage[u + v * width()];
124 }
125
130 inline T& operator()(size_t i)
131 {
132 return m_storage[i];
133 }
134
139 inline const T& operator()(size_t i) const
140 {
141 return m_storage[i];
142 }
143
144 template <class T1>
151 {
152 copy(alt);
153 return *this;
154 }
155
162
168 const PointCloud<T> operator+(const PointCloud<T>& rhs);
169
175 void push_back(const T& pt);
176
180 virtual void clear();
181
190 virtual void fromExternalPC(const char* source, int type, size_t width, size_t height, bool isDense = true);
191
197 template <class T1>
198 void copy(const PointCloud<T1>& alt)
199 {
200 resize(alt.width(), alt.height());
201 if (std::is_same<T, T1>::value) {
202 yAssert(dataSizeBytes() == alt.dataSizeBytes());
203 memcpy(const_cast<char*>(getRawData()), alt.getRawData(), dataSizeBytes());
204 } else {
205 std::vector<int> recipe = getComposition(alt.getPointType());
206 copyFromRawData(getRawData(), alt.getRawData(), recipe);
207 }
208 }
209
210 bool read(yarp::os::ConnectionReader& connection) override;
211
212 bool write(yarp::os::ConnectionWriter& writer) const override;
213
214 virtual std::string toString(int precision = -1, int width = -1) const;
215
220 yarp::os::Bottle toBottle() const;
221
228 bool fromBottle(const yarp::os::Bottle& bt);
229
230 int getBottleTag() const override;
231
236 bool sortDataZ();
237
244 bool filterDataZ(double minZ=0, double maxZ=std::numeric_limits<double>::infinity());
245
246private:
247 yarp::sig::VectorOf<T> m_storage;
248
249 void setPointType();
250};
251
260
261//Tests if the point of the pointcloud has the z member
262template <typename T, typename = void>
263struct has_member_z : std::false_type {};
264template <typename T>
265struct has_member_z<T, std::void_t<decltype(std::declval<T>().z)>> : std::true_type {};
266
267} // namespace yarp::sig
268
269template <>
271{
272 return BOTTLE_TAG_FLOAT64;
273}
274
275template <>
277{
278 return BOTTLE_TAG_FLOAT64;
279}
280
281template <>
286
287template <>
292
293template <>
295{
296 return BOTTLE_TAG_FLOAT64;
297}
298
299template <>
304
305template <>
310
311template <>
316
317
318#endif // YARP_SIG_POINTCLOUD_H
#define BOTTLE_TAG_FLOAT64
Definition Bottle.h:25
std::string toString(const T &value)
convert an arbitrary type to string.
#define yAssert(x)
Definition Log.h:388
int BottleTagMap< yarp::sig::DataXYZ >()
Definition PointCloud.h:276
int BottleTagMap< yarp::sig::DataXYZRGBA >()
Definition PointCloud.h:288
int BottleTagMap< yarp::sig::DataXYZNormalRGBA >()
Definition PointCloud.h:312
int BottleTagMap< yarp::sig::DataXYZNormal >()
Definition PointCloud.h:306
int BottleTagMap< yarp::sig::DataNormal >()
Definition PointCloud.h:282
int BottleTagMap< yarp::sig::DataXYZI >()
Definition PointCloud.h:294
int BottleTagMap< yarp::sig::DataXY >()
Definition PointCloud.h:270
int BottleTagMap< yarp::sig::DataInterestPointXYZ >()
Definition PointCloud.h:300
contains the definition of a Vector type
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
An interface for reading from a network connection.
An interface for writing to a network connection.
The PointCloudBase class.
virtual size_t width() const
virtual int getPointType() const
virtual size_t height() const
The PointCloud class.
Definition PointCloud.h:21
const char * getRawData() const override
Get the pointer to the data.
Definition PointCloud.h:74
const PointCloud< T > & operator=(const PointCloud< T1 > &alt)
Assignment operator.
Definition PointCloud.h:150
const T & operator()(size_t i) const
Obtain the point given by the index (const version).
Definition PointCloud.h:139
T & operator()(size_t u, size_t v)
Obtain the point given by the (column, row) coordinates.
Definition PointCloud.h:110
T & operator()(size_t i)
Obtain the point given by the index.
Definition PointCloud.h:130
PointCloud()
PointCloud, default constructor.
Definition PointCloud.h:40
const T & operator()(size_t u, size_t v) const
Obtain the point given by the (column, row) coordinates (const version).
Definition PointCloud.h:121
PointCloud(const PointCloud< T1 > &alt)
PointCloud, copy constructor.
Definition PointCloud.h:52
size_t dataSizeBytes() const override
Get the size of the data in terms of number of bytes.
Definition PointCloud.h:94
void copy(const PointCloud< T1 > &alt)
Copy operator.
Definition PointCloud.h:198
size_t wireSizeBytes() const override
Get the size of the data + the header in terms of number of bytes.
Definition PointCloud.h:84
size_t size() const override
Definition PointCloud.h:99
Vector operator+(const Vector &a, const double &s)
Mathematical operations.
Definition math.cpp:27
Vector & operator+=(Vector &a, const double &s)
Addition operator between a scalar and a vector (defined in Math.h).
Definition math.cpp:38
STL namespace.
#define YARP_sig_API
Definition api.h:18