VirtualRangeSensor.cpp
Go to the documentation of this file.
00001 /* 
00002  * Copyright (c) 2013 University of Jaume-I.
00003  * All rights reserved. This program and the accompanying materials
00004  * are made available under the terms of the GNU Public License v3.0
00005  * which accompanies this distribution, and is available at
00006  * http://www.gnu.org/licenses/gpl.html
00007  * 
00008  * Contributors:
00009  *     Mario Prats
00010  *     Javier Perez
00011  */
00012 
00013 #include <uwsim/VirtualRangeSensor.h>
00014 #include <uwsim/UWSimUtils.h>
00015 #include <iostream>
00016 
00017 #include <osg/PositionAttitudeTransform>
00018 VirtualRangeSensor::VirtualRangeSensor()
00019 {
00020 }
00021 
00022 VirtualRangeSensor::VirtualRangeSensor(std::string name, std::string parentName, osg::Node *root, osg::Node *trackNode, double range,
00023                                        bool visible,unsigned int mask)
00024 {
00025   init(name,parentName, root, trackNode, range, visible,mask);
00026 }
00027 
00028 void VirtualRangeSensor::init(std::string name, std::string parentName, osg::Node *root, osg::Node *trackNode, double range, bool visible,unsigned int mask)
00029 {
00030   this->name = name;
00031   this->parentLinkName=parentName;
00032   this->root = root;
00033 
00034   this->trackNode = trackNode;
00035   //Add a switchable frame geometry on the sensor frame
00036   osg::ref_ptr < osg::Node > axis = UWSimGeometry::createSwitchableFrame();
00037   //Add label to switchable frame
00038   axis->asGroup()->addChild(UWSimGeometry::createLabel(name));
00039   this->trackNode->asGroup()->addChild(axis);
00040 
00041   this->range = range;
00042   this->visible = visible;
00043 
00044   //make this virtual ray track the node
00045   node_tracker = new IntersectorUpdateCallback(range, visible, root);
00046   trackNode->setUpdateCallback(node_tracker);
00047   trackNode->asGroup()->addChild(node_tracker->geode);
00048 
00049   if(node_tracker->geode)
00050     node_tracker->geode->setNodeMask(mask);
00051 }
00052 
00053 int VirtualRangeSensor::getTFTransform(tf::Pose & pose, std::string & parent){
00054   parent=parentLinkName;
00055   pose.setOrigin(tf::Vector3(trackNode->asTransform()->asPositionAttitudeTransform()->getPosition().x(),
00056                         trackNode->asTransform()->asPositionAttitudeTransform()->getPosition().y(),
00057                         trackNode->asTransform()->asPositionAttitudeTransform()->getPosition().z()));
00058   pose.setRotation( tf::Quaternion(trackNode->asTransform()->asPositionAttitudeTransform()->getAttitude().x(),
00059                         trackNode->asTransform()->asPositionAttitudeTransform()->getAttitude().y(),
00060                         trackNode->asTransform()->asPositionAttitudeTransform()->getAttitude().z(),
00061                         trackNode->asTransform()->asPositionAttitudeTransform()->getAttitude().w()));
00062   return 1;
00063 
00064 }
00065 


uwsim
Author(s): Mario Prats , Javier Perez
autogenerated on Fri Aug 28 2015 13:28:58