00001
00018 #ifndef INC_MI32_LIDARLASFILE_H
00019 #define INC_MI32_LIDARLASFILE_H
00020
00021 #ifndef INC_MI32_FILEACCESS_H
00022 #include <mi32/fileaccess.h>
00023 #endif
00024
00025 #ifndef INC_MI32_RECT_H
00026 #include <mi32/rect.h>
00027 #endif
00028
00029 #ifndef INC_MI32_MISTRING
00030 #include <mi32/mistring.h>
00031 #endif
00032
00033 #ifndef INC_MI32_RECORDBUFFER_H
00034 #include <mi32/recordbuffer.h>
00035 #endif
00036
00037
00038 #ifndef GENERATING_DOXYGEN_OUTPUT
00039
00040 struct COLOR;
00041 class FILE_RAW;
00042 class FILEPATH;
00043 class QUANTIZER_LPOINT3D;
00044 namespace SPATREF {
00045 class COORDREFSYS;
00046 }
00047 namespace LIDAR {
00048 namespace LAS {
00049 class POINTARRAY;
00050 class POINTRECORD;
00051 class FILEHDR;
00052 class VARIABLEREC;
00053 class EVLRHDR;
00054 class SVLRHDR;
00055 }
00056 }
00057 #endif
00058
00059
00060 #ifdef RVCSYSDLL
00061 #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00062 #else
00063 #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00064 #endif
00065
00066
00067 namespace LIDAR {
00068 namespace LAS {
00069
00070
00071
00073 class CLASSLIBEXPORT FILEHDR {
00074 public:
00075
00077 enum POINTGPSTIMETYPE {
00078 POINTGPSTIMETYPE_None,
00079 POINTGPSTIMETYPE_Week,
00080 POINTGPSTIMETYPE_StdAdj
00081 };
00082
00083 FILEHDR ();
00084
00087 void AddPointRecord (
00088 const POINTRECORD& pointrec
00089 );
00090
00093 void AddVariableRecord (
00094 const VARIABLEREC& vrec
00095 );
00096
00098 void ComputeExtentsRaw (
00099 LRECT3D& ExtentsRaw
00100 ) const;
00101
00103 UINT16 GetCreationDayOfYear () const
00104 { return (m_CreationDayOfYear); }
00105
00107 UINT16 GetCreationYear () const
00108 { return (m_CreationYear); }
00109
00110 MISTRING GetDisplayValues () const;
00111
00112 UINT32 GetFileOffsetPointData () const
00113 { return (m_FileOffsetPointData); }
00114
00116 void GetExtents (
00117 DRECT2D& extents
00118 ) const { extents.Set(m_MinX,m_MinY,m_MaxX,m_MaxY); }
00119
00121 void GetExtents (
00122 DRECT3D& extents
00123 ) const { extents.Set(m_MinX,m_MinY,m_MinZ,m_MaxX,m_MaxY,m_MaxZ); }
00124
00126 UINT16 GetFileSourceID () const
00127 { return (m_FileSrcID); }
00128
00129 UINT16 GetHeaderSize () const
00130 { return (m_HeaderSize); }
00131
00133 double GetMaxX () const
00134 { return (m_MaxX); }
00135
00137 double GetMaxY () const
00138 { return (m_MaxY); }
00139
00141 double GetMaxZ () const
00142 { return (m_MaxZ); }
00143
00145 double GetMinX () const
00146 { return (m_MinX); }
00147
00149 double GetMinY () const
00150 { return (m_MinY); }
00151
00153 double GetMinZ () const
00154 { return (m_MinZ); }
00155
00157 UINT32 GetNumPoints () const
00158 { return (m_NumRecords); }
00159
00161 const UINT32 * GetNumPointsByReturn () const
00162 { return (m_NumRecordsByReturn); }
00163
00165 UINT32 GetNumVarRecords () const
00166 { return (m_NumVarLenRecs); }
00167
00168 UINT8 GetPointFormat () const
00169 { return (m_PointDataFormatID); }
00170
00172 const DPOINT3D& GetPointOffset () const
00173 { return (m_Offset); }
00174
00175 const WPOINT3D& GetPointPrecision () const
00176 { return (m_PointPrecision); }
00177
00178 UINT16 GetPointRecordNumFields () const
00179 { return (m_PointRecNumFields); }
00180
00182 UINT16 GetPointRecordSize () const
00183 { return (m_RecordLength); }
00184
00186 const DPOINT3D& GetPointScale () const
00187 { return (m_Scale); }
00188
00190 MISTRING GetProjectID () const;
00191
00193 void GetQuantizer (
00194 QUANTIZER_LPOINT3D& quantizer
00195 ) const;
00196
00198 MISTRING GetSoftware () const;
00199
00201 MISTRING GetSystemID () const;
00202
00204 UINT8 GetVersionMajor () const
00205 { return (m_VersionMajor); }
00206
00208 UINT8 GetVersionMinor () const
00209 { return (m_VersionMinor); }
00210
00211 bool HasPointRecordColor () const;
00212 bool HasPointRecordTime () const;
00213 bool HasPointRecordWaveform () const;
00214
00215 ERRVALUE Read (FILE_RAW& file);
00216
00218 void SetExtents (
00219 const DRECT3D& extents
00220 );
00221
00223 void SetNumPointsByReturn (
00224 const UINT32 *NumPointsByReturn
00225 );
00226
00227 void SetPointFormat (
00228 UINT8 PointFormat
00229 );
00230
00231 void SetPointScaleOffset (
00232 const DPOINT2D& Scale,
00233 const DPOINT2D& Offset
00234 ) { m_Scale.x = Scale.x; m_Scale.y = Scale.y; m_Offset.x = Offset.x; m_Offset.y = Offset.y; }
00235
00236 void SetPointScaleOffset (
00237 const DPOINT3D& Scale,
00238 const DPOINT3D& Offset
00239 ) { m_Scale = Scale; m_Offset = Offset; }
00240
00241 void SetPointScaleOffsetZ (
00242 double ScaleZ,
00243 double OffsetZ
00244 ) { m_Scale.z = ScaleZ; m_Offset.z = OffsetZ; }
00245
00246 void SetSoftware (
00247 const char *Software
00248 );
00249
00250 void SetSystemID (
00251 const char *SystemID
00252 );
00253
00254 ERRVALUE SetupNew (const FILEHDR& srchdr);
00255
00256 ERRVALUE UpdateExtents (
00257 const FILEHDR& srchdr,
00258 FILE_RAW& fileraw
00259 );
00260
00261 ERRVALUE UpdateNumPointsByReturn (
00262 const FILEHDR& srchdr,
00263 FILE_RAW& fileraw
00264 );
00265
00266 void ValidateOffsetInExtents (
00267 POINTARRAY& PointRecArray
00268 );
00269
00270 ERRVALUE Write (FILE_RAW& file);
00271
00272 ERRVALUE WriteChanges (FILE_RAW& file);
00273
00274 private:
00275 #ifndef GENERATING_DOXYGEN_OUTPUT
00276
00277
00278 char m_Signature[4];
00279 UINT16 m_FileSrcID;
00280 UINT16 m_GlobalEncoding;
00281 UINT32 m_GUID1;
00282 UINT16 m_GUID2;
00283 UINT16 m_GUID3;
00284 UINT8 m_GUID4[8];
00285 UINT8 m_VersionMajor;
00286 UINT8 m_VersionMinor;
00287 char m_SystemID[32];
00288 char m_OrigSoftware[32];
00289 UINT16 m_CreationDayOfYear;
00290 UINT16 m_CreationYear;
00291 UINT16 m_HeaderSize;
00292 UINT32 m_FileOffsetPointData;
00293 UINT32 m_NumVarLenRecs;
00294 UINT8 m_PointDataFormatID;
00295 UINT16 m_RecordLength;
00296 UINT32 m_NumRecords;
00297 UINT32 m_NumRecordsByReturn[5];
00298 DPOINT3D m_Scale;
00299 DPOINT3D m_Offset;
00300 double m_MaxX;
00301 double m_MinX;
00302 double m_MaxY;
00303 double m_MinY;
00304 double m_MaxZ;
00305 double m_MinZ;
00306 UINT64 m_OffsetWaveData;
00307
00308
00309 WPOINT3D m_PointPrecision;
00310 UINT16 m_PointRecNumFields;
00311 POINTGPSTIMETYPE m_PointTimeType;
00312 bool m_IsChanged;
00313
00314 void CalcNumFields ();
00315 void CalcPrecision ();
00316 void Clear ();
00317 void SwapBytes ();
00318 #endif
00319
00320 };
00321
00322
00326 class CLASSLIBEXPORT FILE {
00327 public:
00328
00329 enum USERID {
00330 USERID_Unknown = 0,
00331 USERID_LASF_Spec = 1,
00332 USERID_LASF_Projection = 2,
00333 USERID_MicroImages = 1172,
00334 };
00335
00336 enum POINTCLASS {
00337 POINTCLASS_ClassMask = 0x1F,
00338 POINTCLASS_Synthetic = 0x20,
00339 POINTCLASS_KeyPoint = 0x40,
00340 POINTCLASS_Deleted = 0x80
00341 };
00342
00343 enum RECORDID {
00344 RECORDID_LASF_Projection_GeoKeyDirectoryTag = 34735,
00345 RECORDID_LASF_Projection_GeoDoubleParamsTag = 34736,
00346 RECORDID_LASF_Projection_GeoAsciiParamsTag = 34737,
00347 RECORDID_LASF_Spec_ClassificationLookup = 0,
00348 RECORDID_LASF_Spec_WaveformPacketDescBase = 100,
00349 RECORDID_LASF_Spec_WaveformPacketDescMax = 355,
00350 };
00351
00352 private:
00353 #ifndef GENERATING_DOXYGEN_OUTPUT
00354 class PRIV;
00355 #endif
00356 public:
00357
00360 static bool FileTypeIsFormat (FILE_RAW& file);
00361
00363 static void FileTypeRegister ();
00364
00366 static USERID UserIdStrToEnum (const char *UserIdStr);
00367
00369 FILE ();
00370
00372 ~FILE ();
00373
00375 ERRVALUE AddPointRecord (
00376 const POINTRECORD& pointrec
00377 );
00378
00380 ERRVALUE AddVariableRecord (
00381 const VARIABLEREC& record
00382 );
00383
00385 void Close ();
00386
00388 const FILEHDR& GetHeader () const;
00389
00391 UINT32 GetPointRecordCount () const
00392 { return (GetHeader().GetNumPoints()); }
00393
00395 UINT8 GetPointFormat () const
00396 { return (GetHeader().GetPointFormat()); }
00397
00399 const WPOINT3D& GetPointPrecision () const
00400 { return (GetHeader().GetPointPrecision()); }
00401
00403 UINT16 GetPointRecordNumFields () const
00404 { return (GetHeader().GetPointRecordNumFields()); }
00405
00407 UINT16 GetPointRecordSize () const
00408 { return (GetHeader().GetPointRecordSize()); }
00409
00411 bool HasPointRecordColor () const
00412 { return (GetHeader().HasPointRecordColor()); }
00413
00415 bool HasPointRecordTime () const
00416 { return (GetHeader().HasPointRecordTime()); }
00417
00419 bool HasPointRecordWaveform () const
00420 { return (GetHeader().HasPointRecordWaveform()); }
00421
00423 bool IsOpen () const
00424 { return (m_pPriv != 0); }
00425
00427 bool IsWritable () const
00428 { return (m_IsWritable); }
00429
00431 ERRVALUE Make (
00432 const FILEPATH& filepath,
00433 const FILEHDR& header
00434 );
00435
00437 ERRVALUE Open (
00438 const FILEPATH& filepath,
00439 FILE_ACCESS access = FILE_ACCESS_Read
00440 );
00441
00443 ERRVALUE ReadCoordRefSys (
00444 SPATREF::COORDREFSYS& CoordRefSys
00445 );
00446
00449 ERRVALUE ReadPointRecords (
00450 POINTARRAY& pointrecs,
00451 UINT32 NumPoints,
00452 UINT32 FirstPointIdx = UINT32_MAX
00453 );
00454
00456 ERRVALUE ReadVarLenRecHdr (
00457 SVLRHDR& header,
00458 UINT32 RecordNum = UINT32_MAX
00459 );
00460
00462 ERRVALUE ReadVariableRecord (
00463 VARIABLEREC& variablerec,
00464 UINT32 RecordNum = UINT32_MAX
00465 );
00466
00469 ERRVALUE SetupPointArray (
00470 POINTARRAY& PointArray,
00471 UINT32 NumPoints
00472 );
00473
00475 ERRVALUE UpdateHeaderExtents (
00476 const FILEHDR& header
00477 );
00478
00480 ERRVALUE UpdateHeaderNumPointsByReturn (
00481 const FILEHDR& header
00482 );
00483
00485 ERRVALUE WriteCoordRefSys (
00486 const SPATREF::COORDREFSYS& crs
00487 );
00488
00490 ERRVALUE WritePointRecord (
00491 const POINTRECORD& pointrec,
00492 UINT32 PointIdx
00493 );
00494
00495 private:
00496 #ifndef GENERATING_DOXYGEN_OUTPUT
00497
00498 PRIV *m_pPriv;
00499 UINT32 m_PointIdxNextRead;
00500 UINT32 m_VarRecordNumNextRead;
00501 bool m_IsWritable;
00502
00503
00504
00505 FILE (const FILE&);
00506 FILE& operator= (const FILE&);
00507 #endif
00508 };
00509
00510
00511
00513 class CLASSLIBEXPORT SVLRHDR {
00514 public:
00515
00517 SVLRHDR ();
00518
00520 ERRVALUE Create (
00521 const char *UserID,
00522 UINT16 RecordID,
00523 UINT16 RecordLen,
00524 const char *Desc = 0
00525 );
00526
00528 const char* GetDescription () const
00529 { return (m_Description); }
00530
00532 UINT16 GetRecordID () const
00533 { return (m_RecordID); }
00534
00536 UINT16 GetRecordLength () const
00537 { return (m_RecordLength); }
00538
00540 FILE::USERID GetUserID () const
00541 { return (FILE::UserIdStrToEnum(m_UserIdStr)); }
00542
00544 const char* GetUserIdStr () const
00545 { return (m_UserIdStr); }
00546
00548 ERRVALUE Read (FILE_RAW& file, INT64 offset);
00549
00551 ERRVALUE Write (FILE_RAW& file) const;
00552
00553 private:
00554 #ifndef GENERATING_DOXYGEN_OUTPUT
00555 UINT16 m_Reserved;
00556 char m_UserIdStr[16];
00557 UINT16 m_RecordID;
00558 UINT16 m_RecordLength;
00559 char m_Description[32];
00560
00561 #ifdef BYTEORDER_HiLo
00562 void SwapBytes ();
00563 #endif
00564 #endif
00565 };
00566
00567
00568
00570 class CLASSLIBEXPORT EVLRHDR {
00571 public:
00572
00574 EVLRHDR ();
00575
00577 const char* GetDescription () const
00578 { return (m_Description); }
00579
00581 UINT16 GetRecordID () const
00582 { return (m_RecordID); }
00583
00585 UINT64 GetRecordLength () const
00586 { return (m_RecordLength); }
00587
00589 FILE::USERID GetUserID () const
00590 { return (FILE::UserIdStrToEnum(m_UserIdStr)); }
00591
00593 const char* GetUserIdStr () const
00594 { return (m_UserIdStr); }
00595
00597 ERRVALUE Read (FILE_RAW& file, INT64 offset);
00598
00600 ERRVALUE Write (FILE_RAW& file) const;
00601
00602 private:
00603 #ifndef GENERATING_DOXYGEN_OUTPUT
00604 UINT16 m_Reserved;
00605 char m_UserIdStr[16];
00606 UINT16 m_RecordID;
00607 UINT64 m_RecordLength;
00608 char m_Description[32];
00609
00610 #ifdef BYTEORDER_HiLo
00611 void SwapBytes ();
00612 #endif
00613 #endif
00614 };
00615
00616
00617
00619 class CLASSLIBEXPORT VARIABLEREC {
00620 public:
00622 VARIABLEREC ();
00623
00625 ~VARIABLEREC ();
00626
00628 ERRVALUE Create (
00629 const char *UserID,
00630 UINT16 RecordID,
00631 UINT16 RecordLen,
00632 const char *Desc = 0
00633 );
00634
00636 const RECORDBUFFER_LSBFIRST& GetBuffer () const
00637 { return (m_Buffer); }
00638
00640 RECORDBUFFER_LSBFIRST& GetBuffer ()
00641 { return (m_Buffer); }
00642
00644 const UINT8* GetData () const
00645 { return (m_Buffer.GetPtr()); }
00646
00648 UINT16 GetDataSize () const
00649 { return (m_Header.GetRecordLength()); }
00650
00652 const SVLRHDR& GetHeader () const
00653 { return (m_Header); }
00654
00656 SVLRHDR& GetHeader ()
00657 { return (m_Header); }
00658
00659 ERRVALUE ReadData (FILE_RAW& file);
00660
00661 private:
00662 #ifndef GENERATING_DOXYGEN_OUTPUT
00663 SVLRHDR m_Header;
00664 RECORDBUFFER_LSBFIRST m_Buffer;
00665
00666
00667 VARIABLEREC (const VARIABLEREC&);
00668 VARIABLEREC& operator= (const VARIABLEREC&);
00669 #endif
00670 };
00671
00672
00673
00675 class CLASSLIBEXPORT WAVEFORMPACKETDESC {
00676 public:
00677
00679 WAVEFORMPACKETDESC ();
00680
00682 ERRVALUE Read (FILE_RAW& file);
00683
00685 ERRVALUE Write (FILE_RAW& file) const;
00686
00687 private:
00688 #ifndef GENERATING_DOXYGEN_OUTPUT
00689 UINT8 m_BitsPerSample;
00690 UINT8 m_CompressionType;
00691 UINT32 m_NumSamples;
00692 UINT32 m_TemporalSampleSpacing;
00693 double m_DigitizerGain;
00694 double m_DigitizerOffset;
00695 #endif
00696 };
00697
00698
00699
00700 }
00701 }
00702
00703 #undef CLASSLIBEXPORT
00704
00705 #endif // INC_MI32_LIDARLASFILE_H