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

RotationInterpolationCompressor.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 ROTATION_INTERPOLATION_COMPRESSOR_H_
00026 #define ROTATION_INTERPOLATION_COMPRESSOR_H_
00027 
00028 namespace Lamp{
00029 
00030 class RotationInterpolator;
00031 class EulerArrayInterpolator;
00032 class QuaternionArrayInterpolator;
00033 
00034 //------------------------------------------------------------------------------
00035 /**
00036  * 回転補間圧縮
00037  */
00038 class RotationInterpolationCompressor{
00039 public:
00040     //--------------------------------------------------------------------------
00041     // 生成、破棄
00042     //--------------------------------------------------------------------------
00043     /**
00044      * コンストラクタ
00045      */
00046     RotationInterpolationCompressor();
00047 
00048     /**
00049      * デストラクタ
00050      */
00051     virtual ~RotationInterpolationCompressor();
00052 
00053     //--------------------------------------------------------------------------
00054     // 圧縮
00055     //--------------------------------------------------------------------------
00056     /**
00057      * 圧縮
00058      * @param source 圧縮を行うオイラー回転配列補間
00059      * @param tolerance 許容誤差の角度をラジアンで指定する
00060      * @return 圧縮を行った回転補間
00061      */
00062     virtual RotationInterpolator* compress(
00063         EulerArrayInterpolator* source, float tolerance);
00064 
00065     //--------------------------------------------------------------------------
00066     /**
00067      * 圧縮
00068      * @param source 圧縮を行う四元数回転配列補間
00069      * @param tolerance 許容誤差の角度をラジアンで指定する
00070      * @return 圧縮を行った回転補間
00071      */
00072     virtual RotationInterpolator* compress(
00073         QuaternionArrayInterpolator* source, float tolerance);
00074 
00075     //--------------------------------------------------------------------------
00076     // 圧縮結果
00077     //--------------------------------------------------------------------------
00078     /**
00079      * 許容誤差の取得
00080      * @return 許容誤差
00081      */
00082     virtual float getTolerance() const{ return tolerance_; }
00083 
00084     /**
00085      * 長さの取得
00086      * @return 長さ
00087      */
00088     virtual float getLength() const{ return length_; }
00089 
00090     //--------------------------------------------------------------------------
00091     /**
00092      * ソースキー数の取得
00093      * @return ソースキー数
00094      */
00095     virtual int getSourceKeyCount() const{ return sourceKeyCount_; }
00096 
00097     /**
00098      * ソースサイズの取得
00099      * @return ソースサイズ
00100      */
00101     virtual int getSourceSize() const{
00102         return getSourceKeyCount() * sourceKeySize_;
00103     }
00104 
00105     //--------------------------------------------------------------------------
00106     /**
00107      * 圧縮後キー数の取得
00108      * @return 圧縮後キー数
00109      */
00110     virtual int getCompressedKeyCount() const{ return compressedKeyCount_; }
00111 
00112     /**
00113      * 圧縮後サイズの取得
00114      * @return 圧縮後サイズ
00115      */
00116     virtual int getCompressedSize() const{
00117         return getCompressedKeyCount() * compressedKeySize_;
00118     }
00119 
00120     //--------------------------------------------------------------------------
00121     /**
00122      * 圧縮率の取得
00123      * @return 圧縮率
00124      */
00125     virtual float getCompressionRate() const{
00126         if(getSourceSize() == 0){ return 0.f; }
00127         return (float)getCompressedSize() / (float)getSourceSize();
00128     }
00129 
00130     /**
00131      * 結果文字列の取得
00132      * @return 結果文字列
00133      */
00134     virtual String getResultString() const;
00135 
00136 protected:
00137     //--------------------------------------------------------------------------
00138     /// 線形キー
00139     class LinearKey{
00140     friend class RotationInterpolationCompressor;
00141     private:
00142         /// 値
00143         Quaternion value_;
00144         /// 時間
00145         float time_;
00146         /// 最大誤差のコサイン
00147         float errorCos_;
00148     };
00149 
00150     //--------------------------------------------------------------------------
00151     // 圧縮
00152     //--------------------------------------------------------------------------
00153     /**
00154      * 圧縮準備
00155      * @param source 圧縮を行う四元数回転配列補間
00156      * @param tolerance 許容誤差
00157      */
00158     virtual void compressSetup(
00159         QuaternionArrayInterpolator* source, float tolerance);
00160 
00161     /**
00162      * 定数圧縮
00163      * @param source 圧縮を行う四元数回転配列補間
00164      * @return 圧縮結果、失敗ならNULL
00165      */
00166     virtual RotationInterpolator* compressConstant(
00167         QuaternionArrayInterpolator* source);
00168 
00169     /**
00170      * 線形圧縮
00171      * @param source 圧縮を行う四元数回転配列補間
00172      * @return 圧縮結果、失敗ならNULL
00173      */
00174     virtual RotationInterpolator* compressLinear(
00175         QuaternionArrayInterpolator* source);
00176 
00177     /**
00178      * 線形圧縮誤差の再計算
00179      * @param source 圧縮を行う四元数回転配列補間
00180      * @param preKey 前のキー
00181      * @param key 再計算するキー
00182      * @param postKey 後ろのキー
00183      */
00184     virtual void recalcLinearError(QuaternionArrayInterpolator* source,
00185         LinearKey& preKey, LinearKey& key, LinearKey& postKey);
00186 
00187     /**
00188      * 圧縮結果の設定
00189      * @param compressedKeyCount 圧縮後キー数
00190      * @param compressedKeySize 圧縮後キーサイズ
00191      */
00192     virtual void setCompressedData(
00193         int compressedKeyCount, int compressedKeySize){
00194         compressedKeyCount_ = compressedKeyCount;
00195         compressedKeySize_ = compressedKeySize;
00196     }
00197 
00198     //--------------------------------------------------------------------------
00199     // メンバ
00200     //--------------------------------------------------------------------------
00201     /// ソースキーサイズ
00202     static const int sourceKeySize_ = sizeof(Quaternion);
00203 
00204 private:
00205     //--------------------------------------------------------------------------
00206     // コピーコンストラクタの隠蔽
00207     RotationInterpolationCompressor(const RotationInterpolationCompressor& copy);
00208 
00209     // 代入コピーの隠蔽
00210     void operator =(const RotationInterpolationCompressor& copy);
00211 
00212     //--------------------------------------------------------------------------
00213     // メンバ
00214     //--------------------------------------------------------------------------
00215     // 許容誤差
00216     float tolerance_;
00217     // 長さ
00218     float length_;
00219     // ソースキー数
00220     int sourceKeyCount_;
00221     // 圧縮後キー数
00222     int compressedKeyCount_;
00223     // 圧縮後キーサイズ
00224     int compressedKeySize_;
00225 
00226 };
00227 
00228 //------------------------------------------------------------------------------
00229 } // End of namespace Lamp
00230 #endif // End of ROTATION_INTERPOLATION_COMPRESSOR_H_
00231 //------------------------------------------------------------------------------
00232 

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