Callback function for selecting triangular faces of patch objects
The function can find the index of the face in a patch object which was clicked on by the mouse. The function should be used as a callback function for the ButtonDownFcn event of patch object and it will call a user defined function with the same arguments as the ButtonDownFcn call, but adding an extra argument, the face index. Thus the user defined
callback function will have the following header:
callbackfun(obj,hit,faceIndex)
The function can detect if the mouse click was on a face or on an edge of the patch object.
Input:
obj The patch object that calls the function.
hit Hit object that contains the point where the object was hit.
callbackfun User function that will be called in case of a click event on obj. It should have the following header:
callbackfun(obj,hit,faceIndex)
where face Index contains the index of the face that was clicked on, it can contain a single index or two depending on the selection type.
selection String defines three diferent selection criteria when the callbackfun() function will be called:
'face' The callbackfun() will be triggered if a face was clicked (numel(faceIndex)==1).
'edge' The callbackfun() will be triggered if an edge is clicked (numel(faceIndex)==2).
'all' The callbackfun() will be triggered for both faces and edges.
Example:
The color of any face of the red triangulated icosahedron will be
changed to green if clicked on.
mesh = icomesh(1);
V = mesh.Points;
F = mesh.ConnectivityList;
hPatch = patch('Faces',F,'Vertices',V,'FaceColor','r','EdgeColor','none');
axis equal
box on
view(3)
camlight('right')
hPatch.FaceColor = 'flat';
hPatch.FaceVertexCData = repmat([1 0 0],[size(F,1) 1]);
fun = @(obj,hif,face)set(obj,'FaceVertexCData',[obj.FaceVertexCData(1:(face-1),:); [0 1 0]; obj.FaceVertexCData((face+1):end,:)]);
hPatch.ButtonDownFcn = @(obj,hit)patchfacefcn(obj,hit,fun,'face');
引用格式
Sandor Toth (2024). Callback function for selecting triangular faces of patch objects (https://www.mathworks.com/matlabcentral/fileexchange/61078-callback-function-for-selecting-triangular-faces-of-patch-objects), MATLAB Central File Exchange. 检索时间: .
MATLAB 版本兼容性
平台兼容性
Windows macOS Linux类别
- MATLAB > Graphics > 2-D and 3-D Plots > Surfaces, Volumes, and Polygons > Polygons >
- MATLAB > Graphics > Graphics Objects > Graphics Object Programming >
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!patchface/
版本 | 已发布 | 发行说明 | |
---|---|---|---|
1.0.0.0 | Added graphics.
|