Commit fff2ee54 authored by Mark Olesen's avatar Mark Olesen
Browse files

Merge branch 'surface-declutter' into 'develop'

Surface declutter - issue #294

Removing various clutter from surfMesh and triSurface
- unused classes/files (backup copies on non-release repo)
- relocate some triSurface-related classes to where they make more sense, and where they can be reused.
- improve handling of various face types in MeshedSurface and UnsortedMeshedSurface (to bridge the gap to triSurface)
- improve transfer methods for reclaiming/reusing surface allocations

See merge request !77
parents 704620ae e112eb50
Test-faces.C
EXE = $(FOAM_USER_APPBIN)/Test-faces
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -21,47 +21,64 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::hashSignedLabel
Application
Test-faces
Description
hash for signed integers (Hash\<label\> only works for unsigned ints)
Simple tests for various faces
\*---------------------------------------------------------------------------*/
#ifndef HashSignedLabel_H
#define HashSignedLabel_H
#include "argList.H"
#include "labelledTri.H"
#include "List.H"
#include "word.H"
using namespace Foam;
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class hashSignedLabel Declaration
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
class hashSignedLabel
int main(int argc, char *argv[])
{
face f1{ 1, 2, 3, 4 };
Info<< "face:" << f1 << nl;
public:
triFace t1{ 1, 2, 3 };
Info<< "triFace:" << t1 << nl;
hashSignedLabel()
{}
f1 = t1;
Info<< "face:" << f1 << nl;
f1 = t1.triFaceFace();
Info<< "face:" << f1 << nl;
label operator()(const label key, const label tableSize) const
// expect these to fail
FatalError.throwExceptions();
try
{
labelledTri l1{ 1, 2, 3, 10, 24 };
Info<< "labelled:" << l1 << nl;
}
catch (Foam::error& err)
{
return mag(key)%tableSize;
WarningInFunction
<< "Caught FatalError " << err << nl << endl;
}
};
FatalError.dontThrowExceptions();
} // End namespace Foam
labelledTri l2{ 1, 2, 3 };
Info<< "labelled:" << l2 << nl;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
labelledTri l3{ 1, 2, 3, 10 };
Info<< "labelled:" << l3 << nl;
#endif
t1.flip();
l3.flip();
// ************************************************************************* //
Info<< "flip:" << t1 << nl;
Info<< "flip:" << l3 << nl;
return 0;
}
// ************************************************************************* //
......@@ -41,6 +41,9 @@ Usage
- \par -orient
Check face orientation on the input surface
- \par -testModify
Test modification mechanism
- \par -scale \<scale\>
Specify a scaling factor for writing the files
......@@ -65,6 +68,7 @@ Note
#include "PackedBoolList.H"
#include "MeshedSurfaces.H"
#include "ModifiableMeshedSurface.H"
#include "UnsortedMeshedSurfaces.H"
#include "IStringStream.H"
......@@ -93,6 +97,13 @@ int main(int argc, char *argv[])
"orient",
"check surface orientation"
);
argList::addBoolOption
(
"testModify",
"Test modification mechanism (MeshedSurface)"
);
argList::addBoolOption
(
"surfMesh",
......@@ -389,6 +400,34 @@ int main(int argc, char *argv[])
Info<< endl;
}
if (args.optionFound("testModify"))
{
Info<< "Use ModifiableMeshedSurface to shift (1, 0, 0)" << endl;
Info<< "original" << nl;
surf.writeStats(Info);
Info<< endl;
ModifiableMeshedSurface<face> tsurf(surf.xfer());
// ModifiableMeshedSurface<face> tsurf;
// tsurf.reset(surf.xfer());
Info<< "in-progress" << nl;
surf.writeStats(Info);
Info<< endl;
tsurf.storedPoints() += vector(1, 0, 0);
surf.transfer(tsurf);
Info<< "updated" << nl;
surf.writeStats(Info);
Info<< endl;
Info<< "modifier" << nl;
tsurf.writeStats(Info);
Info<< endl;
}
Info<< "writing " << exportName;
if (scaleFactor <= 0)
{
......
......@@ -794,7 +794,6 @@ DebugSwitches
surfaceIntersection 0;
surfaceNormalFixedValue 0;
surfacePatch 0;
surfacePatchIOList 0;
surfaceScalarField 0;
surfaceScalarField::Internal 0;
surfaceSlipDisplacement 0;
......
......@@ -418,6 +418,7 @@ $(cellShape)/cellShapeIOList.C
meshes/Identifiers/patch/patchIdentifier.C
meshes/Identifiers/patch/coupleGroupIdentifier.C
meshes/Identifiers/surface/surfZoneIdentifier.C
meshes/MeshObject/meshObject.C
......
......@@ -97,14 +97,11 @@ Foam::surfZoneIdentifier::~surfZoneIdentifier()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::surfZoneIdentifier::write(Ostream& os) const
{
if (geometricType_.size())
{
os.writeKeyword("geometricType")
<< geometricType_
<< token::END_STATEMENT << nl;
os.writeEntry("geometricType", geometricType_);
}
}
......@@ -112,7 +109,6 @@ void Foam::surfZoneIdentifier::write(Ostream& os) const
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// needed for list output
bool Foam::surfZoneIdentifier::operator!=
(
const surfZoneIdentifier& rhs
......@@ -129,8 +125,9 @@ bool Foam::surfZoneIdentifier::operator==
{
return
(
name() == rhs.name()
&& geometricType() == rhs.geometricType()
(index() == rhs.index())
&& (name() == rhs.name())
&& (geometricType() == rhs.geometricType())
);
}
......@@ -139,8 +136,7 @@ bool Foam::surfZoneIdentifier::operator==
Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj)
{
is >> obj.name_
>> obj.geometricType_;
is >> obj.name_ >> obj.geometricType_;
return is;
}
......@@ -148,7 +144,8 @@ Foam::Istream& Foam::operator>>(Istream& is, surfZoneIdentifier& obj)
Foam::Ostream& Foam::operator<<(Ostream& os, const surfZoneIdentifier& obj)
{
os << obj.name_ << ' ' << obj.geometricType_;
// newlines to separate, since that is what triSurface currently expects
os << nl << obj.name_ << nl << obj.geometricType_;
os.check("Ostream& operator<<(Ostream&, const surfZoneIdentifier&)");
return os;
......
......@@ -40,7 +40,6 @@ SourceFiles
#include "word.H"
#include "label.H"
#include "typeInfo.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -56,7 +55,7 @@ Istream& operator>>(Istream&, surfZoneIdentifier&);
Ostream& operator<<(Ostream&, const surfZoneIdentifier&);
/*---------------------------------------------------------------------------*\
Class surfZoneIdentifier Declaration
Class surfZoneIdentifier Declaration
\*---------------------------------------------------------------------------*/
class surfZoneIdentifier
......
......@@ -155,8 +155,8 @@ public:
//- Construct from list of labels
explicit inline face(const labelUList&);
//- Construct from list of labels
explicit inline face(const labelList&);
//- Construct from an initializer list of labels
explicit inline face(std::initializer_list<label>);
//- Construct by transferring the parameter contents
explicit inline face(const Xfer<labelList>&);
......
......@@ -57,7 +57,7 @@ inline Foam::face::face(const labelUList& lst)
{}
inline Foam::face::face(const labelList& lst)
inline Foam::face::face(std::initializer_list<label> lst)
:
labelList(lst)
{}
......@@ -79,7 +79,7 @@ inline Foam::face::face(Istream& is)
inline Foam::pointField Foam::face::points(const pointField& meshPoints) const
{
// There are as many points as there labels for them
// There are as many points as there are labels for them
pointField p(size());
// For each point in list, set it to the point in 'pnts' addressed
......
......@@ -43,8 +43,6 @@ namespace Foam
typedef List<face> faceList;
typedef SubList<face> faceSubList;
typedef List<faceList> faceListList;
// same as faceUList:
typedef UList<face> unallocFaceList;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -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.
......@@ -64,29 +64,44 @@ class labelledTri
label region_;
// Private Member Functions
//- Assign from a list of 3 or 4 labels.
// Default region is 0.
inline void assign(const labelUList&);
public:
// Constructors
//- Construct null
//- Construct null with invalid point labels and region (-1).
inline labelledTri();
//- Construct from triFace and a region label
//- Construct from triFace and region label.
// Default region is 0 if not specified.
inline labelledTri
(
const triFace&,
const label region
const label region = 0
);
//- Construct from three point labels and a region label
//- Construct from three point labels and a region label.
// Default region is 0 if not specified.
inline labelledTri
(
const label a,
const label b,
const label c,
const label region
const label region = 0
);
//- Construct from a list of 3 or 4 labels.
// Default region is 0.
explicit inline labelledTri(const labelUList&);
//- Construct from an initializer list of 3 or 4 labels.
explicit inline labelledTri(std::initializer_list<label>);
//- Construct from Istream
inline labelledTri(Istream&);
......@@ -102,17 +117,6 @@ public:
inline label& region();
// Check
// Edit
// Write
// Friend Functions
// Friend Operators
// IOstream Operators
inline friend Istream& operator>>(Istream&, labelledTri&);
......
......@@ -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,34 @@ License
#include "IOstreams.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline void Foam::labelledTri::assign(const labelUList& lst)
{
const label sz = lst.size();
// checkSize
if (sz < 3 || sz > 4)
{
FatalErrorInFunction
<< "size " << sz << " != (3 or 4)"
<< abort(FatalError);
}
for (label i=0; i<3; ++i)
{
operator[](i) = lst[i];
}
region_ = (sz > 3 ? lst[3] : 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::labelledTri::labelledTri()
:
triFace(),
region_(-1)
{}
......@@ -57,6 +81,24 @@ inline Foam::labelledTri::labelledTri
{}
inline Foam::labelledTri::labelledTri(const labelUList& lst)
:
triFace(),
region_(0)
{
assign(lst);
}
inline Foam::labelledTri::labelledTri(std::initializer_list<label> initLst)
:
triFace(),
region_(0)
{
assign(labelList(initLst));
}
inline Foam::labelledTri::labelledTri(Istream& is)
{
operator>>(is, *this);
......
......@@ -75,7 +75,7 @@ public:
// Constructors
//- Construct null
//- Construct null with invalid point labels (-1)
inline triFace();
//- Construct from three point labels
......@@ -86,9 +86,12 @@ public:
const label c
);
//- Construct from a list of labels
//- Construct from a list of 3 labels.
explicit inline triFace(const labelUList&);
//- Construct from an initializer list of 3 labels
explicit inline triFace(std::initializer_list<label>);
//- Construct from Istream
inline triFace(Istream&);
......
......@@ -62,6 +62,8 @@ inline int Foam::triFace::compare(const triFace& a, const triFace& b)
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::triFace::triFace()
:
FixedList<label, 3>(-1)
{}
......@@ -84,6 +86,12 @@ inline Foam::triFace::triFace(const labelUList& lst)
{}
inline Foam::triFace::triFace(std::initializer_list<label> lst)
:
FixedList<label, 3>(lst)
{}
inline Foam::triFace::triFace(Istream& is)
:
FixedList<label, 3>(is)
......
......@@ -10,6 +10,9 @@ ensight/type/ensightPTraits.C
nas/NASCore.C
fire/FIRECore.C
starcd/STARCDCore.C
stl/STLCore.C
stl/STLReader.C
stl/STLReaderASCII.L
vtk/foamVtkCore.C
vtk/format/foamVtkAppendBase64Formatter.C
......
......@@ -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.
......@@ -23,36 +23,75 @@ License
\*---------------------------------------------------------------------------*/
#include "STLsurfaceFormatCore.H"
#include "STLCore.H"
#include "gzstream.h"
#include "OSspecific.H"
#include "Map.H"
#include "IFstream.H"
#include "Ostream.H"
#undef DEBUG_STLBINARY
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
//! \cond fileScope
// check binary by getting the header and number of facets
// The number of bytes in the STL binary header
static const unsigned STLHeaderSize = 80;
//! \endcond
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STLCore::STLCore()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STLCore::isBinaryName
(
const fileName& filename,
const STLFormat& format
)
{
return (format == DETECT ? (filename.ext() == "stlb") : format == BINARY);
}
// Check binary by getting the header and number of facets
// this seems to work better than the old token-based method
// - some programs (eg, pro-STAR) have 'solid' as the first word in
// the binary header.
// - using wordToken can cause an abort if non-word (binary) content
// is detected ... this is not exactly what we want.
int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
int Foam::fileFormats::STLCore::detectBinaryHeader
(
const fileName& filename
)
{
off_t dataFileSize = Foam::fileSize(filename);
bool compressed = false;
autoPtr<istream> streamPtr
(
new ifstream(filename.c_str(), std::ios::binary)
);
// If the file is compressed, decompress it before further checking.
if (!streamPtr->good() && isFile(filename + ".gz", false))
{
compressed = true;
streamPtr.reset(new igzstream((filename + ".gz").c_str()));
}
istream& is = streamPtr();
IFstream str(filename, IOstream::BINARY);
istream& is = str().stdStream();
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< " or file " << filename + ".gz"
<< exit(FatalError);
}
// Read the STL header
char header[headerSize];
is.read(header, headerSize);
char header[STLHeaderSize];
is.read(header, STLHeaderSize);
// Check that stream is OK, if not this may be an ASCII file
if (!is.good())
......@@ -60,7 +99,7 @@ int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
return 0;
}
// Read the number of triangles in the STl file
// Read the number of triangles in the STL file
// (note: read as int so we can check whether >2^31)
int nTris;
is.read(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
......@@ -74,33 +113,73 @@ int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
(
!is
|| nTris < 0
|| nTris < (dataFileSize - headerSize)/50
|| nTris > (dataFileSize - headerSize)/25