@@ -69,10 +69,13 @@ std::vector<std::string> split(const std::string &text, char sep) {
69
69
70
70
71
71
72
- Mat loadPLYSimple (const char * fileName, int withNormals)
72
+ Mat loadPLYSimple (const char * fileName, int withNormals /* = 0 */ )
73
73
{
74
74
Mat cloud;
75
75
int numVertices=0 ;
76
+ int numCols=3 ;
77
+ bool with_color = false ;
78
+ bool with_alpha = false ; // alpha transparency
76
79
77
80
std::ifstream ifs (fileName);
78
81
@@ -90,41 +93,57 @@ Mat loadPLYSimple(const char* fileName, int withNormals)
90
93
{
91
94
numVertices = atoi (tokens[2 ].c_str ());
92
95
}
96
+ if (tokens.size () ==3 && tokens[0 ] == " property" )
97
+ {
98
+ if (tokens[3 ]==" nx" || tokens[3 ]==" normal_x" )
99
+ {
100
+ withNormals = true ;
101
+ numCols+=3 ;
102
+ }
103
+ else if (tokens[3 ]==" r" || tokens[3 ]==" red" )
104
+ {
105
+ with_color = true ;
106
+ numCols+=3 ;
107
+ }
108
+ else if (tokens[3 ]==" a" || tokens[3 ]==" alpha" )
109
+ {
110
+ with_alpha = true ;
111
+ numCols+=1 ;
112
+ }
113
+ }
93
114
else if (tokens.size () > 1 && tokens[0 ] == " format" )
94
115
{
95
116
if (tokens[1 ]!=" ascii" ){
96
117
printf (" Cannot read file, only ascii ply format is currently supported...\n " );
118
+ // uncomment below when CV_StsBadArg can be located
119
+ // OPENCV_ERROR (CV_StsBadArg, "loadPLYSimple", "Cannot read file, only ascii ply format is currently supported...");
97
120
return Mat ();
98
121
}
99
122
}
100
123
std::getline (ifs, str);
101
124
}
102
125
103
- if (withNormals)
104
- cloud=Mat (numVertices, 6 , CV_32FC1);
105
- else
106
- cloud=Mat (numVertices, 3 , CV_32FC1);
126
+ cloud=Mat (numVertices, numCols, CV_32FC1);
107
127
108
128
for (int i = 0 ; i < numVertices; i++)
109
129
{
110
130
float * data = cloud.ptr <float >(i);
131
+ for (int col = 0 ; col < numCols; ++col)
132
+ {
133
+ ifs >> data[col];
134
+ }
111
135
if (withNormals)
112
136
{
113
- ifs >> data[0 ] >> data[1 ] >> data[2 ] >> data[3 ] >> data[4 ] >> data[5 ];
114
137
115
138
// normalize to unit norm
116
139
double norm = sqrt (data[3 ]*data[3 ] + data[4 ]*data[4 ] + data[5 ]*data[5 ]);
117
140
if (norm>0.00001 )
118
141
{
119
- data[3 ]/=( float ) norm;
120
- data[4 ]/=( float ) norm;
121
- data[5 ]/=( float ) norm;
142
+ data[3 ]/=static_cast < float >( norm) ;
143
+ data[4 ]/=static_cast < float >( norm) ;
144
+ data[5 ]/=static_cast < float >( norm) ;
122
145
}
123
146
}
124
- else
125
- {
126
- ifs >> data[0 ] >> data[1 ] >> data[2 ];
127
- }
128
147
}
129
148
130
149
// cloud *= 5.0f;
0 commit comments