ENH: add stream operators for MeshedSurface, UnsortedMeshedSurface

- add corrsponding testing into surfaceMeshConvertTesting too
This commit is contained in:
Mark Olesen
2016-09-06 14:45:44 +02:00
parent ba413e1f9a
commit 29d5a10f97
10 changed files with 412 additions and 62 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -66,6 +66,9 @@ Note
#include "MeshedSurfaces.H"
#include "UnsortedMeshedSurfaces.H"
#include "IStringStream.H"
#include "OStringStream.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -84,11 +87,33 @@ int main(int argc, char *argv[])
argList::validArgs.append("outputFile");
argList::addBoolOption("clean");
argList::addBoolOption("orient");
argList::addBoolOption("surfMesh");
argList::addBoolOption
(
"orient",
"check surface orientation"
);
argList::addBoolOption
(
"surfMesh",
"test surfMesh output"
);
argList::addBoolOption("triSurface");
argList::addBoolOption("unsorted");
argList::addBoolOption("triFace");
argList::addBoolOption
(
"unsorted",
"use UnsortedMeshedSurface instead of MeshedSurface, "
"or unsorted output (with -triSurface option)"
);
argList::addBoolOption
(
"triFace",
"use triFace instead of face"
);
argList::addBoolOption
(
"stdout",
"ignore output filename and write to stdout"
);
argList::addOption
(
@ -99,10 +124,11 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
const bool optStdout = args.optionFound("stdout");
const scalar scaleFactor = args.optionLookupOrDefault("scale", 0.0);
const fileName importName = args[1];
const fileName exportName = args[2];
const fileName exportName = optStdout ? "-stdout" : args[2];
if (importName == exportName)
{
@ -114,7 +140,11 @@ int main(int argc, char *argv[])
if
(
!MeshedSurface<face>::canRead(importName, true)
|| !MeshedSurface<face>::canWriteType(exportName.ext(), true)
||
(
!optStdout
&& !MeshedSurface<face>::canWriteType(exportName.ext(), true)
)
)
{
return 1;
@ -128,6 +158,19 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
// check: output to ostream, construct from istream
{
OStringStream os;
os << surf;
IStringStream is(os.str());
triSurface surf2(is);
// is.rewind();
// is >> surf2; // FAIL: uses List<labelledTri> base class
// surf2.read(is); // FAIL: private method
}
if (args.optionFound("orient"))
{
Info<< "Checking surface orientation" << endl;
@ -156,8 +199,15 @@ int main(int argc, char *argv[])
Info<< endl;
}
// write sorted by region
surf.write(exportName, true);
if (optStdout)
{
Info<< surf;
}
else
{
// normally write sorted (looks nicer)
surf.write(exportName, !args.optionFound("unsorted"));
}
}
else if (args.optionFound("unsorted"))
{
@ -167,6 +217,23 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
// check: output to ostream, construct from istream
{
OStringStream os;
os << surf;
IStringStream is(os.str());
// both work:
UnsortedMeshedSurface<face> surf2(is);
// OR
// is.rewind();
// UnsortedMeshedSurface<face> surf2;
// is >> surf2;
// surf2.read(is); // FAIL: private method
}
if (args.optionFound("orient"))
{
Info<< "Checking surface orientation" << endl;
@ -194,9 +261,16 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
}
surf.write(exportName);
if (optStdout)
{
Info<< surf;
}
else
{
surf.write(exportName);
}
}
#if 1
else if (args.optionFound("triFace"))
{
MeshedSurface<triFace> surf(importName);
@ -205,6 +279,23 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
// check: output to ostream, construct from istream
{
OStringStream os;
os << surf;
IStringStream is(os.str());
// both work:
MeshedSurface<face> surf2(is);
// OR
// is.rewind();
// MeshedSurface<face> surf2;
// is >> surf2;
// surf2.read(is); // FAIL: private method
}
if (args.optionFound("orient"))
{
Info<< "Checking surface orientation" << endl;
@ -232,9 +323,16 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
}
surf.write(exportName);
if (optStdout)
{
Info<< surf;
}
else
{
surf.write(exportName);
}
}
#endif
else
{
MeshedSurface<face> surf(importName);
@ -243,6 +341,23 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
// check: output to ostream, construct from istream
{
OStringStream os;
os << surf;
IStringStream is(os.str());
// both work:
MeshedSurface<face> surf2(is);
// OR
// is.rewind();
// MeshedSurface<face> surf2;
// is >> surf2;
// surf2.read(is); // FAIL: private method
}
if (args.optionFound("orient"))
{
Info<< "Checking surface orientation" << endl;
@ -258,7 +373,6 @@ int main(int argc, char *argv[])
Info<< endl;
}
Info<< "writing " << exportName;
if (scaleFactor <= 0)
{
@ -271,7 +385,15 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
}
surf.write(exportName);
if (optStdout)
{
Info<< surf;
}
else
{
surf.write(exportName);
}
if (args.optionFound("surfMesh"))
{
@ -287,7 +409,6 @@ int main(int argc, char *argv[])
Info<< "runTime.instance() = " << runTime.instance() << endl;
Info<< "runTime.timeName() = " << runTime.timeName() << endl;
Info<< "write MeshedSurface 'yetAnother' via proxy as surfMesh"
<< endl;
surf.write
@ -312,14 +433,11 @@ int main(int argc, char *argv[])
MeshedSurface<face> surfIn2(runTime, "foobar");
Info<<"surfIn2 = " << surfIn2.size() << endl;
Info<< "surfIn = " << surfIn.size() << endl;
Info<< "writing surfMesh as obj = oldSurfIn.obj" << endl;
surfIn.write("oldSurfIn.obj");
Info<< "runTime.instance() = " << runTime.instance() << endl;
surfMesh surfOut