transformer.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Willow Garage, Inc.
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  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 #include <rve_common/registry.h>
00031 #include <rve_properties/property_node.h>
00032 #include <rve_render_client/client_context.h>
00033 #include <rve_render_client/context_object_collection.h>
00034 #include <rve_render_client/scene_object_collection.h>
00035 #include <rve_render_client/scene.h>
00036 
00037 #include <ros/callback_queue.h>
00038 
00039 #include <rve_transformer/transformer.h>
00040 
00041 namespace rve_transformer
00042 {
00043 
00044 Transformer::Transformer()
00045 : callback_queue_(0)
00046 , manager_(0)
00047 , scene_objects_(rve_render_client::createSceneObjectCollection())
00048 , context_objects_(rve_render_client::createContextObjectCollection())
00049 {
00050 }
00051 
00052 Transformer::~Transformer()
00053 {
00054   property_node_->removeChangeCallback(this);
00055   property_node_.reset();
00056   subs_.clear();
00057   pubs_.clear();
00058   delete callback_queue_;
00059 }
00060 
00061 void Transformer::init(TransformerManager* manager, const rve_properties::PropertyNodePtr& property_node)
00062 {
00063   manager_ = manager;
00064   property_node_ = property_node;
00065 
00066   if (!property_node_)
00067   {
00068     property_node_.reset(new rve_properties::PropertyNode);
00069   }
00070 
00071   callback_queue_ = new ros::CallbackQueue();
00072 
00073   onInit();
00074 }
00075 
00076 void Transformer::update()
00077 {
00078   callback_queue_->callAvailable();
00079   onUpdate();
00080 }
00081 
00082 void Transformer::setSubscription(const std::string& name, const std::string& topic)
00083 {
00084   V_Sub::iterator it = subs_.begin();
00085   V_Sub::iterator end = subs_.end();
00086   for (; it != end; ++it)
00087   {
00088     const SubPtr& sub = *it;
00089 
00090     if (sub->name == name)
00091     {
00092       if (topic.empty())
00093       {
00094         sub->sub->unsubscribe();
00095       }
00096       else
00097       {
00098         ros::NodeHandle nh;
00099         sub->sub->subscribe(nh, topic, sub->queue_size, ros::TransportHints(), callback_queue_);
00100       }
00101       return;
00102     }
00103   }
00104 
00105   throw std::runtime_error("No subscription named " + name);
00106 }
00107 
00108 void Transformer::addObjectImpl(const rve_render_client::SceneObjectPtr& obj)
00109 {
00110   scene_objects_->addObject(obj);
00111 }
00112 
00113 void Transformer::removeObject(const rve_render_client::SceneObjectPtr& obj)
00114 {
00115   scene_objects_->removeObject(obj);
00116 }
00117 
00118 void Transformer::addObjectImpl(const rve_render_client::ContextObjectPtr& obj)
00119 {
00120   context_objects_->addObject(obj);
00121 }
00122 
00123 void Transformer::removeObject(const rve_render_client::ContextObjectPtr& obj)
00124 {
00125   context_objects_->removeObject(obj);
00126 }
00127 
00128 void Transformer::attachToScene(rve_render_client::Scene* scene)
00129 {
00130   scene->addObject(scene_objects_.get());
00131 }
00132 
00133 void Transformer::detachFromScene(rve_render_client::Scene* scene)
00134 {
00135   scene->removeObject(scene_objects_.get());
00136 }
00137 
00138 void Transformer::attachToContext(rve_render_client::ClientContext* context)
00139 {
00140   context->addObject(context_objects_.get());
00141 }
00142 
00143 void Transformer::detachFromContext(rve_render_client::ClientContext* context)
00144 {
00145   context->removeObject(context_objects_.get());
00146 }
00147 
00148 bool Transformer::addToRegistry( rve_common::RegistryPtr registry, rve_common::RegistrantWPtr registrant )
00149 {
00150   return scene_objects_->addToRegistry( registry, registrant );
00151 }
00152 
00153 bool Transformer::removeFromRegistry( rve_common::RegistryPtr registry, rve_common::RegistrantWPtr registrant )
00154 {
00155   return scene_objects_->removeFromRegistry( registry, registrant );
00156 }
00157 
00158 } // namespace rve_transformer


rve_transformer
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:51