addShape
R2026bDescription
displays one or more shapes in the point cloud viewer specified by
roi = addShape(pcview,shape,position)pcview. Specify the shape type and location with shape and position, respectively.
You can control the properties of the displayed shape or shapes after creation by using the
corresponding shape object in roi.
specifies options using one or more name-value arguments in addition to the input arguments
from the previous syntax. For example, roi = addShape(___,Name=Value)Color="yellow" sets the color of
each shape to yellow.
Examples
Read an aerial lidar point cloud, remove the ground, and segment the remaining points into clusters.
reader = lasFileReader("aerialLidarData.laz");
ptCloud = readPointCloud(reader);
groundIdx = segmentGroundSMRF(ptCloud);
nonGroundPc = select(ptCloud, ~groundIdx);
[labels, numClusters] = pcsegdist(nonGroundPc,1,NumClusterPoints=50);Compute properties for each cluster including oriented bounding boxes, centroids, principal axis lengths, and sphericity.
clusterProps = pcclusterprops(nonGroundPc,labels,"All");
cuboids = vertcat(clusterProps.OrientedBoundingBox);
centroids = vertcat(clusterProps.Centroid);
axLengths = vertcat(clusterProps.PrincipalAxisLength);Visualize the point cloud and overlay oriented bounding boxes for the five largest clusters by volume.
volumes = cuboids(:,4) .* cuboids(:,5) .* cuboids(:,6);
[~, sortIdx] = sort(volumes,"descend");
pcview = pcviewer(nonGroundPc);
rois = addShape(pcview,"cuboids",cuboids(sortIdx(1:5),:),Color="green");
Identify the ten most spherical clusters and annotate them with spheres. Display both the bounding boxes and spheres together.
sphericity = [clusterProps.Sphericity]'; [~, sphereIdx] = sort(sphericity,"descend"); top10 = sphereIdx(1:10); sphereData = zeros(10, 4); for i = 1:10 sphereData(i,:) = [centroids(top10(i),:), max(axLengths(top10(i),:))/2]; end pcview2 = pcviewer(nonGroundPc);

addShape(pcview2, "cuboids", cuboids(sortIdx(1:5),:), Color="green"); addShape(pcview2, "spheres", sphereData, Color="magenta");
Input Arguments
Point cloud viewer in which to display shape, specified as a pcviewer
object.
Type of shape to display, specified as one of these values:
"points""cuboids""lines""polylines""spheres""cylinders""planes""arrows""plusses""ellipsoids"
Position of the shape in the display, specified as one of these options:
| Shape | Dimension | Description |
|---|---|---|
"points" | M-by-3 matrix | Each row specifies the [x y z] location of one point. |
"cuboids" |
| If you specify a matrix, each row specifies one cuboid in the form [xctr yctr zctr xlen ylen zlen xrot yrot zrot], where the values define the cuboid center, dimensions, and orientation. |
"lines" | M-by-6 matrix | Each row specifies one line segment in the form [x1 y1 z1 x2 y2 z2]. |
"polylines" | M-by-3 matrix | Each row specifies one polyline vertex in the form [x y
z]. You must separate individual polylines with rows of
NaN values. |
"spheres" |
| If you specify a matrix, each row specifies one sphere in the form [x y z radius], where [x y z] defines the sphere center. |
"cylinders" |
| If you specify a matrix, each row specifies one cylinder in the form [x y z radius height ox oy oz], where [x y z] is the cylinder center and [ox oy oz] is the orientation vector. |
"planes" |
| If you specify a matrix, each row specifies one plane in the form [x y z width height u v w], where [x y z] is a location on the plane and [u v w] is the normal vector. |
"arrows" | M-by-6 matrix | Each row specifies one arrow in the form [x y z u v w], where [x y z] is the arrow tail location and [u v w] is the direction vector. |
"plusses" | M-by-3 matrix | Each row specifies one plus symbol location in the form [x y z]. |
"ellipsoids" | M-by-9 matrix | Each row specifies one ellipsoid in the form [x y z xsemi ysemi zsemi xrot yrot zrot], where the values define the ellipsoid center, semiaxis lengths, and orientation. |
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN, where Name is
the argument name and Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: addShape(pcview,shape,positionColor="yellow") sets the color
of each shape to yellow.
Shape color, specified as an RGB triplet, a short color name, a long color name,
or an M-by-3 matrix of RGB triplets. When you specify a single
color, the function applies that color to all shapes. When you specify multiple
colors, the number of colors must match the number of shapes specified by
position.
Shape opacity, specified as a numeric scalar in the range [0,
1]. When you set Alpha to 1, the
shapes are fully opaque. When you set Alpha to
0, the shapes are fully transparent.
Shape visibility, specified as "on" or
"off", or as a numeric or
logical 1 (true) or 0
(false). The visibility value applies to all shapes. A
value of "on" is equivalent to true, and
"off" is equivalent to false. Thus, you can
use the value of the property set by this argument as a logical value. The value is
stored as an on/off logical value of type OnOffSwitchState.
Output Arguments
Added shape, returned as a shape object or an M-element array of
shape objects. The type of object or objects returned in roi
depends on the value of the shape argument and returned as one of:
Points— Points objectLines— Lines objectPolyines— Polylines objectCuboids— Cuboids objectAngles— Angles objectElevations— Elevations objectCircles— Circles objectFreehand— Freehand object
Version History
Introduced in R2026b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)