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;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2015 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -42,8 +42,38 @@ Description
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 (!edgeMesh::canReadType(readType, true))
{
good = false;
}
if (!edgeMesh::canWriteType(writeType, true))
{
good = false;
}
return good;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
@ -55,44 +85,64 @@ int main(int argc, char *argv[])
argList::addArgument("input", "The input edge file");
argList::addArgument("output", "The output edge file");
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",
"Geometry scaling factor - default is 1"
"Input geometry scaling factor"
);
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName importName = args[1];
const fileName exportName = args[2];
const fileName importName(args[1]);
const fileName exportName(args[2]);
// Disable inplace editing
if (importName == exportName)
{
FatalErrorInFunction
<< "Output file " << exportName << " would overwrite input file."
FatalError
<< "Output file would overwrite input file."
<< exit(FatalError);
}
// Check that reading/writing is supported
if
const word readFileType
(
!edgeMesh::canReadType(importName.ext(), true)
|| !edgeMesh::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);
}
edgeMesh mesh(importName);
edgeMesh mesh(importName, readFileType);
Info<< "\nRead edgeMesh " << importName << nl;
mesh.writeStats(Info);
Info<< nl
<< "\nwriting " << exportName;
scalar scaleFactor = 0;
scalar scaleFactor(0);
if (args.readIfPresent("scale", scaleFactor) && scaleFactor > 0)
{
Info<< " with scaling " << scaleFactor << endl;
@ -103,7 +153,7 @@ int main(int argc, char *argv[])
Info<< " without scaling" << endl;
}
mesh.write(exportName);
mesh.write(exportName, writeFileType);
mesh.writeStats(Info);
Info<< "\nEnd\n" << endl;

View File

