Filter löschen
Filter löschen

Converting MATLAB Isosurface into Triangulation object for .stl export

24 Ansichten (letzte 30 Tage)
I am trying to build a code which can take a .tiff file with volumetric data, get a 3-D mesh representation and export that as a .stl geometry for use in COMSOL multiphysics.
I have gotten to the point where I have the face and vertices data from the isosurface function, and want to create a triangulation object(?) for use in stlwrite to export this format. However, when I try to use the face and vertices data, I get the error:
"
Error using indexing
The input must contain index values; entries with Inf, NaN, zero, negative, or fractional parts are not permitted.
Error in testing_dxl_file_conversion (line 62)
triangulationObj = triangulation(faces, vertices);
"
Code attached! It starts with a script to generate a test .tiff file composed of spheres within a volume (originally thought .dxf file conversion was possible, hence the name of the file).
  1 Kommentar
Fabio Freschi
Fabio Freschi am 18 Okt. 2023
When running your file, the following error appears
Unrecognized function or variable 'numFrames'.
Error in testing_dxl_file_conversion (line 44)
tiffStack = zeros(tiffInfo(1).Width, tiffInfo(1).Height, numFrames, 'uint16'); % Use the appropriate data type

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Fabio Freschi
Fabio Freschi am 18 Okt. 2023
Bearbeitet: Fabio Freschi am 18 Okt. 2023
You don't need to use surf2patch. You can extract infos directly from the struct created by isosurface
isosurf = isosurface(tiffStack, isovalue);
faces = isosurf.faces;
vertices = isosurf.vertices;
In addition, the call to stlwrite is wrong: the triangulation goes first
stlwrite(triangulationObj,stlFileName);
Beacuase I don't have all info to run your code, I show you a simple example
clear all, close all
[x,y,z] = meshgrid(-3:0.25:3);
V = x.*exp(-x.^2 -y.^2 -z.^2);
p = isosurface(x,y,z,V,1e-4);
% create triangulation
TR = triangulation(p.faces,p.vertices);
% save STL
stlwrite(TR,'mytest.stl');
% check: read STL
TR2 = stlread('mytest.stl');
% plot
figure
triplot(TR2);
  3 Kommentare
Saurav
Saurav am 3 Apr. 2024
@Joshua Prince I have .tiff stack file now I want to create .stl file for the geomtery analysis of stone.
Can you plz assit me in how to feed .tiff stack file in you code "testing_dxl_file_conversion.m"
I have attached .tiff folder.
Joshua Prince
Joshua Prince am 3 Apr. 2024
the code I ulpoaded both generates the .tiff file and processes it. If your .tiff file is already on hand, you can start at line 43 of the code by entering your .tiff filename (assuming its in the same directory as your .m file), then run it through the code. Don't forget to make the adjustments based on the above anser!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by