test_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 "test_transformer.h"
00031 #include "rve_render_client/client_context.h"
00032 #include "rve_render_server/init.h"
00033 #include "rve_render_client/init.h"
00034 #include "rve_render_client/render_window.h"
00035 #include "rve_render_client/scene.h"
00036 #include "rve_render_client/mesh_instance.h"
00037 #include "rve_render_client/camera.h"
00038 #include "rve_render_client/sphere.h"
00039 #include "rve_render_client/billboard_text.h"
00040 #include <rve_transformer/transformer_manager.h>
00041 #include <rve_transformer/frame_manager.h>
00042 #include <rve_common_transformers/urdf.h>
00043 #include <rve_common_transformers/orbit_camera.h>
00044 #include <rve_properties/property_node.h>
00045 #include <rve_properties/messages.h>
00046 
00047 #include <rve_qt/render_widget.h>
00048 
00049 #include <rve_msgs/make_vector3.h>
00050 #include <rve_msgs/make_quaternion.h>
00051 
00052 #include <urdf/model.h>
00053 
00054 #include <Eigen/Geometry>
00055 
00056 #include <ros/package.h>
00057 #include <ros/time.h>
00058 
00059 #include <ros/time.h>
00060 #include <ros/ros.h>
00061 
00062 #include <QtGui/QtGui>
00063 
00064 using namespace rve_render_client;
00065 
00066 MyWidget::MyWidget(const ClientContextPtr& context, QWidget* parent)
00067 : RenderWidget(context.get(), parent)
00068 , private_nh_("~")
00069 , left_mouse_down_( false )
00070 , middle_mouse_down_( false )
00071 , right_mouse_down_( false )
00072 , mouse_x_( 0 )
00073 , mouse_y_( 0 )
00074 {
00075   context_ = context;
00076 
00077   scene_ = rve_render_client::createScene(context_);
00078   camera_ = rve_render_client::createCamera(scene_.get());
00079   camera_->setPosition(rve_msgs::makeVector3(-10, 0, 0));
00080   camera_->lookAt(rve_msgs::makeVector3(0, 0, 0));
00081   getRemoteRenderWindow()->attachCamera(camera_);
00082 
00083   transformer_manager_.reset(new rve_transformer::TransformerManager());
00084   transformer_manager_->getFrameManager()->setFixedFrame("base_footprint");
00085 
00086 //  urdf_ = transformer_manager_->createTransformer<rve_common_transformers::URDF>();
00087 //  urdf_->attachToScene(scene_.get());
00088 //  urdf_->attachToContext(context_.get());
00089 
00090   cam_ = transformer_manager_->createTransformer<rve_common_transformers::OrbitCamera>();
00091   cam_->setCamera(camera_);
00092   cam_->setSubscription("mouse_input", getMouseEventTopic());
00093   cam_->getPropertyNode()->set("target_frame", "wide_stereo_optical_frame");
00094 
00095   text_ = rve_render_client::createBillboardText( scene_.get(), "Cheese monkey" );
00096   text_->setPosition(rve_msgs::makeVector3(0,10,0));
00097   text_->setCharacterHeight(0.1);
00098   rve_msgs::ColorRGB c;
00099   c.r = 1;
00100   c.g = 0;
00101   c.b = 0;
00102   text_->setColor(c);
00103   text_->setHorizontalAlignment(rve_msgs::TextAlignment::H_CENTER);
00104   text_->setVerticalAlignment(rve_msgs::TextAlignment::V_CENTER);
00105 
00106   ball_ = rve_render_client::createSphere( scene_.get() );
00107   ball_->setPosition(rve_msgs::makeVector3(10,0,0));
00108 
00109   flag_ = rve_render_client::createMeshInstance(scene_.get(), "package://test_rve/flag.dae");
00110   flag_->setPosition(rve_msgs::makeVector3(0,0,0));
00111 
00112   QTimer* timer = new QTimer(this);
00113   connect(timer, SIGNAL(timeout()), this, SLOT(update()));
00114   timer->start(33);
00115 }
00116 
00117 void MyWidget::update()
00118 {
00119   try
00120   {
00121     transformer_manager_->update();
00122     getRemoteRenderWindow()->requestRender();
00123   }
00124   catch (std::exception& e)
00125   {
00126     ROS_ERROR("%s", e.what());
00127   }
00128 }
00129 
00130 int main(int argc, char** argv)
00131 {
00132   int ret = 0;
00133 
00134   try
00135   {
00136     QApplication app(argc, argv);
00137     ros::init(argc, argv, "test_playpen", ros::init_options::NoSigintHandler);
00138     rve_render_server::init(true, "render_server");
00139     rve_render_client::init();
00140     ros::AsyncSpinner as(0);
00141     as.start();
00142 
00143     ClientContextPtr context = createContext("render_server", ros::NodeHandle("render_server"));
00144     MyWidget window(context);
00145     window.resize(1024, 768);
00146     window.show();
00147     window.setWindowTitle(QApplication::translate("toplevel", "test_transformer"));
00148 
00149     ret = app.exec();
00150 
00151   }
00152   catch (std::exception& e)
00153   {
00154     ROS_ERROR("Caught exception: %s", e.what());
00155   }
00156 
00157   rve_render_client::shutdown();
00158   rve_render_server::shutdown();
00159   return ret;
00160 }
00161 


test_rve
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:32:08