Last active
September 17, 2017 20:53
-
-
Save mintar/5e0ac1f2cfb61e9305a198ddd24c8cb4 to your computer and use it in GitHub Desktop.
Example to demonstrate use of PointCloud2 count field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8.3) | |
project(test_pointcloud_count) | |
## Find catkin macros and libraries | |
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) | |
## is used, also find other catkin packages | |
find_package(catkin REQUIRED COMPONENTS | |
roscpp | |
pcl_ros | |
pcl_conversions | |
) | |
find_package(PCL 1.7 REQUIRED REQUIRED) | |
include_directories(${PCL_INCLUDE_DIRS}) | |
link_directories(${PCL_LIBRARY_DIRS}) | |
add_definitions(${PCL_DEFINITIONS}) | |
################################### | |
## catkin specific configuration ## | |
################################### | |
## The catkin_package macro generates cmake config files for your package | |
## Declare things to be passed to dependent projects | |
## INCLUDE_DIRS: uncomment this if you package contains header files | |
## LIBRARIES: libraries you create in this project that dependent projects also need | |
## CATKIN_DEPENDS: catkin_packages dependent projects also need | |
## DEPENDS: system dependencies of this project that dependent projects also need | |
catkin_package( | |
# INCLUDE_DIRS include | |
# LIBRARIES test_pointcloud_count | |
# CATKIN_DEPENDS roscpp | |
# DEPENDS system_lib | |
) | |
########### | |
## Build ## | |
########### | |
## Specify additional locations of header files | |
## Your package locations should be listed before other locations | |
# include_directories(include) | |
include_directories( | |
${catkin_INCLUDE_DIRS} | |
) | |
## Declare a C++ executable | |
add_executable(count_test_node count_test_node.cpp) | |
## Add cmake target dependencies of the executable | |
add_dependencies(count_test_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS}) | |
## Specify libraries to link a library or executable target against | |
target_link_libraries(count_test_node | |
${catkin_LIBRARIES} | |
${PCL_LIBRARIES} | |
) | |
############# | |
## Install ## | |
############# | |
## Mark executables and/or libraries for installation | |
install(TARGETS count_test_node | |
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} | |
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} | |
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2016, DFKI GmbH | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without | |
* modification, are permitted provided that the following conditions are met: | |
* | |
* * Redistributions of source code must retain the above copyright | |
* notice, this list of conditions and the following disclaimer. | |
* * Redistributions in binary form must reproduce the above copyright | |
* notice, this list of conditions and the following disclaimer in the | |
* documentation and/or other materials provided with the distribution. | |
* * Neither the name of DFKI GmbH nor the names of its | |
* contributors may be used to endorse or promote products derived from | |
* this software without specific prior written permission. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
* POSSIBILITY OF SUCH DAMAGE. | |
* | |
* Authors: | |
* Martin Günther <martin.guenther@dfki.de> | |
* | |
*/ | |
#include <ros/ros.h> | |
#include <pcl_conversions/pcl_conversions.h> | |
#include <sensor_msgs/PointCloud2.h> | |
#include <pcl_ros/point_cloud.h> | |
typedef pcl::FPFHSignature33 PointT; | |
typedef pcl::PointCloud<PointT> PointCloudT; | |
int main(int argc, char **argv) | |
{ | |
ros::init(argc, argv, "count_test_node"); | |
ros::NodeHandle nh; | |
ros::Publisher pub = nh.advertise<PointCloudT>("cloud", 1); | |
ROS_INFO("initialized"); | |
ros::Rate r(10); | |
while (ros::ok()) | |
{ | |
PointCloudT::Ptr cloud = boost::make_shared<PointCloudT>(); | |
cloud->header.frame_id = "some_frame"; | |
cloud->header.stamp = ros::Time::now().toNSec() / 1000; | |
cloud->width = 1; | |
cloud->height = 1; | |
cloud->is_dense = true; | |
PointT p; | |
size_t count = sizeof(p.histogram) / sizeof(float); // == 33 | |
for (size_t i = 0; i < count; ++i) | |
{ | |
// need to initialize data | |
p.histogram[i] = 0.f; | |
} | |
p.histogram[15] = 23.42f; | |
cloud->points.push_back(p); | |
pub.publish(cloud); | |
ros::spinOnce(); | |
r.sleep(); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0"?> | |
<package format="2"> | |
<name>test_pointcloud_count</name> | |
<version>0.0.0</version> | |
<description>Example to demonstrate use of PointCloud2 count field</description> | |
<maintainer email="martin.guenther@dfki.de">Martin Günther</maintainer> | |
<author email="martin.guenther@dfki.de">Martin Günther</author> | |
<license>BSD</license> | |
<buildtool_depend>catkin</buildtool_depend> | |
<depend>roscpp</depend> | |
<depend>pcl_ros</depend> | |
<depend>libpcl-all-dev</depend> | |
</package> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment