From 2c7162028725bebe649d2b92b4ceaab2d861796e Mon Sep 17 00:00:00 2001
From: Joseph Mirabel <jmirabel@laas.fr>
Date: Sat, 13 Apr 2019 11:25:32 +0200
Subject: [PATCH] Add node type as attribute of MeshLoader.

---
 include/hpp/fcl/mesh_loader/loader.h | 39 +++++++++++++++++++++++-----
 src/mesh_loader/loader.cpp           | 14 ++++------
 2 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/include/hpp/fcl/mesh_loader/loader.h b/include/hpp/fcl/mesh_loader/loader.h
index bc04b05b..ce8a30af 100644
--- a/include/hpp/fcl/mesh_loader/loader.h
+++ b/include/hpp/fcl/mesh_loader/loader.h
@@ -39,6 +39,7 @@
 
 #include <boost/shared_ptr.hpp>
 #include <hpp/fcl/fwd.hh>
+#include <hpp/fcl/config.hh>
 #include <hpp/fcl/math/vec_3f.h>
 #include <hpp/fcl/collision_object.h>
 
@@ -52,9 +53,23 @@ namespace fcl {
     public:
       virtual ~MeshLoader() {}
 
-      virtual CollisionGeometryPtr_t load (const std::string& filename,
+      /// \param bvType ignored
+      /// \deprecated Use MeshLoader::load(const std::string&, const Vec3f&)
+      CollisionGeometryPtr_t load (const std::string& filename,
           const Vec3f& scale,
-          const NODE_TYPE& bvType);
+          const NODE_TYPE& bvType) HPP_FCL_DEPRECATED
+      {
+        (void) bvType;
+        return load (filename, scale);
+      }
+
+      virtual CollisionGeometryPtr_t load (const std::string& filename,
+          const Vec3f& scale);
+
+      MeshLoader (const NODE_TYPE& bvType = BV_OBBRSS) : bvType_ (bvType) {}
+
+    private:
+      const NODE_TYPE bvType_;
   };
 
   /// Class for building polyhedron from files with cache mechanism.
@@ -66,17 +81,27 @@ namespace fcl {
     public:
       virtual ~CachedMeshLoader() {}
 
-      virtual CollisionGeometryPtr_t load (const std::string& filename,
+      CachedMeshLoader (const NODE_TYPE& bvType = BV_OBBRSS) : MeshLoader (bvType) {}
+
+      /// \param bvType ignored
+      /// \deprecated Use MeshLoader::load(const std::string&, const Vec3f&)
+      CollisionGeometryPtr_t load (const std::string& filename,
           const Vec3f& scale,
-          const NODE_TYPE& bvType);
+          const NODE_TYPE& bvType) HPP_FCL_DEPRECATED
+      {
+        (void) bvType;
+        return load(filename, scale);
+      }
+
+      virtual CollisionGeometryPtr_t load (const std::string& filename,
+          const Vec3f& scale);
 
       struct Key {
         std::string filename;
         Vec3f scale;
-        NODE_TYPE bvType;
 
-        Key (const std::string& f, const Vec3f& s, const NODE_TYPE& t)
-          : filename (f), scale (s), bvType (t) {}
+        Key (const std::string& f, const Vec3f& s)
+          : filename (f), scale (s) {}
 
         bool operator< (const CachedMeshLoader::Key& b) const;
       };
diff --git a/src/mesh_loader/loader.cpp b/src/mesh_loader/loader.cpp
index 21392445..d2e9b36a 100644
--- a/src/mesh_loader/loader.cpp
+++ b/src/mesh_loader/loader.cpp
@@ -45,8 +45,6 @@ namespace fcl {
   bool CachedMeshLoader::Key::operator< (const CachedMeshLoader::Key& b) const
   {
     const CachedMeshLoader::Key& a = *this;
-    if (a.bvType < b.bvType) return true;
-    if (a.bvType > b.bvType) return false;
     for (int i = 0; i < 3; ++i) {
       if (a.scale[i] < b.scale[i]) return true;
       else if (a.scale[i] > b.scale[i]) return false;
@@ -63,10 +61,9 @@ namespace fcl {
   }
 
   CollisionGeometryPtr_t MeshLoader::load (const std::string& filename,
-      const Vec3f& scale,
-      const NODE_TYPE& bvType)
+      const Vec3f& scale)
   {
-    switch (bvType) {
+    switch (bvType_) {
       case BV_AABB  : return _load <AABB  > (filename, scale);
       case BV_OBB   : return _load <OBB   > (filename, scale);
       case BV_RSS   : return _load <RSS   > (filename, scale);
@@ -81,13 +78,12 @@ namespace fcl {
   }
 
   CollisionGeometryPtr_t CachedMeshLoader::load (const std::string& filename,
-      const Vec3f& scale,
-      const NODE_TYPE& bvType)
+      const Vec3f& scale)
   {
-    Key key (filename, scale, bvType);
+    Key key (filename, scale);
     Cache_t::const_iterator _cached = cache_.find (key);
     if (_cached == cache_.end()) {
-      CollisionGeometryPtr_t geom = MeshLoader::load (filename, scale, bvType);
+      CollisionGeometryPtr_t geom = MeshLoader::load (filename, scale);
       cache_.insert (std::make_pair(key, geom));
       return geom;
     } else {
-- 
GitLab