1 /*
2 ===============================================================================
3 
4   FILE:  lasquantizer.hpp
5 
6   CONTENTS:
7 
8     This class assists with converting between a fixed-point notation based on
9     scaled integers plus large offsets and standard double-precision floating-
10     point numbers. For efficieny in storage and uniform precision (far from the
11     origin) the LAS format stores all point coordinates as scaled and offset
12     32-bit integers.
13 
14   PROGRAMMERS:
15 
16     martin.isenburg@rapidlasso.com  -  http://rapidlasso.com
17 
18   COPYRIGHT:
19 
20     (c) 2007-2015, martin isenburg, rapidlasso - fast tools to catch reality
21 
22     This is free software; you can redistribute and/or modify it under the
23     terms of the GNU Lesser General Licence as published by the Free Software
24     Foundation. See the LICENSE.txt file for more information.
25 
26     This software is distributed WITHOUT ANY WARRANTY and without even the
27     implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 
29   CHANGE HISTORY:
30 
31     19 July 2015 -- created after FOSS4GE in the train back from Lake Como
32 
33 ===============================================================================
34 */
35 #ifndef LAS_QUANTIZER_HPP
36 #define LAS_QUANTIZER_HPP
37 
38 #include "mydefs.hpp"
39 
40 class LASquantizer
41 {
42 public:
43   F64 x_scale_factor;
44   F64 y_scale_factor;
45   F64 z_scale_factor;
46   F64 x_offset;
47   F64 y_offset;
48   F64 z_offset;
49 
get_x(const I32 X) const50   inline F64 get_x(const I32 X) const { return x_scale_factor*X+x_offset; };
get_y(const I32 Y) const51   inline F64 get_y(const I32 Y) const { return y_scale_factor*Y+y_offset; };
get_z(const I32 Z) const52   inline F64 get_z(const I32 Z) const { return z_scale_factor*Z+z_offset; };
53 
get_X(const F64 x) const54   inline I64 get_X(const F64 x) const { if (x >= x_offset) return (I64)(((x-x_offset)/x_scale_factor)+0.5); else return (I64)(((x-x_offset)/x_scale_factor)-0.5); };
get_Y(const F64 y) const55   inline I64 get_Y(const F64 y) const { if (y >= y_offset) return (I64)(((y-y_offset)/y_scale_factor)+0.5); else return (I64)(((y-y_offset)/y_scale_factor)-0.5); };
get_Z(const F64 z) const56   inline I64 get_Z(const F64 z) const { if (z >= z_offset) return (I64)(((z-z_offset)/z_scale_factor)+0.5); else return (I64)(((z-z_offset)/z_scale_factor)-0.5); };
57 
LASquantizer()58   LASquantizer()
59   {
60     x_scale_factor = 0.01;
61     y_scale_factor = 0.01;
62     z_scale_factor = 0.01;
63     x_offset = 0.0;
64     y_offset = 0.0;
65     z_offset = 0.0;
66   };
67 
operator =(const LASquantizer & quantizer)68   LASquantizer & operator=(const LASquantizer & quantizer)
69   {
70     this->x_scale_factor = quantizer.x_scale_factor;
71     this->y_scale_factor = quantizer.y_scale_factor;
72     this->z_scale_factor = quantizer.z_scale_factor;
73     this->x_offset = quantizer.x_offset;
74     this->y_offset = quantizer.y_offset;
75     this->z_offset = quantizer.z_offset;
76     return *this;
77   };
78 };
79 
80 #endif
81