Go to the documentation of this file.00001
00010 #include <pcl/io/pcd_io.h>
00011 #include <pcl/point_types.h>
00012 #include <pcl/filters/voxel_grid.h>
00013 #include "PointCloudViewer.h"
00014 #include "hrpsys/idl/pointcloud.hh"
00015 #include <string>
00016
00017
00018
00019 static const char* spec[] =
00020 {
00021 "implementation_id", "PointCloudViewer",
00022 "type_name", "PointCloudViewer",
00023 "description", "Point Cloud Viewer",
00024 "version", HRPSYS_PACKAGE_VERSION,
00025 "vendor", "AIST",
00026 "category", "example",
00027 "activity_type", "DataFlowComponent",
00028 "max_instance", "10",
00029 "language", "C++",
00030 "lang_type", "compile",
00031
00032
00033 ""
00034 };
00035
00036
00037 PointCloudViewer::PointCloudViewer(RTC::Manager* manager)
00038 : RTC::DataFlowComponentBase(manager),
00039
00040 m_cloudIn("cloud", m_cloud),
00041
00042 m_viewer("Point Cloud Viewer"),
00043 dummy(0)
00044 {
00045 }
00046
00047 PointCloudViewer::~PointCloudViewer()
00048 {
00049 }
00050
00051
00052
00053 RTC::ReturnCode_t PointCloudViewer::onInitialize()
00054 {
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 addInPort("cloudIn", m_cloudIn);
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 RTC::Properties& prop = getProperties();
00077
00078 return RTC::RTC_OK;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 RTC::ReturnCode_t PointCloudViewer::onActivated(RTC::UniqueId ec_id)
00105 {
00106 std::cout << m_profile.instance_name<< ": onActivated(" << ec_id << ")" << std::endl;
00107 return RTC::RTC_OK;
00108 }
00109
00110 RTC::ReturnCode_t PointCloudViewer::onDeactivated(RTC::UniqueId ec_id)
00111 {
00112 std::cout << m_profile.instance_name<< ": onDeactivated(" << ec_id << ")" << std::endl;
00113 return RTC::RTC_OK;
00114 }
00115
00116 RTC::ReturnCode_t PointCloudViewer::onExecute(RTC::UniqueId ec_id)
00117 {
00118
00119
00120 if (m_cloudIn.isNew()){
00121 m_cloudIn.read();
00122
00123 bool is_color_points = false;
00124 for (int i = 0; i < m_cloud.fields.length(); i++) {
00125 std::string tmp_name(m_cloud.fields[i].name);
00126 if (tmp_name.find("r") != std::string::npos || tmp_name.find("g") != std::string::npos || tmp_name.find("b") != std::string::npos) {
00127 is_color_points = true;
00128 }
00129 }
00130
00131
00132 if (is_color_points) {
00133 pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
00134 cloud->is_dense = m_cloud.is_dense;
00135 cloud->points.resize(m_cloud.width*m_cloud.height);
00136 float *src = reinterpret_cast<float*>(m_cloud.data.get_buffer());
00137 for (unsigned int i = 0; i< cloud->points.size(); i++) {
00138 cloud->points[i].x = src[0];
00139 cloud->points[i].y = src[1];
00140 cloud->points[i].z = src[2];
00141 cloud->points[i].rgb = src[3];
00142 src += 4;
00143 }
00144 if (!m_viewer.wasStopped()){
00145 m_viewer.showCloud(cloud);
00146 }
00147 } else {
00148 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
00149 cloud->points.resize(m_cloud.width*m_cloud.height);
00150 float *src = (float *)m_cloud.data.get_buffer();
00151 for (unsigned int i=0; i<cloud->points.size(); i++){
00152 cloud->points[i].x = src[0];
00153 cloud->points[i].y = src[1];
00154 cloud->points[i].z = src[2];
00155 src += 4;
00156 }
00157 if (!m_viewer.wasStopped()){
00158 m_viewer.showCloud(cloud);
00159 }
00160 }
00161 }
00162
00163 return RTC::RTC_OK;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 extern "C"
00204 {
00205
00206 void PointCloudViewerInit(RTC::Manager* manager)
00207 {
00208 RTC::Properties profile(spec);
00209 manager->registerFactory(profile,
00210 RTC::Create<PointCloudViewer>,
00211 RTC::Delete<PointCloudViewer>);
00212 }
00213
00214 };
00215
00216