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


C++ OccupancyGrid::ny方法代码示例

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


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

示例1: display

void display() {

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, grid_texture);

  glColor3ub(255,255,255);

  glBegin(GL_QUADS);

  glTexCoord2f(1, 0);
  glVertex2f(grid.nx(), 0);

  glTexCoord2f(0, 0);
  glVertex2f(0, 0);

  glTexCoord2f(0, 1);
  glVertex2f(0, grid.ny());

  glTexCoord2f(1, 1);
  glVertex2f(grid.nx(), grid.ny());

  glEnd();

  glDisable(GL_TEXTURE_2D);

  if (valid(init)) {
    glPushMatrix();

    glColor3ub(63,255,63);
    glTranslated(init.x(), init.y(), 0);
    gluDisk(quadric, 0, goalr, 32, 1);

    glRotated(initTheta*180/M_PI, 0, 0, 1);
    glBegin(GL_TRIANGLES);
    glVertex2f(6, 0);
    glVertex2f(0, 2);
    glVertex2f(0, -2);
    glEnd();

    glPopMatrix();

  }

  if (valid(goal)) {
    glPushMatrix();
    glColor3ub(255,63,63);
    glTranslated(goal.x(), goal.y(), 0);
    gluDisk(quadric, 0, goalr, 32, 1);
    glPopMatrix();
  }

  draw(searchResult, true);

  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  gluOrtho2D(0, width, 0, height);

  std::ostringstream ostr;
  ostr << "Goal pos:     (" << goal.x() << ", " << goal.y() << ")\n"
       << "Init pos:     (" << init.x() << ", " << init.y() << ")\n"
       << "Init theta:   " << initTheta*180/M_PI << "\n"
       << "XY inflation: " << inflate_h << "\n"
       << "Z inflation:  " << inflate_z << "\n"
       << "Max depth:    " << maxDepth << "\n"
       << "View depth:   " << viewDepth << "\n"
       << "Auto-plan:    " << (auto_plan ? "on" : "off") << "\n"
       << "\n"
       << "Plan cost: " << (searchResult ? searchResult->costToCome : 0) << "\n"
       << "Plan time: " << (searchResult ? planTime : 0) << "\n";

  if (show_help) { 
    ostr << "\n\n"
         << " Left-click init pos\n"
         << "Shift+click init theta\n"
         << "Right-click goal pos\n\n"
         << "        1/2 max depth\n"
         << "        3/4 view depth\n"
         << "        -/+ XY inflation\n"
         << "          A auto-plan\n"
         << "      Enter re-plan\n"
         << "        ESC quit\n"
         << "          ? hide help";
  } else {
    ostr << "\nPress ? to toggle help.";
  }
    


  std::string str = ostr.str();
  
  void* font = GLUT_BITMAP_8_BY_13;
  const int tx = 8;
  const int ty = 13;
  const int th = ty+2;
  int maxwidth = 0;
  int linewidth = 0;
  int rh = th;
//.........这里部分代码省略.........
开发者ID:jacquelinekay,项目名称:biped-footstep-planner,代码行数:101,代码来源:bipedDemo.cpp

示例2: makeSVG

