Skip to content

Commit 47237bf

Browse files
ahundtterfendail
authored andcommitted
surface_matching loadPLYSimple() reports only ascii ply is supported (+1 squashed commit)
Squashed commits: [802ce32] surface_matching loadPLYSimple() reports only ascii ply is supported (+1 squashed commit) Squashed commits: [e240207] surface_matching loadPLYSimple() reports only ascii ply is supported
1 parent e80393b commit 47237bf

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

modules/surface_matching/src/ppf_helpers.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ void getRandQuat(double q[4]);
5454
void getRandomRotation(double R[9]);
5555
void meanCovLocalPC(const float* pc, const int ws, const int point_count, double CovMat[3][3], double Mean[4]);
5656
void meanCovLocalPCInd(const float* pc, const int* Indices, const int ws, const int point_count, double CovMat[3][3], double Mean[4]);
57+
std::vector<std::string> split(const std::string &text, char sep);
58+
59+
std::vector<std::string> split(const std::string &text, char sep) {
60+
std::vector<std::string> tokens;
61+
std::size_t start = 0, end = 0;
62+
while ((end = text.find(sep, start)) != std::string::npos) {
63+
tokens.push_back(text.substr(start, end - start));
64+
start = end + 1;
65+
}
66+
tokens.push_back(text.substr(start));
67+
return tokens;
68+
}
69+
70+
5771

5872
Mat loadPLYSimple(const char* fileName, int withNormals)
5973
{
@@ -71,10 +85,17 @@ Mat loadPLYSimple(const char* fileName, int withNormals)
7185
std::string str;
7286
while (str.substr(0, 10) !="end_header")
7387
{
74-
std::string entry = str.substr(0, 14);
75-
if (entry == "element vertex")
88+
std::vector<std::string> tokens = split(str,' ');
89+
if (tokens.size() == 3 && tokens[0] == "element" && tokens[1] == "vertex")
7690
{
77-
numVertices = atoi(str.substr(15, str.size()-15).c_str());
91+
numVertices = atoi(tokens[2].c_str());
92+
}
93+
else if (tokens.size() > 1 && tokens[0] == "format")
94+
{
95+
if (tokens[1]!="ascii"){
96+
printf("Cannot read file, only ascii ply format is currently supported...\n");
97+
return Mat();
98+
}
7899
}
79100
std::getline(ifs, str);
80101
}

0 commit comments

Comments
 (0)