Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RobotAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software
ArmarX
RobotAPI
Commits
55014d64
Commit
55014d64
authored
1 year ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
auto format
parent
09b356e3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!392
Fix visu of underactuated joints
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp
+50
-35
50 additions, 35 deletions
source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp
with
50 additions
and
35 deletions
source/RobotAPI/components/ArViz/Coin/VisualizationRobot.cpp
+
50
−
35
View file @
55014d64
#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
<<
"'"
<<
"
\n
Consider specifying the containing ArmarX package and relative data path instead to "
<<
"
\n
Consider 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.0
f
;
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"
<<
"
\n
Robot: "
<<
VAROUT
(
project
)
<<
", "
<<
VAROUT
(
filename
)
ARMARX_WARNING
<<
"Encountered empty robot instance pool while trying "
"to clone new instance"
<<
"
\n
Robot: "
<<
VAROUT
(
project
)
<<
", "
<<
VAROUT
(
filename
)
<<
"
\n
Used instances: "
<<
instancePool
.
usedInstances
<<
"
\n
Robots: "
<<
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"
<<
"
\n
Robot: "
<<
VAROUT
(
loaded
.
project
)
<<
", "
<<
VAROUT
(
loaded
.
filename
)
<<
"
\n
Robot: "
<<
VAROUT
(
loaded
.
project
)
<<
", "
<<
VAROUT
(
loaded
.
filename
)
<<
"
\n
Used 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."
<<
"
\n
ID: "
<<
element
.
id
<<
"
\n
Project: "
<<
element
.
project
<<
"
\n
ID: "
<<
element
.
id
<<
"
\n
Project: "
<<
element
.
project
<<
"
\n
Filename: "
<<
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment