Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

VectorInterpolationCompressor.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Lamp : Open source game middleware
00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 //
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 //------------------------------------------------------------------------------
00019 
00020 /** @file
00021  * ベクトル補間圧縮ヘッダ
00022  * @author Junpee
00023  */
00024 
00025 #ifndef VECTOR_INTERPOLATION_COMPRESSOR_H_
00026 #define VECTOR_INTERPOLATION_COMPRESSOR_H_
00027 
00028 namespace Lamp{
00029 
00030 class VectorInterpolator;
00031 class VectorArrayInterpolator;
00032 
00033 //------------------------------------------------------------------------------
00034 /**
00035  * ベクトル補間圧縮
00036  */
00037 class VectorInterpolationCompressor{
00038 public:
00039     //--------------------------------------------------------------------------
00040     // 生成、破棄
00041     //--------------------------------------------------------------------------
00042     /**
00043      * コンストラクタ
00044      */
00045     VectorInterpolationCompressor();
00046 
00047     /**
00048      * デストラクタ
00049      */
00050     virtual ~VectorInterpolationCompressor();
00051 
00052     //--------------------------------------------------------------------------
00053     // 圧縮
00054     //--------------------------------------------------------------------------
00055     /**
00056      * 圧縮
00057      * @param source 圧縮を行うベクトル配列補間
00058      * @param tolerance 許容誤差
00059      * @return 圧縮を行ったベクトル補間
00060      */
00061     virtual VectorInterpolator* compress(
00062         VectorArrayInterpolator* source, float tolerance);
00063 
00064     //--------------------------------------------------------------------------
00065     // 圧縮結果
00066     //--------------------------------------------------------------------------
00067     /**
00068      * 許容誤差の取得
00069      * @return 許容誤差
00070      */
00071     virtual float getTolerance() const{ return tolerance_; }
00072 
00073     /**
00074      * 長さの取得
00075      * @return 長さ
00076      */
00077     virtual float getLength() const{ return length_; }
00078 
00079     //--------------------------------------------------------------------------
00080     /**
00081      * ソースキー数の取得
00082      * @return ソースキー数
00083      */
00084     virtual int getSourceKeyCount() const{ return sourceKeyCount_; }
00085 
00086     /**
00087      * ソースサイズの取得
00088      * @return ソースサイズ
00089      */
00090     virtual int getSourceSize() const{
00091         return getSourceKeyCount() * sourceKeySize_;
00092     }
00093 
00094     //--------------------------------------------------------------------------
00095     /**
00096      * 圧縮後キー数の取得
00097      * @return 圧縮後キー数
00098      */
00099     virtual int getCompressedKeyCount() const{ return compressedKeyCount_; }
00100 
00101     /**
00102      * 圧縮後サイズの取得
00103      * @return 圧縮後サイズ
00104      */
00105     virtual int getCompressedSize() const{
00106         return getCompressedKeyCount() * compressedKeySize_;
00107     }
00108 
00109     //--------------------------------------------------------------------------
00110     /**
00111      * 圧縮率の取得
00112      * @return 圧縮率
00113      */
00114     virtual float getCompressionRate() const{
00115         if(getSourceSize() == 0){ return 0.f; }
00116         return (float)getCompressedSize() / (float)getSourceSize();
00117     }
00118 
00119     /**
00120      * 結果文字列の取得
00121      * @return 結果文字列
00122      */
00123     virtual String getResultString() const;
00124 
00125 protected:
00126     //--------------------------------------------------------------------------
00127     /// 線形キー
00128     class LinearKey{
00129     friend class VectorInterpolationCompressor;
00130     private:
00131         /// 値
00132         Vector3 value_;
00133         /// 時間
00134         float time_;
00135         /// 最大誤差の二乗
00136         float squaredError_;
00137     };
00138 
00139     //--------------------------------------------------------------------------
00140     // 圧縮
00141     //--------------------------------------------------------------------------
00142     /**
00143      * 圧縮準備
00144      * @param source 圧縮を行うベクトル配列補間
00145      * @param tolerance 許容誤差
00146      */
00147     virtual void compressSetup(
00148         VectorArrayInterpolator* source, float tolerance);
00149 
00150     /**
00151      * 定数圧縮
00152      * @param source 圧縮を行うベクトル配列補間
00153      * @return 圧縮結果、失敗ならNULL
00154      */
00155     virtual VectorInterpolator* compressConstant(
00156         VectorArrayInterpolator* source);
00157 
00158     /**
00159      * 線形圧縮
00160      * @param source 圧縮を行うベクトル配列補間
00161      * @return 圧縮結果、失敗ならNULL
00162      */
00163     virtual VectorInterpolator* compressLinear(
00164         VectorArrayInterpolator* source);
00165 
00166     /**
00167      * 線形圧縮誤差の再計算
00168      * @param source 圧縮を行うベクトル配列補間
00169      * @param preKey 前のキー
00170      * @param key 再計算するキー
00171      * @param postKey 後ろのキー
00172      */
00173     virtual void recalcLinearError(VectorArrayInterpolator* source,
00174         LinearKey& preKey, LinearKey& key, LinearKey& postKey);
00175 
00176     /**
00177      * 圧縮結果の設定
00178      * @param compressedKeyCount 圧縮後キー数
00179      * @param compressedKeySize 圧縮後キーサイズ
00180      */
00181     virtual void setCompressedData(
00182         int compressedKeyCount, int compressedKeySize){
00183         compressedKeyCount_ = compressedKeyCount;
00184         compressedKeySize_ = compressedKeySize;
00185     }
00186 
00187     //--------------------------------------------------------------------------
00188     // メンバ
00189     //--------------------------------------------------------------------------
00190     /// ソースキーサイズ
00191     static const int sourceKeySize_ = sizeof(Vector3);
00192 
00193 private:
00194     //--------------------------------------------------------------------------
00195     // コピーコンストラクタの隠蔽
00196     VectorInterpolationCompressor(const VectorInterpolationCompressor& copy);
00197 
00198     // 代入コピーの隠蔽
00199     void operator =(const VectorInterpolationCompressor& copy);
00200 
00201     //--------------------------------------------------------------------------
00202     // メンバ
00203     //--------------------------------------------------------------------------
00204     // 許容誤差
00205     float tolerance_;
00206     // 長さ
00207     float length_;
00208     // ソースキー数
00209     int sourceKeyCount_;
00210     // 圧縮後キー数
00211     int compressedKeyCount_;
00212     // 圧縮後キーサイズ
00213     int compressedKeySize_;
00214 
00215 };
00216 
00217 //------------------------------------------------------------------------------
00218 } // End of namespace Lamp
00219 #endif // End of VECTOR_INTERPOLATION_COMPRESSOR_H_
00220 //------------------------------------------------------------------------------
00221 

Generated on Wed Mar 16 10:29:38 2005 for Lamp by doxygen 1.3.2