surfMesh changes
- use new HashSet capabilities and sortedOrder function - make STL format a MeshedSurface instead of an UnsortedMeshedSurface for better (MeshedSurface) reader efficiency
This commit is contained in:
parent
e3c70a839b
commit
a5179ff417
@ -29,7 +29,6 @@ License
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "Time.H"
|
||||
#include "SortableList.H"
|
||||
#include "ListOps.H"
|
||||
#include "polyBoundaryMesh.H"
|
||||
#include "polyMesh.H"
|
||||
@ -42,38 +41,14 @@ License
|
||||
template<class Face>
|
||||
Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes()
|
||||
{
|
||||
wordHashSet known(2*fileExtensionConstructorTablePtr_->size());
|
||||
|
||||
forAllIter
|
||||
(
|
||||
typename fileExtensionConstructorTable::iterator,
|
||||
*fileExtensionConstructorTablePtr_,
|
||||
iter
|
||||
)
|
||||
{
|
||||
known.insert(iter.key());
|
||||
}
|
||||
|
||||
return known;
|
||||
return wordHashSet(*fileExtensionConstructorTablePtr_);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::wordHashSet Foam::MeshedSurface<Face>::writeTypes()
|
||||
{
|
||||
wordHashSet supported(2*writefileExtensionMemberFunctionTablePtr_->size());
|
||||
|
||||
forAllIter
|
||||
(
|
||||
typename writefileExtensionMemberFunctionTable::iterator,
|
||||
*writefileExtensionMemberFunctionTablePtr_,
|
||||
iter
|
||||
)
|
||||
{
|
||||
supported.insert(iter.key());
|
||||
}
|
||||
|
||||
return supported;
|
||||
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
|
||||
}
|
||||
|
||||
|
||||
@ -91,11 +66,16 @@ bool Foam::MeshedSurface<Face>::canReadType
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
wordHashSet available = readTypes();
|
||||
available += SiblingType::readTypes();
|
||||
|
||||
return checkSupport(available, ext, verbose, "reading");
|
||||
else
|
||||
{
|
||||
return checkSupport
|
||||
(
|
||||
readTypes() | SiblingType::readTypes(),
|
||||
ext,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -141,8 +121,9 @@ void Foam::MeshedSurface<Face>::write
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "MeshedSurface::write(const fileName&, const MeshedSurface&) : "
|
||||
"writing MeshedSurface to " << fName
|
||||
Info<< "MeshedSurface::write"
|
||||
"(const fileName&, const MeshedSurface&) : "
|
||||
"writing to " << fName
|
||||
<< endl;
|
||||
}
|
||||
|
||||
|
@ -69,7 +69,7 @@ Foam::MeshedSurface<Face>::New
|
||||
(
|
||||
"MeshedSurface<Face>::New"
|
||||
"(const fileName&, const word&) : "
|
||||
"constructing UnsortedMeshedSurface"
|
||||
"constructing MeshedSurface"
|
||||
) << "Unknown file extension " << ext << nl << nl
|
||||
<< "Valid types are :" << nl
|
||||
<< supported
|
||||
|
@ -29,11 +29,8 @@ License
|
||||
#include "IFstream.H"
|
||||
#include "OFstream.H"
|
||||
#include "Time.H"
|
||||
#include "boundBox.H"
|
||||
#include "polyBoundaryMesh.H"
|
||||
#include "polyMesh.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "SortableList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -42,38 +39,14 @@ License
|
||||
template<class Face>
|
||||
Foam::wordHashSet Foam::UnsortedMeshedSurface<Face>::readTypes()
|
||||
{
|
||||
wordHashSet supported(2*fileExtensionConstructorTablePtr_->size());
|
||||
|
||||
forAllIter
|
||||
(
|
||||
typename fileExtensionConstructorTable::iterator,
|
||||
*fileExtensionConstructorTablePtr_,
|
||||
iter
|
||||
)
|
||||
{
|
||||
supported.insert(iter.key());
|
||||
}
|
||||
|
||||
return supported;
|
||||
return wordHashSet(*fileExtensionConstructorTablePtr_);
|
||||
}
|
||||
|
||||
|
||||
template<class Face>
|
||||
Foam::wordHashSet Foam::UnsortedMeshedSurface<Face>::writeTypes()
|
||||
{
|
||||
wordHashSet supported(2*writefileExtensionMemberFunctionTablePtr_->size());
|
||||
|
||||
forAllIter
|
||||
(
|
||||
typename writefileExtensionMemberFunctionTable::iterator,
|
||||
*writefileExtensionMemberFunctionTablePtr_,
|
||||
iter
|
||||
)
|
||||
{
|
||||
supported.insert(iter.key());
|
||||
}
|
||||
|
||||
return supported;
|
||||
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
|
||||
}
|
||||
|
||||
|
||||
@ -89,11 +62,16 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
wordHashSet available = readTypes();
|
||||
available += SiblingType::readTypes();;
|
||||
|
||||
return checkSupport(available, ext, verbose, "reading");
|
||||
else
|
||||
{
|
||||
return checkSupport
|
||||
(
|
||||
readTypes() | SiblingType::readTypes(),
|
||||
ext,
|
||||
verbose,
|
||||
"reading"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -139,8 +117,9 @@ void Foam::UnsortedMeshedSurface<Face>::write
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "UnsortedMeshedSurface::write(const fileName&, const UnsortedMeshedSurface&) : "
|
||||
"writing UnsortedMeshedSurface to " << fName
|
||||
Info<< "UnsortedMeshedSurface::write"
|
||||
"(const fileName&, const UnsortedMeshedSurface&) : "
|
||||
"writing to " << fName
|
||||
<< endl;
|
||||
}
|
||||
|
||||
|
@ -107,6 +107,23 @@ public:
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// The output is always sorted by regions.
|
||||
static void write
|
||||
@ -126,23 +143,6 @@ public:
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write object
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
@ -76,7 +76,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -85,7 +85,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
AC3DsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
|
@ -95,6 +95,23 @@ public:
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// The output is sorted by regions
|
||||
static void write
|
||||
@ -114,23 +131,6 @@ public:
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write object
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
@ -55,7 +55,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -64,7 +64,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
@ -72,10 +72,9 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
gts
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -84,7 +83,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
GTSsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
|
@ -109,6 +109,23 @@ public:
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// The output is sorted by regions
|
||||
static void write
|
||||
@ -128,23 +145,6 @@ public:
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write object
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
@ -54,6 +54,25 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
@ -74,25 +93,6 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
OBJsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
obj
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +91,23 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// The output is sorted by region.
|
||||
static void write
|
||||
@ -110,23 +127,6 @@ public:
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write object
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ namespace fileFormats
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -47,7 +47,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
@ -55,10 +55,9 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
smesh
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -67,7 +66,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
SMESHsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
|
@ -119,6 +119,13 @@ public:
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// The output is sorted by regions
|
||||
static void write
|
||||
@ -127,13 +134,6 @@ public:
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write to Ostream as one large file - not really useful
|
||||
virtual void write(Ostream&) const
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
@ -76,7 +76,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -85,7 +85,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
STARCDsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
|
@ -25,6 +25,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "STLsurfaceFormat.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -289,35 +290,70 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
|
||||
// read in the values
|
||||
STLsurfaceFormatCore reader(fName);
|
||||
|
||||
// generate the faces:
|
||||
List<Face>& faceLst = this->storedFaces();
|
||||
faceLst.setSize(reader.regions().size());
|
||||
|
||||
// transfer
|
||||
// transfer points
|
||||
this->storedPoints().transfer(reader.points());
|
||||
this->storedRegions().transfer(reader.regions());
|
||||
|
||||
label ptI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
// get the original region information
|
||||
List<word> names(xferMove(reader.names()));
|
||||
List<label> unsortedRegions(xferMove(reader.regions()));
|
||||
|
||||
// and determine the sorted order:
|
||||
// avoid SortableList since we discard the main list anyhow
|
||||
List<label> faceMap;
|
||||
sortedOrder(unsortedRegions, faceMap);
|
||||
|
||||
// generate the sorted faces and sorted regions:
|
||||
List<Face> faceLst(faceMap.size());
|
||||
|
||||
DynamicList<label> dynPatchSizes;
|
||||
label prevRegion = -1;
|
||||
label regionSize = 0;
|
||||
|
||||
forAll(faceMap, faceI)
|
||||
{
|
||||
triFace fTri;
|
||||
const label startPt = 3*faceMap[faceI];
|
||||
const label regionI = unsortedRegions[faceMap[faceI]];
|
||||
|
||||
fTri[0] = ptI++;
|
||||
fTri[1] = ptI++;
|
||||
fTri[2] = ptI++;
|
||||
faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
|
||||
|
||||
faceLst[faceI] = fTri;
|
||||
if (prevRegion != regionI)
|
||||
{
|
||||
if (regionSize)
|
||||
{
|
||||
dynPatchSizes.append(regionSize);
|
||||
}
|
||||
prevRegion = regionI;
|
||||
regionSize = 0;
|
||||
}
|
||||
regionSize++;
|
||||
}
|
||||
|
||||
if (reader.binary())
|
||||
if (regionSize)
|
||||
{
|
||||
this->setPatches(reader.maxRegionId());
|
||||
}
|
||||
else
|
||||
{
|
||||
this->setPatches(reader.groupToPatch());
|
||||
dynPatchSizes.append(regionSize);
|
||||
}
|
||||
|
||||
// transfer:
|
||||
this->storedFaces().transfer(faceLst);
|
||||
unsortedRegions.clear();
|
||||
faceMap.clear();
|
||||
|
||||
label start = 0;
|
||||
surfGroupList newPatches(dynPatchSizes.size());
|
||||
forAll(newPatches, patchI)
|
||||
{
|
||||
newPatches[patchI] = surfGroup
|
||||
(
|
||||
names[patchI],
|
||||
dynPatchSizes[patchI],
|
||||
start,
|
||||
patchI
|
||||
);
|
||||
|
||||
start += dynPatchSizes[patchI];
|
||||
}
|
||||
|
||||
this->addPatches(newPatches);
|
||||
this->stitchFaces(SMALL);
|
||||
return true;
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ Class
|
||||
Description
|
||||
Provide a means of reading/writing STL files (ASCII and binary).
|
||||
|
||||
Note
|
||||
For efficiency, the regions are sorted before creating the faces.
|
||||
The class is thus derived from MeshedSurface.
|
||||
|
||||
SourceFiles
|
||||
STLsurfaceFormat.C
|
||||
STLsurfaceFormatASCII.L
|
||||
@ -49,13 +53,13 @@ namespace fileFormats
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class STLsurfaceFormat Declaration
|
||||
Class STLsurfaceFormat Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Face>
|
||||
class STLsurfaceFormat
|
||||
:
|
||||
public UnsortedMeshedSurface<Face>
|
||||
public MeshedSurface<Face>
|
||||
{
|
||||
// Private Member Functions
|
||||
|
||||
@ -106,14 +110,13 @@ public:
|
||||
|
||||
// Selectors
|
||||
|
||||
//- Read file and return keyedSurface
|
||||
//- Read file and return surface
|
||||
static autoPtr<UnsortedMeshedSurface<Face> > New
|
||||
static autoPtr<MeshedSurface<Face> > New
|
||||
(
|
||||
const fileName& fName
|
||||
)
|
||||
{
|
||||
return autoPtr<UnsortedMeshedSurface<Face> >
|
||||
return autoPtr<MeshedSurface<Face> >
|
||||
(
|
||||
new STLsurfaceFormat<Face>(fName)
|
||||
);
|
||||
@ -128,13 +131,6 @@ public:
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write UnsortedMeshedSurface (as ASCII) sorted by region
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface (as ASCII)
|
||||
static void write
|
||||
(
|
||||
@ -142,6 +138,20 @@ public:
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write UnsortedMeshedSurface (as ASCII) sorted by region
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// ASCII output is sorted by region; binary output is unsorted
|
||||
static void write
|
||||
@ -150,13 +160,6 @@ public:
|
||||
const UnsortedMeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write object (only ASCII output)
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
@ -72,14 +72,14 @@ class STLASCIILexer
|
||||
{
|
||||
// Private data
|
||||
|
||||
short groupID_; // current region
|
||||
short maxGroupID_; // max region
|
||||
label groupID_; // current region
|
||||
label lineNo_;
|
||||
word startError_;
|
||||
|
||||
DynamicList<point> points_;
|
||||
DynamicList<label> facets_;
|
||||
HashTable<label> groupToPatch_;
|
||||
DynamicList<word> names_;
|
||||
HashTable<label> nameIndex_;
|
||||
|
||||
public:
|
||||
|
||||
@ -110,11 +110,10 @@ public:
|
||||
}
|
||||
|
||||
//- region names
|
||||
HashTable<label>& groupToPatch()
|
||||
DynamicList<word>& names()
|
||||
{
|
||||
return groupToPatch_;
|
||||
return names_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -122,7 +121,6 @@ STLASCIILexer::STLASCIILexer(istream* is, const label approxNpoints)
|
||||
:
|
||||
yyFlexLexer(is),
|
||||
groupID_(-1),
|
||||
maxGroupID_(-1),
|
||||
lineNo_(1),
|
||||
points_(approxNpoints),
|
||||
facets_(approxNpoints)
|
||||
@ -237,37 +235,35 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
|
||||
}
|
||||
|
||||
<readSolidName>{string} {
|
||||
word group(Foam::string::validate<word>(YYText()));
|
||||
word name(Foam::string::validate<word>(YYText()));
|
||||
|
||||
HashTable<label>::const_iterator findGroup =
|
||||
groupToPatch_.find(group);
|
||||
|
||||
if (findGroup != groupToPatch_.end())
|
||||
HashTable<label>::const_iterator fnd = nameIndex_.find(name);
|
||||
if (fnd != nameIndex_.end())
|
||||
{
|
||||
groupID_ = findGroup();
|
||||
groupID_ = fnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
groupID_ = ++maxGroupID_;
|
||||
groupToPatch_.insert(group, groupID_);
|
||||
groupID_ = names_.size();
|
||||
names_.append(name);
|
||||
nameIndex_.insert(name, groupID_);
|
||||
}
|
||||
BEGIN(INITIAL);
|
||||
}
|
||||
|
||||
<readSolidName>{space}\n {
|
||||
word group("solid");
|
||||
word name("solid");
|
||||
|
||||
HashTable<label>::const_iterator findGroup =
|
||||
groupToPatch_.find(group);
|
||||
|
||||
if (findGroup != groupToPatch_.end())
|
||||
HashTable<label>::const_iterator fnd = nameIndex_.find(name);
|
||||
if (fnd != nameIndex_.end())
|
||||
{
|
||||
groupID_ = findGroup();
|
||||
groupID_ = fnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
groupID_ = ++maxGroupID_;
|
||||
groupToPatch_.insert(group, groupID_);
|
||||
groupID_ = names_.size();
|
||||
names_.append(name);
|
||||
nameIndex_.insert(name, groupID_);
|
||||
}
|
||||
|
||||
lineNo_++;
|
||||
@ -394,7 +390,8 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readASCII
|
||||
// transfer to normal lists
|
||||
points_.transfer(lexer.points());
|
||||
regions_.transfer(lexer.facets());
|
||||
groupToPatch_.transfer(lexer.groupToPatch());
|
||||
names_.transfer(lexer.names());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ License
|
||||
|
||||
#include "STLsurfaceFormatCore.H"
|
||||
#include "OSspecific.H"
|
||||
#include "Map.H"
|
||||
|
||||
#undef DEBUG_STLBINARY
|
||||
|
||||
@ -143,6 +144,9 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
|
||||
points_.setSize(3*nTris);
|
||||
regions_.setSize(nTris);
|
||||
|
||||
Map<label> regionToPatch;
|
||||
DynamicList<word> dynNames;
|
||||
|
||||
label ptI = 0;
|
||||
forAll(regions_, faceI)
|
||||
{
|
||||
@ -155,20 +159,31 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
|
||||
points_[ptI++] = stlTri.c();
|
||||
|
||||
// interprete colour as a region
|
||||
regions_[faceI] = stlTri.region();
|
||||
if (maxRegionId_ < stlTri.region())
|
||||
const label stlRegion = stlTri.region();
|
||||
|
||||
Map<label>::const_iterator fnd = regionToPatch.find(stlRegion);
|
||||
label regionI;
|
||||
if (fnd != regionToPatch.end())
|
||||
{
|
||||
maxRegionId_ = stlTri.region();
|
||||
regionI = fnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
regionI = dynNames.size();
|
||||
dynNames.append(word("patch") + ::Foam::name(regionI));
|
||||
regionToPatch.insert(stlRegion, regionI);
|
||||
}
|
||||
|
||||
regions_[faceI] = regionI;
|
||||
|
||||
#ifdef DEBUG_STLBINARY
|
||||
if (prevRegion != stlTri.region())
|
||||
if (prevRegion != regionI)
|
||||
{
|
||||
if (prevRegion != -1)
|
||||
{
|
||||
Info<< "endsolid region" << prevRegion << nl;
|
||||
}
|
||||
prevRegion = stlTri.region();
|
||||
prevRegion = regionI;
|
||||
|
||||
Info<< "solid region" << prevRegion << nl;
|
||||
}
|
||||
@ -183,6 +198,8 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
|
||||
#endif
|
||||
}
|
||||
|
||||
names_.transfer(dynNames);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -197,8 +214,7 @@ Foam::fileFormats::STLsurfaceFormatCore::STLsurfaceFormatCore
|
||||
binary_(false),
|
||||
points_(0),
|
||||
regions_(0),
|
||||
maxRegionId_(0),
|
||||
groupToPatch_(0)
|
||||
names_(0)
|
||||
{
|
||||
off_t fileSize = Foam::size(fName);
|
||||
|
||||
@ -228,14 +244,17 @@ void Foam::fileFormats::STLsurfaceFormatCore::writeHeaderBINARY
|
||||
unsigned int nTris
|
||||
)
|
||||
{
|
||||
// Write the STL header, avoid possible trailing junk
|
||||
string header("STL binary file", headerSize);
|
||||
for (label i = header.size(); i < headerSize; ++i)
|
||||
// STL header with extra information about nTris
|
||||
char header[headerSize];
|
||||
sprintf(header, "STL binary file %u facets", nTris);
|
||||
|
||||
// avoid trailing junk
|
||||
for (size_t i = strlen(header); i < headerSize; ++i)
|
||||
{
|
||||
header[i] = 0;
|
||||
}
|
||||
os.write(header.c_str(), headerSize);
|
||||
|
||||
os.write(header, headerSize);
|
||||
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
|
||||
|
||||
}
|
||||
|
@ -67,9 +67,8 @@ class STLsurfaceFormatCore
|
||||
//- The regions associated with the faces
|
||||
List<label> regions_;
|
||||
|
||||
label maxRegionId_;
|
||||
|
||||
HashTable<label> groupToPatch_;
|
||||
//- The solid names, in the order of their first appearance
|
||||
List<word> names_;
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
@ -93,7 +92,7 @@ public:
|
||||
// Static Data
|
||||
|
||||
//- The number of bytes in the STL binary header
|
||||
static const int headerSize = 80;
|
||||
static const unsigned int headerSize = 80;
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
@ -128,7 +127,7 @@ public:
|
||||
{
|
||||
points_.clear();
|
||||
regions_.clear();
|
||||
groupToPatch_.clear();
|
||||
names_.clear();
|
||||
}
|
||||
|
||||
//- Return full access to the faces
|
||||
@ -143,16 +142,10 @@ public:
|
||||
return regions_;
|
||||
}
|
||||
|
||||
//- The max regionId when reading binary files
|
||||
label maxRegionId() const
|
||||
//- The list of solid names in the order of their first appearance
|
||||
List<word>& names()
|
||||
{
|
||||
return maxRegionId_;
|
||||
}
|
||||
|
||||
//- The group/patch information when reading ASCII files
|
||||
const HashTable<label>& groupToPatch() const
|
||||
{
|
||||
return groupToPatch_;
|
||||
return names_;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -38,7 +38,7 @@ namespace fileFormats
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
@ -46,7 +46,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
@ -55,7 +55,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
@ -63,7 +63,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
@ -71,45 +71,6 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
@ -148,6 +109,44 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
stlb
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stl
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
STLsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
stlb
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,6 +165,7 @@ Foam::fileFormats::surfaceFormatsCore::findMeshName
|
||||
return findMeshName(d, meshSubDir);
|
||||
}
|
||||
|
||||
|
||||
// Returns patch info.
|
||||
// Sets faceMap to the indexing according to patch numbers.
|
||||
// Patch numbers start at 0.
|
||||
|
@ -156,12 +156,11 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
|
||||
word rawName(lineStream);
|
||||
word groupName("patch" + rawName(1, rawName.size()-1));
|
||||
|
||||
HashTable<label>::const_iterator findGroup =
|
||||
groupToPatch.find(groupName);
|
||||
HashTable<label>::const_iterator fnd = groupToPatch.find(groupName);
|
||||
|
||||
if (findGroup != groupToPatch.end())
|
||||
if (fnd != groupToPatch.end())
|
||||
{
|
||||
groupID = findGroup();
|
||||
groupID = fnd();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -187,7 +186,6 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
|
||||
this->storedPoints().transfer(pointLst);
|
||||
this->storedRegions().transfer(regionLst);
|
||||
|
||||
label ptI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
const label startPt = 3 * faceI;
|
||||
|
@ -103,6 +103,23 @@ public:
|
||||
//- Read from file
|
||||
virtual bool read(const fileName&);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// By default, the output is not sorted by regions
|
||||
static void write
|
||||
@ -122,23 +139,6 @@ public:
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write object
|
||||
// By default, the output is not sorted by regions
|
||||
virtual void write(Ostream& os) const
|
||||
|
@ -56,7 +56,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
@ -73,10 +73,9 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
tri
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
@ -85,7 +84,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
UnsortedMeshedSurface,
|
||||
TRIsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
|
@ -88,6 +88,23 @@ public:
|
||||
|
||||
// Write
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write UnsortedMeshedSurface
|
||||
// By default, the output is not sorted by regions.
|
||||
static void write
|
||||
@ -107,23 +124,6 @@ public:
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
Ostream&,
|
||||
const MeshedSurface<Face>&
|
||||
);
|
||||
|
||||
//- Write MeshedSurface
|
||||
static void write
|
||||
(
|
||||
const fileName& fName,
|
||||
const MeshedSurface<Face>& surf
|
||||
)
|
||||
{
|
||||
write(OFstream(fName)(), surf);
|
||||
}
|
||||
|
||||
//- Write object
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
@ -36,6 +36,25 @@ namespace Foam
|
||||
namespace fileFormats
|
||||
{
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
@ -56,25 +75,6 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
VTKsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
vtk
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user