Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "ogre_visuals/marker.h"
00033
00034 #include <OGRE/OgreVector3.h>
00035 #include <OGRE/OgreSceneNode.h>
00036 #include <OGRE/OgreSceneManager.h>
00037 #include <OGRE/OgreEntity.h>
00038 #include <OGRE/OgreMeshManager.h>
00039
00040 namespace marker_rviz_plugin {
00041
00042 MarkerResources Marker::static_resources_;
00043
00044 MarkerResources::MarkerResources() {
00045
00046 Ogre::Plane imagePlane;
00047 imagePlane.normal = Ogre::Vector3::UNIT_Z;
00048 imagePlane.d = 0;
00049
00050 Ogre::MeshManager::getSingleton().createPlane("imagePlane",
00051 Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
00052 imagePlane,
00053 1.0, 1.0,
00054 1, 1, true, 1,
00055 1.0, 1.0,
00056 Ogre::Vector3::UNIT_X);
00057
00058
00059 Ogre::MaterialPtr planeMaterial = Ogre::MaterialManager::getSingleton().create("imagePlaneMaterial", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
00060 planeMaterial->setCullingMode(Ogre::CULL_NONE);
00061 planeMaterial->setSceneBlending(Ogre::SBT_REPLACE);
00062 planeMaterial->setReceiveShadows(false);
00063 planeMaterial->getTechnique(0)->setLightingEnabled(false);
00064
00065 Ogre::TextureUnitState *tu = planeMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();
00066 tu->setTextureName("textures/marker_rect_icon.png");
00067 tu->setTextureFiltering(Ogre::TFO_NONE);
00068 tu->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0);
00069 }
00070
00071 MarkerResources::~MarkerResources() {
00072
00073 }
00074
00075 Marker::Marker(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node, int id)
00076 : rviz::Object(scene_manager) {
00077 if (!parent_node) {
00078 parent_node = scene_manager_->getRootSceneNode();
00079 }
00080
00081 scene_node_ = parent_node->createChildSceneNode();
00082
00083 markerNode_ = scene_node_->createChildSceneNode();
00084 markerEntity_ = scene_manager_->createEntity("imagePlane");
00085 markerEntity_->setCastShadows(false);
00086 markerEntity_->setMaterialName("imagePlaneMaterial");
00087 markerNode_->attachObject(markerEntity_);
00088 markerNode_->setScale(1.0, 1.0, 1.0);
00089
00090 axes_ = new rviz::Axes(scene_manager_, scene_node_, 0.7, 0.07);
00091
00092 std::stringstream ss;
00093 if (id >= 0) {
00094 ss << "#" << id;
00095 } else {
00096 ss << "-";
00097 }
00098 text_ = new rviz::MovableText(ss.str(), "Arial", 0.4);
00099 text_->setTextAlignment(rviz::MovableText::H_CENTER, rviz::MovableText::V_BELOW);
00100 text_->setColor(Ogre::ColourValue(0.70, 0.70, 0.70));
00101
00102 text_node_ = scene_node_->createChildSceneNode();
00103 text_node_->setPosition(0.20, 0.20, 0.30);
00104 text_node_->attachObject(text_);
00105 }
00106
00107 Marker::~Marker() {
00108 delete axes_;
00109 delete text_;
00110
00111 if(markerNode_)
00112 scene_manager_->destroySceneNode(markerNode_);
00113
00114 if (markerEntity_)
00115 scene_manager_->destroyEntity(markerEntity_);
00116
00117 scene_manager_->destroySceneNode(scene_node_->getName());
00118 }
00119
00120 void Marker::setShowAxes(bool showAxes) {
00121 axes_->getSceneNode()->setVisible(showAxes);
00122 }
00123
00124 void Marker::setShowMarker(bool showMarker) {
00125 markerEntity_->setVisible(showMarker);
00126 }
00127
00128 void Marker::setShowLabel(bool showLabel) {
00129 text_node_->setVisible(showLabel);
00130 }
00131 void Marker::setColorLabel(Ogre::ColourValue color) {
00132 text_->setColor(color);
00133 }
00134
00135 void Marker::setColor(float r, float g, float b, float a) {}
00136
00137 void Marker::setPosition(const Ogre::Vector3 &position) {
00138 scene_node_->setPosition(position);
00139 }
00140
00141 void Marker::setOrientation(const Ogre::Quaternion &orientation) {
00142 scene_node_->setOrientation(orientation);
00143 }
00144
00145 void Marker::setScale(const Ogre::Vector3 &scale) {
00146 scene_node_->setScale(scale);
00147 }
00148
00149 const Ogre::Vector3 &Marker::getPosition() {
00150 return scene_node_->getPosition();
00151 }
00152
00153 const Ogre::Quaternion &Marker::getOrientation() {
00154 return scene_node_->getOrientation();
00155 }
00156
00157 void Marker::setUserData(const Ogre::Any &data) {
00158 axes_->setUserData(data);
00159
00160 if (markerEntity_)
00161 markerEntity_->getUserObjectBindings().setUserAny(data);
00162 }
00163
00164 }