Import STL as Mesh

This commit is contained in:
Matthias Hochsteger 2019-09-20 11:31:52 +02:00
parent ec40e605a3
commit f6f4976402
4 changed files with 31 additions and 0 deletions

View File

@ -7,6 +7,7 @@
#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <stlgeom.hpp>
#include <meshing.hpp>
#include "writeuser.hpp"
@ -648,6 +649,33 @@ namespace netgen
ReadFNFFormat (mesh, filename);
}
if ( ( (strlen (filename) > 4) && strcmp (&filename[strlen (filename)-4], ".stl") == 0 ) ||
( (strlen (filename) > 5) && strcmp (&filename[strlen (filename)-5], ".stlb") == 0 ) )
{
ifstream ist{string{filename}};
auto geom = shared_ptr<STLGeometry>(STLGeometry::Load(ist));
mesh.SetDimension (3);
auto & points = geom->GetPoints();
for (auto & p : points)
mesh.AddPoint(MeshPoint(p));
mesh.AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1));
for (auto ti : IntRange(geom->GetNT()))
{
auto & trig = geom->GetTriangle(ti);
Element2d el(TRIG);
for (auto i : IntRange(3))
el[i] = (*geom)[STLTrigIndex(ti)][i];
el.SetIndex(1);
mesh.AddSurfaceElement(el);
}
}
}
}

View File

@ -231,6 +231,7 @@ loadmeshinifile;
{"Universal format" {.unv} }
{"Olaf format" {.emt} }
{"TET format" {.tet} }
{"STL format" {.stl .stlb} }
{"Pro/ENGINEER neutral format" {.fnf} }
}
set file [tk_getOpenFile -filetypes $types ]

View File

@ -405,6 +405,7 @@ namespace netgen
PrintMessage (2, mesh->GetNP(), " Points, ",
mesh->GetNE(), " Elements.");
SetGlobalMesh (mesh);
mesh->SetGlobalH (mparam.maxh);
mesh->CalcLocalH(mparam.grading);

View File

@ -861,6 +861,7 @@ const char * ngscript[] = {""
,"{\"Universal format\" {.unv} }\n"
,"{\"Olaf format\" {.emt} }\n"
,"{\"TET format\" {.tet} }\n"
,"{\"STL format\" {.stl .stlb} }\n"
,"{\"Pro/ENGINEER neutral format\" {.fnf} }\n"
,"}\n"
,"set file [tk_getOpenFile -filetypes $types ]\n"