MrSID Decode SDK for LiDAR Reference Manual  1.1.3.4427
PointData.h
Go to the documentation of this file.
00001 /* //////////////////////////////////////////////////////////////////////////
00002 //                                                                         //
00003 // This code is Copyright (c) 2008-2010 LizardTech, Inc, 1008 Western      //
00004 // Avenue, Suite 200, Seattle, WA 98104.  Unauthorized use or distribution //
00005 // prohibited.  Access to and use of this code is permitted only under     //
00006 // license from LizardTech, Inc.  Portions of the code are protected by    //
00007 // US and foreign patents and other filings. All Rights Reserved.          //
00008 //                                                                         //
00010 /* PUBLIC */
00011 
00012 #ifndef __LIDAR_POINT_DATA_H__
00013 #define __LIDAR_POINT_DATA_H__
00014 
00015 #include "lidar/Base.h"
00016 
00017 LT_BEGIN_LIDAR_NAMESPACE
00018 class ChannelData;
00019 class PointData;
00020 
00026 enum DataType
00027 {
00028    // don't change the values they are serialized
00029    // all values must be less then 1 << 16
00030 
00031    DATATYPE_INVALID = 0x0000,
00032 
00033    DATATYPE_UINT8  = 0x0100,
00034    DATATYPE_SINT8  = 0x0101,
00035    DATATYPE_UINT16 = 0x0200,
00036    DATATYPE_SINT16 = 0x0201,
00037    DATATYPE_UINT32 = 0x0400,
00038    DATATYPE_SINT32 = 0x0401,
00039    DATATYPE_UINT64 = 0x0800,
00040    DATATYPE_SINT64 = 0x0801,
00041 
00042    DATATYPE_FLOAT32 = 0x0403,
00043    DATATYPE_FLOAT64 = 0x0803
00044 };
00045 
00049 struct DataTypeUtils
00050 {
00058    static inline bool isSigned(DataType dt)    { return (dt & 0x1) == 0x1; }
00059    
00067    static inline bool isFloat(DataType dt)     { return (dt & 0x2) == 0x2; }
00068    
00077    static inline int byteWidth(DataType dt)    { return (dt >> 8) & 0xFF; }
00078    
00087    static const char *toString(DataType dt);
00088    static DataType toDataType(const char *str);
00089 };
00090 
00094 #define CHANNEL_NAME_X               "X"
00095 #define CHANNEL_NAME_Y               "Y"
00096 #define CHANNEL_NAME_Z               "Z"
00097 #define CHANNEL_NAME_Intensity       "Intensity"
00098 #define CHANNEL_NAME_ReturnNum       "ReturnNum"
00099 #define CHANNEL_NAME_NumReturns      "NumReturns"
00100 #define CHANNEL_NAME_ScanDir         "ScanDir"
00101 #define CHANNEL_NAME_EdgeFlightLine  "EdgeFlightLine"
00102 #define CHANNEL_NAME_ClassId         "ClassId"
00103 #define CHANNEL_NAME_ScanAngle       "ScanAngle"
00104 #define CHANNEL_NAME_UserData        "UserData"
00105 #define CHANNEL_NAME_SourceId        "SourceId"
00106 #define CHANNEL_NAME_GPSTime_Week    "GPSTime"
00107 #define CHANNEL_NAME_GPSTime_Adjusted  "GPSTime_Adjusted"
00108 #define CHANNEL_NAME_Red             "Red"
00109 #define CHANNEL_NAME_Green           "Green"
00110 #define CHANNEL_NAME_Blue            "Blue"
00111 
00112 // Used with the TXTPointReader to skip a field
00113 #define CHANNEL_NAME_Skip            "@Skip"
00114 
00115 
00116 
00123 class ChannelInfo
00124 {
00125    SIMPLE_OBJECT(ChannelInfo);
00126 public:
00127    ~ChannelInfo(void);
00128    ChannelInfo(void);
00129 
00130    void init(const char *name, DataType datatype, int bits, double quantization = 0);
00131    void init(const ChannelInfo &info);
00132 
00138    const char *getName(void) const;
00139 
00145    DataType getDataType(void) const;
00146    
00154    size_t getBits(void) const;
00155 
00161    double getQuantization(void) const;
00162 
00163    bool operator==(const ChannelInfo &rhs) const;
00164    bool operator!=(const ChannelInfo &rhs) const { return !operator==(rhs); }
00165 
00166 protected:
00167    char *m_name;
00168    DataType m_datatype;
00169    int m_bits;
00170    double m_quantization;
00171 };
00172 
00181 class PointInfo
00182 {
00183    SIMPLE_OBJECT(PointInfo);
00184 public:
00185    ~PointInfo(void);
00186    PointInfo(void);
00187    
00188    void init(size_t numChannels);
00189    void init(const PointInfo &pointInfo);
00190    void init(const PointData &pointData);
00191    
00197    size_t getNumChannels(void) const;
00198    
00207    const ChannelInfo &getChannel(size_t idx) const;
00208 
00217    ChannelInfo &getChannel(size_t idx);
00218    
00227    bool hasChannel(const char *name) const;
00228    
00237    const ChannelInfo *getChannel(const char *name) const;
00238 
00247    ChannelInfo *getChannel(const char *name);
00248    
00257    size_t getChannelIndex(const char *name) const;
00258    
00265    bool hasValidXYZ(void) const;
00266 
00267 
00268    bool operator==(const PointInfo &rhs) const;
00269    bool operator!=(const PointInfo &rhs) const { return !operator==(rhs); }
00270 
00271 protected:
00272    size_t m_numChannels;
00273    ChannelInfo *m_channel;
00274 };
00275 
00279 class ChannelData : public ChannelInfo
00280 {
00281    DISABLE_COPY(ChannelData);
00282 public:
00283    ~ChannelData(void);
00284    ChannelData(void);
00285 
00286    void init(const ChannelInfo &info, size_t numSamples);
00287 
00294    size_t getNumSamples(void) const;
00295 
00304    const void *getData(void) const;
00305    
00314    void *getData(void);
00315 
00329    static void copy(ChannelData &dst, size_t dstOffset,
00330                     const ChannelData &src, size_t srcOffset,
00331                     size_t length);
00332    
00348    static void convert(ChannelData &dst, size_t dstOffset,
00349                        const ChannelData &src, size_t srcOffset,
00350                        size_t length);
00351 
00371    static void convert(ChannelData &dst, size_t dstOffset,
00372                        const ChannelData &src, size_t srcOffset,
00373                        double offset, double scale,
00374                        size_t length);
00375 
00385    void setDataType(DataType datatype);
00386 
00393    void resize(size_t newNumSamples);
00394 
00396    void setOffset(size_t offset);
00397 protected:
00398    size_t m_numSamples;
00399    size_t m_offset;
00400    void *m_data;
00401 };
00402 
00411 class PointData
00412 {
00413    SIMPLE_OBJECT(PointData);
00414 public:
00415    ~PointData(void);
00416    PointData(void);
00417 
00418    void init(const PointInfo &pointInfo, size_t numSamples);
00419 
00425    size_t getNumChannels(void) const;
00426 
00433    size_t getNumSamples(void) const;
00434 
00443    const ChannelData &getChannel(size_t idx) const;
00444    
00453    ChannelData &getChannel(size_t idx);
00454 
00463    bool hasChannel(const char *name) const;
00464 
00473    const ChannelData *getChannel(const char *name) const;
00474    
00483    ChannelData *getChannel(const char *name);
00484 
00490    const double *getX(void) const;
00491    
00497    double *getX(void);
00498    
00504    const double *getY(void) const;
00505    
00511    double *getY(void);
00512    
00518    const double *getZ(void) const;
00519    
00525    double *getZ(void);
00526 
00540    static void copy(PointData &dst, size_t dstOffset,
00541                     const PointData &src, size_t srcOffset,
00542                     size_t length);
00543 
00557    static void merge(PointData &dst, size_t dstNumPoints,
00558                      const PointData &src, size_t srcNumPoints);
00559 
00566    void resize(size_t newNumSamples);
00567 
00569    void setOffset(size_t offset);
00570 protected:
00571    size_t m_numChannels;
00572    ChannelData *m_channel;
00573    size_t m_numSamples;
00574    size_t m_offset;
00575 
00576    // just pointers into m_channel[]
00577    double *m_x;
00578    double *m_y;
00579    double *m_z;
00580 };
00581 
00582 LT_END_LIDAR_NAMESPACE
00583 #endif /* __LIDAR_POINT_DATA_H__ */