LineSegments2DVisual.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <ros/ros.h>
31 
32 #include <OGRE/OgreVector3.h>
33 #include <OGRE/OgreMatrix3.h>
34 #include <OGRE/OgreSceneNode.h>
35 #include <OGRE/OgreSceneManager.h>
36 
38 
39 namespace tuw_geometry_rviz
40 {
41 LineSegments2DVisual::LineSegments2DVisual(Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node)
42 {
43  scene_manager_ = scene_manager;
44 
45  // Ogre::SceneNode s form a tree, with each node storing the
46  // transform (position and orientation) of itself relative to its
47  // parent. Ogre does the math of combining those transforms when it
48  // is time to render.
49  //
50  // Here we create a node to store the pose of the MarkerDetection's header frame
51  // relative to the RViz fixed frame.
52  frame_node_ = parent_node->createChildSceneNode();
53 
54  // We create the visual objects within the frame node so that we can
55  // set thier position and direction relative to their header frame.
57 }
58 
60 {
61  // Destroy the frame node since we don't need it anymore.
62  scene_manager_->destroySceneNode(frame_node_);
63 }
64 
65 void LineSegments2DVisual::setMessage(const tuw_geometry_msgs::LineSegments::ConstPtr& msg)
66 {
67  linesegments_->clear();
68  linesegments_->setMaxPointsPerLine(2);
69  linesegments_->setNumLines(msg->segments.size());
70  for (int i = 0; i < msg->segments.size(); i++)
71  {
72  Ogre::Vector3 start = Ogre::Vector3(msg->segments[i].p0.x, msg->segments[i].p0.y, msg->segments[i].p0.z);
73  Ogre::Vector3 end = Ogre::Vector3(msg->segments[i].p1.x, msg->segments[i].p1.y, msg->segments[i].p1.z);
74 
75  // start new Line (except for first)
76  if (i != 0)
77  linesegments_->newLine();
78 
79  linesegments_->addPoint(start);
80  linesegments_->addPoint(end);
81  }
82 }
83 
84 // Position is passed through to the SceneNode.
85 void LineSegments2DVisual::setFramePosition(const Ogre::Vector3& position)
86 {
87  frame_node_->setPosition(position);
88 }
89 
90 // Orientation is passed through to the SceneNode.
91 void LineSegments2DVisual::setFrameOrientation(const Ogre::Quaternion& orientation)
92 {
93  frame_node_->setOrientation(orientation);
94 }
95 
96 // Color is passed through to the BillboardLine object.
97 void LineSegments2DVisual::setColorSegments(Ogre::ColourValue color)
98 {
99  linesegments_->setColor(color.r, color.g, color.b, color.a);
100 }
101 
102 // Scale is passed through to the BillboardLine object.
104 {
105  linesegments_->setScale(Ogre::Vector3(scale, scale, scale));
106 }
107 
108 // Width is passed through to the BillboardLine object.
110 {
111  linesegments_->setLineWidth(width);
112 }
113 
114 } // end namespace marker_rviz_plugin
void setFramePosition(const Ogre::Vector3 &position)
void setMessage(const tuw_geometry_msgs::LineSegments::ConstPtr &msg)
boost::shared_ptr< rviz::BillboardLine > linesegments_
LineSegments2DVisual(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node)
void setColorSegments(Ogre::ColourValue color)
void setFrameOrientation(const Ogre::Quaternion &orientation)


tuw_geometry_rviz
Author(s): Markus Macsek , Markus Bader
autogenerated on Mon Jun 10 2019 15:40:07