Пример #1
0
    bool readHeader(LASHeader& header)
    {
        fseek(fp_, 32*3 + 11, SEEK_SET);
        size_t result = fread(&header.point_count, 4, 1, fp_);
        if (result != 1)
        {
            return false;
        }

        fseek(fp_, 32*3, SEEK_SET);
        result = fread(&header.data_offset, 4, 1, fp_);
        if (result != 1)
        {
            return false;
        }

        fseek(fp_, 32*3+4, SEEK_SET);
        result = fread(&header.vlr_count, 4, 1, fp_);
        if (result != 1)
        {
            return false;
        }


        fseek(fp_, 32*3-2, SEEK_SET);
        result = fread(&header.header_size, 2, 1, fp_);
        if (result != 1)
        {
            return false;
        }

        fseek(fp_, 32*3 + 8, SEEK_SET);
        result = fread(&header.point_format_id, 1, 1, fp_);
        if (result != 1)
        {
            return false;
        }

        uint8_t compression_bit_7 = (header.point_format_id & 0x80) >> 7;
        uint8_t compression_bit_6 = (header.point_format_id & 0x40) >> 6;

        if (!compression_bit_7 && !compression_bit_6 )
        {
            return false;
        }
        if (compression_bit_7 && compression_bit_6)
        {
            return false;
        }

        header.point_format_id = header.point_format_id & 0x3f;

        fseek(fp_, 32*3 + 8+1, SEEK_SET);
        result = fread(&header.point_record_length, 2, 1, fp_);
        if (result != 1)
        {
            return false;
        }


        size_t start = 32*3 + 35;
        fseek(fp_, start, SEEK_SET);

        result = fread(&header.scale, 8, 3, fp_ );
        if (result != 3)
        {
            return false;
        }


        result = fread(&header.offset, 8, 3, fp_ );
        if (result != 3)
        {
            return false;
        }

        result = fread(&header.maxs[0], 8, 1, fp_ );
        if (result != 1)
        {
            return false;
        }

        result = fread(&header.mins[0], 8, 1, fp_ );
        if (result != 1)
        {
            return false;
        }
        result = fread(&header.maxs[1], 8, 1, fp_ );
        if (result != 1)
        {
            return false;
        }
        result = fread(&header.mins[1], 8, 1, fp_ );
        if (result != 1)
        {
            return false;
        }

        result = fread(&header.maxs[2], 8, 1, fp_ );
        if (result != 1)
        {
            return false;
        }
        result = fread(&header.mins[2], 8, 1, fp_ );
        if (result != 1)
        {
            return false;
        }


        fseek(fp_, header_.header_size, SEEK_SET);
        std::vector<VLR*> vlrs = readVLRs(fp_, header_.vlr_count);
        VLR* zvlr = getLASzipVLR(vlrs);

        if (!zvlr)
        {
            return false;
        }
        bool stat = zip_.unpack(&(zvlr->data[0]), zvlr->size);
        if (!stat)
        {
            return false;
        }

        fseek(fp_, header_.data_offset, SEEK_SET);
        stat = unzipper_.open(fp_, &zip_);
        if (!stat)
        {
            return false;
        }

        for (size_t i = 0; i < vlrs.size(); ++i)
        {
            delete vlrs[i];
        }
        unsigned int point_offset(0);
        point_ = new unsigned char*[zip_.num_items];
        uint32_t point_size(0);
        for (unsigned i = 0; i < zip_.num_items; i++)
        {
            point_size += zip_.items[i].size;
        }

        bytes_ = new uint8_t[ point_size ];

        for (unsigned i = 0; i < zip_.num_items; i++)
        {
            point_[i] = &(bytes_[point_offset]);
            point_offset += zip_.items[i].size;
        }

        return true;
    }
