Пример #1
0
    //! Read points from file. May throw.
    static void
    points(const std::string                   &file_name,
           std::vector<las::point>             &points,
           public_header_block                 *phb_ptr = 0,
           std::vector<variable_length_record> *vlr_ptr = 0)
    {
        las::ifstream ifs(file_name); // May throw.
        public_header_block phb;
        // TODO: set strings to null!
        _read_public_header_block(ifs.stream(), phb); // May throw.
        if (0 != phb_ptr) {
            *phb_ptr = phb;
        }

        _read_variable_length_records(ifs.stream(), phb, vlr_ptr); // May throw.
        _read_point_data_start_signature(ifs.stream());            // May throw.
        _read_points(ifs.stream(), phb, points);                   // May throw.
    }
Пример #2
0
bool
Lwo2::ReadFile( const string& filename )
{
    OSG_INFO  << "Opening file: " << filename << std::endl;

    _fin.open(filename.c_str(), ios::in | ios::binary );
    if (!_fin.is_open())
    {
        OSG_INFO << "Can't open file '" << filename << "'" << std::endl;
        return false;
    }

    // checking EA-IFF85 format
    // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/eaiff85.html
    if (_read_uint() != tag_FORM)
    {
        OSG_INFO << "File '" << filename << "' is not IFF format file." << std::endl;
        _fin.close();
        return false;
    }
    else
    {
        OSG_INFO << "Detected EA-IFF85 format" << std::endl;
    }

    unsigned int form_size = _read_uint();
    OSG_INFO << "Form size: " << form_size << std::endl;

    // checking LWO2 format
    // http://www.lightwave3d.com/developer/75lwsdk/docs/filefmts/lwo2.html
    if (_read_uint() != tag_LWO2)
    {
        unsigned long make_id(const char*);
        OSG_INFO << "File '" << filename << "' is not LWO2 format file." << std::endl;
        _fin.close();
        return false;
    }
    else
    {
        OSG_INFO << "Detected LWO2 format" << std::endl;
    }

    unsigned long read_bytes = 4;
    unsigned long current_tag_name;
    unsigned long current_tag_size;

    // main loop for reading tags
    while (read_bytes < form_size && !_fin.eof())
    {
        current_tag_name = _read_uint();
        current_tag_size = _read_uint();
        read_bytes += 8 + current_tag_size + current_tag_size % 2;

        _print_tag(current_tag_name, current_tag_size);

        if (current_tag_name == tag_TAGS)
        {
            _read_tag_strings(current_tag_size);
        }
        else if (current_tag_name == tag_LAYR)
        {
            _read_layer(current_tag_size);
        }
        else if (current_tag_name == tag_PNTS)
        {
            _read_points(current_tag_size);
        }
        else if (current_tag_name == tag_VMAP)
        {
            _read_vertex_mapping(current_tag_size);
        }
        else if (current_tag_name == tag_VMAD)
        {
            _read_polygons_mapping(current_tag_size);
        }
        else if (current_tag_name == tag_POLS)
        {
            _read_polygons(current_tag_size);
        }
        else if (current_tag_name == tag_PTAG)
        {
            _read_polygon_tag_mapping(current_tag_size);
        }
        else if (current_tag_name == tag_CLIP)
        {
            _read_image_definition(current_tag_size);
        }
        else if (current_tag_name == tag_SURF)
        {
            _read_surface(current_tag_size);
        }
        else
        {
            _fin.seekg(current_tag_size + current_tag_size % 2, ios::cur);
        }
    }

    _fin.close();

    return _successfully_read = true;
}