Skip to content
Snippets Groups Projects
Commit 1223da48 authored by Rainer Kartmann's avatar Rainer Kartmann
Browse files

Merge branch 'arviz/lookup-not-found-objects-in-armarx-objects' into 'master'

Arviz: Lookup not found objects in armarx objects

See merge request ArmarX/RobotAPI!78
parents 7c6bd448 993e9d28
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ set(COMPONENT_LIBS
ArmarXCore
RobotAPICore
RobotAPIInterfaces
RobotAPIArmarXObjects
boost_iostreams #compression
)
......
#include "VisualizationObject.h"
#include <RobotAPI/libraries/ArmarXObjects/ObjectFinder.h>
#include <ArmarXCore/core/system/cmake/CMakePackageFinder.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/core/system/ArmarXDataPath.h>
#include <VirtualRobot/ManipulationObject.h>
#include <VirtualRobot/SceneObject.h>
#include <VirtualRobot/XML/RobotIO.h>
#include <VirtualRobot/XML/ObjectIO.h>
#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
#include <boost/algorithm/string/predicate.hpp>
#include <SimoxUtility/algorithm/string/string_tools.h>
namespace armarx::viz::coin
{
namespace
{
std::string findObjectInArmarXObjects(const std::string& filename)
{
IceUtil::Time start = IceUtil::Time::now();
std::string objectName = std::filesystem::path(filename).filename().stem();
// ARMARX_INFO << "Trying to find object '" << objectName << "' in ArmarXObjects.";
std::string fullFilename;
std::stringstream ss;
armarx::ObjectFinder objectFinder;
if (std::optional<armarx::ObjectInfo> info = objectFinder.findObject("", objectName))
{
fullFilename = info->simoxXML().absolutePath;
ss << "Found '" << objectName << "' in ArmarXObjects as " << *info << " \nat '" << fullFilename << "'.";
}
else
{
ss << "Did not find '" << objectName << "' in ArmarXObjects.";
}
ss << "\n(Lookup took " << (IceUtil::Time::now() - start).toMilliSecondsDouble() << " ms.)";
ARMARX_INFO << ss.str();
return fullFilename;
}
VirtualRobot::ManipulationObjectPtr loadObject(std::string const& project, std::string const& filename)
{
VirtualRobot::ManipulationObjectPtr result;
......@@ -26,21 +55,31 @@ namespace armarx::viz::coin
return result;
}
bool checkArmarXObjects = true;
ArmarXDataPath::FindPackageAndAddDataPath(project);
std::string fullFilename;
if (!ArmarXDataPath::SearchReadableFile(filename, fullFilename))
{
ARMARX_INFO << deactivateSpam()
<< "Unable to find readable file for name "
<< filename;
return result;
fullFilename = "";
if (checkArmarXObjects)
{
fullFilename = findObjectInArmarXObjects(filename);
}
if (fullFilename.empty())
{
ARMARX_INFO << deactivateSpam()
<< "Unable to find readable file for name "
<< filename;
return result;
}
}
try
{
ARMARX_INFO << "Loading object from " << fullFilename;
if (boost::ends_with(fullFilename, ".wrl"))
if (simox::alg::ends_with(fullFilename, ".wrl"))
{
VirtualRobot::VisualizationFactoryPtr factory = VirtualRobot::VisualizationFactory::fromName("inventor", NULL);
VirtualRobot::VisualizationNodePtr vis = factory->getVisualizationFromFile(fullFilename);
......@@ -59,8 +98,6 @@ namespace armarx::viz::coin
<< "\nReason: " << ex.what();
}
return result;
}
......@@ -86,6 +123,7 @@ namespace armarx::viz::coin
result.filename = filename;
result.object = loadObject(project, filename);
objectcache.push_back(result);
return result;
......@@ -102,7 +140,7 @@ namespace armarx::viz::coin
}
if (!loaded.object)
{
ARMARX_WARNING << deactivateSpam(10)
ARMARX_WARNING << deactivateSpam(120)
<< "Object will not be visualized since it could not be loaded."
<< "\nID: " << element.id
<< "\nProject: " << element.project
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment