예제 #1
0
        private void ReadElementInstanceBinary( PLYElementDescription elementDescription )
        {
            string elementName = elementDescription.ElementName;
            foreach( string propertyName in elementDescription.PropertyNames )
            {
                int listLength = ReadListLength( elementDescription, propertyName );
                OnPropertyBegin( elementName, propertyName, listLength );

                PLYScalarType dataType = elementDescription.PropertyDataType( propertyName );
                for( int i = 0; i < listLength; ++i )
                {
                    switch( dataType )
                    {
                        case PLYScalarType.BYTE:
                        {
                            byte val = ReadByteBinary();
                            OnByteRead( elementName, propertyName, i, val );
                            break;
                        }

                        case PLYScalarType.INT:
                        {
                            int val = ReadIntBinary();
                            OnIntRead( elementName, propertyName, i, val );
                            break;
                        }

                        case PLYScalarType.FLOAT:
                        {
                            float val = ReadFloatBinary();
                            OnFloatRead( elementName, propertyName, i, val );
                            break;
                        }

                        case PLYScalarType.DOUBLE:
                        {
                            double val = ReadDoubleBinary();
                            OnDoubleRead( elementName, propertyName, i, val );
                            break;
                        }

                        default:
                            throw new NotImplementedException( "Sorry, I need to implement reading other types" );
                    }
                }

                OnPropertyEnd( elementName, propertyName, listLength );
            }
        }
예제 #2
0
        private int ReadListLength( PLYElementDescription elementDescription, string propertyName )
        {
            int listLength = 1;
            if( elementDescription.IsList( propertyName ) )
            {
                PLYScalarType lengthType = elementDescription.PropertyLengthType( propertyName );
                switch( lengthType )
                {
                    case PLYScalarType.CHAR:
                        listLength = ( int )( ReadCharBinary() );
                        break;
                    
                    case PLYScalarType.BYTE:
                        listLength = ( int )( ReadByteBinary() );
                        break;
                        
                    case PLYScalarType.SHORT:
                        listLength = ( int )( ReadShortBinary() );
                        break;
                    
                    case PLYScalarType.USHORT:
                        listLength = ( int )( ReadUShortBinary() );
                        break;

                    case PLYScalarType.INT:
                        listLength = ReadIntBinary();
                        break;

                    case PLYScalarType.UINT:
                        listLength = ( int )( ReadUIntBinary() );
                        break;

                    default:
                        throw new InvalidDataException( "List length must be an integer type." );
                }
            }

            return listLength;
        }
예제 #3
0
        private void ReadElementDeclarations()
        {
            PLYElementDescription currentElement = null;

            string line = streamReader.ReadLine();
            dataBegin += 1 + line.Length;
            while( line != null && line != "end_header" )
            {
                string[] delimiters = new string[] { " " };
                string[] tokens = line.Split( delimiters, StringSplitOptions.RemoveEmptyEntries );
                switch( tokens[ 0 ] )
                {
                    // on a comment, do nothing
                    case "comment":
                        break;

                    // on an element declaration
                    // append the previous one (unless it's the first)
                    // and create a new one
                    case "element":

                        if( currentElement != null )
                        {
                            plyHeader.AddElementDescription( currentElement );
                        }

                        // and parse the new one
                        if( tokens.Length != 3 )
                        {
                            throw new InvalidDataException( "Invalid element declaration: " + line );
                        }

                        string elementName = tokens[ 1 ];
                        int nInstances = int.Parse( tokens[ 2 ] );
                        currentElement = new PLYElementDescription( elementName, nInstances );

                        break;

                    // on a property declaration
                    // append the property to the current element
                    case "property":

                        if( tokens.Length < 3 )
                        {
                            throw new InvalidDataException( "Invalid property declaration: " + line );
                        }

                        // read the property type
                        string propertyType = tokens[ 1 ];
                        if( propertyType == "list" )
                        {
                            if( tokens.Length < 5 )
                            {
                                throw new InvalidDataException( "Invalid property declaration: " + line );
                            }

                            PLYScalarType lengthType = scalarTypeFromString( tokens[ 2 ] );
                            if( lengthType == PLYScalarType.FLOAT ||
                                lengthType == PLYScalarType.DOUBLE )
                            {
                                throw new InvalidDataException( "List length must be an integer type.  Found: " + tokens[ 2 ] );
                            }

                            PLYScalarType dataType = scalarTypeFromString( tokens[ 3 ] );
                            string propertyName = tokens[ 4 ];

                            currentElement.AddListProperty( propertyName, lengthType, dataType );
                        }
                        else
                        {
                            PLYScalarType dataType = scalarTypeFromString( propertyType );
                            string propertyName = tokens[ 2 ];

                            currentElement.AddScalarProperty( propertyName, dataType );
                        }

                        break;
                }

                line = streamReader.ReadLine();
                dataBegin += 1 + line.Length;
            }

            if( currentElement != null )
            {
                plyHeader.AddElementDescription( currentElement );
            }
        }