Skip to content

Commit

Permalink
Merge pull request #7 from Jimbles/dev
Browse files Browse the repository at this point in the history
Fixed writing vertices and improved comments and docs
  • Loading branch information
Jimbles authored Jul 3, 2020
2 parents 611de4d + 166382c commit 12802fd
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 204 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ This has only been tested on Matlab 2019b with Python 3.8.3
```matlab
P=meshio.read(fname); % .msh .vtk .vtu .stl .obj TetGen ANSYS ...
% P.vtx - verticies
% P.Cells - structure array for each geometry saved in file
% P.Cells.tri - Trigangulation connectivity list for this cell
% P.Cells.type - 'Tetra','Triangle','Line','Vertex'
% all contents can be plotted with
% P.vtx - verticies
% P.Cells - structure array for each geometry saved in file
% P.Cells.tri - Trigangulation connectivity list for this cell
% P.Cells.type - 'Tetra','Triangle','Line','Vertex'
% P.cell_data - Per element data in cell array
% P.cell_data_name - Data names in cell array
% P.point_data - Per point data in cell array
% P.point_data_name - Data names in cell array
% all contents can be plotted using:
meshio.plot(P);
```

Expand All @@ -39,12 +43,22 @@ dt = delaunayTriangulation(x,y,z);
dataex=1:size(dt.ConnectivityList,1);
%write to gmsh file with cell data
meshio.write('example.msh',dt.Points,dt.ConnectivityList,dataex);
meshio.write('example.msh',dt.Points,dt.ConnectivityList,{dataex},{'Data'});
```

This can then be loaded directly into [gmsh](https://gmsh.info/)

![gmsh](examples/figures/RandEx_gmsh.png)

or into paraview (either by writing to .vtu or using meshio paraview plugin)
or into paraview (either by writing to .vtu or loading .msh using meshio paraview plugin)

![paraview](examples/figures/RandEx_paraview.png)

### Convert file

Conversion through `meshio-convert` binary is harder to fit into matlab workflow, so this library can be used too

```matlab
P=meshio.read('example.msh');
meshio.structwrite('example.vtu',P);
```
Binary file removed examples/example1.msh
Binary file not shown.
35 changes: 0 additions & 35 deletions examples/examplecell.vtu

This file was deleted.

Binary file removed examples/examplecell1.msh
Binary file not shown.
Binary file removed examples/examplecell2.msh
Binary file not shown.
24 changes: 0 additions & 24 deletions examples/examplemulti.vtu

This file was deleted.

35 changes: 0 additions & 35 deletions examples/examplepoint.vtu

This file was deleted.

Binary file removed examples/examplepoint1.msh
Binary file not shown.
Binary file removed examples/examplepoint2.msh
Binary file not shown.
Binary file removed examples/examplepointcell.msh
Binary file not shown.
46 changes: 0 additions & 46 deletions examples/examplepointcell.vtu

This file was deleted.

Binary file modified examples/figures/RandEx_gmsh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/figures/RandEx_paraview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions examples/finger_3D.vtu

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions examples/pyexample.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
F=meshio.read(inpathmulti)
meshio.write_points_cells(outpathmultivtu,F.points,F.cells)

fc=F.cells
fnewcell=[]
fnewcell.append((fc[1].type,fc[1].data))
fnewcell.append((fc[2].type,fc[2].data))

meshio.write_points_cells(outpathmultivtu,F.points,fnewcell)
PP=meshio.read(outpathmultivtu)


Expand Down
57 changes: 35 additions & 22 deletions examples/run_examples.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,80 @@
pointdataname={'test','teest','tesest'};

%write with no data
meshio.write('example1.msh',dt.Points,dt.ConnectivityList);
A=meshio.read('example1.msh');
meshio.write('testout/example1.msh',dt.Points,dt.ConnectivityList);
A=meshio.read('testout/example1.msh');

assert(isequal(A.vtx,dt.Points));


%write with cell data
meshio.write('examplecell1.msh',dt.Points,dt.ConnectivityList,celldata(1),celldataname(1));
B=meshio.read('examplecell1.msh');
meshio.write('testout/examplecell1.msh',dt.Points,dt.ConnectivityList,celldata(1),celldataname(1));
B=meshio.read('testout/examplecell1.msh');

assert(isequal(celldata(1),B.cell_data));

meshio.write('examplecell2.msh',dt.Points,dt.ConnectivityList,celldata,celldataname);
C=meshio.read('examplecell2.msh');
meshio.write('testout/examplecell2.msh',dt.Points,dt.ConnectivityList,celldata,celldataname);
C=meshio.read('testout/examplecell2.msh');

assert(isequal(celldata,C.cell_data));


% write with point data
meshio.write('examplepoint1.msh',dt.Points,dt.ConnectivityList,[],[],pointdata(1),pointdataname(1));
D=meshio.read('examplepoint1.msh');
meshio.write('testout/examplepoint1.msh',dt.Points,dt.ConnectivityList,[],[],pointdata(1),pointdataname(1));
D=meshio.read('testout/examplepoint1.msh');

assert(isequal(pointdata(1),D.point_data));

meshio.write('examplepoint2.msh',dt.Points,dt.ConnectivityList,[],[],pointdata,pointdataname);
E=meshio.read('examplepoint2.msh');
meshio.write('testout/examplepoint2.msh',dt.Points,dt.ConnectivityList,[],[],pointdata,pointdataname);
E=meshio.read('testout/examplepoint2.msh');

assert(isequal(pointdata,E.point_data));

%write with both point and cell data
meshio.write('examplepointcell.msh',dt.Points,dt.ConnectivityList,celldata,celldataname,pointdata,pointdataname);
F=meshio.read('examplepointcell.msh');
meshio.write('testout/examplepointcell.msh',dt.Points,dt.ConnectivityList,celldata,celldataname,pointdata,pointdataname);
F=meshio.read('testout/examplepointcell.msh');

assert(isequal(pointdata,F.point_data) && isequal(celldata,F.cell_data));

%convert file using structwrite
meshio.structwrite('examplecell.vtu',C);
meshio.structwrite('examplepoint.vtu',E);
meshio.structwrite('examplepointcell.vtu',F);

meshio.structwrite('testout/examplecell.vtu',C);
meshio.structwrite('testout/examplepoint.vtu',E);
meshio.structwrite('testout/examplepointcell.vtu',F);

%% read gmsh file

% example gmsh file is conversion from .stl file
% this contains vertcies, lines, triangles and tetrahedra which are all read
% order is always vert/line/tri/tetra
fname=('finger_3D.msh');
fname=('finger_3D');

P=meshio.read(fname);
P=meshio.read([fname '.msh']);
meshio.plot(P);

% extract just the lines/triangles/tetrahedra
% extract just the tetrahedra
Ptet=P;
Ptet.cells=Ptet.cells(23:end);
Ptet.cells=Ptet.cells(end);
meshio.plot(Ptet);

meshio.structwrite('examplemulti.vtu',Ptet);
% write file back to vtu N.B. meshio merges cells of the same type
meshio.structwrite([fname '.vtu'],P);
Pvtu=meshio.read([fname '.vtu']);
%Ptvu only has 4 cells, each for all vertex,line,tri,tetra

% meshio cannot write .msh files with different cell types in at the moment
% (meshio v 4.0.16). So write each type to a separate file and merge them
% in gmsh

try
meshio.structwrite('testout/error.msh',P);

catch
fprintf(2,'\n -----------\n meshio can only write 1 cell type (e.g. tetra) to msh file \n -----------\n');
end


%% read vtu and write new data
fname=('NNexample.vtu');
fname='NNexample.vtu';
fnameoutcell='NNexampleNewDataC.vtu';
fnameoutpoint='NNexampleNewDataP.vtu';

Expand Down
1 change: 1 addition & 0 deletions examples/testout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*
Loading

0 comments on commit 12802fd

Please sign in to comment.