From f7f7ca276a5a6d0c6695a5812925a27eaa9299a8 Mon Sep 17 00:00:00 2001
From: Florent Lamiraux <florent@laas.fr>
Date: Wed, 24 Dec 2014 16:15:46 +0100
Subject: [PATCH] Add an interface method that load the collision geometry of
 urdf files.

  - addUrdfCollision loads collision geometry in viewer, while
    addURDF loads visual geometry.
---
 idl/gepetto/viewer/graphical-interface.idl | 19 ++++++++++++++
 src/graphical-interface.impl.cpp           | 30 ++++++++++++++++++++++
 src/graphical-interface.impl.hh            |  5 ++++
 3 files changed, 54 insertions(+)

diff --git a/idl/gepetto/viewer/graphical-interface.idl b/idl/gepetto/viewer/graphical-interface.idl
index 50f510c..bc7f3ec 100644
--- a/idl/gepetto/viewer/graphical-interface.idl
+++ b/idl/gepetto/viewer/graphical-interface.idl
@@ -130,6 +130,25 @@ typedef double Color [4];
     boolean addURDF (in string robotName, in string urdfFilePath,
 		     in string meshDataRootDir) raises (Error);
 
+    /// Create a node from an urdf file
+    /// \param robotName Name of the node that will contain the robot geometry,
+    ///                  each geometric part is prefixed by this name,
+    /// \param urdfFilePath to the package containing the urdf file,
+    ///                       i.e. "/opt/ros/hydro/share/pr2_description",
+    /// \param meshDataRootDir path to the package that contains the collada
+    ///                        files, this path should finish by "/",
+    ///                        i.e. "/opt/ros/hydro/share/"
+    /// \note the parser will replace "package://" by meshDataRootDir in the
+    ///       urdf file.
+    /// a groupNode is created and each link will be child node of this node.
+    /// Links are named "prefix/linkName", linkName is the name of the link
+    /// in the URDF file.
+    ///
+    /// Unlike addURDF, this method will load the collision geometry instead
+    /// of the visual geometry.
+    boolean addUrdfCollision (in string robotName, in string urdfFilePath,
+			      in string meshDataRootDir) raises (Error);
+
     /// create a groupNode called groupName
     /// \param input groupName : name of the group.
     boolean createGroup(in string groupName) raises (Error);
diff --git a/src/graphical-interface.impl.cpp b/src/graphical-interface.impl.cpp
index 7d7d084..c71e492 100644
--- a/src/graphical-interface.impl.cpp
+++ b/src/graphical-interface.impl.cpp
@@ -595,6 +595,36 @@ namespace graphics {
 	}
       }
 
+      bool GraphicalInterface::addUrdfCollision
+      (const char* urdfNameCorba, const char* urdfPathCorba,
+       const char* urdfPackagePathCorba) throw (Error)
+      {
+	try {
+	  const std::string urdfName (urdfNameCorba);
+	  const std::string urdfPath (urdfPathCorba);
+	  const std::string urdfPackagePath (urdfPackagePathCorba);
+	  if (nodes_.find (urdfName) != nodes_.end ()) {
+	    std::cout << "You need to chose an other name, \"" << urdfName
+		      << "\" already exist." << std::endl;
+	    return false;
+	  }
+	  else {
+	    GroupNodePtr_t urdf = urdfParser::parse
+	      (urdfName, urdfPath, urdfPackagePath, "collision");
+	    NodePtr_t link;
+	    for (int i=0; i< urdf->getNumOfChildren (); i++) {
+	      link = urdf->getChild (i);
+	      nodes_[link->getID ()] = link;
+	    }
+	    GraphicalInterface::initParent (urdfName, urdf);
+	    addGroup (urdfName, urdf);
+	    return true;
+	  }
+	} catch (const std::exception& exc) {
+	  throw Error (exc.what ());
+	}
+      }
+
       bool GraphicalInterface::addToGroup (const char* nodeNameCorba,
 					   const char* groupNameCorba)
 	throw (Error)
diff --git a/src/graphical-interface.impl.hh b/src/graphical-interface.impl.hh
index 6657aac..f8d7ca2 100644
--- a/src/graphical-interface.impl.hh
+++ b/src/graphical-interface.impl.hh
@@ -108,6 +108,11 @@ public:
 
   virtual bool addURDF(const char* urdfNameCorba, const char* urdfPathCorba, const char* urdfPackagePathCorba) throw (Error);
 
+  virtual bool addUrdfCollision (const char* urdfNameCorba,
+				 const char* urdfPathCorba,
+				 const char* urdfPackagePathCorba)
+    throw (Error);
+
   virtual bool createGroup(const char* groupNameCorba)  throw (Error);
   virtual bool addToGroup(const char* nodeNameCorba, const char* groupNameCorba)  throw (Error);
 
-- 
GitLab