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


C++ MatrixXd::setConstant方法代码示例

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


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

示例1: simulatetopographyGrid

/**
 * Generates an artificial topographyGrid of size numRows x numCols if no
 * topographic data is available.  Results are dumped into topographyGrid.
 * @param topographyGrid A pointer to a zero-initialized Grid of size
 * numRows x numCols.
 * @param numRows The desired number of non-border rows in the resulting matrix.
 * @param numCols The desired number of non-border cols in the resulting matrix.
 */
void simulatetopographyGrid(Grid* topographyGrid, int numRows, int numCols) {
    Eigen::VectorXd refx = refx.LinSpaced(numCols, -2*M_PI, 2*M_PI);
    Eigen::VectorXd refy = refx.LinSpaced(numRows, -2*M_PI, 2*M_PI);
    Eigen::MatrixXd X = refx.replicate(1, numRows);
    X.transposeInPlace();
    Eigen::MatrixXd Y = refy.replicate(1, numCols);

    // Eigen can only deal with two matrices at a time,
    // so split the computation:
    // topographyGrid = sin(X) * sin(Y) * abs(X) * abs(Y) -pi
    Eigen::MatrixXd absXY = X.cwiseAbs().cwiseProduct(Y.cwiseAbs());
    Eigen::MatrixXd sins = X.array().sin().cwiseProduct(Y.array().sin());
    Eigen::MatrixXd temp;
    temp.resize(numRows, numCols);
    temp = absXY.cwiseProduct(sins);

    // All this work to create a matrix of pi...
    Eigen::MatrixXd pi;
    pi.resize(numRows, numCols);
    pi.setConstant(M_PI);
    temp = temp - pi;
    // And the final result.
    topographyGrid->data.block(border, border, numRows, numCols) =
                              temp.block(0, 0, numRows, numCols);
    // Ignore positive values.
    topographyGrid->data =
            topographyGrid->data.unaryExpr(std::ptr_fun(validateDepth));
    topographyGrid->clearNA();
}
开发者ID:gregorylburgess,项目名称:acoustic-deploy_C,代码行数:37,代码来源:Bathy.cpp

示例2: construct_contrast_matrix

void Model::construct_contrast_matrix(Eigen::MatrixXd &C) {

  if (n_alternatives > 1) {
    C.setConstant(-1.0 / (n_alternatives - 1.0));
  } else {
    C.setZero();
  }

  for (unsigned int i = 0; i < n_alternatives; i++) {
    C(i, i) = 1.0;
  }
}
开发者ID:tkngch,项目名称:choice-models,代码行数:12,代码来源:mdft.cpp

示例3: colorEdgeMeshFaces

void colorEdgeMeshFaces(const Eigen::VectorXd &values,
                        const double &minimum,
                        const double &maximum,
                        Eigen::MatrixXd &C)
{
  C.setConstant(Fbs.rows(),3,1);

  Eigen::MatrixXd colors;
  igl::jet(values, minimum, maximum, colors);

  for (int ei = 0; ei<E.rows(); ++ei)
  {
    const Eigen::RowVector3d &this_color = colors.row(ei);
    int f0 = E2F(ei,0);
    int f1 = E2F(ei,1);
    if(f0 != -1)
    {
      int i0 = -1;
      for (int k = 0; k<3; k++)
        if (F2E(f0,k)== ei)
        {
          i0 = k;
          break;
        }
      C.row(3*f0+i0) = this_color;
    }
    if(f1 != -1)
    {
      int i1 = -1;
      for (int k = 0; k<3; k++)
        if (F2E(f1,k)== ei)
        {
          i1 = k;
          break;
        }
      C.row(3*f1+i1) = this_color;
    }
  }

}
开发者ID:Codermay,项目名称:libigl,代码行数:40,代码来源:main.cpp

示例4: display

