Show
Ignore:
Timestamp:
01/20/11 13:23:04 (4 years ago)
Author:
robert
Message:

From Simon Julier, "I have been using the ply plugin to read files created by bundler and pmvs2 (http://grail.cs.washington.edu/software/pmvs/). This program generates models in the form of vertices only. However, the existing ply reader implementation was not able to handle the models generated in a satisfactory manner for two reasons:

1. It did not support normals applied to individual vertices.
2. It would only support red / green / blue colour triples, but the pmvs models are generated with diffuse colours. (The PLY format, http://local.wasp.uwa.edu.au/~pbourke/dataformats/ply/, lists specular and ambient colour forms as well.)

To partially overcome these limitations, please find attached modified versions of

src/osgPlugins/ply/vertexData.cpp
src/osgPlugins/ply/vertexData.h

The changes I've made are:

1. I have changed the boolean hasColor flag to a vertexField (which is a boolean operation on an enum) to indicate what fields are present in the ply file. (This is required because Turk's ply reader spits out warnings for every line where you try to read fields which do not exist.)
2. I have modified the code to apply valid normals to either triangles or vertices.
3. I have kludged in "support" for the various colour variants. Specifically, all the colour specified can be read from the file. However, they are all applied in the same way (namely as a colour array, bound to each vertex)."

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/ply/vertexData.h

    r10088 r12104  
    3737        // Default constructor 
    3838        VertexData(); 
     39 
    3940         
    4041        // Reads ply file and convert in to osg::Node and returns the same 
     
    4546         
    4647    private: 
     48 
     49        enum VertexFields 
     50        { 
     51          NONE = 0, 
     52          XYZ = 1, 
     53          NORMALS = 2, 
     54          RGB = 4, 
     55          AMBIENT = 8, 
     56          DIFFUSE = 16, 
     57          SPECULAR = 32 
     58        }; 
     59 
    4760        // Function which reads all the vertices and colors if color info is 
    4861        // given and also if the user wants that information 
    4962        void readVertices( PlyFile* file, const int nVertices,  
    50                            const bool readColors ); 
     63                           const int vertexFields ); 
    5164 
    5265        // Reads the triangle indices from the ply file 
     
    6477        // Color array in osg format 
    6578        osg::ref_ptr<osg::Vec4Array>   _colors; 
     79        osg::ref_ptr<osg::Vec4Array>   _ambient; 
     80        osg::ref_ptr<osg::Vec4Array>   _diffuse; 
     81        osg::ref_ptr<osg::Vec4Array>   _specular; 
     82 
    6683        // Normals in osg format 
    6784        osg::ref_ptr<osg::Vec3Array> _normals;