@ -41,26 +41,32 @@ Usage
- \par -clean
Perform some surface checking/cleanup on the input surface.
- \par -scaleIn \<scale\>
Specify a scaling factor when reading files.
- \par -read-format \<type\>
The input file format (default: use file extension)
- \par -scaleOut \<scale\>
Specify a scaling factor when writing files.
- \par -write-format \<type\>
The output file format (default: use file extension)
- \par -read-scale \<scale\>
Input geometry scaling factor.
- \par -write-scale \<scale\>
Output geometry scaling factor.
- \par -dict \<dictionary\>
Specify an alternative dictionary for constant/coordinateSystems.
Alternative dictionary for constant/coordinateSystems.
- \par -from \<coordinateSystem\>
Specify a coordinate System when reading files.
Apply specified coordinate system after reading file.
- \par -to \<coordinateSystem\>
Specify a coordinate System when writing files.
Apply specified coordinate system before writing file.
- \par -tri
Triangulate surface.
Note
The filename extensions are used to determine the file format type.
The filename extensions are used to determine the default file formats.
\*---------------------------------------------------------------------------*/
@ -73,6 +79,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 (!meshedSurface::canReadType(readType, true))
{
good = false;
}
if (!meshedSurface::canWriteType(writeType, true))
{
good = false;
}
return good;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
@ -93,30 +129,46 @@ int main(int argc, char *argv[])
);
argList::addOption
(
"scaleIn",
"factor",
"Geometry scaling factor on input"
"read-format",
"type",
"Input format (default: use file extension)"
);
argList::addOption
(
"scaleOut",
"factor",
"Geometry scaling factor on output"
"write-format",
"type",
"Output format (default: use file extension)"
);
argList::addOption("dict", "file", "Use alternative coordinateSystems");
argList::addOption
(
"read-scale",
"factor",
"Input geometry scaling factor"
);
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",
"system",
"Specify the source coordinate system, applied after '-scaleIn'",
"The source coordinate system, applied after '-read-scale'",
true // advanced
);
argList::addOption
(
"to",
"system",
"Specify the target coordinate system, applied before '-scaleOut'",
"The target coordinate system, applied before '-write-scale'",
true // advanced
);
argList::addBoolOption
@ -129,28 +181,38 @@ int main(int argc, char *argv[])
argList args(argc, argv);
Time runTime(args.rootPath(), args.caseName());
const fileName importName = args[1];
const fileName exportName = args[2];
const fileName importName(args[1]);
const fileName exportName(args[2]);
// disable inplace editing
if (importName == exportName)
{
FatalErrorInFunction
<< "Output file " << exportName << " would overwrite input file."
FatalError
<< "Output file would overwrite input file."
<< exit(FatalError);
}
// Check that reading/writing is supported
if
const word readFileType
(
!MeshedSurface<face>::canRead(importName, true)
|| !MeshedSurface<face>::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);
}
scalar scaleFactor(0);
// The coordinate transformations (must be cartesian)
autoPtr<coordSystem::cartesian> fromCsys;
autoPtr<coordSystem::cartesian> toCsys;
@ -173,7 +235,7 @@ int main(int argc, char *argv[])
if (!ioCsys.typeHeaderOk<coordinateSystems>(false))
{
FatalErrorInFunction
FatalError
<< "Cannot open coordinateSystems file\n "
<< ioCsys.objectPath() << nl
<< exit(FatalError);
@ -188,7 +250,7 @@ int main(int argc, char *argv[])
if (!csPtr)
{
FatalErrorInFunction
FatalError
<< "Cannot find -from " << csName << nl
<< "available coordinateSystems: "
<< flatOutput(globalCoords.names()) << nl
@ -205,7 +267,7 @@ int main(int argc, char *argv[])
if (!csPtr)
{
FatalErrorInFunction
FatalError
<< "Cannot find -to " << csName << nl
<< "available coordinateSystems: "
<< flatOutput(globalCoords.names()) << nl
@ -218,7 +280,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);
}
@ -226,24 +288,23 @@ int main(int argc, char *argv[])
{
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: "
<< fromCsys->name() << endl;
<< fromCsys->name() << nl;
tmp<pointField> tpf = fromCsys->localPosition(surf.points());
surf.movePoints(tpf());
}
@ -251,26 +312,25 @@ int main(int argc, char *argv[])
if (toCsys)
{
Info<< "move points to coordinate system: "
<< toCsys->name() << endl;
<< toCsys->name() << nl;
tmp<pointField> tpf = toCsys->globalPosition(surf.points());
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);
}
if (args.found("tri"))
{
Info<< "triangulate" << endl;
Info<< "triangulate" << nl;
surf.triangulate();
}
Info<< "writing " << exportName;
surf.write(exportName);
surf.write(exportName, writeFileType);
}
Info<< "\nEnd\n" << endl;

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;

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -62,6 +62,36 @@ Description
using namespace Foam;
using namespace Foam::coordinateRotations;
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 (!meshedSurface::canReadType(readType, true))
{
good = false;
}
if (!meshedSurface::canWriteType(writeType, true))
{
good = false;
}
return good;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -119,6 +149,19 @@ int main(int argc, char *argv[])
"Scale by the specified amount - Eg, for uniform [mm] to [m] scaling "
"use either '(0.001 0.001 0.001)' or simply '0.001'"
);
argList::addOption
(
"read-format",
"type",
"Input format (default: use file extension)"
);
argList::addOption
(
"write-format",
"type",
"Output format (default: use file extension)"
);
argList args(argc, argv);
// Verify that an operation has been specified
@ -151,13 +194,34 @@ int main(int argc, char *argv[])
}
}
const fileName surfFileName = args[1];
const fileName outFileName = args[2];
const fileName importName(args[1]);
const fileName exportName(args[2]);
Info<< "Reading surf from " << surfFileName << " ..." << nl
<< "Writing surf to " << outFileName << " ..." << endl;
const word readFileType
(
args.getOrDefault<word>("read-format", getExtension(importName))
);
meshedSurface surf1(surfFileName);
const word writeFileType
(
args.getOrDefault<word>("write-format", getExtension(exportName))
);
// Check that reading/writing is supported
if (!hasReadWriteTypes(readFileType, writeFileType))
{
FatalError
<< "Unsupported file format(s)" << nl
<< exit(FatalError);
}
Info<< "Reading surf from " << importName << " ..." << nl
<< "Writing surf to " << exportName << " ..." << endl;
meshedSurface surf1(importName, readFileType);
pointField points(surf1.points());
@ -169,7 +233,7 @@ int main(int argc, char *argv[])
points += v;
}
vector origin;
vector origin(Zero);
const bool useOrigin = args.readIfPresent("origin", origin);
if (useOrigin)
{
@ -240,7 +304,16 @@ int main(int argc, char *argv[])
{
// readListIfPresent handles single or multiple values
if (scaling.size() == 1)
if
(
scaling.size() == 1
||
(
scaling.size() == 3
&& equal(scaling[0], scaling[1])
&& equal(scaling[0], scaling[2])
)
)
{
Info<< "Scaling points uniformly by " << scaling[0] << nl;
points *= scaling[0];
@ -248,9 +321,9 @@ int main(int argc, char *argv[])
else if (scaling.size() == 3)
{
Info<< "Scaling points by ("
<< scaling[0] << " "
<< scaling[1] << " "
<< scaling[2] << ")" << nl;
<< scaling[0] << ' '
<< scaling[1] << ' '
<< scaling[2] << ')' << nl;
points.replace(vector::X, scaling[0]*points.component(vector::X));
points.replace(vector::Y, scaling[1]*points.component(vector::Y));
@ -272,7 +345,7 @@ int main(int argc, char *argv[])
}
surf1.movePoints(points);
surf1.write(outFileName);
surf1.write(exportName, writeFileType);
Info<< "End\n" << endl;