cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
point.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <iostream>
5#include <limits>
6#include <memory>
7#include <ostream>
8#include <random>
9#include <stdexcept>
10#include <vector>
11
12#include <cpp-toolbox/cpp-toolbox_export.hpp>
14
15namespace toolbox::types
16{
17
46template<typename T>
47struct CPP_TOOLBOX_EXPORT point_t
48{
49 using value_type = T;
50
51 T x;
52 T y;
53 T z;
54
55 // 定义析构函数(五法则/零法则) / Define destructor (Rule of Five/Zero)
56 ~point_t() = default;
57
64 point_t(T x_coord, T y_coord, T z_coord);
65
70 point_t();
71
72 point_t(const point_t& other) = default;
73 point_t(point_t&& other) noexcept =
74 default;
75
76 point_t& operator=(const point_t& other) =
77 default;
78 point_t& operator=(point_t&& other) noexcept =
79 default;
80
86 point_t& operator+=(const point_t& other);
87
93 point_t& operator-=(const point_t& other);
94
100 point_t& operator*=(const T& scalar);
101
108 point_t& operator/=(const T& scalar);
109
115 [[nodiscard]] auto dot(const point_t& other) const -> T;
116
122 [[nodiscard]] auto cross(const point_t& other) const -> point_t;
123
129 [[nodiscard]] auto norm() const -> double;
130
136 [[nodiscard]] auto normalize() const -> point_t<double>;
137
143 [[nodiscard]] auto p_norm(const double& p_value) const -> double;
144
151 [[nodiscard]] auto p_normalize(const double& p_value) const
152 -> point_t<double>;
153
160 [[nodiscard]] auto distance(const point_t& other) const -> double;
161
168 [[nodiscard]] auto distance_p(const point_t& other,
169 const double& p_value) const -> double;
170
171 // 定义比较运算符 / Define comparison operators
172 bool operator==(const point_t& other) const;
173
174 bool operator!=(const point_t& other) const;
175
176 // 为测试目的添加基本的operator< / Add a basic operator< for testing purposes
177 // 注意:这提供了一个任意但一致的排序 / Note: This provides an arbitrary but
178 // consistent ordering.
179 bool operator<(const point_t& other) const;
180
185 [[nodiscard]] static auto min_value() -> point_t;
186
191 [[nodiscard]] static auto max_value() -> point_t;
192};
193
194// 静态成员的特化(保持内联定义) / Specializations for static members (keep
195// inline definitions here)
196template<>
197[[nodiscard]] inline auto point_t<int>::min_value() -> point_t<int>
198{
199 return {std::numeric_limits<int>::min(),
200 std::numeric_limits<int>::min(),
201 std::numeric_limits<int>::min()};
202}
203
204template<>
205[[nodiscard]] inline auto point_t<int>::max_value() -> point_t<int>
206{
207 return {std::numeric_limits<int>::max(),
208 std::numeric_limits<int>::max(),
209 std::numeric_limits<int>::max()};
210}
211
212template<>
213[[nodiscard]] inline auto point_t<float>::min_value() -> point_t<float>
214{
215 return {std::numeric_limits<float>::lowest(),
216 std::numeric_limits<float>::lowest(),
217 std::numeric_limits<float>::lowest()};
218}
219
220template<>
221[[nodiscard]] inline auto point_t<float>::max_value() -> point_t<float>
222{
223 return {std::numeric_limits<float>::max(),
224 std::numeric_limits<float>::max(),
225 std::numeric_limits<float>::max()};
226}
227
235template<typename T>
236auto operator<<(std::ostream& output_stream, const point_t<T>& pt)
237 -> std::ostream&;
238
266template<typename T>
267class CPP_TOOLBOX_EXPORT point_cloud_t : public ::toolbox::io::base_file_data_t
268{
269public:
270 std::vector<point_t<T>> points;
271 std::vector<point_t<T>> normals;
272 std::vector<point_t<T>> colors;
274
275 ~point_cloud_t() = default;
276
278
279 point_cloud_t(const point_cloud_t& other);
280 point_cloud_t(point_cloud_t&& other) noexcept;
281 point_cloud_t& operator=(const point_cloud_t& other);
282 point_cloud_t& operator=(point_cloud_t&& other) noexcept;
283
288 [[nodiscard]] auto size() const -> std::size_t;
289
294 [[nodiscard]] auto empty() const -> bool;
295
299 void clear();
300
306 void reserve(const std::size_t& required_size);
307
313 [[nodiscard]] auto operator+(const point_cloud_t& other) const
314 -> point_cloud_t;
315
321 [[nodiscard]] auto operator+(const point_t<T>& point) const -> point_cloud_t;
322
328 [[nodiscard]] auto operator+(point_t<T>&& point) const -> point_cloud_t;
329
335 [[nodiscard]] auto operator+(point_cloud_t&& other) const -> point_cloud_t;
336
342 point_cloud_t& operator+=(const point_t<T>& point);
343
349 point_cloud_t& operator+=(point_t<T>&& point);
350
356 point_cloud_t& operator+=(const point_cloud_t& other);
357
364 point_cloud_t& operator+=(point_cloud_t&& other);
365};
366
367} // namespace toolbox::types
368
369// 包含实现文件 / Include the implementation file
370#include "cpp-toolbox/types/impl/point_impl.hpp"
文件数据的基类 / Base class for data loaded from files
Definition base.hpp:33
包含点和相关数据的点云类 / A point cloud class containing points and associated data
Definition point.hpp:268
std::vector< point_t< T > > colors
点颜色(可选) / Point colors (optional)
Definition point.hpp:272
std::vector< point_t< T > > points
点坐标 / Point coordinates
Definition point.hpp:270
std::vector< point_t< T > > normals
点法线(可选) / Point normals (optional)
Definition point.hpp:271
T intensity
全局强度值 / Global intensity value
Definition point.hpp:273
Definition minmax_impl.hpp:21
auto operator<<(std::ostream &output_stream, const point_t< T > &pt) -> std::ostream &
point_t的流输出运算符 - 仅声明 / Stream output operator for point_t - Declaration Only
Definition point_impl.hpp:475
3D点/向量模板类 / A 3D point/vector template class
Definition point.hpp:48
point_t(point_t &&other) noexcept=default
移动构造函数 / Move constructor
point_t(const point_t &other)=default
拷贝构造函数 / Copy constructor
T x
X坐标 / X coordinate.
Definition point.hpp:51
T z
Z坐标 / Z coordinate.
Definition point.hpp:53
point_t & operator=(point_t &&other) noexcept=default
移动赋值运算符 / Move assignment
T value_type
Value type for compatibility with STL containers.
Definition point.hpp:49
point_t & operator=(const point_t &other)=default
拷贝赋值运算符 / Copy assignment
T y
Y坐标 / Y coordinate.
Definition point.hpp:52