Skip to content

Commit

Permalink
Merge pull request #618 from richb2k/gui-stl-binary
Browse files Browse the repository at this point in the history
ElmerGui, add reading of binary stl files.  add toLower of file suffix,
  • Loading branch information
raback authored Jan 8, 2025
2 parents 4f2b2f6 + 16fea5d commit 06542e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
45 changes: 41 additions & 4 deletions ElmerGUI/Application/src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ void MainWindow::readInputFile(QString fileName) {
sprintf(cs, "%s", baseFileName.toAscii().data());
#endif

fileSuffix = fileSuffix.toLower();
activeGenerator = GEN_UNKNOWN;
tetlibInputOk = false;
nglibInputOk = false;
Expand Down Expand Up @@ -5245,12 +5246,41 @@ void MainWindow::meshcontrolSlot() {
meshControl->show();
}

int checkStlForAscii(const char * filename)
{
char ch;
char bufin[100];
int stlbinary = 0;
ifstream stlfile(filename);

if (stlfile.is_open()) {
cout << "Open stl input file: " << filename << endl;

for (int j = 0; j < 100; j++) {
stlfile.get(ch);
bufin[j] = ch;
}
//cout << "bufin: " << bufin << endl;
if( strstr(bufin,"facet")) {
cout << "stl input file is in ASCII file format" << endl;
} else {
stlbinary = 1;
cout << "stl input file is in binary file format" << endl;
}
cout << endl;
stlfile.close();
} else {
cout << "stl input file not found or is corrupted" << filename << endl;
}

return stlbinary;
}
// Mesh -> Remesh
//-----------------------------------------------------------------------------
void MainWindow::remeshSlot() {
if (activeGenerator == GEN_UNKNOWN) {
logMessage("Unable to (re)mesh: no input data or mesh generator (please "
"make sure that your input file suffix is in lower case)");
logMessage("Unable to (re)mesh: no input data or mesh generator. Allowed: "
"smesh, poly, off, ply, mesh, stl, grd, FDNEUT, msh, mphtxt, inp, unv, plt, in2d");
return;
}

Expand Down Expand Up @@ -5358,10 +5388,17 @@ void MainWindow::remeshSlot() {

// STL: regenerate structures for nglib:
//--------------------------------------
// check if input file is in ascii or binary format
#if WITH_QT5 || WITH_QT6
int stlbinary = checkStlForAscii(stlFileName.toLatin1().data());
#else
int stlbinary = checkStlForAscii(stlFileName.toAscii().data());
#endif

#if WITH_QT5 || WITH_QT6
nggeom = nglib::Ng_STL_LoadGeometry(stlFileName.toLatin1().data(), 0);
nggeom = nglib::Ng_STL_LoadGeometry(stlFileName.toLatin1().data(), stlbinary);
#else
nggeom = nglib::Ng_STL_LoadGeometry(stlFileName.toAscii().data(), 0);
nggeom = nglib::Ng_STL_LoadGeometry(stlFileName.toAscii().data(), stlbinary);
#endif

if (!nggeom) {
Expand Down
3 changes: 2 additions & 1 deletion ElmerGUI/netgen/libsrc/interface/nglib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,14 +397,15 @@ Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary)
int i;
STLGeometry geom;
STLGeometry* geo;
ifstream ist(filename);

if (binary)
{
ifstream ist(filename, ios::binary);
geo = geom.LoadBinary(ist);
}
else
{
ifstream ist(filename);
geo = geom.Load(ist);
}

Expand Down

0 comments on commit 06542e2

Please sign in to comment.