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 #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 }