Point Cloud Library (PCL)  1.3.1
entropy_range_coder.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of Willow Garage, Inc. nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  *
00035  * Range Coder based on Dmitry Subbotin's carry-less implementation (http://www.compression.ru/ds/)
00036  * Added optimized symbol lookup and added implementation for static range coding (uses fixed precomputed frequency table)
00037  *
00038  * Author: Julius Kammerl (julius@kammerl.de)
00039  */
00040 
00041 #ifndef __PCL_IO_RANGECODING__
00042 #define __PCL_IO_RANGECODING__
00043 
00044 #include <map>
00045 #include <iostream>
00046 #include <vector>
00047 #include <string>
00048 #include <algorithm>
00049 #include <math.h>
00050 #include <stdio.h>
00051 #include <boost/cstdint.hpp>
00052 
00053 namespace pcl
00054 {
00055 
00056   using boost::uint8_t;
00057   using boost::uint32_t;
00058   using boost::uint64_t;
00059 
00061 
00067 
00068   class AdaptiveRangeCoder
00069   {
00070 
00071   public:
00072 
00074     AdaptiveRangeCoder ()
00075     {
00076 
00077     }
00078 
00080     virtual
00081     ~AdaptiveRangeCoder ()
00082     {
00083 
00084     }
00085 
00091     unsigned long
00092     encodeCharVectorToStream (const std::vector<char>& inputByteVector_arg, std::ostream& outputByteStream_arg);
00093 
00099     unsigned long
00100     decodeStreamToCharVector (std::istream& inputByteStream_arg, std::vector<char>& outputByteVector_arg);
00101 
00102   protected:
00103     typedef boost::uint32_t DWord; // 4 bytes
00104 
00105   private:
00108     std::vector<char> outputCharVector_;
00109 
00110   };
00111 
00113 
00119 
00120   class StaticRangeCoder
00121   {
00122 
00123   public:
00124 
00126     StaticRangeCoder ()
00127     {
00128       cFreqTable_.resize (65537);
00129     }
00130 
00132     virtual
00133     ~StaticRangeCoder ()
00134     {
00135 
00136     }
00137 
00143     unsigned long
00144     encodeIntVectorToStream (std::vector<unsigned int>& inputIntVector_arg, std::ostream& outputByterStream_arg);
00145 
00151     unsigned long
00152     decodeStreamToIntVector (std::istream& inputByteStream_arg, std::vector<unsigned int>& outputIntVector_arg);
00153 
00159     unsigned long
00160     encodeCharVectorToStream (const std::vector<char>& inputByteVector_arg, std::ostream& outputByteStream_arg);
00161 
00167     unsigned long
00168     decodeStreamToCharVector (std::istream& inputByteStream_arg, std::vector<char>& outputByteVector_arg);
00169 
00170   protected:
00171     typedef boost::uint32_t DWord; // 4 bytes
00172 
00177     inline double
00178     Log2 (double n_arg)
00179     {
00180       return log (n_arg) / log (2.0);
00181     }
00182 
00183   private:
00186     std::vector<uint64_t> cFreqTable_;
00187 
00190     std::vector<char> outputCharVector_;
00191 
00192   };
00193 }
00194 
00195 
00196 //#include "impl/entropy_range_coder.hpp"
00197 
00198 #endif
00199 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines