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

auto format

parent 09b356e3
No related branches found
No related tags found
1 merge request!392Fix visu of underactuated joints
#include <regex>
#include <fstream>
#include "VisualizationRobot.h"
#include <ArmarXCore/core/system/cmake/CMakePackageFinder.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/core/system/ArmarXDataPath.h>
#include <fstream>
#include <regex>
#include <VirtualRobot/SceneObject.h>
#include <VirtualRobot/XML/RobotIO.h>
#include <VirtualRobot/Visualization/CoinVisualization/CoinVisualization.h>
#include <VirtualRobot/XML/RobotIO.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <ArmarXCore/core/system/ArmarXDataPath.h>
#include <ArmarXCore/core/system/cmake/CMakePackageFinder.h>
namespace armarx::viz::coin
{
namespace
{
VirtualRobot::RobotPtr loadRobot(std::string const& project, std::string const& filename)
VirtualRobot::RobotPtr
loadRobot(std::string const& project, std::string const& filename)
{
VirtualRobot::RobotPtr result;
VirtualRobot::RobotPtr result;
if (filename.empty())
{
......@@ -32,7 +33,8 @@ namespace armarx::viz::coin
ARMARX_INFO << deactivateSpam()
<< "You specified the absolute path to the robot file:"
<< "\n\t'" << filename << "'"
<< "\nConsider specifying the containing ArmarX package and relative data path instead to "
<< "\nConsider specifying the containing ArmarX package and relative "
"data path instead to "
<< "improve portability to other systems.";
}
// We need to always check that the file is readable otherwise, VirtualRobot::RobotIO::loadRobot crashes
......@@ -88,7 +90,8 @@ namespace armarx::viz::coin
static std::vector<RobotInstancePool> robotCache;
LoadedRobot getRobotFromCache(std::string const& project, std::string const& filename)
LoadedRobot
getRobotFromCache(std::string const& project, std::string const& filename)
{
// We can use a global variable, since this code is only executed in the GUI thread
......@@ -104,7 +107,8 @@ namespace armarx::viz::coin
if (instancePool.usedInstances < instancePool.robots.size())
{
// 1) We have still unused instances in the pool ==> Just return one
ARMARX_DEBUG << "Reusing robot instance from cache " << VAROUT(project) << ", " << VAROUT(filename);
ARMARX_DEBUG << "Reusing robot instance from cache " << VAROUT(project)
<< ", " << VAROUT(filename);
result.robot = instancePool.robots[instancePool.usedInstances];
instancePool.usedInstances += 1;
}
......@@ -112,14 +116,17 @@ namespace armarx::viz::coin
else
{
// 2) We do not have unused instances in the pool ==> Clone one
ARMARX_DEBUG << "Cloning robot from cache " << VAROUT(project) << ", " << VAROUT(filename);
ARMARX_DEBUG << "Cloning robot from cache " << VAROUT(project) << ", "
<< VAROUT(filename);
if (instancePool.robots.size() > 0)
{
VirtualRobot::RobotPtr const& robotToClone = instancePool.robots.front();
VirtualRobot::RobotPtr const& robotToClone =
instancePool.robots.front();
float scaling = 1.0f;
bool preventCloningMeshesIfScalingIs1 = true;
result.robot = robotToClone->clone(nullptr, scaling, preventCloningMeshesIfScalingIs1);
result.robot = robotToClone->clone(
nullptr, scaling, preventCloningMeshesIfScalingIs1);
// Insert the cloned robot into the instance pool
instancePool.robots.push_back(result.robot);
......@@ -127,8 +134,10 @@ namespace armarx::viz::coin
}
else
{
ARMARX_WARNING << "Encountered empty robot instance pool while trying to clone new instance"
<< "\nRobot: " << VAROUT(project) << ", " << VAROUT(filename)
ARMARX_WARNING << "Encountered empty robot instance pool while trying "
"to clone new instance"
<< "\nRobot: " << VAROUT(project) << ", "
<< VAROUT(filename)
<< "\nUsed instances: " << instancePool.usedInstances
<< "\nRobots: " << instancePool.robots.size();
}
......@@ -137,7 +146,8 @@ namespace armarx::viz::coin
}
}
ARMARX_DEBUG << "Loading robot from file " << VAROUT(project) << ", " << VAROUT(filename);
ARMARX_DEBUG << "Loading robot from file " << VAROUT(project) << ", "
<< VAROUT(filename);
result.robot = loadRobot(project, filename);
if (result.robot)
{
......@@ -146,13 +156,15 @@ namespace armarx::viz::coin
instancePool.filename = filename;
instancePool.robots.push_back(result.robot);
instancePool.usedInstances = 1;
} else
}
else
{
ARMARX_WARNING << deactivateSpam(5) << "Robot " << VAROUT(project) << ", " << VAROUT(filename) << "could not be loaded!";
ARMARX_WARNING << deactivateSpam(5) << "Robot " << VAROUT(project) << ", "
<< VAROUT(filename) << "could not be loaded!";
}
return result;
}
}
} // namespace
VisualizationRobot::~VisualizationRobot()
{
......@@ -160,7 +172,8 @@ namespace armarx::viz::coin
{
if (instancePool.project == loaded.project && instancePool.filename == loaded.filename)
{
ARMARX_DEBUG << "Removing robot from chace " << VAROUT(loaded.project) << ", " << VAROUT(loaded.filename);
ARMARX_DEBUG << "Removing robot from chace " << VAROUT(loaded.project) << ", "
<< VAROUT(loaded.filename);
std::vector<VirtualRobot::RobotPtr>& robots = instancePool.robots;
auto robotIter = std::find(robots.begin(), robots.end(), loaded.robot);
if (robotIter != robots.end())
......@@ -176,7 +189,8 @@ namespace armarx::viz::coin
{
ARMARX_WARNING << "Expected there to be at least one used instance "
<< "while trying to put robot instance back into the pool"
<< "\nRobot: " << VAROUT(loaded.project) << ", " << VAROUT(loaded.filename)
<< "\nRobot: " << VAROUT(loaded.project) << ", "
<< VAROUT(loaded.filename)
<< "\nUsed instances: " << instancePool.usedInstances;
}
}
......@@ -184,12 +198,14 @@ namespace armarx::viz::coin
}
}
bool VisualizationRobot::update(ElementType const& element)
bool
VisualizationRobot::update(ElementType const& element)
{
IceUtil::Time time_start = IceUtil::Time::now();
(void) time_start;
(void)time_start;
bool robotChanged = loaded.project != element.project || loaded.filename != element.filename;
bool robotChanged =
loaded.project != element.project || loaded.filename != element.filename;
if (robotChanged)
{
// The robot file changed, so reload the robot
......@@ -199,8 +215,7 @@ namespace armarx::viz::coin
{
ARMARX_WARNING << deactivateSpam(10)
<< "Robot will not visualized since it could not be loaded."
<< "\nID: " << element.id
<< "\nProject: " << element.project
<< "\nID: " << element.id << "\nProject: " << element.project
<< "\nFilename: " << element.filename;
return true;
}
......@@ -253,10 +268,8 @@ namespace armarx::viz::coin
if (loadedDrawStyle & data::ModelDrawStyle::OVERRIDE_COLOR)
{
if (loadedColor.r != element.color.r
|| loadedColor.g != element.color.g
|| loadedColor.b != element.color.b
|| loadedColor.a != element.color.a)
if (loadedColor.r != element.color.r || loadedColor.g != element.color.g ||
loadedColor.b != element.color.b || loadedColor.a != element.color.a)
{
int numChildren = node->getNumChildren();
for (int i = 0; i < numChildren; i++)
......@@ -294,7 +307,8 @@ namespace armarx::viz::coin
return true;
}
void VisualizationRobot::recreateVisualizationNodes(int drawStyle)
void
VisualizationRobot::recreateVisualizationNodes(int drawStyle)
{
VirtualRobot::SceneObject::VisualizationType visuType = VirtualRobot::SceneObject::Full;
if (drawStyle & data::ModelDrawStyle::COLLISION)
......@@ -331,8 +345,9 @@ namespace armarx::viz::coin
}
}
void clearRobotCache()
void
clearRobotCache()
{
robotCache.clear();
}
}
} // namespace armarx::viz::coin
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