47 std_msgs::ColorRGBA ret;
49 std::random_device rd_;
50 std::mt19937 gen(rd_());
51 std::uniform_real_distribution<> dis(0.0, 1.0);
52 ret.r =
static_cast<float>(dis(gen));
53 ret.g =
static_cast<float>(dis(gen));
54 ret.b =
static_cast<float>(dis(gen));
59 const Eigen::Ref<const Eigen::MatrixXd> mat)
62 myfile.open(file_name);
75 void LoadOBJ(
const std::string& data, Eigen::VectorXi& tri,
76 Eigen::VectorXd& vert)
78 std::stringstream ss(data);
85 std::size_t line_no{1};
86 while (std::getline(ss, line))
89 if (line.compare(0, 2,
"v ") == 0)
91 vert.conservativeResize((vn + 1) * 3);
92 std::stringstream sss(line.substr(2));
93 sss >> v[0] >> v[1] >> v[2];
95 vert(vn * 3 + 1) = v[1];
96 vert(vn * 3 + 2) = v[2];
100 else if (line.compare(0, 2,
"f ") == 0)
102 std::stringstream sss(line.substr(2));
104 for (i = 0; i < 9 && sss >> vv[i]; ++i)
106 while (sss.peek() ==
'/' || sss.peek() ==
' ')
111 auto vv_eigen = Eigen::Map<Eigen::Matrix<int, 1, 9>>(&vv[0]);
112 ThrowPretty(
"Invalid OBJ format when reading line " << line_no <<
": '" << line <<
"', parsed vv: " << vv_eigen);
114 tri.conservativeResize((tn + 1) * 3);
115 tri(tn * 3) = vv[0] - 1;
116 tri(tn * 3 + 1) = vv[3] - 1;
117 tri(tn * 3 + 2) = vv[6] - 1;
124 std::shared_ptr<octomap::OcTree>
LoadOctree(
const std::string& file_path)
126 std::shared_ptr<octomap::OcTree> octree(
new octomap::OcTree(file_path));
127 if (!octree)
ThrowPretty(
"Could not load OcTree!");
133 std::shared_ptr<octomap::OcTree> octree =
LoadOctree(file_path);
144 temp = abi::__cxa_demangle(type.name(), 0, 0, &status);
145 name = std::string(temp);
152 std::string ret = path;
154 std::regex_search(ret, matches, std::regex(
"\\{([^\\}]+){1,}\\}"));
155 for (
auto& match : matches)
157 std::string
package = match.str();
163 ret = std::regex_replace(ret, std::regex(
"\\{" +
package +
"\\}"), package_path, std::regex_constants::match_any);
165 catch (
const std::regex_error& e)
167 ThrowPretty(
"Package name resolution failed (regex error " << e.code() <<
")");
170 std::regex_search(ret, matches, std::regex(
"package://([^\\/]+){1,}"));
171 for (
auto& match : matches)
173 std::string
package = match.str();
174 if (
package.substr(0, 10) ==
"package://" ||
package ==
"")
continue;
179 ret = std::regex_replace(ret, std::regex(
"package://" +
package +
"/"), package_path +
"/", std::regex_constants::match_any);
181 catch (
const std::regex_error& e)
183 ThrowPretty(
"Package name resolution failed (regex error " << e.code() <<
")");
192 std::ifstream fstream(file_name);
193 if (!fstream)
ThrowPretty(
"File does not exist '" << file_name <<
"'");
196 return std::string((std::istreambuf_iterator<char>(fstream)), std::istreambuf_iterator<char>());
198 catch (
const std::ifstream::failure& e)
200 ThrowPretty(
"Can't read file '" << file_name <<
"'");