From 03a973f1a46e22adc2461ad48323c48b97140566 Mon Sep 17 00:00:00 2001 From: Joseph Mirabel <jmirabel@laas.fr> Date: Fri, 2 Mar 2018 16:16:34 +0100 Subject: [PATCH] Remove URDF caching based on file timestamp. --- .../gepetto/viewer/corba/windows-manager.hh | 16 ---- src/windows-manager.cpp | 84 +++++-------------- 2 files changed, 20 insertions(+), 80 deletions(-) diff --git a/include/gepetto/viewer/corba/windows-manager.hh b/include/gepetto/viewer/corba/windows-manager.hh index 424e014..21874f7 100644 --- a/include/gepetto/viewer/corba/windows-manager.hh +++ b/include/gepetto/viewer/corba/windows-manager.hh @@ -61,13 +61,6 @@ namespace graphics { } }; - struct UrdfFile { - std::string filename; - time_t modTime; - UrdfFile (const std::string& f); - UrdfFile () {} - }; - DEF_CLASS_SMART_PTR(WindowsManager) class WindowsManager @@ -82,9 +75,6 @@ namespace graphics { typedef std::map <std::string, WindowID> WindowIDMap_t; WindowIDMap_t windowIDmap_; - typedef std::map <std::string, UrdfFile> UrdfFileMap_t; - UrdfFileMap_t urdfFileMap_; - private: typedef std::vector <WindowManagerPtr_t> WindowManagerVector_t; typedef std::vector<NodeConfiguration> NodeConfigurations_t; @@ -106,14 +96,8 @@ namespace graphics { NodePtr_t find (const std::string name, GroupNodePtr_t group = GroupNodePtr_t()); void initParent(NodePtr_t node, GroupNodePtr_t parent); void threadRefreshing(WindowManagerPtr_t window); - bool urdfUpToDate (const std::string nodeName, - const std::string filename); bool loadUDRF(const std::string& urdfName, const std::string& urdfPath, bool visual, bool linkFrame); - void registerUrdfNode (const std::string nodeName, - const std::string filename); - bool urdfNodeMustBeAdded (const std::string& nodeName, - const std::string& filename); protected: /** diff --git a/src/windows-manager.cpp b/src/windows-manager.cpp index d5fec37..b456392 100644 --- a/src/windows-manager.cpp +++ b/src/windows-manager.cpp @@ -300,32 +300,6 @@ namespace graphics { } } - UrdfFile::UrdfFile (const std::string& f) - : filename (urdfParser::getFilename(f)) { - struct stat buffer; - if (stat (filename.c_str(), &buffer) != 0) { - perror (filename.c_str()); - modTime = 0; - } - modTime = buffer.st_mtime; - } - - bool WindowsManager::urdfUpToDate (const std::string nodeName, - const std::string filename) - { - UrdfFileMap_t::const_iterator it = urdfFileMap_.find (nodeName); - if (it == urdfFileMap_.end()) - return false; - UrdfFile uf (filename); - return it->second.modTime == uf.modTime; - } - - void WindowsManager::registerUrdfNode (const std::string nodeName, - const std::string filename) - { - urdfFileMap_[nodeName] = UrdfFile (filename); - } - //Public functions bool WindowsManager::setRate (const int& rate) @@ -905,22 +879,6 @@ namespace graphics { return true; } - bool WindowsManager::urdfNodeMustBeAdded (const std::string& nodeName, - const std::string& filename) - { - if (nodes_.find (nodeName) != nodes_.end ()) { - if (urdfUpToDate (nodeName, filename)) { - std::cout << "Urdf already loaded: " << nodeName << std::endl; - return false; - } else { - // Erase existing node. - std::cout << "Urdf deleted: " << nodeName << std::endl; - deleteNode (nodeName, false); - } - } - return true; - } - bool WindowsManager::addURDF (const std::string& urdfName, const std::string& urdfPath) { @@ -964,31 +922,29 @@ namespace graphics { bool WindowsManager::loadUDRF(const std::string& urdfName, const std::string& urdfPath, bool visual, bool linkFrame) { - if (urdfNodeMustBeAdded (urdfName, urdfPath)) { - GroupNodePtr_t urdf = - urdfParser::parse (urdfName, urdfPath, visual, linkFrame); - osgFrameMutex().lock(); - addGroup (urdfName, urdf, true); - NodePtr_t link; - for (std::size_t i=0; i< urdf->getNumOfChildren (); i++) { - link = urdf->getChild (i); - GroupNodePtr_t groupNode (dynamic_pointer_cast - <GroupNode> (link)); - if (groupNode) { - addGroup(link->getID(), groupNode, urdf); - for (std::size_t j=0; j < groupNode->getNumOfChildren (); ++j) { - NodePtr_t object (groupNode->getChild (j)); - addNode(object->getID (), object, groupNode); - } - } else { - addNode(link->getID(), link, urdf); + RETURN_FALSE_IF_NODE_EXISTS(urdfName); + + GroupNodePtr_t urdf = + urdfParser::parse (urdfName, urdfPath, visual, linkFrame); + osgFrameMutex().lock(); + addGroup (urdfName, urdf, true); + NodePtr_t link; + for (std::size_t i=0; i< urdf->getNumOfChildren (); i++) { + link = urdf->getChild (i); + GroupNodePtr_t groupNode (dynamic_pointer_cast + <GroupNode> (link)); + if (groupNode) { + addGroup(link->getID(), groupNode, urdf); + for (std::size_t j=0; j < groupNode->getNumOfChildren (); ++j) { + NodePtr_t object (groupNode->getChild (j)); + addNode(object->getID (), object, groupNode); } + } else { + addNode(link->getID(), link, urdf); } - registerUrdfNode (urdfName, urdfPath); - osgFrameMutex().unlock(); - return true; } - return false; + osgFrameMutex().unlock(); + return true; } bool WindowsManager::addToGroup (const std::string& nodeName, -- GitLab