-
Notifications
You must be signed in to change notification settings - Fork 68
/
modifyLinkVisual.m
127 lines (114 loc) · 4.97 KB
/
modifyLinkVisual.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
function []=modifyLinkVisual(meshHandle,varargin)
% Modifies a single `meshHandle` with the specified changes.
% - Inputs:
% - `meshHandle` : Struct containing the patch type of variable ( `modelMesh` field ) and the original information of the mesh in `fullMesh_bckup` field.
% - Optional Inputs:
% - `color` : Selects the color of the meshes.
% - `transparency` : Sets the alpha value of the patch. Is the
% level of transparency between 0 fully transparent and 1 solid.
% - `wireframe_rendering` : the reduction ratio of faces to
% wireframe. Follows convention of reducepatch.
% - `style` : Selects the style of display of meshes, either fullMesh or wireframe.
% - Outputs:
% - `meshHandles` : Struct that contains all the created handles for the meshes. There can be more than one mesh for each link.
% - `transform` : The transform object for the link
% - `material` : Selects effect with which the patch is rendered. Options are : 'dull','metal','shiny';
% - `useDefault` : Enables the use of the default values instead of ignoring non specified changes.
%
% 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_color= [0.1843 0.3098 0.3098];
default_transparency=0.5;
default_style='fullMesh';
default_wireframe_rendering=0.08;
default_material='dull';
default_useDefault=false;
% accepted values
expected_materials={'dull','metal','shiny'};
expected_styles={'fullMesh','wireframe','invisible'};
% add parameters and validity funcitons
addRequired(p,'structInput');
addParameter(p,'color',default_color,@(x)validateattributes(x,{'numeric'},{'numel', 3}));
addParameter(p,'transparency',default_transparency,@(x) isnumeric(x) && isscalar(x));
addParameter(p,'wireframe_rendering',default_wireframe_rendering,@(x) isnumeric(x) && isscalar(x));
addParameter(p,'style',default_style,@(x) any(validatestring(x,expected_styles)));
addParameter(p,'material',default_material,@(x) any(validatestring(x,expected_materials)));
addParameter(p,'useDefault',default_useDefault);
% Parse inputs
parse(p,meshHandle,varargin{:});
options = p.Results;
for nMeshes = 1:length(meshHandle.modelMesh)
modelMesh = meshHandle.modelMesh(nMeshes);
if ~any(ismember(p.UsingDefaults,'color')) || options.useDefault
changeColor(modelMesh,options.color);
end
if ~any(ismember(p.UsingDefaults,'transparency')) || options.useDefault
alpha(modelMesh,options.transparency);
end
if ~any(ismember(p.UsingDefaults,'material')) || options.useDefault
material(modelMesh,options.material);
end
if ~any(ismember(p.UsingDefaults,'style')) || options.useDefault
[isWF,noColor] = isWireframe(modelMesh);
if strcmpi(options.style,'wireframe') && ~isWF
if noColor
color = options.color;
else
color = modelMesh.FaceColor;
end
reducepatch(modelMesh,options.wireframe_rendering);
modelMesh.FaceColor = 'none';
modelMesh.EdgeColor = color;
end
if strcmpi(options.style,'fullMesh') && isWF
if noColor
color = options.color;
else
color = modelMesh.EdgeColor;
end
modelMesh.Vertices = meshHandle.fullMesh_bckup(nMeshes).vertices;
modelMesh.Faces = meshHandle.fullMesh_bckup(nMeshes).faces;
modelMesh.FaceColor = color;
modelMesh.EdgeColor = 'none';
end
if strcmpi(options.style,'invisible')
% make invisible
modelMesh.Visible = 'off';
else
modelMesh.Visible = 'on';
end
end
end
end
% Utilities
function [] = changeColor(modelMesh,color)
if isWireframe(modelMesh)
modelMesh.EdgeColor = color;
else
modelMesh.FaceColor = color;
end
end
function [isIt, noColor] = isWireframe(meshHandle)
% If there is a numeric value in edges and a char ('none') in faces
% then is wireframe
noColor = false;
if ischar(meshHandle.FaceColor) && ~ischar(meshHandle.EdgeColor)
isIt = true;
end
% As long as there is a color in faces is not wireframe
if ~ischar(meshHandle.FaceColor) && ischar(meshHandle.EdgeColor)
isIt = false;
end
% The mesh is invisble and not on purpose. Make it wireframe.
if ~exist('isIt','var')
isIt = true;
noColor = true;
end
end