Пример #2
0
    bool readHeader(LASHeader& header, pp::Var message)
    {

        pp::VarDictionary dict = pp::VarDictionary(message);
        std::string id = dict.Get("id").AsString();

        std::ostringstream errors;        
        fseek(fp_, 32*3 + 11, SEEK_SET);
        size_t result = fread(&header.point_count, 4, 1, fp_);
        if (result != 1)
        {
            errors << "unable to read point count of size 1, got " << result;
            PostError("readHeader", errors.str(), id);
            return false;
        }
    
        fseek(fp_, 32*3, SEEK_SET);
        result = fread(&header.data_offset, 4, 1, fp_);
        if (result != 1)
        {
            errors << "unable to read data offset of size 1, got " << result;
            PostError("readHeader", errors.str(), id);
            return false;
        }

        fseek(fp_, 32*3+4, SEEK_SET);
        result = fread(&header.vlr_count, 4, 1, fp_);
        if (result != 1)
        {
            errors << "unable to vlr count of size 1, got " << result;
            PostError("readHeader", errors.str(), id);
            return false;
        }
    

        fseek(fp_, 32*3-2, SEEK_SET);
        result = fread(&header.header_size, 2, 1, fp_);
        if (result != 1)
        {
            errors << "unable to header size of size 1, got " << result;
            PostError("readHeader", errors.str(), id);
            return false;
        }

        fseek(fp_, 32*3 + 8, SEEK_SET);
        result = fread(&header.point_format_id, 1, 1, fp_);
        if (result != 1)
        {
            errors << "unable to header point_format_id of size 1, got " << result;
            PostError("readHeader", errors.str(), id);
            return false;
        }

        uint8_t compression_bit_7 = (header.point_format_id & 0x80) >> 7;
        uint8_t compression_bit_6 = (header.point_format_id & 0x40) >> 6;
        
        if (!compression_bit_7 && !compression_bit_6 )
        {
            errors << "This file is not a LASzip file. Is it uncompressed LAS? ";
            PostError("readHeader", errors.str(), id);
            return false;
        }
        if (compression_bit_7 && compression_bit_6)
        {
            errors << "This is LASzip, but it was compressed by an ancient compressor version that is not open source ";
            PostError("readHeader", errors.str(), id);
            return false;            
        }
        header.point_format_id = header.point_format_id &= 0x3f;

        fseek(fp_, 32*3 + 8+1, SEEK_SET);
        result = fread(&header.point_record_length, 2, 1, fp_);
        if (result != 1)
        {
            errors << "unable to header point_record_length of size 1, got " << result;
            PostError("readHeader", errors.str(), id);
            return false;
        }        


        size_t start = 32*3 + 35;
        fseek(fp_, start, SEEK_SET);
    

        result = fread(&header.scale, 8, 3, fp_ );
        if (result != 3)
        {       
            errors << "unable to read scale information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }
        

        result = fread(&header.offset, 8, 3, fp_ );
        if (result != 3)
        {      
            errors << "unable to read offset information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }
        
        result = fread(&header.maxs[0], 8, 1, fp_ );
        if (result != 1)
        {      
            errors << "unable to read minx information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }
        result = fread(&header.mins[0], 8, 1, fp_ );
        if (result != 1)
        {      
            errors << "unable to read minx information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }
        result = fread(&header.maxs[1], 8, 1, fp_ );
        if (result != 1)
        {      
            errors << "unable to read maxy information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }
        result = fread(&header.mins[1], 8, 1, fp_ );
        if (result != 1)
        {      
            errors << "unable to read miny information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }

        result = fread(&header.maxs[2], 8, 1, fp_ );
        if (result != 1)
        {      
            errors << "unable to read maxz information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }
        result = fread(&header.mins[2], 8, 1, fp_ );
        if (result != 1)
        {      
            errors << "unable to read minz information!" << std::endl;
            PostError("readHeader", errors.str(), id);
            return false;
        }


        fseek(fp_, header_.header_size, SEEK_SET);
        std::vector<VLR*> vlrs = readVLRs(fp_, header_.vlr_count);
        VLR* zvlr = getLASzipVLR(vlrs);
    
        if (!zvlr)
        {
            errors << "No LASzip VLRs were found in this file! ";
            PostError("readHeader", errors.str(), id);
            return false;
        }
        bool stat = zip_.unpack(&(zvlr->data[0]), zvlr->size);
        if (!stat)
        {
            errors << "Unable to unpack LASzip VLR!" << std::endl;
            errors << "error msg: " << unzipper_.get_error() << std::endl;            
            PostError("readHeader", errors.str(), id);
            return false;
        }
    
        fseek(fp_, header_.data_offset, SEEK_SET);
        stat = unzipper_.open(fp_, &zip_);
        if (!stat)
        {       
            errors << "Unable to open zip file!" << std::endl;
            errors << "error msg: " << unzipper_.get_error() << std::endl;            
            PostError("readHeader", errors.str(), id);
            return false;
        }
        
        for (int i = 0; i < vlrs.size(); ++i)
        {
            delete vlrs[i];
        }
        unsigned int point_offset(0); 
        point_ = new unsigned char*[zip_.num_items];
        uint32_t point_size(0);
        for (unsigned i = 0; i < zip_.num_items; i++)
        {
            point_size += zip_.items[i].size;
        }

        bytes_ = new uint8_t[ point_size ];

        for (unsigned i = 0; i < zip_.num_items; i++)
        {
            point_[i] = &(bytes_[point_offset]);
            point_offset += zip_.items[i].size;
        }
                
        return true;
    }