14 #ifndef _DS3D_DATALOADER_LIDARSOURCE_CONFIG_H
15 #define _DS3D_DATALOADER_LIDARSOURCE_CONFIG_H
17 #include <ds3d/common/common.h>
18 #include <ds3d/common/func_utils.h>
20 #include "ds3d/common/hpp/yaml_config.hpp"
21 #include "ds3d/common/idatatype.h"
23 #define _PATH_MAX 4096
25 namespace ds3d {
namespace impl {
namespace lidarsource {
44 std::vector<std::deque<std::map<uint64_t, std::string>>>
dataParas;
55 if(dataType ==
"FP32") {
58 LOG_WARNING(
"unsupported datatype: %s, fallback to FP32", dataType.c_str());
67 std::map<uint64_t, std::string> dataParas;
68 std::deque<std::map<uint64_t, std::string>> dataParasQueue;
69 YAML::Node node = YAML::LoadFile(config.realPath);
70 const YAML::Node& listNode = node[
"source-list"];
71 uint64_t timestampPrev = 0;
72 for (std::size_t i = 0; i < listNode.size(); i++) {
73 const YAML::Node& kvs = listNode[i];
74 for (
const auto& kv : kvs) {
75 uint64_t timestamp = kv.first.as<uint64_t>();
76 std::string filename = kv.second.as<std::string>();
77 std::string absFilepath =
"";
78 if (filename[0] ==
'/') {
79 absFilepath = filename;
81 int pos = config.realPath.find_last_of(
"/");
82 std::string tmpPath = config.realPath.substr(0, pos+1);
83 tmpPath = tmpPath + filename;
84 if (!realpath(tmpPath.c_str(), absRealFilePath)) {
85 if (errno != ENOENT) {
90 absFilepath = absRealFilePath;
91 LOG_DEBUG(
"lidar data path %s",absFilepath.c_str());
93 dataParas[timestamp] = absFilepath;
94 timestampPrev = config.lastFileTimestamp;
95 config.lastFileTimestamp = timestamp;
97 dataParasQueue.push_back(dataParas);
100 config.dataParas.push_back(dataParasQueue);
102 if (listNode.size() > 1) {
103 config.frameDuration = config.lastFileTimestamp - timestampPrev;
106 config.frameDuration = 100;
113 parseConfig(
const std::string& content,
const std::string& path, Config& config)
117 "parse lidarsource component content failed");
119 YAML::Node node = YAML::Load(config.compConfig.configBody);
121 if (node[
"data_config_file"]) {
122 auto lidarDataNode = node[
"data_config_file"];
123 std::vector<std::string> lidarDataPaths;
124 if (lidarDataNode.IsSequence()) {
125 lidarDataPaths = lidarDataNode.as<std::vector<std::string>>();
128 lidarDataPaths.resize(1);
129 lidarDataPaths[0] = lidarDataNode.as<std::string>();
131 for (
const auto& item : lidarDataPaths) {
132 config.dataConfigFilePath = item;
133 if (config.dataConfigFilePath[0] ==
'/') {
134 config.realPath = config.dataConfigFilePath;
135 LOG_DEBUG(
"config path %s",config.realPath.c_str());
137 if (!realpath(path.c_str(), absRealFilePath)) {
138 if (errno != ENOENT) {
139 LOG_WARNING(
"Your config file path is not right!");
143 config.realPath = absRealFilePath;
144 int pos = config.realPath.find_last_of(
"/");
145 std::string tmpPath = config.realPath.substr(0, pos+1);
146 config.realPath = tmpPath + config.dataConfigFilePath;
147 LOG_DEBUG(
"config path %s",config.realPath.c_str());
153 if (node[
"mem_type"]) {
154 auto strType = node[
"mem_type"].as<std::string>();
155 if (strncasecmp(strType.c_str(),
"cpu", strType.size()) == 0) {
157 }
else if (strncasecmp(strType.c_str(),
"gpu", strType.size()) == 0) {
161 "unknown mem_type: %s in lidar_file_source config parsing", strType.c_str());
164 if (node[
"gpu_id"]) {
165 config.gpuId = node[
"gpu_id"].as<int32_t>();
167 if (node[
"fixed_points_num"]) {
168 config.fixedPointsNum = node[
"fixed_points_num"].as<
bool>();
170 if (node[
"mem_pool_size"]) {
171 config.memPoolSize = node[
"mem_pool_size"].as<uint32_t>();
173 if (node[
"data_type"]) {
174 std::string dataType = node[
"data_type"].as<std::string>();
177 if (node[
"points_num"]) {
178 config.pointNums = node[
"points_num"].as<uint32_t>();
180 if (node[
"element_stride"]) {
181 config.elementStride = node[
"element_stride"].as<uint32_t>();
183 if (node[
"element_size"]) {
184 config.elementSize = node[
"element_size"].as<uint32_t>();
186 if (node[
"output_datamap_key"]) {
187 auto keyNode = node[
"output_datamap_key"];
188 if (keyNode.IsSequence()) {
189 config.datamapKey = keyNode.as<std::vector<std::string>>();
191 config.datamapKey.resize(1);
192 config.datamapKey[0] = keyNode.as<std::string>();
195 if (node[
"file_loop"]) {
196 config.fileLoop = node[
"file_loop"].as<
bool>();
199 if (node[
"source_id"]) {
200 config.sourceId = node[
"source_id"].as<uint32_t>();
203 if (config.elementStride == 0) {
204 config.elementStride = config.elementSize;
209 "lidar data config element_size: %d must be [3, 4].", config.elementSize);
210 assert(config.elementStride >= config.elementSize);
217 #endif // _DS3D_DATALOADER_LIDARSOURCE_CONFIG_H