marker.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2016, Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  * this list of conditions and the following disclaimer.
00010  *
00011  * 2. Redistributions in binary form must reproduce the above copyright notice,
00012  * this list of conditions and the following disclaimer in the documentation
00013  * and/or other materials provided with the distribution.
00014  *
00015  * 3. Neither the name of the copyright holder nor the names of its contributors
00016  * may be used to endorse or promote products derived from this software without
00017  * specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00020  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00023  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00024  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00025  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00026  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00027  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00028  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00029  * POSSIBILITY OF SUCH DAMAGE.
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         // Create imagePlane mesh
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         // Create image material and load texture
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 }


marker_rviz_plugin
Author(s): Markus Bader, Lukas Pfeifhofer, Markus Macsek
autogenerated on Wed Nov 9 2016 04:02:20