Commit 29d5a10f authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: add stream operators for MeshedSurface, UnsortedMeshedSurface

- add corrsponding testing into surfaceMeshConvertTesting too
parent ba413e1f
......@@ -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
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -343,7 +343,10 @@ Foam::MeshedSurface<Face>::MeshedSurface
template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface(const fileName& name)
Foam::MeshedSurface<Face>::MeshedSurface
(
const fileName& name
)
:
ParentType(List<Face>(), pointField())
{
......@@ -351,6 +354,19 @@ Foam::MeshedSurface<Face>::MeshedSurface(const fileName& name)
}
template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface
(
Istream& is
)
:
ParentType(List<Face>(), pointField()),
zones_()
{
read(is);
}
template<class Face>
Foam::MeshedSurface<Face>::MeshedSurface
(
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -69,11 +69,18 @@ namespace Foam
class Time;
class surfMesh;
class polyBoundaryMesh;
class Istream;
class Ostream;
template<class Face> class MeshedSurface;
template<class Face> class MeshedSurfaceProxy;
template<class Face> class UnsortedMeshedSurface;
template<class Face>
Istream& operator>>(Istream&, MeshedSurface<Face>&);
template<class Face>
Ostream& operator<<(Ostream&, const MeshedSurface<Face>&);
/*---------------------------------------------------------------------------*\
Class MeshedSurface Declaration
\*---------------------------------------------------------------------------*/
......@@ -84,7 +91,7 @@ class MeshedSurface
public PrimitivePatch<Face, ::Foam::List, pointField, point>,
public fileFormats::surfaceFormatsCore
{
// friends - despite different face representationsx
// friends - despite different face representations
template<class Face2> friend class MeshedSurface;
template<class Face2> friend class UnsortedMeshedSurface;
friend class surfMesh;
......@@ -114,6 +121,15 @@ private:
List<surfZone> zones_;
// Private Member functions
//- Read/construct from Istream
Istream& read(Istream&);
//- Write to Ostream
Ostream& write(Ostream&) const;
protected:
// Protected Member functions
......@@ -133,7 +149,7 @@ protected:
//- Non-const access to the faces
List<Face>& storedFaces()
{
return static_cast<List<Face> &>(*this);
return static_cast<List<Face>&>(*this);
}
//- Non-const access to the zones
......@@ -234,8 +250,15 @@ public:
//- Construct from file name (uses extension to determine type)
MeshedSurface(const fileName&, const word& ext);
//- Construct from Istream
MeshedSurface(Istream&);
//- Construct from database
MeshedSurface(const Time&, const word& surfName="");
MeshedSurface
(
const Time&,
const word& surfName = word::null
);
// Declare run-time constructor selection table
......@@ -285,7 +308,11 @@ public:
);
//- Write to file
static void write(const fileName&, const MeshedSurface<Face>&);
static void write
(
const fileName&,
const MeshedSurface<Face>&
);
// Member Functions
......@@ -301,7 +328,7 @@ public:
//- Return const access to the faces
inline const List<Face>& faces() const
{
return static_cast<const List<Face> &>(*this);
return static_cast<const List<Face>&>(*this);
}
//- Const access to the surface zones.
......@@ -353,7 +380,7 @@ public:
// Note, optimized to avoid overwriting data (with Xfer::null)
virtual void reset
(
const Xfer<pointField >& points,
const Xfer<pointField>& points,
const Xfer<List<Face>>& faces,
const Xfer<surfZoneList>& zones
);
......@@ -364,7 +391,7 @@ public:
(
const Xfer<List<point>>& points,
const Xfer<List<Face>>& faces,
const Xfer<surfZoneList >& zones
const Xfer<surfZoneList>& zones
);
//- Remove invalid faces
......@@ -435,7 +462,11 @@ public:
}
//- Write to database
void write(const Time&, const word& surfName="") const;
void write
(
const Time&,
const word& surfName = word::null
) const;
// Member operators
......@@ -444,6 +475,25 @@ public:
//- Conversion operator to MeshedSurfaceProxy
operator MeshedSurfaceProxy<Face>() const;
// IOstream Operators
//- Read MeshedSurface from Istream.
friend Istream& operator>> <Face>
(
Istream&,
MeshedSurface<Face>&
);
//- Write MeshedSurface to Ostream.
friend Ostream& operator<< <Face>
(
Ostream&,
const MeshedSurface<Face>&
);
};
......
......@@ -66,12 +66,4 @@ namespace Foam
} // end of namespace Foam
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -25,10 +25,35 @@ License
#include "MeshedSurface.H"
#include "boundBox.H"
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
Foam::Istream& Foam::MeshedSurface<Face>::read(Istream& is)
{
is >> this->storedZones()
>> this->storedPoints()
>> this->storedFaces();
is.check("MeshedSurface::read(Istream&)");
return is;
}
template<class Face>
Foam::Ostream& Foam::MeshedSurface<Face>::write(Ostream& os) const
{
os << this->surfZones()
<< this->points()
<< this->faces();
os.check("MeshedSurface::write(Ostream&) const");
return os;
}
template<class Face>
void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
{
......@@ -64,4 +89,28 @@ void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Face>
Foam::Istream& Foam::operator>>
(
Foam::Istream& is,
Foam::MeshedSurface<Face>& surf
)
{
return surf.read(is);
}
template<class Face>
Foam::Ostream& Foam::operator<<
(
Foam::Ostream& os,
const Foam::MeshedSurface<Face>& surf
)
{
return surf.write(os);
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -128,7 +128,11 @@ public:
);
//- Write to file
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
static void write
(
const fileName&,
const MeshedSurfaceProxy<Face>&
);
// Member Functions
......@@ -176,7 +180,11 @@ public:
}
//- Write to database
virtual void write(const Time&, const word& surfName = "") const;
virtual void write
(
const Time&,
const word& surfName = word::null
) const;
};
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -263,7 +263,10 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const fileName& name)
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const fileName& name
)
:
ParentType()
{
......@@ -271,6 +274,20 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const fileName& name)
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
Istream& is
)