当前位置: 首页>>代码示例>>C++>>正文


C++ Matrix4d::setOnes方法代码示例

本文整理汇总了C++中eigen::Matrix4d::setOnes方法的典型用法代码示例。如果您正苦于以下问题:C++ Matrix4d::setOnes方法的具体用法?C++ Matrix4d::setOnes怎么用?C++ Matrix4d::setOnes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在eigen::Matrix4d的用法示例。


在下文中一共展示了Matrix4d::setOnes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: result

Eigen::VectorXd interp2lin( const Eigen::Map<Eigen::VectorXd> & xin, const Eigen::Map<Eigen::VectorXd> & yin, const Eigen::Map<Eigen::VectorXd> & zin, const Eigen::Map<Eigen::VectorXd> & xou, const Eigen::Map<Eigen::VectorXd> & you){ 

  // Setting up initial values

  const unsigned int nXGrid = xin.size();
  const unsigned int nYGrid = yin.size();
  const unsigned int nKnownPoints = nXGrid * nYGrid;
  const unsigned int nUnknownPoints = xou.size();
 
  Eigen::VectorXd result(nUnknownPoints);

  // Preliminary checks

  if ( nXGrid != nYGrid ){
    Rcpp::stop("Input Y-grid does not have the same number of points as Input X-grid.");
  } else if ( nKnownPoints != zin.size() ) {  
    Rcpp::stop("Input Z-grid does not have the same number of points as the product of #Input Y-grid times #Input X-grid.");
  } else if ( nUnknownPoints != you.size() ){
    Rcpp::stop("Output Y-grid does not have the same number of points as Output X-grid.");
  } else if ( xin.minCoeff() >  xou.minCoeff() ){
    Rcpp::warning("Output X-grid  is outside the lower range of the input X-grid.");
  } else if ( yin.minCoeff() >  you.minCoeff() ){
    Rcpp::warning("Output X-grid  is outside the lower range of the input X-grid.");
  } else if ( xin.maxCoeff() <  xou.maxCoeff() ){
    Rcpp::warning("Output X-grid  is outside the upper ragne of the input X-grid.");
  } else if ( yin.maxCoeff() <  you.maxCoeff() ){
    Rcpp::warning("Output X-grid  is outside the upper range of the input X-grid.");
  } 
  
 
  const double ymin = yin.minCoeff();
  const double xmin = xin.minCoeff();
  const double ymax = yin.maxCoeff();
  const double xmax = xin.maxCoeff();

  // The actual interpolation routine
  // Check: https://en.wikipedia.org/wiki/Bilinear_interpolation#Alternative_algorithm
  // for a quick reference

  Eigen::RowVector4d fq;
  Eigen::Vector2d xa;
  Eigen::Vector2d ya;
  Eigen::Vector4d za;
  Eigen::Matrix4d A;
  // Column 1
  A.setOnes(); 

  for (unsigned int u = 0; u !=nUnknownPoints; ++u){ 
     
    if ( (xmax  < xou(u))  || (ymax <  you(u)) || // If x/you(u) is above the upper values of xin/yin 
         (xmin  > xou(u))  || (ymin >  you(u)) ){ // If x/you(u) is below the lower values of xin/yin
      result(u) = std::numeric_limits<double>::quiet_NaN() ;
      
    } else {
      // Find the appropriate x coordinates/save them in xa (2-by-1)
      // Get iterator pointing to the first element which is not less than xou(u)
      const double* x1 = std::lower_bound(&xin[0], &xin[nXGrid], xou(u));
      const double* y1 = std::lower_bound(&yin[0], &yin[nYGrid], you(u));

      xa(1) = *x1;
      ya(1) = *y1;

      const double* x1p = std::find(&xin[0], &xin[nXGrid], xa(1));
      const double* y1p = std::find(&yin[0], &yin[nXGrid], ya(1));
      const double* x0p;
      const double* y0p;

     
      if( y1 != &yin[0]){
        ya(0) = *--y1;
        y0p = y1p - 1;
      } else {
        ya(0) = ya(1);
        y0p = y1p;
      }
      if( x1 != &xin[0]){
        xa(0) = *--x1;
        x0p = x1p - 1;
      } else {
        xa(0) = xa(1);
        x0p = x1p;
      }
     

//      const double* x1p = std::find(&xin[0], &xin[nXGrid], xa(1));
//      const double* y1p = std::find(&yin[0], &yin[nXGrid], ya(1));
//      const double* x0p = x1p - 1;
//      const double* y0p = y1p - 1;

      za(0) = zin( (x0p -&xin[0]) * nXGrid + (y0p -&yin[0]) );
      za(1) = zin( (x0p -&xin[0]) * nXGrid + (y1p -&yin[0]) );
      za(2) = zin( (x1p -&xin[0]) * nXGrid + (y0p -&yin[0]) );
      za(3) = zin( (x1p -&xin[0]) * nXGrid + (y1p -&yin[0]) );

      // Column 2  
      A(0,1) = xa(0);   A(1,1) = xa(0);
      A(2,1) = xa(1);   A(3,1) = xa(1);
      // Column 3
      A(0,2) = ya(0);   A(1,2) = ya(1);
      A(2,2) = ya(0);   A(3,2) = ya(1);
//.........这里部分代码省略.........
开发者ID:Chunjui,项目名称:tPACE,代码行数:101,代码来源:interp2lin.cpp


注:本文中的eigen::Matrix4d::setOnes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。