Ejemplo n.º 1
0
void xForm::SetCameraPosition(const xVec3& origin, const xMat3& axis)
{
  xMat4 m(axis, origin); // camera to world space
  m.InverseSelf(); // world to camera space
  D3DXMATRIX mat = dxMat(m), out, out2;

  D3DXMatrixRotationZ(&out, DEG2RAD(90));
  D3DXMatrixMultiply(&out2, &mat, &out); // result in out2

  D3DXMatrixRotationX(&out, DEG2RAD(-90));
  D3DXMatrixMultiply(&mat, &out2, &out); // result in mat

  m_pd3dDevice->SetTransform(D3DTS_VIEW, &mat);
}
bool IPLGradientOperator::cubicSpline(IPLImage* image)
{
   static float k1f[4][4] = {{-0.5,1.5,-1.5,0.5},{1.0,-2.5,2.0,-0.5},{-0.5,0,0.5,0},{0,1.0,0,0}};
   static cv::Mat k1(4,4,CV_32FC1,k1f);
   static float k2f[4][4] = {{-0.5,1.0,-0.5,0},{1.5,-2.5,0,1},{-1.5,2.0,0.5,0},{0.5,-0.5,0,0}};
   static cv::Mat k2(4,4,CV_32FC1,k2f);
 
   int width = image->width();
   int height = image->height();
   int progress = 0;
   int maxProgress = height*width;
 
   notifyProgressEventHandler(-1);

   cv::Mat input = image->toCvMat();
   cv::Mat coeffFull = cv::Mat::zeros(height,width,CV_32FC1);
   cv::Mat coeff = cv::Mat::zeros(height,width,CV_32FC1);

   for (int i=0;i<width;i++)
      for (int j=0;j<height;j++)
         coeffFull.at<cv::Vec<float,1>>(i,j)[0] = static_cast<float>(input.at<cv::Vec<unsigned char,4>>(i,j).val[0]) * FACTOR_TO_FLOAT ;
 
   float dx,dy,x3,x2,y3,y2,xf,yf;
   
   for (int x=1; x < width - 2; x++){
     for (int y = 1; y < height - 2; y++){
       // progress
       notifyProgressEventHandler(100*progress++/maxProgress);
 
       coeffFull(cv::Range(y-1,y+3),cv::Range(x-1,x+3)).copyTo(coeff);

//std::cout << coeff << std::endl;

       coeff = k1*coeff;
       coeff = coeff*k2;
       xf = static_cast<float>(x)/static_cast<float>(width);
       x2 = xf*xf;
       x3 = x2*xf;
       yf = static_cast<float>(y)/static_cast<float>(height);
       y2 = yf*yf;
       y3 = y2*yf;
       float dyMatf[4][4] = {{3.f*y2*x3,3.f*y2*x2,3.f*y2*xf,3.f*y2},
		{2.f*yf*x3,2.f*yf*x2,2.f*yf*xf,2.f*yf},
		{x3,x2,xf,1.f},
		{0.f,0.f,0.f,0.f}};
       float dxMatf[4][4] = {{3.f*x2*y3,2.f*xf*y3,y3,0.f},
		{3.f*x2*y2,2.f*xf*y2,y2,0.f},
		{3.f*x2*yf,2.f*xf*yf,yf,0.f},
		{3.f*x2,2.f*xf,1.f,0.f}};
       cv::Mat dxMat(4,4,CV_32FC1,dxMatf);
       cv::Mat dyMat(4,4,CV_32FC1,dyMatf);
       dx = coeff.dot(dxMat);
       dy = coeff.dot(dyMat);

       double phase = (dx!=0.0 || dy!=0.0 )? atan2( -dy, dx ) : 0.0;

        while( phase > 2.0 * PI ) phase -= 2.0 * PI;
        while( phase < 0.0 ) phase += 2.0 * PI;

        // phase 0.0-1.0
        phase /= 2 * PI;

        _result->phase(x,y) = phase;
        _result->magnitude(x,y) = sqrt(dx*dx + dy*dy);
   }
  }

  return true;
}