scene.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_render_server/scene.h"
00031 #include "rve_render_server/renderer.h"
00032 #include "rve_render_server/camera.h"
00033 #include "rve_render_server/mesh_instance.h"
00034 #include "rve_render_server/billboard_text.h"
00035 #include "rve_render_server/batching/points_manager.h"
00036 #include "rve_render_server/batching/lines_manager.h"
00037 #include "rve_render_server/batching/triangles_manager.h"
00038 
00039 #include <OGRE/OgreSceneManager.h>
00040 #include <OGRE/OgreCamera.h>
00041 #include <OGRE/OgreRoot.h>
00042 #include <OGRE/OgreEntity.h>
00043 
00044 #include <ros/assert.h>
00045 
00046 using namespace rve_common;
00047 
00048 namespace rve_render_server
00049 {
00050 
00051 Scene::Scene(const UUID& id, Ogre::SceneManager* scene_manager)
00052 : id_(id)
00053 , scene_manager_(scene_manager)
00054 , points_manager_(new PointsManager(scene_manager))
00055 , lines_manager_(new LinesManager(scene_manager))
00056 , triangles_manager_(new TrianglesManager(scene_manager))
00057 {
00058 }
00059 
00060 Scene::~Scene()
00061 {
00062   cameras_.clear();
00063   mesh_instances_.clear();
00064   billboard_texts_.clear();
00065   delete points_manager_;
00066   delete lines_manager_;
00067   delete triangles_manager_;
00068   Ogre::Root::getSingleton().destroySceneManager(scene_manager_);
00069 }
00070 
00071 Camera* Scene::createCamera(const UUID& id)
00072 {
00073   Ogre::Camera* ogre_cam = scene_manager_->createCamera(id.toString());
00074   ogre_cam->setPosition(0, 10, 10);
00075   ogre_cam->lookAt(0, 0, 0);
00076   ogre_cam->setNearClipDistance(0.01);
00077   ogre_cam->setFarClipDistance(1000.0);
00078   ogre_cam->setAutoAspectRatio(false);
00079 
00080   CameraPtr cam(new Camera(ogre_cam));
00081   cameras_[id] = cam;
00082 
00083   return cam.get();
00084 }
00085 
00086 void Scene::destroyCamera(const UUID& id)
00087 {
00088   M_Camera::iterator it = cameras_.find(id);
00089   ROS_ASSERT(it != cameras_.end());
00090 
00091   const CameraPtr& cam = it->second;
00092   scene_manager_->destroyCamera(cam->getOgreCamera());
00093 
00094   cameras_.erase(it);
00095 }
00096 
00097 Camera* Scene::getCamera(const UUID& id)
00098 {
00099   M_Camera::iterator it = cameras_.find(id);
00100   if (it == cameras_.end())
00101   {
00102     return 0;
00103   }
00104 
00105   return it->second.get();
00106 }
00107 
00108 MeshInstance* Scene::createMeshInstance(const rve_common::UUID& id, const rve_common::UUID& mesh_id)
00109 {
00110   MeshPtr mesh = getRenderer()->getMesh(mesh_id);
00111   MeshInstancePtr inst(new MeshInstance(id, scene_manager_, mesh));
00112   mesh_instances_[id] = inst;
00113   return inst.get();
00114 }
00115 
00116 MeshInstance* Scene::getMeshInstance(const rve_common::UUID& id)
00117 {
00118   M_MeshInstance::iterator it = mesh_instances_.find(id);
00119   if (it == mesh_instances_.end())
00120   {
00121     throw std::runtime_error("Mesh instance [" + id.toString() + "] does not exist");
00122   }
00123 
00124   return it->second.get();
00125 }
00126 
00127 void Scene::destroyMeshInstance(const rve_common::UUID& id)
00128 {
00129   mesh_instances_.erase(id);
00130 }
00131 
00132 BillboardText* Scene::createBillboardText(const rve_common::UUID& id)
00133 {
00134   BillboardTextPtr bbt(new BillboardText(id, scene_manager_));
00135   billboard_texts_[id] = bbt;
00136   return bbt.get();
00137 }
00138 
00139 void Scene::destroyBillboardText(const rve_common::UUID& id)
00140 {
00141   billboard_texts_.erase(id);
00142 }
00143 
00144 BillboardText* Scene::getBillboardText(const rve_common::UUID& id)
00145 {
00146   M_BillboardText::iterator it = billboard_texts_.find(id);
00147   if (it == billboard_texts_.end())
00148   {
00149     return 0;
00150   }
00151 
00152   return it->second.get();
00153 }
00154 
00155 } // namespace rve_render_server


rve_render_server
Author(s): Josh Faust
autogenerated on Wed Dec 11 2013 14:31:15