From a42ecab606759e11fc86f57af5ed4379bfc52ac0 Mon Sep 17 00:00:00 2001 From: Philippose Rajan Date: Sun, 15 Feb 2009 20:18:21 +0000 Subject: [PATCH] * Added a new demonstrator program for the nglib library which shows how to read in an STL geometry file, initialise the STL geometry, mesh it, and save it as a VOL mesh file. * Modified the makefile to include the new demo program ng_stl during the Linux compile process --- nglib/Makefile.am | 5 +- nglib/ng_stl.cpp | 116 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 nglib/ng_stl.cpp diff --git a/nglib/Makefile.am b/nglib/Makefile.am index a4eacfc8..21f914fc 100644 --- a/nglib/Makefile.am +++ b/nglib/Makefile.am @@ -27,6 +27,9 @@ ng_vol_LDADD = \ libnglib.la - +bin_PROGRAMS = ng_stl +ng_vol_SOURCES = ng_stl.cpp +ng_vol_LDADD = \ + libnglib.la diff --git a/nglib/ng_stl.cpp b/nglib/ng_stl.cpp new file mode 100644 index 00000000..115b776d --- /dev/null +++ b/nglib/ng_stl.cpp @@ -0,0 +1,116 @@ +/*! + \file ng_stl.cpp + \author Philippose Rajan + \date 14 Feb 2009 (Created) + + This sample utility demonstrates the use of the Netgen + nglib library for reading, and meshing an STL geometry. + + The Program takes as input the name of an STL file + saved in the STL ASCII Format, and generates a 3D Volume + mesh which is saved into the file "test.vol". + + test.vol can be viewed using the usual Netgen Mesher GUI +*/ + + +#include +#include + +using namespace std; + +namespace nglib { +#include +} + +int main (int argc, char ** argv) +{ + using namespace nglib; + + cout << "Netgen (nglib) STL Testing" << endl; + + if (argc < 2) + { + cerr << "use: ng_stl STL_filename" << endl; + return 1; + } + + // Define pointer to a new Netgen Mesh + Ng_Mesh *mesh; + + // Define pointer to STL Geometry + Ng_STL_Geometry *stl_geom; + + // Result of Netgen Operations + Ng_Result ng_res; + + // Initialise the Netgen Core library + Ng_Init(); + + // Actually create the mesh structure + mesh = Ng_NewMesh(); + + int np, ne; + + // Read in the STL File + stl_geom = Ng_STL_LoadGeometry(argv[1]); + if(!stl_geom) + { + cout << "Error reading in STL File: " << argv[1] << endl; + return 1; + } + cout << "Successfully loaded STL File: " << argv[1] << endl; + + + // Set the Meshing Parameters to be used + Ng_Meshing_Parameters mp; + mp.maxh = 1.0e+6; + mp.fineness = 0.4; + mp.secondorder = 0; + + cout << "Initialise the STL Geometry structure...." << endl; + ng_res = Ng_STL_InitSTLGeometry(stl_geom); + if(ng_res != NG_OK) + { + cout << "Error Initialising the STL Geometry....Aborting!!" << endl; + return 1; + } + + cout << "Start Edge Meshing...." << endl; + ng_res = Ng_STL_MakeEdges(stl_geom, mesh, &mp); + if(ng_res != NG_OK) + { + cout << "Error in Edge Meshing....Aborting!!" << endl; + return 1; + } + + cout << "Start Surface Meshing...." << endl; + ng_res = Ng_STL_GenerateSurfaceMesh(stl_geom, mesh, &mp); + if(ng_res != NG_OK) + { + cout << "Error in Surface Meshing....Aborting!!" << endl; + return 1; + } + + cout << "Start Volume Meshing...." << endl; + ng_res = Ng_GenerateVolumeMesh (mesh, &mp); + if(ng_res != NG_OK) + { + cout << "Error in Volume Meshing....Aborting!!" << endl; + return 1; + } + + cout << "Meshing successfully completed....!!" << endl; + + // volume mesh output + np = Ng_GetNP(mesh); + cout << "Points: " << np << endl; + + ne = Ng_GetNE(mesh); + cout << "Elements: " << ne << endl; + + cout << "Saving Mesh in VOL Format...." << endl; + Ng_SaveMesh(mesh,"test.vol"); + + return 0; +}