Point cloud to Mesh/Surface/Grid to STL

40 ビュー (過去 30 日間)
Isabella
Isabella 2012 年 1 月 24 日
回答済み: Noah 2025 年 2 月 24 日
I have a data set of (x,y,z) coordinates for several points that form a point cloud in the form of the bones in a human leg. I want to use nearest neighbor interpolation of these points in order to create a grid and eventually an stl file to export to solid works. Thanks
  1 件のコメント
Zara
Zara 2025 年 2 月 5 日
To create an STL file from your point cloud data of a human leg's bones, follow these
1. Preprocess the Point Cloud
  • Ensure your dataset is clean and well-distributed.
  • Remove noise and outliers if needed.
2. Create a Grid Using Nearest Neighbor Interpolation
Since your data is a scattered point cloud, you can use nearest neighbor interpolation to resample it onto a structured grid. This can be done using SciPy’s griddata or sklearn.neighbors.KNeighborsRegressor.
Example using scipy.interpolate.griddata:
import numpy as np
import scipy.interpolate as interp
# Load your point cloud (x, y, z)
points = np.loadtxt("point_cloud.txt") # Assuming x, y, z columns
x, y, z = points[:, 0], points[:, 1], points[:, 2]
# Define grid resolution
grid_x, grid_y = np.meshgrid(np.linspace(min(x), max(x), 100),
np.linspace(min(y), max(y), 100))
# Interpolate z values using nearest neighbor
grid_z = interp.griddata((x, y), z, (grid_x, grid_y), method='nearest')
3. Generate a Mesh from the Grid
  • Convert the interpolated grid into a mesh.
  • Use matplotlib.tri or scipy.spatial.Delaunay for triangulation.
Example using Delaunay:
from scipy.spatial import Delaunay
points2D = np.vstack((x, y)).T
tri = Delaunay(points2D)
4. Export to STL Format
Use trimesh or meshio to export the triangulated mesh into an STL file.
Example using trimesh:
import trimesh
mesh = trimesh.Trimesh(vertices=points, faces=tri.simplices)
mesh.export("bone_mesh.stl")
5. Open in SolidWorks
  • Import the bone_mesh.stl file into SolidWorks.
  • Use the "Mesh to BREP" function to convert it into a solid body.
Alternative Approach
If you need a smoother surface, consider using Poisson surface reconstruction (open3d.geometry.TriangleMesh.create_from_point_cloud_poisson).
To know fore more details

サインインしてコメントする。

採用された回答

Caleb Williams
Caleb Williams 2017 年 7 月 10 日
Five years later, but may still be relevant...
Try using the "boundary" function. You can input a point cloud of (x,y,z) coordinates and it will return the solid formed by them. You can graph it using "trisurf."
Hope this helps!
  7 件のコメント
Zhaowei Liu
Zhaowei Liu 2024 年 4 月 12 日
It still works in 2024!
志乾
志乾 2024 年 12 月 17 日
still works until December 2024 !
here's my code:
points = [X,Y,Z];
points = unique(points,"rows");
T = boundary(points(:,1),points(:,2), points(:,3));
tri = triangulation(T,points(:,1),points(:,2), points(:,3));
stlwrite(tri,'output.stl');
trisurf(T,points(:,1),points(:,2), points(:,3));

サインインしてコメントする。

その他の回答 (6 件)

Andrew
Andrew 2012 年 1 月 24 日
... it has lots of tools for creating meshes from various types of data.

KSSV
KSSV 2012 年 1 月 24 日
Check the following file in mathworks file exchange...It will convert the mesh to stl file, which you can export to other wares..
Sreenu
  1 件のコメント
Isabella
Isabella 2012 年 1 月 24 日
i need a way to convert the point cloud to a mesh. That is the step i am hung up on. There is also a function in the file exchange that converts surfaces to stl so i need to convert my point cloud to these forms first.

サインインしてコメントする。


Walter Roberson
Walter Roberson 2012 年 1 月 24 日
I suggest you look in the FEX for John D'Errico's work on Alpha Shapes.
  2 件のコメント
Isabella
Isabella 2012 年 1 月 24 日
Could you post a link to the specific file you are referring to? Thank you
Walter Roberson
Walter Roberson 2012 年 1 月 24 日
Darn, I get confused sometimes about what John has released or not. He has spoken of his code in the past, but it looks like he has not put it on the FEX.

サインインしてコメントする。


Anil Kamat
Anil Kamat 2021 年 4 月 22 日
編集済み: Anil Kamat 2021 年 4 月 22 日
You can also do it using tri and trimesh function:
example:
DefoNodes--> x,y and z coordinates of each Node
tri = delaunay(DefoNodes(1,:),DefoNodes(2,:));
trimesh(tri, DefoNodes(1,:), DefoNodes(2,:), DefoNodes(3,:),'EdgeColor','k');

mars bim
mars bim 2021 年 12 月 21 日
Hi, Great writing! I have a question about using PointCab Suite. I read introduction of Point cloud to BIM on an article https://www.marsbim.com/blog/scan-to-bim-introduction-from-technology-to-the-bim-model/ and understand about PointCab Suite Revit. And I know that PointCab Suite is powerfull tool for point cloud modeling and easily manage .LAS files and covert it into .RCP format. But when to load that file in Revit, I received some issue on that process. Is there any other format to directly open point cloud files in to Revit? Thanks.

Noah
Noah 2025 年 2 月 24 日
% Define the system of equations
A = [7 -3; -3 45];
B = [5.3; 0];
% Solve for currents I1 and I
currents = A\B;
I1 = currents(1);
I = currents(2);
% Compute voltages using Ohm's Law
V1 = 3 * (I1 - I);
V2 = 12 * (3 * I);
% Display results
disp(['I1 = ', num2str(I1)]);
disp(['I = ', num2str(I)]);
disp(['V1 = ', num2str(V1)]);
disp(['V2 = ', num2str(V2)]);

カテゴリ

Help Center および File ExchangeDelaunay Triangulation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by