void display()
{
  using namespace Eigen;
  using namespace igl;
  using namespace std;

  if(!trackball_on && tot_num_samples < 10000)
  {
    if(S.size() == 0)
    {
      S.resize(V.rows());
      S.setZero();
    }
    VectorXd Si;
    const int num_samples = 20;
    ambient_occlusion(ei,V,N,num_samples,Si);
    S *= (double)tot_num_samples;
    S += Si*(double)num_samples;
    tot_num_samples += num_samples;
    S /= (double)tot_num_samples;
  }

  // Convert to 1-intensity
  C.conservativeResize(S.rows(),3);
  if(ao_on)
  {
    C<<S,S,S;
    C.array() = (1.0-ao_factor*C.array());
  }else
  {
    C.setConstant(1.0);
  }
  if(ao_normalize)
  {
    C.col(0) *= ((double)C.rows())/C.col(0).sum();
    C.col(1) *= ((double)C.rows())/C.col(1).sum();
    C.col(2) *= ((double)C.rows())/C.col(2).sum();
  }
  C.col(0) *= color(0);
  C.col(1) *= color(1);
  C.col(2) *= color(2);

  glClearColor(back[0],back[1],back[2],0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  // All smooth points
  glEnable( GL_POINT_SMOOTH );

  glDisable(GL_LIGHTING);
  if(lights_on)
  {
    lights();
  }
  push_scene();
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
  glEnable(GL_NORMALIZE);
  glEnable(GL_COLOR_MATERIAL);
  glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
  push_object();

  // Draw the model
  // Set material properties
  glEnable(GL_COLOR_MATERIAL);
  draw_mesh(V,F,N,C);

  pop_object();

  // Draw a nice floor
  glPushMatrix();
  const double floor_offset =
    -2./bbd*(V.col(1).maxCoeff()-mid(1));
  glTranslated(0,floor_offset,0);
  const float GREY[4] = {0.5,0.5,0.6,1.0};
  const float DARK_GREY[4] = {0.2,0.2,0.3,1.0};
  draw_floor(GREY,DARK_GREY);
  glPopMatrix();

  pop_scene();

  report_gl_error();

  TwDraw();
  glutSwapBuffers();
  glutPostRedisplay();
}
开发者ID:kevinsunsh,项目名称:libigl,代码行数:85,代码来源:example.cpp

示例5: main


//.........这里部分代码省略.........
    std::vector<std::string> contourLevels;
    parseCDString(&contourLevels, acousticParams["contourDepths"], ',');
    // Note the number of contours we need to graph
    acousticParams.insert({ "numContourDepths",
                            std::to_string(contourLevels.size()) });

    // TODO(Greg) Sort is broken, throws segfaults.  Possibly b/c file doesn't
    //   exist (tried with pal5m.asc).  fix plx.
    // sort(&contourLevels, &contourLevels + numContourDepths);

    // File path variables
    std::string outputDataFilePath = "data/", outputDataFileType = ".dat",
           bathymetryTitle = "Topography", habitatTitle = "Habitat",
           goodnessTitle = "Goodness",
           coverageTitle = "Acoustic Coverage",
           bathymetryFilePath = outputDataFilePath + bathymetryTitle +
                                outputDataFileType,
           habitatFilePath    = outputDataFilePath + habitatTitle +
                                outputDataFileType,
           goodnessFilePath   = outputDataFilePath + goodnessTitle +
                                outputDataFileType,
           coverageFilePath   = outputDataFilePath + coverageTitle +
                                outputDataFileType;

    Grid bGrid(rowDist + 2 * border, colDist + 2 * border, "Behavior");
    Grid gGrid(rowDist + 2 * border, colDist + 2 * border, "Goodness");
    Grid tGrid(rowDist + 2 * border, colDist + 2 * border, "Topography");
    Grid cGrid(rowDist + 2 * border, colDist + 2 * border, "Coverage");

    Eigen::MatrixXd suppressionReference;
    Eigen::MatrixXd distanceGradient;
    Eigen::MatrixXd detectionGradient;
    distanceGradient.resize(sensorDetectionDiameter, sensorDetectionDiameter);
    distanceGradient.setConstant(0);
    detectionGradient.resize(sensorDetectionDiameter, sensorDetectionDiameter);
    detectionGradient.setConstant(0);
    // Create a gradient of distances to avoid redundant computation
    makeDistGradient(&distanceGradient, sensorDetectionRange);
    // Create a gradient of probability of detection (due to sensorRange) to
    // avoid redundant computation
    makeDetectionGradient(&detectionGradient, & distanceGradient,
                   sensorPeakDetectionProbability, SDofSensorDetectionRange);

    // Fetch or simulate topography
    std::cout << "Getting topography...";
    if (simulateBathy) {
        // Simulate topography
        simulatetopographyGrid(&tGrid, rowDist, colDist);
    } else {
        // Fetch actual topography
        getBathy(&tGrid, acousticParams["inputFile"],
                 acousticParams["inputFileType"], size_t(startRow),
                 size_t(startCol), size_t(rowDist), size_t(colDist),
                 acousticParams["seriesName"], acousticParams["timestamp"]);
    }
    std::cout << bGrid.data;
    // Fill in Behavior Grid
    std::cout << "\nGetting Behavior...";
    populateBehaviorGrid(&tGrid, &bGrid, bias, cellSize, ousdx, ousdy, oucor, mux,
                         muy, fishmodel);

    // Initalize the Coverage Grid
    cGrid.data.block(border, border, rowDist, colDist).setConstant(1);

    // Mr. Gaeta, START THE CLOCK!
    vizBegin = clock();
开发者ID:gregorylburgess,项目名称:acoustic-deploy_C,代码行数:67,代码来源:Main.cpp


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