Changeset 652:34ac9fdad9dc


Ignore:
Timestamp:
05/16/08 15:58:00 (2 years ago)
Author:
Howard Butler <hobu.inc@…>
Branch:
default
Convert:
svn:1766ff46-f334-0410-ab20-d63176f87757/trunk@719
Message:

support for writing VLR records

Files:
8 edited

Legend:

Unmodified
Added
Removed
  • include/liblas/detail/writer.hpp

    r586 r652  
    6060    virtual void WritePointRecord(PointRecord const& record) = 0; 
    6161    virtual void WritePointRecord(PointRecord const& record, double const& time) = 0; 
     62     
     63    virtual void WriteVLR(LASHeader const& header) = 0; 
    6264 
    6365    // TODO: fix constness 
  • include/liblas/detail/writer10.hpp

    r586 r652  
    6464    void WritePointRecord(PointRecord const& record, double const& time); 
    6565     
     66    void WriteVLR(LASHeader const& header); 
    6667    // TODO: fix constness 
    6768    std::ostream& GetStream(); 
  • include/liblas/detail/writer11.hpp

    r586 r652  
    6363    void WritePointRecord(PointRecord const& record); 
    6464    void WritePointRecord(PointRecord const& record, double const& time); 
    65  
     65     
     66    void WriteVLR(LASHeader const& header); 
    6667    // TODO: fix constness 
    6768    std::ostream& GetStream(); 
  • src/detail/reader10.cpp

    r649 r652  
    220220 
    221221    m_ifs.seekg(header.GetHeaderSize(), std::ios::beg); 
    222   
     222     
    223223    for (uint32_t i = 0; i < header.GetRecordsCount(); ++i) 
    224224    { 
     
    245245    //       Testing reading of VLRecords with GeoKeys 
    246246    ReadGeoreference(header); 
    247  
    248247    return true; 
    249248} 
     
    255254#else 
    256255    // TODO: Under construction 
    257     VLRHeader vlrh = { 0 }; 
     256 
    258257    std::string const uid("LASF_Projection"); 
    259258    ST_TIFF *st = ST_Create(); 
    260259 
    261 //    m_ifs.seekg(header.GetHeaderSize(), std::ios::beg); 
    262  
    263     printf("Records count: %d\n", (int)header.GetRecordsCount()); 
    264  
    265260    for (uint16_t i = 0; i < header.GetRecordsCount(); ++i) 
    266261    { 
    267262        LASVLR record = header.GetVLR(i); 
    268263        std::vector<uint8_t> data = record.GetData(); 
    269  
    270         printf("record.GetUserId(): '%s' record.GetRecordId: %d\n", record.GetUserId(true).c_str(), record.GetRecordId()); 
    271264        if (uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId()) 
    272265        { 
    273             printf("uid == record.GetUserId(true).c_str() && 34735 == record.GetRecordId()\n"); 
    274  
    275266            int16_t count = data.size()/sizeof(int16_t); 
    276  
    277             printf("count for int16_t: %d\n", count); 
    278  
    279267            ST_SetKey( st, record.GetRecordId(), count, STT_SHORT,  
    280268                       &(data[0]) ); 
     
    283271        if (uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId()) 
    284272        { 
    285             printf("uid == record.GetUserId(true).c_str() && 34736 == record.GetRecordId()\n"); 
    286  
    287273            int count = data.size() / sizeof(double); 
    288             printf("count for int: %d\n", count); 
    289  
    290274            ST_SetKey( st, record.GetRecordId(), count, STT_DOUBLE,  
    291275                       &(data[0]) ); 
     
    294278        if (uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId()) 
    295279        { 
    296             printf("uid == record.GetUserId(true).c_str() && 34737 == record.GetRecordId()\n"); 
    297  
    298280            uint8_t count = data.size()/sizeof(uint8_t); 
    299              
    300             printf("count for string: %d data.size(): %d", count, (int)data.size()); 
    301281            ST_SetKey( st, record.GetRecordId(), count, STT_ASCII,  
    302282                       &(data[0]) ); 
     
    305285 
    306286    GTIF *gtif = GTIFNewSimpleTags( st ); 
    307  
    308     //GTIFPrint(gtif,0,0); 
    309  
    310287    GTIFDefn defn; 
    311288    if (GTIFGetDefn(gtif, &defn))  
  • src/detail/reader11.cpp

    r649 r652  
    297297} 
    298298 
    299 bool ReaderImpl::ReadVLR(LASHeader& header) 
    300 {     
    301     // TODO: To be implemented 
     299bool ReaderImpl::ReadVLR(LASHeader& header) { 
     300     
    302301    VLRHeader vlrh = { 0 }; 
    303     LASVLR vlr; 
    304  
    305     // TODO: To be removed, when objects are used 
    306     UNREFERENCED_PARAMETER(header); 
    307     UNREFERENCED_PARAMETER(vlrh); 
    308     UNREFERENCED_PARAMETER(vlr); 
     302 
     303    m_ifs.seekg(header.GetHeaderSize(), std::ios::beg); 
     304     
     305    for (uint32_t i = 0; i < header.GetRecordsCount(); ++i) 
     306    { 
     307        read_n(vlrh, m_ifs, sizeof(VLRHeader)); 
     308 
     309        int16_t count = vlrh.recordLengthAfterHeader; 
     310          
     311        std::vector<uint8_t> data; 
     312        data.resize( count ); 
     313 
     314        read_n(data.front(), m_ifs, count ); 
     315          
     316        LASVLR vlr; 
     317        vlr.SetReserved(vlrh.reserved); 
     318        vlr.SetUserId(std::string(vlrh.userId)); 
     319        vlr.SetDescription(std::string(vlrh.description)); 
     320        vlr.SetRecordLength(vlrh.recordLengthAfterHeader); 
     321        vlr.SetRecordId(vlrh.recordId); 
     322        vlr.SetData(data); 
     323 
     324        header.AddVLR(vlr); 
     325    } 
    309326 
    310327    return true; 
  • src/detail/writer10.cpp

    r588 r652  
    149149 
    150150    // 14. Offset to data 
    151     // At this point, no variable length records are written, so  
    152     // data offset is equal to (header size + data start signature size): 
    153     // 227 + 2 = 229 
    154     // TODO: This value must be updated after new variable length record is added. 
    155     uint32_t const dataSignatureSize = 2; 
    156     n4 = header.GetHeaderSize() + dataSignatureSize; 
    157     assert(229 <= n4); 
     151    n4 = header.GetDataOffset(); 
    158152    detail::write_n(m_ofs, n4, sizeof(n4)); 
    159153 
     
    205199    detail::write_n(m_ofs, header.GetMaxZ(), sizeof(double)); 
    206200    detail::write_n(m_ofs, header.GetMinZ(), sizeof(double)); 
    207   
     201 
     202    WriteVLR(header); 
     203 
     204    uint8_t const sgn1 = 0xCC; 
     205    uint8_t const sgn2 = 0xDD; 
     206    detail::write_n(m_ofs, sgn1, sizeof(uint8_t)); 
     207    detail::write_n(m_ofs, sgn2, sizeof(uint8_t)); 
     208 
    208209    // If we already have points, we're going to put it at the end of the file.   
    209210    // If we don't have any points,  we're going to leave it where it is. 
     
    228229void WriterImpl::WritePointRecord(detail::PointRecord const& record) 
    229230{ 
    230     // Write point data record format 0 
    231     if (0 == m_pointCount) 
    232     { 
    233         // Two bytes of point data start signature, required by LAS 1.0 
    234         uint8_t const sgn1 = 0xCC; 
    235         uint8_t const sgn2 = 0xDD; 
    236         detail::write_n(m_ofs, sgn1, sizeof(uint8_t)); 
    237         detail::write_n(m_ofs, sgn2, sizeof(uint8_t)); 
    238     } 
    239231 
    240232    // TODO: Static assert would be better 
     
    257249} 
    258250 
     251void WriterImpl::WriteVLR(LASHeader const& header)  
     252{ 
     253 
     254    m_ofs.seekp(header.GetHeaderSize(), std::ios::beg); 
     255  
     256    for (uint32_t i = 0; i < header.GetRecordsCount(); ++i) 
     257    { 
     258          
     259        LASVLR vlr = header.GetVLR(i); 
     260         
     261        detail::write_n(m_ofs, vlr.GetReserved(), sizeof(uint16_t)); 
     262        detail::write_n(m_ofs, vlr.GetUserId(true).c_str(), 16); 
     263        detail::write_n(m_ofs, vlr.GetRecordId(), sizeof(uint16_t)); 
     264        detail::write_n(m_ofs, vlr.GetRecordLength(), sizeof(uint16_t)); 
     265        detail::write_n(m_ofs, vlr.GetDescription(true).c_str(), 32); 
     266        std::vector<uint8_t> data = vlr.GetData(); 
     267        detail::write_n(m_ofs, data.front(), data.size()); 
     268    } 
     269 
     270} 
    259271std::ostream& WriterImpl::GetStream() 
    260272{ 
  • src/detail/writer11.cpp

    r588 r652  
    155155    // so  data offset is equal to header size (227) 
    156156    // TODO: This value must be updated after new variable length record is added. 
    157     n4 = header.GetHeaderSize(); 
     157    n4 = header.GetDataOffset(); 
    158158    detail::write_n(m_ofs, n4, sizeof(n4)); 
    159159 
     
    206206    detail::write_n(m_ofs, header.GetMinZ(), sizeof(double)); 
    207207 
     208    WriteVLR(header); 
     209 
    208210    // If we already have points, we're going to put it at the end of the file.   
    209211    // If we don't have any points,  we're going to leave it where it is. 
    210212    if (m_pointCount != 0) 
    211213        m_ofs.seekp(0, std::ios::end); 
     214     
     215 
    212216} 
    213217 
     
    246250} 
    247251 
     252void WriterImpl::WriteVLR(LASHeader const& header)  
     253{ 
     254    printf("Writing VLR records in writer11.cpp... \n"); 
     255 
     256    m_ofs.seekp(header.GetHeaderSize(), std::ios::beg); 
     257  
     258    for (uint32_t i = 0; i < header.GetRecordsCount(); ++i) 
     259    { 
     260          
     261        LASVLR vlr = header.GetVLR(i); 
     262         
     263        detail::write_n(m_ofs, vlr.GetReserved(), sizeof(uint16_t)); 
     264        detail::write_n(m_ofs, vlr.GetUserId(true).c_str(), 16); 
     265        detail::write_n(m_ofs, vlr.GetRecordId(), sizeof(uint16_t)); 
     266        detail::write_n(m_ofs, vlr.GetRecordLength(), sizeof(uint16_t)); 
     267        detail::write_n(m_ofs, vlr.GetDescription(true).c_str(), 32); 
     268        std::vector<uint8_t> data = vlr.GetData(); 
     269        detail::write_n(m_ofs, data.front(), data.size()); 
     270    } 
     271 
     272} 
     273 
    248274std::ostream& WriterImpl::GetStream() 
    249275{ 
  • src/lasheader.cpp

    r649 r652  
    129129        m_dataOffset = rhs.m_dataOffset; 
    130130        m_recordsCount = rhs.m_recordsCount; 
     131//        m_recordsCount = 0; 
    131132        m_dataFormatId = rhs.m_dataFormatId; 
    132133        m_dataRecordLen = rhs.m_dataRecordLen; 
     
    498499{ 
    499500    m_vlrs.push_back(v); 
    500     m_dataRecordLen = static_cast<uint16_t>(m_vlrs.size()); 
     501    uint32_t size; 
     502    if (m_vlrs.size() > m_recordsCount ) { 
     503        m_recordsCount = m_vlrs.size(); 
     504        size = GetDataOffset() + 2 + 16 + 2 + 2 + 32 + v.GetData().size()*sizeof(uint8_t); 
     505        SetDataOffset(size); 
     506    } 
    501507} 
    502508 
     
    511517         
    512518    m_vlrs.erase(m_vlrs.begin() + index); 
    513     m_dataRecordLen = static_cast<uint16_t>(m_vlrs.size()); 
     519    m_recordsCount = m_vlrs.size(); 
    514520     
    515521} 
Note: See TracChangeset for help on using the changeset viewer.