@@ -54,6 +54,20 @@ void getRandQuat(double q[4]);
54
54
void getRandomRotation (double R[9 ]);
55
55
void meanCovLocalPC (const float * pc, const int ws, const int point_count, double CovMat[3 ][3 ], double Mean[4 ]);
56
56
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
+
57
71
58
72
Mat loadPLYSimple (const char * fileName, int withNormals)
59
73
{
@@ -71,10 +85,17 @@ Mat loadPLYSimple(const char* fileName, int withNormals)
71
85
std::string str;
72
86
while (str.substr (0 , 10 ) !=" end_header" )
73
87
{
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" )
76
90
{
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
+ }
78
99
}
79
100
std::getline (ifs, str);
80
101
}
0 commit comments