2012-02-26 24 views
0

イメージの一部を別の回転バージョンに置き換えようとしています。イメージソースは、origin_sourceがimage * thisのorign_destに終わるように表示する必要があります。また、ピクセルを置き換える前に、source_sourceの周りを回転させる必要があります。キャンバスに回転したイメージを描く

以下のコードは、Rがミラー行列の場合に機能しますが、実際に回転行列を作成すると、結果の画像が剪定されます。なにが問題ですか?

T =二重

template<class T> 
struct Matrix22 
{ 
T xx; 
T xy; 
T yx; 
T yy; 
}; 

方向

inline Matrix22<double> transformRotationCreate(const Vector2d<double>& direction) 
{ 
return (Matrix22<double>){direction.x, -direction.y, direction.y, direction.x}; 
} 

また

Vector2d<T>& operator*=(const Matrix22<T>& M) 
    { 
    x=x*M.xx + y*M.xy; 
    y=x*M.yx + y*M.yy; 
    return *this; 
    } 
正規化ベクトルである:ここ

void Image::imageApply(const Image& source,const Point& origin_dest,const Point& origin_source,const Point& direction) 
{ 
Matrix22<double> R=transformRotationCreate(direction); 
Point source_new_size=sqrt(2)*((Point){source.widthGet(),source.heightGet()}); 
Point blit_start=origin_dest; 
for(unsigned int k=0;k<source_new_size.y;k++) 
    { 
    for(unsigned int l=0;l<source_new_size.x;l++) 
     { 
     Point point_source=(Point){l,k}; 
     Point point_dest=point_source-origin_source; 
     point_dest*=R; 
     point_dest+=blit_start; 

     if(point_source.rectangleInIs((Point){0,0},(Point){source.widthGet(),source.heightGet()}) 
      &&point_dest.rectangleInIs((Point){0,0},(Point){widthGet(),heightGet()})) 
      { 
      (*this)(point_dest)=source(point_source); 
      } 
     } 
    } 
} 

が使用されるいくつかの他の関数であります

+0

あなたは 'transformRotationCreate()'のコードを投稿できますか? – user1118321

答えて

0

私はすべての

まず、行列ベクトル乗算演算子が間違っていた、それを解決:

Vector2d<T>& operator*=(const Matrix22<T>& M) 
    { 
    T x_old=x; //Need to save old x value (Stupid error but anyone does so sometimes) 
    x=x*M.xx + y*M.xy; 
    y=x_old*M.yx + y*M.yy; 
    return *this; 
    } 

このように、最終的な「回転・アンド・ペースト」ルーチンルックス:

void Image::imageApply(const Image& source,const Point& origin_dest,const Point& origin_source,const Point& direction) 
{ 
Matrix22<double> R=transformRotationCreate(direction); 
Point blit_start=origin_dest-(Point){source.sizeMaxGet(),source.sizeMaxGet()}; 
Point blit_end=origin_dest+(Point){source.sizeMaxGet(),source.sizeMaxGet()}; 

for(unsigned int k=blit_start.y;k<blit_end.y;k++) 
    { 
    for(unsigned int l=blit_start.x;l<blit_end.x;l++) 
     { 
     Point point_dest=(Point){l,k}; 
     Point point_source=R*(point_dest - origin_dest) + origin_source; 
     if(point_source.rectangleInIs((Point){0,0},(Point){source.widthGet(),source.heightGet()})) 
      { 
      float alpha_source=source(point_source).alpha; 
      (*this)(point_dest)=(1.0f-alpha_source)*(*this)(point_dest) 
           + alpha_source*source(point_source); 
      } 
     } 
    } 
} 

最後に、回転方向は間違っていましたが、それは変換におけるxy要素の単なるスワップです。

関連する問題