marker.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
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  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "ogre_visuals/marker.h"
33 
34 #include <OGRE/OgreVector3.h>
35 #include <OGRE/OgreSceneNode.h>
36 #include <OGRE/OgreSceneManager.h>
37 #include <OGRE/OgreEntity.h>
38 #include <OGRE/OgreMeshManager.h>
39 
40 namespace marker_rviz_plugin {
41 
42  MarkerResources Marker::static_resources_;
43 
45  // Create imagePlane mesh
46  Ogre::Plane imagePlane;
47  imagePlane.normal = Ogre::Vector3::UNIT_Z;
48  imagePlane.d = 0;
49 
50  Ogre::MeshManager::getSingleton().createPlane("imagePlane",
51  Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
52  imagePlane,
53  1.0, 1.0,
54  1, 1, true, 1,
55  1.0, 1.0,
56  Ogre::Vector3::UNIT_X);
57 
58  // Create image material and load texture
59  Ogre::MaterialPtr planeMaterial = Ogre::MaterialManager::getSingleton().create("imagePlaneMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
60  planeMaterial->setCullingMode(Ogre::CULL_NONE);
61  planeMaterial->setSceneBlending(Ogre::SBT_REPLACE);
62  planeMaterial->setReceiveShadows(false);
63  planeMaterial->getTechnique(0)->setLightingEnabled(false);
64 
65  Ogre::TextureUnitState *tu = planeMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();
66  tu->setTextureName("textures/marker_rect_icon.png");
67  tu->setTextureFiltering(Ogre::TFO_NONE);
68  tu->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0);
69  }
70 
72 
73  }
74 
75  Marker::Marker(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node, int id)
76  : rviz::Object(scene_manager) {
77  if (!parent_node) {
78  parent_node = scene_manager_->getRootSceneNode();
79  }
80 
81  scene_node_ = parent_node->createChildSceneNode();
82 
83  markerNode_ = scene_node_->createChildSceneNode();
84  markerEntity_ = scene_manager_->createEntity("imagePlane");
85  markerEntity_->setCastShadows(false);
86  markerEntity_->setMaterialName("imagePlaneMaterial");
87  markerNode_->attachObject(markerEntity_);
88  markerNode_->setScale(1.0, 1.0, 1.0);
89 
90  axes_ = new rviz::Axes(scene_manager_, scene_node_, 0.7, 0.07);
91 
92  std::stringstream ss;
93  if (id >= 0) {
94  ss << "#" << id;
95  } else {
96  ss << "-";
97  }
98  text_ = new rviz::MovableText(ss.str(), "Arial", 0.4);
100  text_->setColor(Ogre::ColourValue(0.70, 0.70, 0.70));
101 
102  text_node_ = scene_node_->createChildSceneNode();
103  text_node_->setPosition(0.20, 0.20, 0.30);
104  text_node_->attachObject(text_);
105  }
106 
108  delete axes_;
109  delete text_;
110 
111  if(markerNode_)
112  scene_manager_->destroySceneNode(markerNode_);
113 
114  if (markerEntity_)
115  scene_manager_->destroyEntity(markerEntity_);
116 
117  scene_manager_->destroySceneNode(scene_node_->getName());
118  }
119 
120  void Marker::setShowAxes(bool showAxes) {
121  axes_->getSceneNode()->setVisible(showAxes);
122  }
123 
124  void Marker::setShowMarker(bool showMarker) {
125  markerEntity_->setVisible(showMarker);
126  }
127 
128  void Marker::setShowLabel(bool showLabel) {
129  text_node_->setVisible(showLabel);
130  }
131  void Marker::setColorLabel(Ogre::ColourValue color) {
132  text_->setColor(color);
133  }
134 
135  void Marker::setColor(float r, float g, float b, float a) {}
136 
137  void Marker::setPosition(const Ogre::Vector3 &position) {
138  scene_node_->setPosition(position);
139  }
140 
141  void Marker::setOrientation(const Ogre::Quaternion &orientation) {
142  scene_node_->setOrientation(orientation);
143  }
144 
145  void Marker::setScale(const Ogre::Vector3 &scale) {
146  scene_node_->setScale(scale);
147  }
148 
149  const Ogre::Vector3 &Marker::getPosition() {
150  return scene_node_->getPosition();
151  }
152 
153  const Ogre::Quaternion &Marker::getOrientation() {
154  return scene_node_->getOrientation();
155  }
156 
157  void Marker::setUserData(const Ogre::Any &data) {
158  axes_->setUserData(data);
159 
160  if (markerEntity_)
161  markerEntity_->getUserObjectBindings().setUserAny(data);
162  }
163 
164 }
void setUserData(const Ogre::Any &data)
Definition: marker.cpp:157
virtual const Ogre::Quaternion & getOrientation()
Definition: marker.cpp:153
virtual void setOrientation(const Ogre::Quaternion &orientation)
Definition: marker.cpp:141
Ogre::SceneNode * text_node_
Definition: marker.h:95
virtual void setScale(const Ogre::Vector3 &scale)
Definition: marker.cpp:145
void setShowLabel(bool showLabel)
Definition: marker.cpp:128
Ogre::Entity * markerEntity_
Definition: marker.h:92
rviz::MovableText * text_
Definition: marker.h:94
rviz::Axes * axes_
Definition: marker.h:93
Marker(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=0, int id=-1)
Definition: marker.cpp:75
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
void setShowMarker(bool showMarker)
Definition: marker.cpp:124
virtual const Ogre::Vector3 & getPosition()
Definition: marker.cpp:149
void setColor(const Ogre::ColourValue &color)
Ogre::SceneNode * markerNode_
Definition: marker.h:90
void setShowAxes(bool showAxes)
Definition: marker.cpp:120
Ogre::SceneManager * scene_manager_
Ogre::SceneNode * getSceneNode()
void setUserData(const Ogre::Any &data)
virtual void setPosition(const Ogre::Vector3 &position)
Definition: marker.cpp:137
void setColorLabel(Ogre::ColourValue color)
Definition: marker.cpp:131
static MarkerResources static_resources_
Definition: marker.h:87
virtual void setColor(float r, float g, float b, float a)
Definition: marker.cpp:135
Ogre::SceneNode * scene_node_
Definition: marker.h:89


marker_rviz_plugin
Author(s): Markus Bader, Lukas Pfeifhofer, Markus Macsek
autogenerated on Mon Jun 10 2019 13:54:22