select_point_cloud_publish_action.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 
3 #include <QPainter>
4 #include <QLineEdit>
5 #include <QPushButton>
6 #include <QVBoxLayout>
7 #include <QHBoxLayout>
8 #include <QLabel>
9 #include <QTimer>
10 #include <QColor>
11 #include <QFont>
12 
16 
17 #include "rviz/config.h"
23 
24 #include <std_msgs/Empty.h>
25 #include <sensor_msgs/PointCloud2.h>
26 
28 #include "ros/time.h"
29 
30 using namespace rviz;
31 
32 namespace jsk_rviz_plugins
33 {
34 
35  SelectPointCloudPublishAction::SelectPointCloudPublishAction( QWidget* parent )
36  : rviz::Panel( parent )
37  {
38  select_pointcloud_publisher_ = nh_.advertise<sensor_msgs::PointCloud2>("selected_pointcloud", 1);
39  layout = new QVBoxLayout;
40 
41  //Button to send cancel topic
42  publish_pointcloud_button_ = new QPushButton("SelectPointCloudPublish Action");
43  layout->addWidget( publish_pointcloud_button_ );
44 
45  setLayout( layout );
46 
47  connect( publish_pointcloud_button_, SIGNAL( clicked() ), this, SLOT( publishPointCloud ()));
48  }
49 
52  int num_children = model_->rowCount();
53  if( num_children > 0 )
54  {
55  ROS_INFO("num > %d!", num_children);
56  sensor_msgs::PointCloud2 pc2;
57  pc2.header.stamp = ros::Time::now();
58  pc2.header.frame_id = "camera_depth_optical_frame";
59  pc2.height = 1;
60  pc2.width = num_children;
61 
62  pc2.fields.resize(4);
63  pc2.fields[0].name = "x";
64  pc2.fields[1].name = "y";
65  pc2.fields[2].name = "z";
66  pc2.fields[3].name = "rgb";
67  pc2.fields[0].offset = 0;
68  pc2.fields[1].offset = 4;
69  pc2.fields[2].offset = 8;
70  pc2.fields[3].offset = 12;
71  pc2.fields[0].count = pc2.fields[1].count = pc2.fields[2].count = pc2.fields[3].count = 1;
72  pc2.fields[0].datatype = pc2.fields[1].datatype = pc2.fields[2].datatype = pc2.fields[3].datatype = sensor_msgs::PointField::FLOAT32;
73 
74  pc2.data.resize(num_children * 4 * sizeof(float));
75  for( int i = 0; i < num_children; i++ )
76  {
77  QModelIndex child_index = model_->index( i, 0, QModelIndex());
78  VectorProperty* vec_data = qobject_cast<VectorProperty* >(model_->getProp( child_index )->childAt(0));
79  ColorProperty* color_data = qobject_cast<ColorProperty* >(model_->getProp( child_index )->childAt(1));
80 
81  Ogre::Vector3 point_vec = vec_data->getVector();
82  // check if color_data is available
83  // if not color_data is available, set the color to black(0,0,0)
84  int rgb_int = 0;
85  if (color_data != NULL && color_data->getColor().isValid()) {
86  Ogre::ColourValue point_color = color_data->getOgreColor();
87  rgb_int = (int)point_color.r << 16 | (int)point_color.g << 8 | (int)point_color.b << 0;
88  }
89  float x = point_vec.x, y = point_vec.y, z = point_vec.z;
90  //Tty to add color, but point_color's value are all zero!!!!!!
91  float rgb_float = *reinterpret_cast<float*>(&rgb_int);
92  memcpy(&pc2.data[i*4*sizeof(float)], &x, sizeof(float));
93  memcpy(&pc2.data[(i*4+1)*sizeof(float)], &y, sizeof(float));
94  memcpy(&pc2.data[(i*4+2)*sizeof(float)], &z, sizeof(float));
95  memcpy(&pc2.data[(i*4+3)*sizeof(float)], &rgb_float, sizeof(float));
96  }
97 
98  pc2.point_step = 16;
99  pc2.row_step = pc2.point_step * pc2.width;
100  pc2.is_dense = false;
102  }
103  }
104 
106  {
108  }
109 
110  // Load all configuration data for this panel from the given Config object.
112  {
114  }
115 
116 }
117 
rviz::Property::childAt
Property * childAt(int index) const
rviz::ColorProperty::getColor
virtual QColor getColor() const
jsk_rviz_plugins::SelectPointCloudPublishAction::save
virtual void save(rviz::Config config) const
Definition: select_point_cloud_publish_action.cpp:105
NULL
#define NULL
jsk_rviz_plugins::SelectPointCloudPublishAction::layout
QVBoxLayout * layout
Definition: select_point_cloud_publish_action.h:41
config.h
rviz::Panel
rviz::PropertyTreeModel
bounding_box_sample.z
z
Definition: bounding_box_sample.py:28
time.h
rviz::VisualizationManager::getSelectionManager
SelectionManager * getSelectionManager() const override
selection_manager.h
jsk_rviz_plugins::SelectPointCloudPublishAction::nh_
ros::NodeHandle nh_
Definition: select_point_cloud_publish_action.h:47
rviz::PropertyTreeModel::getProp
Property * getProp(const QModelIndex &index) const
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
rviz::PropertyTreeModel::rowCount
int rowCount(const QModelIndex &parent=QModelIndex()) const override
rviz::ColorProperty
visualization_manager.h
class_list_macros.h
property_tree_model.h
rviz
jsk_rviz_plugins::SelectPointCloudPublishAction::load
virtual void load(const rviz::Config &config)
Definition: select_point_cloud_publish_action.cpp:111
bounding_box_sample.x
x
Definition: bounding_box_sample.py:26
rviz::PropertyTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bounding_box_sample.y
y
Definition: bounding_box_sample.py:27
jsk_rviz_plugins::SelectPointCloudPublishAction::publish_pointcloud_button_
QPushButton * publish_pointcloud_button_
Definition: select_point_cloud_publish_action.h:39
status_list.h
PLUGINLIB_EXPORT_CLASS
PLUGINLIB_EXPORT_CLASS(jsk_rviz_plugins::PictogramArrayDisplay, rviz::Display)
rviz::SelectionManager::getPropertyModel
PropertyTreeModel * getPropertyModel()
rviz::Panel::load
virtual void load(const Config &config)
property_tree_widget.h
jsk_rviz_plugins::SelectPointCloudPublishAction
Definition: select_point_cloud_publish_action.h:24
property.h
rviz::Panel::save
virtual void save(Config config) const
jsk_rviz_plugins::SelectPointCloudPublishAction::select_pointcloud_publisher_
ros::Publisher select_pointcloud_publisher_
Definition: select_point_cloud_publish_action.h:44
jsk_rviz_plugins::SelectPointCloudPublishAction::publishPointCloud
void publishPointCloud()
Definition: select_point_cloud_publish_action.cpp:50
rviz::VectorProperty
select_point_cloud_publish_action.h
vector_property.h
ROS_INFO
#define ROS_INFO(...)
rviz::VectorProperty::getVector
virtual Ogre::Vector3 getVector() const
config
config
jsk_rviz_plugins
Definition: __init__.py:1
rviz::Config
color_property.h
rviz::ColorProperty::getOgreColor
Ogre::ColourValue getOgreColor() const
ros::Time::now
static Time now()
rviz::Panel::vis_manager_
VisualizationManager * vis_manager_


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Fri Aug 2 2024 08:50:14