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 -write-format \<type\>
Specify output 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\>
Specify an 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[])
@ -100,46 +115,65 @@ int main(int argc, char *argv[])
);
argList::addOption
(
"scaleIn",
"factor",
"Geometry scaling factor on input - default is 1"
"write-format",
"type",
"Output 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 the source coordinate system, applied after '-scaleIn'",
"system",
"The source coordinate system, applied after '-read-scale'",
true // advanced
);
argList::addOption
(
"to",
"coordinateSystem",
"Specify the target coordinate system, applied before '-scaleOut'",
"system",
"The target coordinate system, applied before '-write-scale'",
true // advanced
);
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName exportName = args[1];
const word importName = args.get<word>("name", "default");
const fileName exportName(args[1]);
const word importName(args.get<word>("name", "default"));
// check that writing is supported
if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
const word writeFileType
(
args.getOrDefault<word>("write-format", getExtension(exportName))
);
// Check read/write support for formats
if (!meshedSurface::canWriteType(writeFileType, 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;
@ -162,7 +196,7 @@ int main(int argc, char *argv[])
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
{
FatalErrorInFunction
FatalError
<< ioCsys.objectPath() << nl
<< exit(FatalError);
}
@ -176,7 +210,7 @@ int main(int argc, char *argv[])
if (!csPtr)
{
FatalErrorInFunction
FatalError
<< "Cannot find -from " << csName << nl
<< "available coordinateSystems: "
<< flatOutput(globalCoords.names()) << nl
@ -193,7 +227,7 @@ int main(int argc, char *argv[])
if (!csPtr)
{
FatalErrorInFunction
FatalError
<< "Cannot find -to " << csName << nl
<< "available coordinateSystems: "
<< flatOutput(globalCoords.names()) << nl
@ -206,7 +240,7 @@ 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);
}
@ -228,22 +262,21 @@ int main(int argc, char *argv[])
Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
// Simply copy for now, but really should have a separate write method
// Simply copy for now, but really could have a separate write method
MeshedSurface<face> surf(smesh);
meshedSurface surf(smesh);
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.valid())
{
Info<< "move points from coordinate system: "
@ -260,19 +293,17 @@ 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 << endl;
surf.scalePoints(scaleFactor);
}
surf.writeStats(Info);
Info<< endl;
Info<< "writing " << exportName << endl;
surf.write(exportName);
Info<< "writing " << exportName << nl;
surf.write(exportName, writeFileType);
Info<< "\nEnd\n" << endl;