ENH: support independent specification of surface read/write format (#1600)

- adjustments to internal handling to improve run-time addition of
  other formats (eg, with additional user library)

  For example, to write a binary STL with a '.stl' extension:

    $ surfaceMeshConvert input.obj  -write-format stlb  output.stl

  Or in a sampler,
  to specify the input type without ambiguity:

  surf
  {
      type        meshedSurface;
      surface     sampling.inp;

      fileType    starcd;
      scale       0.001;
      ...
  }

STYLE: regularize naming for input/output scaling

  * -read-scale   (compat: -scaleIn)
  * -write-scale  (compat: -scaleOut)

CONFIG: change edge/surface selection name for STARCD format

- now select as "starcd" instead of "inp" to avoid naming ambiguity
  with abaqus
This commit is contained in:
Mark Olesen
2020-04-01 18:16:47 +02:00
parent ae14a1ef31
commit 560c053bc8
50 changed files with 1338 additions and 766 deletions

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,6 +40,12 @@ Usage
- \par -clean
Perform some surface checking/cleanup on the input surface
- \par -read-format \<type\>
Specify input file format
- \par -write-format \<type\>
Specify output file format
- \par -scale \<scale\>
Specify a scaling factor for writing the files
@ -59,6 +66,36 @@ Note
using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
}
// Non-short-circuiting check to get all warnings
static bool hasReadWriteTypes(const word& readType, const word& writeType)
{
volatile bool good = true;
if (!triSurface::canReadType(readType, true))
{
good = false;
}
if (!triSurface::canWriteType(writeType, true))
{
good = false;
}
return good;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -84,6 +121,18 @@ int main(int argc, char *argv[])
"Reorder faces into groups; one per region"
);
argList::addOption
(
"read-format",
"type",
"The input format (default: use file extension)"
);
argList::addOption
(
"write-format",
"type",
"The output format (default: use file extension)"
);
argList::addOption
(
"scale",
"factor",
@ -93,7 +142,7 @@ int main(int argc, char *argv[])
(
"precision",
"int",
"Write to output with the specified precision"
"The output precision"
);
argList::addOptionCompat("precision", {"writePrecision", 1812});
@ -110,30 +159,47 @@ int main(int argc, char *argv[])
}
}
const fileName importName = args[1];
const fileName exportName = args[2];
const fileName importName(args[1]);
const fileName exportName(args[2]);
if (importName == exportName)
{
FatalErrorInFunction
<< "Output file " << exportName << " would overwrite input file."
FatalError
<< "Output file would overwrite input file." << nl
<< exit(FatalError);
}
// Check that reading/writing is supported
if
const word readFileType
(
!triSurface::canRead(importName, true)
|| !triSurface::canWriteType(exportName.ext(), true)
)
args.getOrDefault<word>("read-format", getExtension(importName))
);
const word writeFileType
(
args.getOrDefault<word>("write-format", getExtension(exportName))
);
// Check that reading/writing is supported
if (!hasReadWriteTypes(readFileType, writeFileType))
{
return 1;
FatalError
<< "Unsupported file format(s)" << nl
<< exit(FatalError);
}
const scalar scaleFactor = args.get<scalar>("scale", -1);
scalar scaleFactor(0);
Info<< "Reading : " << importName << endl;
triSurface surf(importName, scaleFactor);
triSurface surf(importName, readFileType, scaleFactor);
if (args.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
{
Info<< "scale input " << scaleFactor << nl;
surf.scalePoints(scaleFactor);
}
Info<< "Read surface:" << endl;
surf.writeStats(Info);
@ -159,10 +225,9 @@ int main(int argc, char *argv[])
Info<< "Maintaining face ordering" << endl;
}
Info<< "writing " << exportName;
Info<< endl;
Info<< "writing " << exportName << endl;
surf.write(exportName, sortByRegion);
surf.write(exportName, writeFileType, sortByRegion);
Info<< "\nEnd\n" << endl;