RSMesh 1.0.0
一个曲面重构的系统,输入为点云,输出为obj,stl等主流格式的网格文件,使用的方法为径向基函数插值,采取了并行优化、Intel-MKL等优化措施,支持百万级别的点云
载入中...
搜索中...
未找到
roundtrip_string.h
1//
2// Created by RainSure on 2023/11/11.
3//
4
5#ifndef RSMESH_ROUNDTRIP_STRING_H
6#define RSMESH_ROUNDTRIP_STRING_H
7
8#include "double-conversion/double-conversion.h"
9
10#include <array>
11#include <limits>
12#include <string>
13#include <type_traits>
14
19namespace rsmesh::numeric {
20 namespace detail {
21 template <class Floating>
22 void to_string(Floating value, double_conversion::StringBuilder* builder);
23
24 template <>
25 inline void to_string(double value, double_conversion::StringBuilder* builder) {
26 double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToShortest(value, builder);
27 }
28
29 template <>
30 inline void to_string(float value, double_conversion::StringBuilder* builder) {
31 double_conversion::DoubleToStringConverter::EcmaScriptConverter().ToShortestSingle(value, builder);
32 }
33 } // namespace detail
34
35 inline double to_double(const std::string& str) {
36 double_conversion::StringToDoubleConverter converter(
37 double_conversion::StringToDoubleConverter::ALLOW_TRAILING_JUNK |
38 double_conversion::StringToDoubleConverter::ALLOW_CASE_INSENSITIVITY,
39 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), "inf",
40 "nan");
41 int processed_chars = 0;
42 return converter.StringToDouble(str.c_str(), static_cast<int>(str.size()), &processed_chars);
43 }
44
45 inline float to_float(const std::string& str) {
46 double_conversion::StringToDoubleConverter converter(
47 double_conversion::StringToDoubleConverter::ALLOW_TRAILING_JUNK |
48 double_conversion::StringToDoubleConverter::ALLOW_CASE_INSENSITIVITY,
49 std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN(), "inf",
50 "nan");
51 int processed_chars = 0;
52 return converter.StringToFloat(str.c_str(), static_cast<int>(str.size()), &processed_chars);
53 }
54
55 template <class Floating,
56 std::enable_if_t<std::is_floating_point<Floating>::value, std::nullptr_t> = nullptr>
57 std::string to_string(Floating value) {
58 static constexpr std::size_t buffer_size = 32;
59
60 std::array<char, buffer_size> buffer{};
61 double_conversion::StringBuilder builder(buffer.data(), buffer_size);
62
63 detail::to_string(value, &builder);
64
65 return builder.Finalize();
66 }
67}
68
69
70#endif //RSMESH_ROUNDTRIP_STRING_H
该命名空间下主要定义了数值计算相关的类和函数