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

@ -45,11 +45,14 @@ Usage
- \par -name \<name\>
Specify an alternative surface name when writing.
- \par -scaleIn \<scale\>
Specify a scaling factor when reading files.
- \par -read-format \<type\>
Specify input file format
- \par -scaleOut \<scale\>
Specify a scaling factor when writing files.
- \par -read-scale \<scale\>
Scale factor when reading files.
- \par -write-scale \<scale\>
Scale factor when writing files.
- \par -dict \<dictionary\>
Use alternative dictionary for constant/coordinateSystems.
@ -74,6 +77,18 @@ Note
using namespace Foam;
static word getExtension(const fileName& name)
{
word ext(name.ext());
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return ext;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
@ -95,35 +110,44 @@ int main(int argc, char *argv[])
(
"name",
"name",
"Specify an alternative surface name when writing - "
"default is 'default'"
"The surface name when writing (default is 'default')"
);
argList::addOption
(
"scaleIn",
"factor",
"Geometry scaling factor on input - default is 1"
"read-format",
"type",
"Input format (default: use file extension)"
);
argList::addOption
(
"scaleOut",
"read-scale",
"factor",
"Geometry scaling factor on output - default is 1"
"Input geometry scaling factor"
);
argList::addOption("dict", "file", "Use alternative coordinateSystems");
argList::addOption
(
"write-scale",
"factor",
"Output geometry scaling factor"
);
argList::addOptionCompat("read-scale", {"scaleIn", 1912});
argList::addOptionCompat("write-scale", {"scaleOut", 1912});
argList::addOption("dict", "file", "Alternative coordinateSystems");
argList::addOption
(
"from",
"coordinateSystem",
"Specify a local coordinate system when reading files.",
"system",
"The source coordinate system, applied after '-read-scale'",
true // advanced
);
argList::addOption
(
"to",
"coordinateSystem",
"Specify a local coordinate system when writing files.",
"system",
"The target coordinate system, applied before '-write-scale'",
true // advanced
);
@ -143,16 +167,25 @@ int main(int argc, char *argv[])
}
const fileName importName = args[1];
const word exportName = args.get<word>("name", "default");
const fileName importName(args[1]);
const word exportName(args.get<word>("name", "default"));
// check that reading is supported
if (!MeshedSurface<face>::canRead(importName, true))
const word readFileType
(
args.getOrDefault<word>("read-format", getExtension(importName))
);
// Check that reading is supported
if (!meshedSurface::canRead(readFileType, true))
{
return 1;
FatalError
<< "Unsupported file format(s)" << nl
<< exit(FatalError);
}
scalar scaleFactor(0);
// The coordinate transformations (must be cartesian)
autoPtr<coordSystem::cartesian> fromCsys;
autoPtr<coordSystem::cartesian> toCsys;
@ -175,7 +208,7 @@ int main(int argc, char *argv[])
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
{
FatalErrorInFunction
FatalError
<< ioCsys.objectPath() << nl
<< exit(FatalError);
}
@ -189,7 +222,7 @@ int main(int argc, char *argv[])
if (!csPtr)
{
FatalErrorInFunction
FatalError
<< "Cannot find -from " << csName << nl
<< "available coordinateSystems: "
<< flatOutput(globalCoords.names()) << nl
@ -206,7 +239,7 @@ int main(int argc, char *argv[])
if (!csPtr)
{
FatalErrorInFunction
FatalError
<< "Cannot find -to " << csName << nl
<< "available coordinateSystems: "
<< flatOutput(globalCoords.names()) << nl
@ -219,28 +252,26 @@ int main(int argc, char *argv[])
// Maybe fix this later
if (fromCsys && toCsys)
{
FatalErrorInFunction
FatalError
<< "Only allowed '-from' or '-to' option at the moment."
<< exit(FatalError);
}
}
MeshedSurface<face> surf(importName);
meshedSurface surf(importName, readFileType);
if (args.readIfPresent("read-scale", scaleFactor) && scaleFactor > 0)
{
Info<< "scale input " << scaleFactor << nl;
surf.scalePoints(scaleFactor);
}
if (args.found("clean"))
{
surf.cleanup(true);
}
scalar scaleIn = 0;
if (args.readIfPresent("scaleIn", scaleIn) && scaleIn > 0)
{
Info<< "scale input " << scaleIn << endl;
surf.scalePoints(scaleIn);
}
if (fromCsys)
{
Info<< "move points from coordinate system: "
@ -257,11 +288,10 @@ int main(int argc, char *argv[])
surf.movePoints(tpf());
}
scalar scaleOut = 0;
if (args.readIfPresent("scaleOut", scaleOut) && scaleOut > 0)
if (args.readIfPresent("write-scale", scaleFactor) && scaleFactor > 0)
{
Info<< "scale output " << scaleOut << endl;
surf.scalePoints(scaleOut);
Info<< "scale output " << scaleFactor << nl;
surf.scalePoints(scaleFactor);
}
surfMesh smesh