void DubinSearch::makeSVG(Dubin* goal, std::string filename, OccupancyGrid& grid, 
							float goalx, float goaly, float goalr, int zoom){

    //TODO
    FILE* svg = fopen(filename.c_str(), "w");
    if (!svg) {
        std::cerr << "error opening svg for output! \n";
        return;
    }

    int width = grid.nx() * zoom;
    int height = grid.ny() * zoom;

    fprintf(svg, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
    fprintf(svg, "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n");
    fprintf(svg, "  \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
    fprintf(svg, "<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\"\n");
    fprintf(svg, "     xmlns:xlink=\"http://www.w3.org/1999/xlink\"\n");
    fprintf(svg, "     width=\"%upx\" height=\"%upx\" viewBox=\"0 0 %u %u\" >\n", 
          width, height, width, height);


    // Draw background and obstacle
    int f;
    for (size_t y=0; y<grid.ny(); ++y) {
        for (size_t x=0; x<grid.nx(); ++x) {

            if (grid(x,y)==0){
                f = 0;
            }
            else{
                f = 255;
            }
                    
            fprintf(svg, "  <rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" "
                "fill=\"#%02x%02x%02x\" />\n", 
                (int)x*zoom, (int)y*zoom, zoom, zoom, f, f, f);
        }
    }
	
	fprintf(svg, "  <circle cx=\"%f\" cy=\"%f\" r=\"%f\" stroke=\"red\" stroke-width=\"2\" fill=\"none\"/>\n",
				goalx*zoom, goaly*zoom, goalr*zoom);
   
    fprintf(svg, "  <g stroke=\"#bfbfbf\" stroke-width=\"1.5\">\n");

    // Draw nodes and lines expanded
    Dubin* curr;
    Dubin* pred;
    while (!_poppedNodes.empty()){
        curr = _poppedNodes.back();
        float cx = (curr->x + 0.5)*zoom;
        float cy = (curr->y + 0.5)*zoom;
        pred = curr->predecessor;
        float r = 0.2 * zoom;
        
        if(pred!=NULL){
            float cxp = (pred->x + 0.5)*zoom;
            float cyp = (pred->y + 0.5)*zoom;
			float r = curr->archRadius * zoom;
			if (r ==0) {
				fprintf(svg, "    <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" %s/>\n",
					cx, cy, cxp, cyp, "");
			} else {
				fprintf(svg, "    <path d=\"M %f %f A %f %f 0 0 %d %f %f \" fill=\"none\"/>\n",
					cxp, cyp, fabs(r), fabs(r), int(r>0), cx, cy);
			}
				

        }

        fprintf(svg, "    <circle cx=\"%f\" cy=\"%f\" r=\"%f\" fill=\"%s\" %s/>\n",
                cx, cy, r, "#ffffff","");
        

        _poppedNodes.pop_back();
    }
	
	while (!_queue.empty()){
        curr = _queue.back();
        float cx = (curr->x + 0.5)*zoom;
        float cy = (curr->y + 0.5)*zoom;
        pred = curr->predecessor;
        float r = 0.5 * zoom;
        
        if(pred!=NULL){
            float cxp = (pred->x + 0.5)*zoom;
            float cyp = (pred->y + 0.5)*zoom;
			float r = curr->archRadius * zoom;
			if (r ==0) {
				fprintf(svg, "    <line x1=\"%f\" y1=\"%f\" x2=\"%f\" y2=\"%f\" %s/>\n",
					cx, cy, cxp, cyp, "");
			} else {
				fprintf(svg, "    <path d=\"M %f %f A %f %f 0 0 %d %f %f \" fill=\"none\"/>\n",
					cxp, cyp, fabs(r), fabs(r), int(r>0), cx, cy);
			}
				

        }
		fprintf(svg, "  </g>\n");
		fprintf(svg, "  <g stroke=\"#0000ff\" stroke-width=\"1\">\n");
//.........这里部分代码省略.........
开发者ID:jacquelinekay,项目名称:biped-footstep-planner,代码行数:101,代码来源:dubinSearch.cpp

示例3: main

int main(int argc, char** argv) {
  
  getInputSegments(); //initialize the path planner

  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
  glutInitWindowSize(640, 480);

  if (argc < 2) { usage(1); }

  grid.load(argv[1]);
  if (grid.empty()) { 
    std::cerr << "Error loading grid: " << argv[1] << "\n";
    exit(1);
  }

  glutCreateWindow("Biped plan demo");
  glutDisplayFunc(display);
  glutReshapeFunc(reshape);
  glutKeyboardFunc(keyboard);
  glutMouseFunc(mouse);
  glutMotionFunc(motion);
  
  glClearColor(1,1,1,1);

  glViewport(0, 0, 640, 480); 
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  glOrtho(0, 640, 0, 480, 1, -1);

  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glGenTextures(1, &grid_texture);
  glBindTexture(GL_TEXTURE_2D, grid_texture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

  std::vector<unsigned char> rgbbuf(grid.nx() * grid.ny() * 4);
  int offs = 0;
  for (size_t y=0; y<grid.ny(); ++y) {
    for (size_t x=0; x<grid.nx(); ++x) {
      rgbbuf[offs++] = grid(x,y);
      rgbbuf[offs++] = grid(x,y);
      rgbbuf[offs++] = grid(x,y);
      rgbbuf[offs++] = 255;
    }
  }
    
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
               grid.nx(), grid.ny(), 0, GL_RGBA,
               GL_UNSIGNED_BYTE, &(rgbbuf[0]));

  quadric = gluNewQuadric();

  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  searchTrajectory();
  glutMainLoop();

  return 0;

}
开发者ID:swatbotics,项目名称:e91-final,代码行数:64,代码来源:bipedDemo.cpp


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