Skip to content

Commit

Permalink
Leverage tesseract_common loadYamlFile and loadYamlString
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jan 4, 2025
1 parent 11d935b commit f7afe1d
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <map>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_common/fwd.h>
#include <tesseract_common/filesystem.h>
#include <tesseract_common/plugin_loader.h>
#include <tesseract_common/plugin_info.h>
Expand Down Expand Up @@ -115,13 +116,14 @@ class ContactManagersPluginFactory
* @brief Load plugins from file path
* @param config The config file path
*/
ContactManagersPluginFactory(const tesseract_common::fs::path& config);
ContactManagersPluginFactory(const tesseract_common::fs::path& config,
const tesseract_common::ResourceLocator& locator);

/**
* @brief Load plugins from string
* @param config The config string
*/
ContactManagersPluginFactory(const std::string& config);
ContactManagersPluginFactory(const std::string& config, const tesseract_common::ResourceLocator& locator);

/**
* @brief Add location for the plugin loader to search
Expand Down
11 changes: 7 additions & 4 deletions tesseract_collision/core/src/contact_managers_plugin_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_collision/core/discrete_contact_manager.h>
#include <tesseract_collision/core/continuous_contact_manager.h>
#include <tesseract_common/resource_locator.h>
#include <tesseract_common/plugin_loader.hpp>
#include <tesseract_common/yaml_utils.h>
#include <tesseract_common/yaml_extenstions.h>
Expand Down Expand Up @@ -71,13 +72,15 @@ ContactManagersPluginFactory::ContactManagersPluginFactory(YAML::Node config) :
}
}

ContactManagersPluginFactory::ContactManagersPluginFactory(const tesseract_common::fs::path& config)
: ContactManagersPluginFactory(YAML::LoadFile(config.string()))
ContactManagersPluginFactory::ContactManagersPluginFactory(const tesseract_common::fs::path& config,
const tesseract_common::ResourceLocator& locator)
: ContactManagersPluginFactory(tesseract_common::loadYamlFile(config.string(), locator))
{
}

ContactManagersPluginFactory::ContactManagersPluginFactory(const std::string& config)
: ContactManagersPluginFactory(YAML::Load(config))
ContactManagersPluginFactory::ContactManagersPluginFactory(const std::string& config,
const tesseract_common::ResourceLocator& locator)
: ContactManagersPluginFactory(tesseract_common::loadYamlString(config, locator))
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
#include <tesseract_collision/core/contact_managers_plugin_factory.h>
#include <tesseract_collision/core/discrete_contact_manager.h>
#include <tesseract_collision/bullet/bullet_factories.h>
#include <tesseract_common/yaml_utils.h>
#include <tesseract_common/resource_locator.h>

using namespace tesseract_collision;

Expand Down Expand Up @@ -63,10 +65,11 @@ TEST(TesseractContactManagersFactoryUnit, StaticLoadPlugin) // NOLINT
BulletCastSimpleManager:
class: BulletCastSimpleManagerFactory)";

ContactManagersPluginFactory factory(config);
tesseract_common::GeneralResourceLocator locator;
ContactManagersPluginFactory factory(config, locator);
factory.clearSearchLibraries();
factory.clearSearchPaths();
YAML::Node plugin_config = YAML::Load(config);
YAML::Node plugin_config = tesseract_common::loadYamlString(config, locator);

DiscreteContactManager::UPtr cm = factory.createDiscreteContactManager("BulletDiscreteBVHManager");
EXPECT_TRUE(cm != nullptr);
Expand Down
22 changes: 14 additions & 8 deletions tesseract_collision/test/contact_managers_factory_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP
#include <tesseract_collision/core/contact_managers_plugin_factory.h>
#include <tesseract_collision/core/discrete_contact_manager.h>
#include <tesseract_collision/core/continuous_contact_manager.h>
#include <tesseract_common/yaml_utils.h>
#include <tesseract_common/resource_locator.h>

using namespace tesseract_collision;

void runContactManagersFactoryTest(const tesseract_common::fs::path& config_path)
{
ContactManagersPluginFactory factory(config_path);
YAML::Node plugin_config = YAML::LoadFile(config_path.string());
tesseract_common::GeneralResourceLocator locator;
ContactManagersPluginFactory factory(config_path, locator);
YAML::Node plugin_config = tesseract_common::loadYamlFile(config_path.string(), locator);

const YAML::Node& plugin_info = plugin_config["contact_manager_plugins"];
const YAML::Node& search_paths = plugin_info["search_paths"];
Expand Down Expand Up @@ -152,8 +155,9 @@ TEST(TesseractContactManagersFactoryUnit, LoadStringPluginTest) // NOLINT
BulletCastSimpleManager:
class: BulletCastSimpleManagerFactory)";

ContactManagersPluginFactory factory(config);
YAML::Node plugin_config = YAML::Load(config);
tesseract_common::GeneralResourceLocator locator;
ContactManagersPluginFactory factory(config, locator);
YAML::Node plugin_config = tesseract_common::loadYamlString(config, locator);

const YAML::Node& plugin_info = plugin_config["contact_manager_plugins"];
const YAML::Node& search_paths = plugin_info["search_paths"];
Expand Down Expand Up @@ -318,8 +322,9 @@ TEST(TesseractContactManagersFactoryUnit, LoadOnlyDiscretePluginTest) // NOLINT
FCLDiscreteBVHManager:
class: FCLDiscreteBVHManagerFactory)";

ContactManagersPluginFactory factory(config);
YAML::Node plugin_config = YAML::Load(config);
tesseract_common::GeneralResourceLocator locator;
ContactManagersPluginFactory factory(config, locator);
YAML::Node plugin_config = tesseract_common::loadYamlString(config, locator);

const YAML::Node& plugin_info = plugin_config["contact_manager_plugins"];
const YAML::Node& search_paths = plugin_info["search_paths"];
Expand Down Expand Up @@ -372,8 +377,9 @@ TEST(TesseractContactManagersFactoryUnit, LoadOnlyContinuousPluginTest) // NOLI
BulletCastSimpleManager:
class: BulletCastSimpleManagerFactory)";

ContactManagersPluginFactory factory(config);
YAML::Node plugin_config = YAML::Load(config);
tesseract_common::GeneralResourceLocator locator;
ContactManagersPluginFactory factory(config, locator);
YAML::Node plugin_config = tesseract_common::loadYamlString(config, locator);

const YAML::Node& plugin_info = plugin_config["contact_manager_plugins"];
const YAML::Node& search_paths = plugin_info["search_paths"];
Expand Down
Loading

0 comments on commit f7afe1d

Please sign in to comment.