Revision: 7445
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7445&view=rev
Author:   natepak
Date:     2009-03-10 09:39:14 +0000 (Tue, 10 Mar 2009)

Log Message:
-----------
Added missing objects

Added Paths:
-----------
    code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc
    code/branches/federation/gazebo/server/GraphicsIfaceHandler.hh
    code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc
    code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh

Added: code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc
===================================================================
--- code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc              
                (rev 0)
+++ code/branches/federation/gazebo/server/GraphicsIfaceHandler.cc      
2009-03-10 09:39:14 UTC (rev 7445)
@@ -0,0 +1,292 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+/* Desc: Handles messages from the graphics ifaces
+ * Author: Nate Koenig
+ * Date: 9 Mar 2009
+ * SVN: $Id:$
+ */
+
+#include "gazebo.h"
+#include "World.hh"
+#include "Entity.hh"
+#include "GazeboError.hh"
+#include "GazeboMessage.hh"
+#include "IfaceFactory.hh"
+#include "OgreVisual.hh"
+#include "OgreCreator.hh"
+#include "OgreVisualManager.hh"
+#include "OgreDynamicLines.hh"
+#include "GraphicsIfaceHandler.hh"
+#include "OgreAdaptor.hh"
+
+using namespace gazebo;
+
+////////////////////////////////////////////////////////////////////////////////
+/// Constructor
+GraphicsIfaceHandler::GraphicsIfaceHandler()
+{
+  this->threeDIface = NULL;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Destructor
+GraphicsIfaceHandler::~GraphicsIfaceHandler()
+{
+  if (this->threeDIface)
+    delete this->threeDIface;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Load the graphics handler
+void GraphicsIfaceHandler::Load(const std::string &_name, Entity *_parent)
+{
+  this->name = _name;
+
+  // Create the graphics3d interface
+  try
+  {
+    this->threeDIface = (Graphics3dIface*)IfaceFactory::NewIface("graphics3d");
+
+    this->threeDIface->Create(World::Instance()->GetGzServer(), _name);
+  }
+  catch (std::string err)
+  {
+    gzerr(0) << "Error: Unable to make graphics3d interface";
+    gzthrow(err);
+  }
+
+  this->parent = _parent;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Init the graphics handler
+void GraphicsIfaceHandler::Init()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Update the graphics handler
+void GraphicsIfaceHandler::Update()
+{
+  OgreVisual *vis = NULL;
+  std::map<std::string, OgreVisual* >::iterator iter;
+
+  this->threeDIface->Lock(1);
+  for (unsigned int i=0; i < this->threeDIface->data->cmdCount; i++)
+  {
+    // Get the name of visual to create/modify
+    std::string visName = this->threeDIface->data->commands[i].name;
+
+    iter = this->visuals.find(visName);
+
+    if (iter == this->visuals.end())
+    {
+      std::ostringstream nodeName;
+      nodeName << "GraphicsIfaceHandler_" << this->name << ": " 
+               << this->visuals.size();
+
+      if (this->parent)
+        vis = OgreVisualManager::Instance()->CreateVisual(nodeName.str(), 
+            this->parent->GetVisualNode());
+      else
+        vis = OgreVisualManager::Instance()->CreateVisual(nodeName.str());
+
+      this->visuals[visName] = vis;
+    }
+    else
+      vis = iter->second;
+
+    switch( this->threeDIface->data->commands[i].drawMode )
+    {
+      case Graphics3dDrawData::POINTS:
+      case Graphics3dDrawData::LINES:
+      case Graphics3dDrawData::LINE_STRIP:
+        this->DrawSimple(vis, &this->threeDIface->data->commands[i]);
+        break;
+
+      case Graphics3dDrawData::PLANE:
+      case Graphics3dDrawData::SPHERE:
+      case Graphics3dDrawData::CUBE:
+      case Graphics3dDrawData::BILLBOARD:
+        this->DrawShape(vis, &this->threeDIface->data->commands[i] );
+        break;
+
+      default:
+        gzerr(0) << "Unknown draw mode[" 
+          << this->threeDIface->data->commands[i].drawMode << "\n";
+        break;
+    }
+  }
+
+  this->threeDIface->data->cmdCount = 0;
+  this->threeDIface->Unlock();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Helper funciton used to draw simple elements
+void GraphicsIfaceHandler::DrawSimple(OgreVisual *vis, Graphics3dDrawData 
*data)
+{
+  Vector3 pos;
+  bool attached = false;
+  OgreDynamicRenderable::OperationType opType;
+  OgreDynamicLines *line;
+
+  switch(data->drawMode)
+  {
+    case Graphics3dDrawData::POINTS:
+      opType = OgreDynamicRenderable::OT_POINT_LIST;
+      break;
+    case Graphics3dDrawData::LINES:
+      opType = OgreDynamicRenderable::OT_LINE_LIST;
+      break;
+    case Graphics3dDrawData::LINE_STRIP:
+      opType = OgreDynamicRenderable::OT_LINE_STRIP;
+      break;
+    case Graphics3dDrawData::TRIANGLES:
+      opType = OgreDynamicRenderable::OT_TRIANGLE_LIST;
+      break;
+    case Graphics3dDrawData::TRIANGLE_STRIP:
+      opType = OgreDynamicRenderable::OT_TRIANGLE_STRIP;
+      break;
+    case Graphics3dDrawData::TRIANGLE_FAN:
+      opType = OgreDynamicRenderable::OT_TRIANGLE_FAN;
+      break;
+    default:
+      gzerr(0) << "Unknown draw operation mode[" 
+               << data->drawMode << "]\n";
+      return;
+  }
+
+
+  if (vis->GetNumAttached() > 0)
+  {
+    line = (OgreDynamicLines*)(vis->GetAttached(0));
+    attached = true;
+  }
+  else
+    line = new OgreDynamicLines(opType);
+
+  line->setMaterial(OgreCreator::CreateMaterial( data->color.r,
+                                                 data->color.g,
+                                                 data->color.b,
+                                                 data->color.a ));
+
+  // Set the line vertices
+  for (unsigned int i=0; i < data->pointCount; i++)
+  {
+    pos.Set( data->points[i].x, data->points[i].y, data->points[i].z);
+
+    if (attached)
+      line->SetPoint(i,pos);
+    else
+      line->AddPoint(pos);
+  }
+
+  line->Update();
+
+  if (!attached)
+    vis->AttachObject(line);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Helper funciton used to draw shapes
+void GraphicsIfaceHandler::DrawShape(OgreVisual *vis, Graphics3dDrawData *data)
+{
+  switch(data->drawMode)
+  {
+    case Graphics3dDrawData::CUBE:
+      {
+        if (vis->GetNumAttached() <= 0)
+          vis->AttachMesh("unit_box");
+
+        vis->SetScale(Vector3(data->size.x, data->size.y, data->size.z) );
+        vis->SetPosition(Vector3(data->pose.pos.x, 
+                                 data->pose.pos.y, 
+                                 data->pose.pos.z) );
+        break;
+      }
+
+    case Graphics3dDrawData::CYLINDER:
+      {
+        if (vis->GetNumAttached() <= 0)
+          vis->AttachMesh("unit_cylinder");
+
+        vis->SetScale(Vector3(data->size.x, data->size.y, data->size.z) );
+        vis->SetPosition(Vector3(data->pose.pos.x, 
+                                 data->pose.pos.y, 
+                                 data->pose.pos.z) );
+        break;
+      }
+
+    case Graphics3dDrawData::SPHERE:
+      {
+        if (vis->GetNumAttached() <= 0)
+          vis->AttachMesh("unit_sphere");
+
+        vis->SetScale(Vector3(data->size.x, data->size.y, data->size.z) );
+        vis->SetPosition(Vector3(data->pose.pos.x, 
+                                 data->pose.pos.y, 
+                                 data->pose.pos.z) );
+        break;
+      }
+    case Graphics3dDrawData::BILLBOARD:
+      {
+        bool attached = false;
+        Ogre::BillboardSet *bset = NULL;
+
+        if (vis->GetNumAttached() >0)
+        {
+          attached = true;
+          bset = (Ogre::BillboardSet *)vis->GetAttached(0);
+          bset->clear();
+        }
+        else
+        {
+          std::ostringstream bname;
+
+          bname << "BILLBOARD_" << this->name;
+          bset = OgreAdaptor::Instance()->sceneMgr->createBillboardSet(
+              bname.str().c_str());
+        }
+
+        Ogre::Billboard *billboard = bset->createBillboard(
+            Ogre::Vector3(data->pose.pos.x,
+              data->pose.pos.y,
+              data->pose.pos.z));
+
+        billboard->setDimensions(data->size.x, data->size.y);
+        bset->setMaterialName(
+            OgreCreator::CreateMaterialFromTexFile( data->billboardTexture));
+
+        if (!attached)
+          vis->AttachObject(bset);
+
+        break;
+      }
+    default:
+      {
+        gzerr(0) << "Unknown draw mode for shapes[" 
+          << data->drawMode << "]\n";
+        break;
+      }
+  }
+}
+

Added: code/branches/federation/gazebo/server/GraphicsIfaceHandler.hh
===================================================================
--- code/branches/federation/gazebo/server/GraphicsIfaceHandler.hh              
                (rev 0)
+++ code/branches/federation/gazebo/server/GraphicsIfaceHandler.hh      
2009-03-10 09:39:14 UTC (rev 7445)
@@ -0,0 +1,72 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+/* Desc: Handles messages from the graphics ifaces
+ * Author: Nate Koenig
+ * Date: 9 Mar 2009
+ * SVN: $Id:$
+ */
+
+#ifndef GRAPHICS_HH
+#define GRAPHICS_HH
+
+#include <map>
+#include "gazebo.h"
+
+namespace gazebo
+{
+
+  class Graphics3dIface;
+  class Entity;
+  class OgreVisual;
+  
+  /// \brief Used to handle message from the graphics3d libgazebo iface
+  class GraphicsIfaceHandler
+  {
+    /// \brief Constructor
+    public: GraphicsIfaceHandler();
+  
+    /// \brief Destructor
+    public: virtual ~GraphicsIfaceHandler();
+
+    /// \brief Load the graphics handler
+    public: void Load(const std::string &name, Entity *parent = NULL);
+
+    /// \brief Init the graphics handler
+    public: void Init();
+  
+    /// \brief Update the graphics handler
+    public: void Update();
+
+    /// \brief Helper funciton used to draw simple primitives
+    private: void DrawSimple(OgreVisual *vis, Graphics3dDrawData *data);
+
+    /// \brief Helper funciton used to draw shapes
+    private: void DrawShape(OgreVisual *vis, Graphics3dDrawData *data);
+
+    private: std::string name;
+    private: std::map<std::string, OgreVisual* > visuals;
+    private: Graphics3dIface *threeDIface;
+    private: Entity *parent;
+  };
+
+}
+
+#endif

Added: code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc       
                        (rev 0)
+++ code/branches/federation/gazebo/server/rendering/OgreVisualManager.cc       
2009-03-10 09:39:14 UTC (rev 7445)
@@ -0,0 +1,122 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+/* Desc: Manager of Ogre Visuals
+ * Author: Nate Koenig
+ * Date: 09 Mar 2009
+ * SVN: $Id:$
+ */
+
+#include "Model.hh"
+#include "GazeboError.hh"
+#include "Entity.hh"
+#include "OgreVisual.hh"
+#include "OgreVisualManager.hh"
+
+using namespace gazebo;
+
+////////////////////////////////////////////////////////////////////////////////
+/// Constructor
+OgreVisualManager::OgreVisualManager()
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Destructor
+OgreVisualManager::~OgreVisualManager()
+{
+}
+ 
+////////////////////////////////////////////////////////////////////////////////
+/// Create a new ogre visual 
+OgreVisual *OgreVisualManager::CreateVisual( const std::string &name,
+    OgreVisual *parent, Entity *owner)
+{
+  OgreVisual *newVis = NULL;
+  std::map<std::string, OgreVisual*>::iterator iter;
+
+  iter = this->visuals.find(name);
+
+  if (iter == this->visuals.end())
+  {
+    newVis = new OgreVisual(parent, owner);
+    newVis->SetName(name);
+    this->visuals[name] = newVis;
+  }
+  else
+    gzthrow(std::string("Name of ogre visual already exists: ") + name);
+
+  return newVis;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Create a standalone visual  
+OgreVisual *OgreVisualManager::CreateStandaloneVisual( const std::string 
&name, 
+                                                       const std::string &type 
)
+{
+  OgreVisual *newVis = NULL;
+  std::map<std::string, OgreVisual*>::iterator iter;
+
+  iter = this->visuals.find(name);
+
+  if (iter == this->visuals.end())
+  {
+    newVis = new OgreVisual(NULL, NULL);
+    newVis->SetName(name);
+    this->visuals[name] = newVis;
+  }
+  else
+    gzthrow(std::string("Name of ogre visual already exists: ") + name);
+
+  return newVis;
+}
+
+
+////////////////////////////////////////////////////////////////////////////////
+/// Remove a visual
+void OgreVisualManager::RemoveVisual( const std::string &name )
+{
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Update all the visuals
+void OgreVisualManager::Update()
+{
+  /*std::map<std::string, OgreVisual*>::iterator iter;
+  OgreVisual *vis = NULL;
+  Entity *owner = NULL;
+  Pose3d pose;
+
+  printf("----------------------\n");
+  for (iter = this->visuals.begin(); iter != this->visuals.end(); iter++)
+  {
+    vis = iter->second;
+    owner = vis->GetOwner();
+    Model *model = dynamic_cast<Model*>(owner);
+
+    if (owner)
+    {
+      //std::cout << "Vis[" << owner->GetName() << "] Pose[" << 
owner->GetPoseRelative() << "]\n";
+      //vis->SetPose(owner->GetPoseRelative());
+    }
+  }
+  */
+}
+ 

Added: code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh
===================================================================
--- code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh       
                        (rev 0)
+++ code/branches/federation/gazebo/server/rendering/OgreVisualManager.hh       
2009-03-10 09:39:14 UTC (rev 7445)
@@ -0,0 +1,79 @@
+/*
+ *  Gazebo - Outdoor Multi-Robot Simulator
+ *  Copyright (C) 2003  
+ *     Nate Koenig & Andrew Howard
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+/* Desc: Manager of Ogre Visuals
+ * Author: Nate Koenig
+ * Date: 09 Mar 2009
+ * SVN: $Id:$
+ */
+
+#ifndef OGREVISUALMANAGER_HH
+#define OGREVISUALMANAGER_HH
+
+#include <map>
+
+#include "SingletonT.hh"
+
+namespace gazebo
+{
+  class OgreVisual;
+  class Entity;
+
+  /// \brief Class to manage all the ogre visuals  
+  class OgreVisualManager : public SingletonT<OgreVisualManager>
+  {
+    /// \brief Constructor
+    private: OgreVisualManager();
+
+    /// \brief Destructor
+    private: virtual ~OgreVisualManager();
+ 
+    /// \brief Create a new ogre visual 
+    /// \param name Unique name for the new visual
+    /// \param parent Parent visual
+    /// \param owner The entity that owns the visual
+    /// \return The new ogre visual
+    public: OgreVisual *CreateVisual( const std::string &name,
+                                      OgreVisual *parent=NULL, 
+                                      Entity *owner = NULL );
+
+    /// \brief Create a standalone visual  
+    /// \param name Unique name
+    /// \param type Type of visual object to create
+    /// \return The newly created visual
+    public: OgreVisual *CreateStandaloneVisual( const std::string &name, 
+                                               const std::string &type );
+
+    /// \brief Remove a visual
+    /// \param name Unique name of the visual to remove
+    public: void RemoveVisual( const std::string &name );
+
+    /// \brief Update all the visuals
+    public: void Update();
+ 
+    // All the visuals 
+    private: std::map<std::string, OgreVisual*> visuals;
+  
+    private: friend class DestroyerT<OgreVisualManager>;
+    private: friend class SingletonT<OgreVisualManager>;
+  };
+}
+
+#endif


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to