ann_grid_demo.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 
36 #include <ros/ros.h>
38 
39 using namespace jsk_footstep_planner;
40 
41 int main(int argc, char** argv)
42 {
43  ros::init(argc, argv, "ann_grid_demo");
44  pcl::PointCloud<pcl::PointNormal> cloud;
45  for (double x = -2; x < 2; x += 0.01) {
46  for (double y = -2; y < 2; y += 0.01) {
47  pcl::PointNormal p;
48  p.x = x;
49  p.y = y;
50  p.z = cos(x) * cos(y);
51  cloud.points.push_back(p);
52  }
53  }
54  ANNGrid::Ptr ann_grid(new ANNGrid(0.1));
55  ann_grid->build(cloud);
56  cv::Mat grid_image;
57  ann_grid->toImage(grid_image);
58  std::cout << "ann grid size is "
59  << grid_image.rows << "x" << grid_image.cols << std::endl;
60  cv::imshow("ann_grid", grid_image);
61 
62  cv::Mat grid_image2;
63  ANNGrid::IndexArray pixels = ann_grid->bresenham(Eigen::Vector3f(1, 1, 0), Eigen::Vector3f(-1, -1, 0));
64  ann_grid->toImage(grid_image2, pixels);
65  cv::imshow("ann_grid2", grid_image2);
66 
67  cv::Mat grid_image3;
68  ANNGrid::IndexArray box_pixels = ann_grid->box(Eigen::Vector3f(1, 1, 0),
69  Eigen::Vector3f(-1, 1, 0),
70  Eigen::Vector3f(-1, -1, 0),
71  Eigen::Vector3f(1, -1, 0));
72  ann_grid->toImage(grid_image3, box_pixels);
73  cv::imshow("ann_grid3", grid_image3);
74 
75  cv::Mat grid_image4;
76  ANNGrid::IndexArray filled_pixels = ann_grid->fillByBox(Eigen::Vector3f(1, 1, 0),
77  Eigen::Vector3f(-1, 1, 0),
78  Eigen::Vector3f(-1, -1, 0),
79  Eigen::Vector3f(1, -1, 0));
80  std::cout << "filled pixels: " << filled_pixels.size() << std::endl;
81  ann_grid->toImage(grid_image4, filled_pixels);
82  cv::imshow("ann_grid4", grid_image4);
83 
84  pcl::PointIndices near_indices;
85  ann_grid->approximateSearchInBox(Eigen::Vector3f(1, 1, 0),
86  Eigen::Vector3f(-1, 1, 0),
87  Eigen::Vector3f(-1, -1, 0),
88  Eigen::Vector3f(1, -1, 0),
89  near_indices);
90  for (size_t i = 0; i < near_indices.indices.size(); i++) {
91  std::cout << cloud.points[near_indices.indices[i]] << std::endl;
92  }
93 
94  while(1) {
95  cv::waitKey(0);
96  }
97  return 0;
98 }
boost::shared_ptr< ANNGrid >
i
int i
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
cloud
pcl::PointCloud< pcl::PointNormal >::Ptr cloud
Definition: footstep_projection_demo.cpp:49
jsk_footstep_planner::ANNGrid
ANNGrid is a class to provide approximate near neighbors search based on 2.5-D representation....
Definition: ann_grid.h:125
jsk_footstep_planner
Definition: ann_grid.h:50
jsk_footstep_planner::ANNGrid::IndexArray
std::vector< Index > IndexArray
Definition: ann_grid.h:130
y
double y
argv
ROS_INFO ROS_ERROR int pointer * argv
pose_array.p
p
Definition: pose_array.py:21
cos
double cos()
main
int main(int argc, char **argv)
Definition: ann_grid_demo.cpp:41
x
double x
ann_grid.h


jsk_footstep_planner
Author(s): Ryohei Ueda
autogenerated on Wed Jan 24 2024 04:05:29