MrSID Decode SDK for LiDAR Reference Manual  1.1.4.4709
Types.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_TYPES_H__
00013 #define __LIDAR_TYPES_H__
00014 
00015 #include "lidar/Base.h"
00016 #include <math.h>
00017 /* this should be a vaild C header file */
00018 
00019 LT_BEGIN_LIDAR_NAMESPACE
00020 
00021 #ifdef _WIN32
00022 /* it looks like windows.h defined min() and max() */
00023 #undef min
00024 #undef max
00025 #endif
00026 
00033 struct Range
00034 {
00035    double min;  /* -HUGE_VAL is valid */
00036    double max;  /* +HUGE_VAL is valid */
00037 
00038 #ifdef __cplusplus
00039    Range(double amin = +HUGE_VAL, double amax = -HUGE_VAL) :
00040       min(amin), max(amax) {}
00041 
00042    bool operator==(const Range &r) const
00043    {
00044       return min == r.min && max == r.max;
00045    }
00046 
00047    bool operator!=(const Range &r) const
00048    {
00049       return min != r.min || max != r.max;
00050    }
00051    
00053    bool contains(double v) const
00054    {
00055       return min <= v && v <= max;
00056    }
00057 
00059    bool overlaps(const Range &r) const
00060    {
00061       // assumes both are not empty()
00062       return min <= r.max && max >= r.min;
00063    }
00064 
00066    bool empty(void) const
00067    {
00068       return min >= max;
00069    }
00070 
00072    double length(void) const
00073    {
00074       return max - min;
00075    }
00076 
00078    void shift(double v)
00079    {
00080       min += v;
00081       max += v;
00082    }
00083 
00085    void scale(double v)
00086    {
00087       min *= v;
00088       max *= v;
00089    }
00090 
00092    void clip(const Range &r)
00093    {
00094       if(r.min > min)
00095          min = r.min;
00096       if(r.max < max)
00097          max = r.max;
00098    }
00099 
00101    void grow(const Range &r)
00102    {
00103       if(r.min < min)
00104          min = r.min;
00105       if(r.max > max)
00106          max = r.max;
00107    }
00108 
00110    void grow(double v)
00111    {
00112       if(v < min)
00113          min = v;
00114       if(v > max)
00115          max = v;
00116    }
00117 #endif
00118 };
00119 typedef struct Range Range;
00120 
00127 struct Bounds
00128 {
00129    Range x;
00130    Range y;
00131    Range z;
00132 
00133 #ifdef __cplusplus
00134 
00135    static const Bounds &Huge(void);
00136 
00137    Bounds(double xmin = +HUGE_VAL, double xmax = -HUGE_VAL,
00138           double ymin = +HUGE_VAL, double ymax = -HUGE_VAL,
00139           double zmin = +HUGE_VAL, double zmax = -HUGE_VAL) :
00140       x(xmin, xmax), y(ymin, ymax), z(zmin, zmax) {}
00141 
00142    Bounds(const Range &ax, const Range &ay, const Range &az) :
00143       x(ax), y(ay), z(az) {}
00144 
00145    bool operator==(const Bounds &b) const
00146    {
00147       return x == b.x && y == b.y && z == b.z;
00148    }
00149 
00150    bool operator!=(const Bounds &b) const
00151    {
00152       return x != b.x || y != b.y || z != b.z;
00153    }
00154 
00156    bool contains(double ax, double ay, double az) const
00157    {
00158       return x.contains(ax) && y.contains(ay) && z.contains(az);
00159    }
00160 
00162    bool overlaps(const Bounds &b) const
00163    {
00164       return x.overlaps(b.x) && y.overlaps(b.y) && z.overlaps(b.z);
00165    }
00166 
00168    bool empty(void) const
00169    {
00170       return x.empty() || y.empty() || z.empty();
00171    }
00172 
00174    double volume(void) const
00175    {
00176       return x.length() * y.length() * z.length();
00177    }
00178 
00180    void shift(double dx, double dy, double dz)
00181    {
00182       x.shift(dx);
00183       y.shift(dy);
00184       z.shift(dz);
00185    }
00186 
00188    void scale(double dx, double dy, double dz)
00189    {
00190       x.scale(dx);
00191       y.scale(dy);
00192       z.scale(dz);
00193    }
00194 
00196    void clip(const Bounds &r)
00197    {
00198       x.clip(r.x);
00199       y.clip(r.y);
00200       z.clip(r.z);
00201    }
00202 
00204    void grow(const Bounds &r)
00205    {
00206       x.grow(r.x);
00207       y.grow(r.y);
00208       z.grow(r.z);
00209    }
00210 
00212    void grow(double ax, double ay, double az)
00213    {
00214       x.grow(ax);
00215       y.grow(ay);
00216       z.grow(az);
00217    }
00218    
00227    static double overlapFraction(const Bounds &r1, const Bounds &r2);
00228 #endif
00229 };
00230 typedef struct Bounds Bounds;
00231 
00232 LT_END_LIDAR_NAMESPACE
00233 #endif /* __LIDAR_TYPES_H__ */