Proposed libLAS Class Organization
This wiki page is designed to describe the proposed organization and structure for the classes and data structures associated with libLAS. These will be exposed directly to C++ users, or will be exposed via a stable C API, as well as using SWIG to bind with Python, C#, Java, etc...
After speaking with Howard, I think we should probably gank types out of CPL in order to save on headaches relating to portability.
TBD: Exception handling -- we should probably try to make use of structured exceptions. Perhaps create a generic exception class? Also, LASPoint might need further fleshing out, this I am not certain of.
Point Structure
Each point read will be described by the following structure:
struct LASPoint { float nfX; float nfY; float nfZ; float nfIntensity; double ndGPSTime; LASClassifications nClassification; /* LASClassifications will be an enum of the ASPRS-defined classifications */ };
All points will be pre-scaled and pre-offset unless anyone objects.
Header Record Structure
All extended header record entries will be provided as the following structure:
class LASHeaderEntry { int nRecordID; int nRecordLen; char psUserID[16]; char pszDescription[32]; char *pszData; /* nRecordLen bytes */ public: LASHeaderEntry(...); ~LASHeaderEntry(); int GetRecordID() { return nRecordID; } int GetRecordLen() { return nRecordLen; } const char *GetUserID() { return psUserID; } const char *GetDescription() { return pszDescription; } const char *GetData() { return pszData; } };
Exception Class
All exceptions thrown should be of this class, or of a subclass of this class.
class LASException { protected: char *pszLongDescription; char *pszShortDescription; char *pszFunction LASError eType; /* LASError is an enum containing information as to whether the exception is fatal or not */ public: LASException(const char *pszFunction, const char *pszShort, const char *pszLong, LASError eType); ~LASException(); char *GetExceptionString(); const char *GetLongDescription(); const char *GetShortDescription(); const char *GetFunctionName(); LASError GetErrorType() { return eType; } };
As a guideline, maybe all exceptions that are thrown outside of the library should be of this class, and perhaps only subclasses of it are used internally?
Main Class
All libLAS operations would be centred around a single class, LASFile (?). The structure of this class of object is as follows:
class LASFile { FILE *fp; long long nlNextPoint; long long nlPointCount; /* ... necessary variables from header for scaling, offset, etc... */ public: LASFile(const char *pszFilename); /* read-only, fails if file does not exist? */ LASFile(const char *pszFilename, int nCreateFlags); /* read/write/update */ ~LASFile(); const LASHeaderEntry &GetHeaderRecord(int nEntryID); /* Get a specific point */ const LASPoint &GetPointByID(long long nPointID); /* for iterating over the entire file, one point at a time */ const LASPoint &GetNextPoint(); void Rewind(); /* return to zero */ void SkipTo(long long nRecords); /* skip to (nlNextPoint - 1) + nRecords */ /* for writing point records */ void WritePoint(const LASPoint &roPoint, long long nPointID); };
