addMesh
Description
adds one or more meshes to the truncated signed distance field (TSDF), computes the TSDF
around the added meshes, and returns an indication of which meshes were successfully
added.isAdded = addMesh(mTSDF,meshStruct)
Examples
Create two collision boxes and one collision sphere. The collision boxes represent a static environment and the sphere represents a dynamic obstacle with a pose that could change at any time.
box1 = collisionBox(0.5,1,0.1);
box2 = collisionBox(0.5,0.1,0.2,Pose=trvec2tform([0 -0.45 0.15]));
sph = collisionSphere(0.125,Pose=trvec2tform([-0.1 0.25 0.75]));
showCollisionArray({box1,box2,sph});
title("Static Environment and Dynamic Obstacle")
v = [110 10];
view(v);
Create a mesh TSDF manager with a resolution of 25 cells per meter.
tsdfs = meshtsdf(Resolution=25);
To improve the efficiency of signed distance field computation, combine meshes that represent the static environment.
staticMeshes = geom2struct({box1,box2});
staticEnv = staticMeshes(1);
staticEnv.Pose = eye(4);
staticEnv.Vertices = [];
staticEnv.Faces = [];
for i = 1:numel(staticMeshes)
H = staticMeshes(i).Pose;
V = staticMeshes(i).Vertices*H(1:3,1:3)'+ H(1:3,end)';
nVert = size(staticEnv.Vertices,1);
staticEnv.Vertices = [staticEnv.Vertices; V];
staticEnv.Faces = [staticEnv.Faces; staticMeshes(i).Faces+nVert];
end
staticEnv.ID = 1;Add the static environment mesh to the TSDF manager.
addMesh(tsdfs,staticEnv);
Convert the sphere collision geometry into a structure for the mesh TSDF manager. Assign it an ID of 2 and add it to the mesh TSDF manager.
obstacleID = 2; dynamicObstacle = geom2struct(sph,obstacleID); addMesh(tsdfs,dynamicObstacle); show(tsdfs) view(v) axis equal title("Mesh TSDFs of Static Environment and Dynamic Obstacle")

Update the pose of the dynamic obstacle in the mesh TSDF manager by changing Pose property of the object handle of the obstacle. Then use the updatePose function to update the pose of the mesh in the TSDF manager.
dynamicObstacle.Pose = trvec2tform([0.2 0.25 0.2]); updatePose(tsdfs,dynamicObstacle)
ans = 1
show(tsdfs) view(v) axis equal title("Updated Dynamic Obstacle Pose")

Input Arguments
Truncated signed distance field for 3-D meshes, specified as a meshtsdf
object.
Example: meshtsdf(meshes,TruncationDistance=5) creates a TSDF for the
specified meshes with a truncation distance of 5
meters.
Geometry mesh, returned as a structure or an N-element structure array. N is the total number of collision objects.
Each structure contains these fields:
ID— ID of the geometry structure stored as a positive integer. By default, the ID of each structure corresponds to the index of the structure inmeshStruct. For example, ifmeshStructcontains five mesh structures, the first mesh structure at index 1 has anIDof1, and the last mesh structure at index 5 has anIDof5.Vertices— Vertices of the geometry, stored as an M-by-3 matrix. Each row represents a vertex in the form [x y z] with respect to the reference frame defined byPose. M is the number of vertices needed to represent the convex hull of the mesh.Faces— Faces of the geometry, stored as an M-by-3 matrix. Each row contains three indices corresponding to vertices inVerticesthat define a triangle faces of the geometry. M is the number of vertices inVertices.Pose— Pose of the geometry as a 4-by-4 homogeneous transformation matrix specifying a transformation from the world frame to the frame in which the vertices are defined.
Data Types: struct
Output Arguments
Indication of whether meshes were added or not, returned as logical
1 (true) if the mesh was successfully added or
0 (false) if the mesh you are adding a mesh with
an ID that already exists in mTSDF. If
meshStruct is an N-element of mesh structures,
then isAdded is an N-element vector of logical
scalars corresponding to each of the N mesh structures in
meshStruct.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2024a
See Also
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.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)