5 #include <boost/filesystem.hpp>
6 #include <boost/algorithm/string/replace.hpp>
7 #include "mesh_msgs/MeshFaceCluster.h"
9 using namespace boost::filesystem;
22 if (!is_directory(p) && !
exists(p))
30 "get_labeled_clusters",
40 "get_labeled_cluster_group",
57 ROS_INFO_STREAM(
"Got msg for mesh: " << msg->uuid <<
" with label: " << msg->cluster.label);
59 std::vector<uint> indices;
60 std::string fileName =
getFileName(msg->uuid, msg->cluster.label);
68 if (readIndices.empty())
70 indices = msg->cluster.face_indices;
74 for (
size_t i = 0; i < msg->cluster.face_indices.size(); i++)
76 uint idx = msg->cluster.face_indices[i];
79 if (std::find(readIndices.begin(), readIndices.end(), idx) == readIndices.end())
81 indices.push_back(idx);
88 indices = msg->cluster.face_indices;
96 if (!is_directory(p) || !
exists(p))
105 mesh_msgs::GetLabeledClusters::Request& req,
106 mesh_msgs::GetLabeledClusters::Response& res
112 directory_iterator end_itr;
114 if (!is_directory(p) || !
exists(p))
116 ROS_DEBUG_STREAM(
"No labeled clusters for uuid '" << req.uuid <<
"' found");
121 for (directory_iterator itr(p); itr != end_itr; ++itr)
124 if (is_regular_file(itr->path()))
126 std::string label = itr->path().filename().string();
128 boost::replace_all(label, itr->path().filename().extension().string(),
"");
130 mesh_msgs::MeshFaceCluster c;
134 res.clusters.push_back(c);
142 label_manager::GetLabelGroups::Request& req,
143 label_manager::GetLabelGroups::Response& res)
146 directory_iterator end_itr;
148 if (!is_directory(p) || !
exists(p))
150 ROS_WARN_STREAM(
"No labeled clusters for uuid '" << req.uuid <<
"' found");
155 for (directory_iterator itr(p); itr != end_itr; ++itr)
158 if (is_regular_file(itr->path()))
160 std::string label = itr->path().filename().string();
162 boost::replace_all(label, itr->path().filename().extension().string(),
"");
167 label = label.substr(0, label.find_first_of(
"_", 0));
170 if (std::find(res.labels.begin(), res.labels.end(), label) == res.labels.end())
172 res.labels.push_back(label);
182 label_manager::DeleteLabel::Request& req,
183 label_manager::DeleteLabel::Response& res)
187 if (!is_regular_file(p) || !
exists(p))
189 ROS_WARN_STREAM(
"Could not delete label '" << req.label <<
"' of mesh '" << req.uuid <<
"'.");
195 res.cluster.label = req.label;
201 label_manager::GetLabeledClusterGroup::Request& req,
202 label_manager::GetLabeledClusterGroup::Response& res)
205 directory_iterator end_itr;
207 if (!is_directory(p) || !
exists(p))
209 ROS_WARN_STREAM(
"No labeled clusters for uuid '" << req.uuid <<
"' found");
214 for (directory_iterator itr(p); itr != end_itr; ++itr)
217 if (is_regular_file(itr->path()) && itr->path().filename().string().find(req.labelGroup) == 0)
219 std::string label = itr->path().filename().string();
221 boost::replace_all(label, itr->path().filename().extension().string(),
"");
223 mesh_msgs::MeshFaceCluster c;
227 res.clusters.push_back(c);
236 const std::string& fileName,
237 const std::vector<uint>& indices,
248 std::ios_base::openmode mode =
append ? (std::ios::out|std::ios::app) : std::ios::out;
249 std::ofstream ofs(fileName.c_str(), mode);
261 size_t size = indices.size();
262 for (
size_t i = 0; i < size; i++)
287 std::ifstream ifs(fileName.c_str(), std::ios::in);
288 std::vector<uint> faceIndices;
293 ROS_DEBUG_STREAM(
"File " << fileName <<
" does not exists. Nothing to read...");
298 std::string stringNumber;
299 while (std::getline(ifs, stringNumber,
','))
301 faceIndices.push_back(atoi(stringNumber.c_str()));
309 return folderPath +
"/" +uuid +
"/" + label +
".dat";