forked from robotology/idyntree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifyLinksVisualization.m
54 lines (51 loc) · 2.57 KB
/
modifyLinksVisualization.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function []=modifyLinksVisualization(Visualizer,varargin)
% Allows the modifications of the meshes of the selected links. By default it will modify all objects in the Visualizer variable
% - `modifyLinksVisualization` : Updates the figure image with the new robot state. To be launched after `setRobotState` has been used.
% - Inputs:
% - `Visualizer` : variable output from the `prepareVisualization` function. It contains the relevant variables `linkNames`,`transforms` and `NOBJ`.
% - `linkNames` : variable that contains the link names.
% - `meshHandles` : variable that has the handles of the mesh objects.
% - `NOBJ` : variable that contains the number of visual objects to update.
% - Optional Inputs:
% - `linksToModify` : Cell array containing the names of the links to modify
% - `linksIndices` : array containing the indices of the links to modify
% :exclamation: Note: all extra variables are sent to `modifyLinkVisual`
%
% Author : Francisco Andrade ([email protected])
%
% SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
% SPDX-License-Identifier: BSD-3-Clause
%% input parser section
p = inputParser;
p.StructExpand = false;
p.KeepUnmatched= true;
% Default values
default_linksToModify={'all'};
default_linksIndices=-99;
% add parameters and validity funcitons
addRequired(p,'structInput');
addParameter(p,'linksToModify',default_linksToModify,@(x) iscell(x));
addParameter(p,'linksIndices',default_linksIndices,@(x)isnumeric(x) && all(x>0) && ~any(x>Visualizer.NOBJ));
% parse inputs
parse(p,Visualizer,varargin{:});
options=p.Results;
if ~any(ismember(p.UsingDefaults,'linksToModify')) || ~any(ismember(p.UsingDefaults,'linksIndices'))
% select the indices of the links to modify
if ~any(ismember(p.UsingDefaults,'linksIndices'))
indices=options.linksIndices;
else
[~,indices_temp]=ismember(options.linksToModify,Visualizer.linkNames);
indices=nonzeros(indices_temp);
if length(indices_temp)~=length(indices)
notInModel=length(indices_temp)-length(indices);
indices_notInModel=find(indices_temp==0);
warndlg(sprintf('The list of links to modify contains %d names (positions [ %s ] ) that are not in the list of links of the model',notInModel,num2str(indices_notInModel')));
end
end
else
% by default modify all links
indices=1:Visualizer.NOBJ;
end
for it=1:length(indices)
iDynTreeWrappers.modifyLinkVisual(Visualizer.meshHandles(indices(it)),varargin{:});
end