- Timestamp:
- 03/22/10 15:55:52 (3 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/branches/OpenSceneGraph-2.8/src/osgPlugins/ply/vertexData.cpp
r10012 r11274 10 10 11 11 #include "typedefs.h" 12 13 12 #include "vertexData.h" 14 13 #include "ply.h" 14 15 15 #include <cstdlib> 16 16 #include <algorithm> … … 127 127 128 128 // read in the faces, asserting that they are only triangles 129 uint8_t ind1 = _invertFaces ? 2 : 0;130 uint8_t ind3 = _invertFaces ? 0 : 2;129 int ind1 = _invertFaces ? 2 : 0; 130 int ind3 = _invertFaces ? 0 : 2; 131 131 for( int i = 0; i < nFaces; ++i ) 132 132 { … … 158 158 float version; 159 159 bool result = false; 160 int nComments; 161 char** comments; 162 163 PlyFile* file = ply_open_for_reading( const_cast< char* >( filename ), 160 int nComments; 161 char** comments; 162 163 PlyFile* file = NULL; 164 165 // Try to open ply file as for reading 166 try{ 167 file = ply_open_for_reading( const_cast< char* >( filename ), 164 168 &nPlyElems, &elemNames, 165 169 &fileType, &version ); 170 } 171 // Catch the if any exception thrown 172 catch( exception& e ) 173 { 174 MESHERROR << "Unable to read PLY file, an exception occured: " 175 << e.what() << endl; 176 } 166 177 167 178 if( !file ) … … 173 184 174 185 MESHASSERT( elemNames != 0 ); 186 175 187 176 188 nComments = file->num_comments; … … 196 208 int nProps; 197 209 198 PlyProperty** props = ply_get_element_description( file, elemNames[i], 199 &nElems, &nProps ); 210 PlyProperty** props = NULL; 211 try{ 212 props = ply_get_element_description( file, elemNames[i], 213 &nElems, &nProps ); 214 } 215 catch( exception& e ) 216 { 217 MESHERROR << "Unable to get PLY file description, an exception occured: " 218 << e.what() << endl; 219 } 200 220 MESHASSERT( props != 0 ); 201 221 … … 222 242 if( ignoreColors ) 223 243 MESHINFO << "Colors in PLY file ignored per request." << endl; 224 225 // Read vertices and store in a std::vector array 226 readVertices( file, nElems, hasColors && !ignoreColors ); 227 // Check whether all vertices are loaded or not 228 MESHASSERT( _vertices->size() == static_cast< size_t >( nElems ) ); 229 // Check all color elements read or not 230 if( hasColors && !ignoreColors ) 231 MESHASSERT( _colors->size() == static_cast< size_t >( nElems ) ); 244 245 try { 246 // Read vertices and store in a std::vector array 247 readVertices( file, nElems, hasColors && !ignoreColors ); 248 // Check whether all vertices are loaded or not 249 MESHASSERT( _vertices->size() == static_cast< size_t >( nElems ) ); 250 // Check all color elements read or not 251 if( hasColors && !ignoreColors ) 252 { 253 MESHASSERT( _colors->size() == static_cast< size_t >( nElems ) ); 254 } 255 256 result = true; 257 } 258 catch( exception& e ) 259 { 260 MESHERROR << "Unable to read vertex in PLY file, an exception occured: " 261 << e.what() << endl; 262 // stop for loop by setting the loop variable to break condition 263 // this way resources still get released even on error cases 264 i = nPlyElems; 265 266 } 232 267 } 233 268 // If the string is face means triangle info started … … 273 308 274 309 // If the normals are not calculated calculate the normals for faces 275 if(!_normals.valid()) 276 _calculateNormals(); 277 278 279 // set the normals 280 geom->setNormalArray(_normals.get()); 281 geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 310 if(_triangles.valid()) 311 { 312 if(!_normals.valid()) 313 _calculateNormals(); 314 315 // set the normals 316 geom->setNormalArray(_normals.get()); 317 geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); 318 } 282 319 283 320 // Add the premetive set 284 geom->addPrimitiveSet(_triangles.get()); 321 if (_triangles.valid() && _triangles->size() > 0 ) 322 geom->addPrimitiveSet(_triangles.get()); 323 else 324 geom->addPrimitiveSet(new osg::DrawArrays(GL_POINTS, 0, _vertices->size())); 285 325 286 326 // if color info is given set the color array
