30 #include <boost/bind.hpp> 32 #include <OgreSceneNode.h> 33 #include <OgreSceneManager.h> 34 #include <OgreManualObject.h> 35 #include <OgreBillboardSet.h> 36 #include <OgreMatrix4.h> 59 PathVecDisplay::PathVecDisplay()
61 style_property_ =
new EnumProperty(
"Line Style",
"Lines",
62 "The rendering operation to use to draw the grid lines.",
63 this, SLOT( updateStyle() ));
65 style_property_->addOption(
"Lines", LINES );
66 style_property_->addOption(
"Billboards", BILLBOARDS );
69 "The width, in meters, of each path line." 70 "Only works with the 'Billboards' style.",
71 this, SLOT( updateLineWidth() ),
this );
72 line_width_property_->setMin( 0.001 );
73 line_width_property_->hide();
75 color_property_ =
new ColorProperty(
"Color", QColor( 25, 255, 0 ),
76 "Color to draw the path.",
this );
79 "Amount of transparency to apply to the path.",
this );
81 buffer_length_property_ =
new IntProperty(
"Buffer Length", 1,
82 "Number of paths to display.",
83 this, SLOT( updateBufferLength() ));
84 buffer_length_property_->setMin( 1 );
86 offset_property_ =
new VectorProperty(
"Offset", Ogre::Vector3::ZERO,
87 "Allows you to offset the path from the origin of the reference frame. In meters.",
88 this, SLOT( updateOffset() ));
90 pose_style_property_ =
new EnumProperty(
"Pose Style",
"None",
"Shape to display the pose as.",
91 this, SLOT( updatePoseStyle() ));
92 pose_style_property_->addOption(
"None", NONE );
93 pose_style_property_->addOption(
"Axes", AXES );
94 pose_style_property_->addOption(
"Arrows", ARROWS );
97 "Length of the axes.",
98 this, SLOT(updatePoseAxisGeometry()) );
100 "Radius of the axes.",
101 this, SLOT(updatePoseAxisGeometry()) );
104 QColor( 255, 85, 255 ),
105 "Color to draw the poses.",
106 this, SLOT(updatePoseArrowColor()));
108 "Length of the arrow shaft.",
110 SLOT(updatePoseArrowGeometry()));
112 "Length of the arrow head.",
114 SLOT(updatePoseArrowGeometry()));
116 "Diameter of the arrow shaft.",
118 SLOT(updatePoseArrowGeometry()));
120 "Diameter of the arrow head.",
122 SLOT(updatePoseArrowGeometry()));
123 pose_axes_length_property_->hide();
124 pose_axes_radius_property_->hide();
125 pose_arrow_color_property_->hide();
126 pose_arrow_shaft_length_property_->hide();
127 pose_arrow_head_length_property_->hide();
128 pose_arrow_shaft_diameter_property_->hide();
129 pose_arrow_head_diameter_property_->hide();
132 PathVecDisplay::~PathVecDisplay()
135 destroyPoseAxesChain();
136 destroyPoseArrowChain();
139 void PathVecDisplay::onInitialize()
141 MFDClass::onInitialize();
142 updateBufferLength();
145 void PathVecDisplay::reset()
148 updateBufferLength();
152 void PathVecDisplay::allocateAxesVector(std::vector<rviz::Axes*>& axes_vect,
int num)
154 if (num > axes_vect.size()) {
155 for (
size_t i = axes_vect.size(); i < num; i++) {
157 pose_axes_length_property_->getFloat(),
158 pose_axes_radius_property_->getFloat());
159 axes_vect.push_back(axes);
162 else if (num < axes_vect.size()) {
163 for (
int i = axes_vect.size() - 1; num <= i; i--) {
166 axes_vect.resize(num);
170 void PathVecDisplay::allocateArrowVector(std::vector<rviz::Arrow*>& arrow_vect,
int num)
172 if (num > arrow_vect.size()) {
173 for (
size_t i = arrow_vect.size(); i < num; i++) {
175 arrow_vect.push_back(arrow);
178 else if (num < arrow_vect.size()) {
179 for (
int i = arrow_vect.size() - 1; num <= i; i--) {
180 delete arrow_vect[i];
182 arrow_vect.resize(num);
186 void PathVecDisplay::destroyPoseAxesChain()
188 for(
size_t i = 0; i < axes_chain_.size(); i++ )
190 for(
size_t j = 0; j < axes_chain_[i].size(); j++ )
192 allocateAxesVector(axes_chain_[i][j], 0);
194 axes_chain_[i].resize(0);
196 axes_chain_.resize(0);
199 void PathVecDisplay::destroyPoseArrowChain()
201 for(
size_t i = 0; i < arrow_chain_.size(); i++ )
203 for(
size_t j = 0; j < arrow_chain_[i].size(); j++ )
205 allocateArrowVector(arrow_chain_[i][j], 0);
207 arrow_chain_[i].resize(0);
209 arrow_chain_.resize(0);
212 void PathVecDisplay::updateStyle()
220 line_width_property_->hide();
224 line_width_property_->show();
228 updateBufferLength();
231 void PathVecDisplay::updateLineWidth()
234 float line_width = line_width_property_->getFloat();
236 if(style == BILLBOARDS) {
237 for(
size_t i = 0; i < billboard_lines_.size(); i++ )
238 for(
size_t j = 0; j < billboard_lines_[i].size(); j++ )
241 if( billboard_line ) billboard_line->
setLineWidth( line_width );
244 context_->queueRender();
247 void PathVecDisplay::updateOffset()
249 scene_node_->setPosition( offset_property_->getVector() );
250 context_->queueRender();
253 void PathVecDisplay::updatePoseStyle()
259 pose_axes_length_property_->show();
260 pose_axes_radius_property_->show();
261 pose_arrow_color_property_->hide();
262 pose_arrow_shaft_length_property_->hide();
263 pose_arrow_head_length_property_->hide();
264 pose_arrow_shaft_diameter_property_->hide();
265 pose_arrow_head_diameter_property_->hide();
268 pose_axes_length_property_->hide();
269 pose_axes_radius_property_->hide();
270 pose_arrow_color_property_->show();
271 pose_arrow_shaft_length_property_->show();
272 pose_arrow_head_length_property_->show();
273 pose_arrow_shaft_diameter_property_->show();
274 pose_arrow_head_diameter_property_->show();
277 pose_axes_length_property_->hide();
278 pose_axes_radius_property_->hide();
279 pose_arrow_color_property_->hide();
280 pose_arrow_shaft_length_property_->hide();
281 pose_arrow_head_length_property_->hide();
282 pose_arrow_shaft_diameter_property_->hide();
283 pose_arrow_head_diameter_property_->hide();
285 updateBufferLength();
288 void PathVecDisplay::updatePoseAxisGeometry()
290 for(
size_t i = 0; i < axes_chain_.size() ; i++)
292 for(
size_t j = 0; i < axes_chain_[i].size() ; j++)
294 std::vector<rviz::Axes*>& axes_vect = axes_chain_[i][j];
295 for(
size_t k = 0; k < axes_vect.size() ; k++)
297 axes_vect[k]->set( pose_axes_length_property_->getFloat(),
298 pose_axes_radius_property_->getFloat() );
302 context_->queueRender();
305 void PathVecDisplay::updatePoseArrowColor()
307 QColor color = pose_arrow_color_property_->getColor();
309 for(
size_t i = 0; i < arrow_chain_.size(); i++ )
311 for(
size_t j = 0; j < arrow_chain_[i].size(); j++ )
313 std::vector<rviz::Arrow*>& arrow_vect = arrow_chain_[i][j];
314 for(
size_t k = 0; k < arrow_vect.size(); k++ )
316 arrow_vect[k]->setColor( color.redF(), color.greenF(), color.blueF(), 1.0f );
320 context_->queueRender();
323 void PathVecDisplay::updatePoseArrowGeometry()
325 for(
size_t i = 0; i < arrow_chain_.size(); i++ )
327 for(
size_t j = 0; j < arrow_chain_[i].size(); j++ )
329 std::vector<rviz::Arrow*>& arrow_vect = arrow_chain_[i][j];
330 for(
size_t k = 0; k < arrow_vect.size(); k++ )
332 arrow_vect[k]->set(pose_arrow_shaft_length_property_->getFloat(),
333 pose_arrow_shaft_diameter_property_->getFloat(),
334 pose_arrow_head_length_property_->getFloat(),
335 pose_arrow_head_diameter_property_->getFloat());
339 context_->queueRender();
342 void PathVecDisplay::destroyObjects()
345 for(
size_t i = 0; i < manual_objects_.size(); i++ )
347 for(
size_t j = 0; j < manual_objects_[i].size(); j++ )
349 Ogre::ManualObject*& manual_object = manual_objects_[ i ][ j ];
352 manual_object->clear();
353 scene_manager_->destroyManualObject( manual_object );
354 manual_object =
NULL;
360 for(
size_t i = 0; i < billboard_lines_.size(); i++ )
362 for(
size_t j = 0; j < billboard_lines_[i].size(); j++ )
367 delete billboard_line;
368 billboard_line =
NULL;
374 void PathVecDisplay::updateBufferLength()
380 destroyPoseAxesChain();
381 destroyPoseArrowChain();
384 int buffer_length = buffer_length_property_->getInt();
386 pathsSize_ .resize( buffer_length );
392 manual_objects_.resize( buffer_length );
393 for(
size_t i = 0; i < manual_objects_.size(); i++ )
395 manual_objects_[i].resize(pathsSize_[i]);
396 for(
size_t j = 0; j < manual_objects_[i].size(); j++ )
398 Ogre::ManualObject* manual_object = scene_manager_->createManualObject();
399 manual_object->setDynamic(
true );
400 scene_node_->attachObject( manual_object );
402 manual_objects_[ i ][ j ] = manual_object;
408 billboard_lines_.resize( buffer_length );
409 for(
size_t i = 0; i < billboard_lines_.size(); i++ )
411 billboard_lines_[i].resize(pathsSize_[i]);
412 for(
size_t j = 0; j < billboard_lines_[i].size(); j++ )
415 billboard_lines_[ i ][ j ] = billboard_line;
420 axes_chain_ .resize( buffer_length );
for(
size_t i = 0; i < axes_chain_ .size(); ++i ){ axes_chain_ [i].resize(pathsSize_[i]); }
421 arrow_chain_.resize( buffer_length );
for(
size_t i = 0; i < arrow_chain_.size(); ++i ){ arrow_chain_[i].resize(pathsSize_[i]); }
432 void PathVecDisplay::processMessage(
const tuw_nav_msgs::PathVec::ConstPtr& msg )
435 size_t bufferIndex = messages_received_ % buffer_length_property_->getInt();
437 pathsSize_ [bufferIndex] = msg->paths.size();
439 updateBufferLength();
449 Ogre::Vector3 position;
450 Ogre::Quaternion orientation;
451 if( !context_->getFrameManager()->getTransform( msg->header, position, orientation ))
453 ROS_DEBUG(
"Error transforming from frame '%s' to frame '%s'", msg->header.frame_id.c_str(), qPrintable( fixed_frame_ ));
456 Ogre::Matrix4 transform( orientation );
457 transform.setTrans( position );
462 Ogre::ColourValue color = color_property_->getOgreColor();
463 color.a = alpha_property_->getFloat();
465 float line_width = line_width_property_->getFloat();
467 QColor colorArrow = pose_arrow_color_property_->getColor();
471 case LINES : manual_objects_ [bufferIndex].resize(msg->paths.size());
break;
472 case BILLBOARDS:billboard_lines_[bufferIndex].resize(msg->paths.size());
break;
475 for(
size_t k = 0; k < msg->paths.size(); ++k ) {
477 auto& msgPathI = msg->paths[k];
478 uint32_t num_points = msgPathI.poses.size();
483 Ogre::ManualObject* manual_object = manual_objects_ [ bufferIndex ][k];
484 manual_object->estimateVertexCount( num_points );
485 manual_object->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP );
486 for( uint32_t i=0; i < num_points; ++i)
488 const geometry_msgs::Point& pos = msgPathI.poses[ i ].pose.position;
489 Ogre::Vector3 xpos = transform * Ogre::Vector3( pos.x, pos.y, pos.z );
490 manual_object->position( xpos.x, xpos.y, xpos.z );
491 manual_object->colour( color );
494 manual_object->end();
503 for( uint32_t i=0; i < num_points; ++i)
505 const geometry_msgs::Point& pos = msgPathI.poses[ i ].pose.position;
506 Ogre::Vector3 xpos = transform * Ogre::Vector3( pos.x, pos.y, pos.z );
507 billboard_line->
addPoint( xpos, color );
518 std::vector<rviz::Axes*>& axes_vect = axes_chain_ [ bufferIndex ][k];
519 allocateAxesVector(axes_vect, num_points);
520 for( uint32_t i=0; i < num_points; ++i)
522 const geometry_msgs::Point& pos = msgPathI.poses[ i ].pose.position;
523 Ogre::Vector3 xpos = transform * Ogre::Vector3( pos.x, pos.y, pos.z );
524 axes_vect[i]->setPosition(xpos);
525 Ogre::Quaternion orientation(msgPathI.poses[ i ].pose.orientation.w,
526 msgPathI.poses[ i ].pose.orientation.x,
527 msgPathI.poses[ i ].pose.orientation.y,
528 msgPathI.poses[ i ].pose.orientation.z);
529 axes_vect[i]->setOrientation(orientation);
534 std::vector<rviz::Arrow*>& arrow_vect = arrow_chain_[ bufferIndex ][k];
535 allocateArrowVector(arrow_vect, num_points);
536 for( uint32_t i=0; i < num_points; ++i)
538 const geometry_msgs::Point& pos = msgPathI.poses[ i ].pose.position;
539 Ogre::Vector3 xpos = transform * Ogre::Vector3( pos.x, pos.y, pos.z );
542 arrow_vect[i]->setColor( colorArrow.redF(), colorArrow.greenF(), colorArrow.blueF(), 1.0f );
544 arrow_vect[i]->set(pose_arrow_shaft_length_property_->getFloat(),
545 pose_arrow_shaft_diameter_property_->getFloat(),
546 pose_arrow_head_length_property_->getFloat(),
547 pose_arrow_head_diameter_property_->getFloat());
548 arrow_vect[i]->setPosition(xpos);
549 Ogre::Quaternion orientation(msgPathI.poses[ i ].pose.orientation.w,
550 msgPathI.poses[ i ].pose.orientation.x,
551 msgPathI.poses[ i ].pose.orientation.y,
552 msgPathI.poses[ i ].pose.orientation.z);
554 Ogre::Vector3 dir(1, 0, 0);
555 dir = orientation * dir;
556 arrow_vect[i]->setDirection(dir);
564 context_->queueRender();
void addPoint(const Ogre::Vector3 &point)
bool validateFloats(const visualization_msgs::InteractiveMarker &msg)
void setNumLines(uint32_t num)
void setMaxPointsPerLine(uint32_t max)
Displays a tuw_nav_msgs::PathVec message.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void setLineWidth(float width)