surfMesh code cleanup

- added protected storedPoints(), storedFaces() functions for non-const
   access to the data. Mixing protected non-const versions and public const
   versions of the same method does not agree with the compiler
 - better handling of triFace/face distinction
This commit is contained in:
Mark Olesen
2008-11-15 23:29:50 +01:00
parent 59bfd4ecef
commit c651a0ba29
45 changed files with 639 additions and 739 deletions

View File

@ -71,6 +71,7 @@ int main(int argc, char *argv[])
argList::validOptions.insert("scale", "scale"); argList::validOptions.insert("scale", "scale");
argList::validOptions.insert("triSurface", ""); argList::validOptions.insert("triSurface", "");
argList::validOptions.insert("unsorted", ""); argList::validOptions.insert("unsorted", "");
argList::validOptions.insert("triFace", "");
# include "setRootCase.H" # include "setRootCase.H"
const stringList& params = args.additionalArgs(); const stringList& params = args.additionalArgs();
@ -125,7 +126,7 @@ int main(int argc, char *argv[])
} }
else if (args.options().found("unsorted")) else if (args.options().found("unsorted"))
{ {
unsortedMeshedSurface surf(importName); UnsortedMeshedSurface<face> surf(importName);
if (args.options().found("clean")) if (args.options().found("clean"))
{ {
@ -146,9 +147,33 @@ int main(int argc, char *argv[])
surf.write(exportName); surf.write(exportName);
} }
#if 1
else if (args.options().found("triFace"))
{
MeshedSurface<triFace> surf(importName);
if (args.options().found("clean"))
{
surf.cleanup(true);
surf.checkOrientation(true);
}
Info<< "writing " << exportName;
if (scaleFactor <= 0)
{
Info<< " without scaling" << endl;
}
else
{
Info<< " with scaling " << scaleFactor << endl;
surf.scalePoints(scaleFactor);
}
surf.write(exportName);
}
#endif
else else
{ {
meshedSurface surf(importName); MeshedSurface<face> surf(importName);
if (args.options().found("clean")) if (args.options().found("clean"))
{ {

View File

@ -44,6 +44,13 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Face>
inline bool Foam::MeshedSurface<Face>::isTri()
{
return false;
}
template<class Face> template<class Face>
bool Foam::MeshedSurface<Face>::canRead(const word& ext, const bool verbose) bool Foam::MeshedSurface<Face>::canRead(const word& ext, const bool verbose)
{ {
@ -165,8 +172,8 @@ Foam::MeshedSurface<Face>::MeshedSurface
ParentType(List<Face>(), pointField()), ParentType(List<Face>(), pointField()),
patches_(patchLst) patches_(patchLst)
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
} }
@ -182,8 +189,8 @@ Foam::MeshedSurface<Face>::MeshedSurface
: :
ParentType(List<Face>(), pointField()) ParentType(List<Face>(), pointField())
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
surfGroupList newPatches(patchSizes.size()); surfGroupList newPatches(patchSizes.size());
@ -216,8 +223,8 @@ Foam::MeshedSurface<Face>::MeshedSurface
: :
ParentType(List<Face>(), pointField()) ParentType(List<Face>(), pointField())
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
if if
( (
@ -257,8 +264,8 @@ Foam::MeshedSurface<Face>::MeshedSurface
: :
ParentType(List<Face>(), pointField()) ParentType(List<Face>(), pointField())
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
if (regionIds.size() != nFaces()) if (regionIds.size() != nFaces())
{ {
@ -316,14 +323,14 @@ Foam::MeshedSurface<Face>::MeshedSurface
if (useGlobalPoints) if (useGlobalPoints)
{ {
// copy in the global points and the global face addressing // copy in the global points and the global face addressing
points() = mesh.points(); storedPoints() = mesh.points();
faces() = allBoundary; storedFaces() = allBoundary;
} }
else else
{ {
// copy in the local points and the local face addressing // copy in the local points and the local face addressing
points() = allBoundary.localPoints(); storedPoints() = allBoundary.localPoints();
faces() = allBoundary.localFaces(); storedFaces() = allBoundary.localFaces();
} }
// create patch list // create patch list
@ -405,7 +412,7 @@ Foam::MeshedSurface<Face>::MeshedSurface
newFaces[faceI] = origFaces[faceMap[faceI]]; newFaces[faceI] = origFaces[faceMap[faceI]];
} }
faces().transfer(newFaces); storedFaces().transfer(newFaces);
} }
@ -595,7 +602,7 @@ void Foam::MeshedSurface<Face>::sortFacesByRegion
} }
faceMap.clear(); faceMap.clear();
faces().transfer(newFaces); storedFaces().transfer(newFaces);
} }
} }
@ -610,8 +617,8 @@ void Foam::MeshedSurface<Face>::clear()
{ {
ParentType::clearOut(); ParentType::clearOut();
points().clear(); storedPoints().clear();
faces().clear(); storedFaces().clear();
patches_.clear(); patches_.clear();
} }
@ -626,7 +633,7 @@ void Foam::MeshedSurface<Face>::movePoints(const pointField& newPoints)
ParentType::movePoints(newPoints); ParentType::movePoints(newPoints);
// Copy new points // Copy new points
points() = newPoints; storedPoints() = newPoints;
} }
@ -642,7 +649,7 @@ void Foam::MeshedSurface<Face>::scalePoints(const scalar& scaleFactor)
// Adapt for new point position // Adapt for new point position
ParentType::movePoints(pointField()); ParentType::movePoints(pointField());
points() *= scaleFactor; storedPoints() *= scaleFactor;
} }
} }
@ -741,8 +748,8 @@ void Foam::MeshedSurface<Face>::transfer
{ {
clear(); clear();
points().transfer(surf.points()); storedPoints().transfer(surf.storedPoints());
faces().transfer(surf.faces()); storedFaces().transfer(surf.storedFaces());
patches_.transfer(surf.patches_); patches_.transfer(surf.patches_);
surf.clear(); surf.clear();
@ -756,7 +763,7 @@ void Foam::MeshedSurface<Face>::transfer
) )
{ {
clear(); clear();
points().transfer(surf.points()); storedPoints().transfer(surf.storedPoints());
labelList faceMap; labelList faceMap;
surfGroupList patchLst = surf.sortedRegions(faceMap); surfGroupList patchLst = surf.sortedRegions(faceMap);
@ -765,7 +772,7 @@ void Foam::MeshedSurface<Face>::transfer
surf.regions_.clear(); surf.regions_.clear();
surf.patches_.clear(); surf.patches_.clear();
List<Face>& oldFaces = surf.faces(); const List<Face>& oldFaces = surf.faces();
List<Face> newFaces(oldFaces.size()); List<Face> newFaces(oldFaces.size());
// this is somewhat like ListOps reorder and/or IndirectList // this is somewhat like ListOps reorder and/or IndirectList
@ -774,7 +781,7 @@ void Foam::MeshedSurface<Face>::transfer
newFaces[faceI] = oldFaces[faceMap[faceI]]; newFaces[faceI] = oldFaces[faceMap[faceI]];
} }
faces().transfer(newFaces); storedFaces().transfer(newFaces);
surf.clear(); surf.clear();
} }
@ -852,8 +859,8 @@ void Foam::MeshedSurface<Face>::operator=(const MeshedSurface& surf)
{ {
clear(); clear();
faces() = surf.faces(); storedPoints() = surf.points();
points() = surf.points(); storedFaces() = surf.faces();
patches_ = surf.patches_; patches_ = surf.patches_;
} }

View File

@ -87,7 +87,6 @@ class MeshedSurface
private: private:
//- Private typedefs for convenience //- Private typedefs for convenience
typedef MeshedSurface<Face> ThisType;
typedef PrimitivePatchExtra typedef PrimitivePatchExtra
< <
Face, Face,
@ -117,6 +116,22 @@ private:
//- Read OpenFOAM Surface format //- Read OpenFOAM Surface format
bool read(Istream&); bool read(Istream&);
protected:
// Protected member functions
//- Return non-const access to global points
pointField& storedPoints()
{
return const_cast<pointField&>(ParentType::points());
}
//- Return non-const access to the faces
List<Face>& storedFaces()
{
return static_cast<List<Face> &>(*this);
}
public: public:
//- Runtime type information //- Runtime type information
@ -124,6 +139,9 @@ public:
// Static // Static
//- Only handles triangulated faces
inline static bool isTri();
//- Can we read this file format? //- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false); static bool canRead(const word& ext, const bool verbose=false);
@ -270,7 +288,7 @@ public:
//- Return the number of points //- Return the number of points
label nPoints() const label nPoints() const
{ {
return points().size(); return ParentType::points().size();
} }
//- Return the number of faces //- Return the number of faces
@ -291,30 +309,13 @@ public:
return ParentType::points(); return ParentType::points();
} }
//- Return non-const access to global points
pointField& points()
{
return const_cast<pointField&>(ParentType::points());
}
//- Return const access to the faces //- Return const access to the faces
const List<Face>& faces() const const List<Face>& faces() const
{ {
return static_cast<const List<Face> &>(*this); return static_cast<const List<Face> &>(*this);
} }
//- Return non-const access to the faces const List<surfGroup>& patches() const
List<Face>& faces()
{
return static_cast<List<Face> &>(*this);
}
const surfGroupList& patches() const
{
return patches_;
}
surfGroupList& patches()
{ {
return patches_; return patches_;
} }
@ -403,6 +404,22 @@ public:
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Specialization for holding triangulated information
template<>
inline bool MeshedSurface<triFace>::isTri()
{
return true;
}
//- Specialization for holding triangulated information
template<>
inline label MeshedSurface<triFace>::triangulate()
{
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -48,7 +48,7 @@ bool Foam::MeshedSurface<Face>::stitchFaces
const bool verbose const bool verbose
) )
{ {
pointField& pointLst = points(); pointField& pointLst = storedPoints();
// Merge points // Merge points
labelList pointMap(pointLst.size()); labelList pointMap(pointLst.size());
@ -70,7 +70,7 @@ bool Foam::MeshedSurface<Face>::stitchFaces
// Set the coordinates to the merged ones // Set the coordinates to the merged ones
pointLst.transfer(newPoints); pointLst.transfer(newPoints);
List<Face>& faceLst = faces(); List<Face>& faceLst = storedFaces();
// ensure we have at some patches, and they cover all the faces // ensure we have at some patches, and they cover all the faces
checkPatches(); checkPatches();
@ -78,7 +78,7 @@ bool Foam::MeshedSurface<Face>::stitchFaces
// Reset the point labels to the unique points array // Reset the point labels to the unique points array
label oldFaceI = 0; label oldFaceI = 0;
label newFaceI = 0; label newFaceI = 0;
forAll (patches_, patchI) forAll(patches_, patchI)
{ {
surfGroup& p = patches_[patchI]; surfGroup& p = patches_[patchI];
@ -89,7 +89,7 @@ bool Foam::MeshedSurface<Face>::stitchFaces
for (; oldFaceI < patchEnd; ++oldFaceI) for (; oldFaceI < patchEnd; ++oldFaceI)
{ {
Face& f = faceLst[oldFaceI]; Face& f = faceLst[oldFaceI];
forAll (f, fp) forAll(f, fp)
{ {
f[fp] = pointMap[f[fp]]; f[fp] = pointMap[f[fp]];
} }
@ -141,14 +141,14 @@ void Foam::MeshedSurface<Face>::checkFaces(const bool verbose)
// Simple check on indices ok. // Simple check on indices ok.
const label maxPointI = points().size() - 1; const label maxPointI = points().size() - 1;
List<Face>& faceLst = faces(); List<Face>& faceLst = storedFaces();
// Phase 0: detect badly labelled faces // Phase 0: detect badly labelled faces
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
const Face& f = faceLst[faceI]; const Face& f = faceLst[faceI];
forAll (f, fp) forAll(f, fp)
{ {
if (f[fp] < 0 || f[fp] > maxPointI) if (f[fp] < 0 || f[fp] > maxPointI)
{ {
@ -170,7 +170,7 @@ void Foam::MeshedSurface<Face>::checkFaces(const bool verbose)
label oldFaceI = 0; label oldFaceI = 0;
label newFaceI = 0; label newFaceI = 0;
forAll (patches_, patchI) forAll(patches_, patchI)
{ {
surfGroup& p = patches_[patchI]; surfGroup& p = patches_[patchI];
@ -191,7 +191,7 @@ void Foam::MeshedSurface<Face>::checkFaces(const bool verbose)
// Check if faceNeighbours use same points as this face. // Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged. // Note: discards normal information - sides of baffle are merged.
forAll (neighbours, neighI) forAll(neighbours, neighI)
{ {
if (neighbours[neighI] <= oldFaceI) if (neighbours[neighI] <= oldFaceI)
{ {
@ -199,7 +199,7 @@ void Foam::MeshedSurface<Face>::checkFaces(const bool verbose)
continue; continue;
} }
const face& nei = faceLst[neighbours[neighI]]; const Face& nei = faceLst[neighbours[neighI]];
if (f == nei) if (f == nei)
{ {
@ -271,10 +271,10 @@ template<class Face>
Foam::label Foam::MeshedSurface<Face>::triangulate() Foam::label Foam::MeshedSurface<Face>::triangulate()
{ {
label nTri = 0; label nTri = 0;
List<Face>& faceLst = faces(); List<Face>& faceLst = storedFaces();
// determine how many triangles are needed // determine how many triangles are needed
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
nTri += faceLst[faceI].size() - 2; nTri += faceLst[faceI].size() - 2;
} }
@ -293,7 +293,7 @@ Foam::label Foam::MeshedSurface<Face>::triangulate()
// Reset the point labels to the unique points array // Reset the point labels to the unique points array
label oldFaceI = 0; label oldFaceI = 0;
label newFaceI = 0; label newFaceI = 0;
forAll (patches_, patchI) forAll(patches_, patchI)
{ {
surfGroup& p = patches_[patchI]; surfGroup& p = patches_[patchI];

View File

@ -61,17 +61,17 @@ bool Foam::MeshedSurface<Face>::read(Istream& is)
} }
// read points: // read points:
is >> points(); is >> storedPoints();
// read faces: // read faces:
// TODO - specialization to triangulate on-the-fly // TODO - specialization to triangulate on-the-fly
if (mustTriangulate) if (mustTriangulate)
{ {
is >> faces(); is >> storedFaces();
} }
else else
{ {
is >> faces(); is >> storedFaces();
} }
return is.good(); return is.good();

View File

@ -39,6 +39,13 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Face>
inline bool Foam::UnsortedMeshedSurface<Face>::isTri()
{
return false;
}
template<class Face> template<class Face>
bool Foam::UnsortedMeshedSurface<Face>::canRead bool Foam::UnsortedMeshedSurface<Face>::canRead
( (
@ -205,8 +212,8 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
regions_(regionIds), regions_(regionIds),
patches_(patchLst) patches_(patchLst)
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
} }
@ -222,8 +229,8 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
ParentType(List<Face>(), pointField()), ParentType(List<Face>(), pointField()),
regions_(regionIds) regions_(regionIds)
{ {
faces().transfer(faceLst()); storedPoints().transfer(pointLst());
points().transfer(pointLst()); storedFaces().transfer(faceLst());
if (&regionNames) if (&regionNames)
{ {
@ -250,8 +257,8 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
ParentType(List<Face>(), pointField()), ParentType(List<Face>(), pointField()),
regions_(regionIds) regions_(regionIds)
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
// set patch names from (name => id) mapping // set patch names from (name => id) mapping
setPatches(labelToRegion); setPatches(labelToRegion);
@ -269,8 +276,8 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
regions_(faceLst().size(), 0), // single default patch regions_(faceLst().size(), 0), // single default patch
patches_() patches_()
{ {
points().transfer(pointLst()); storedPoints().transfer(pointLst());
faces().transfer(faceLst()); storedFaces().transfer(faceLst());
setPatches(0); setPatches(0);
} }
@ -310,12 +317,12 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
if (useGlobalPoints) if (useGlobalPoints)
{ {
// copy in the global points // copy in the global points
points() = mesh.points(); storedPoints() = mesh.points();
} }
else else
{ {
// copy in the local points // copy in the local points
points() = allBoundary.localPoints(); storedPoints() = allBoundary.localPoints();
} }
// global or local face addressing // global or local face addressing
@ -345,7 +352,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
} }
} }
faces().transfer(newFaces); storedFaces().transfer(newFaces);
regions_.transfer(newRegions); regions_.transfer(newRegions);
patches_.transfer(newPatches); patches_.transfer(newPatches);
} }
@ -380,7 +387,7 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
} }
} }
faces().transfer(newFaces); storedFaces().transfer(newFaces);
regions_.transfer(newRegions); regions_.transfer(newRegions);
patches_.transfer(newPatches); patches_.transfer(newPatches);
} }
@ -606,8 +613,8 @@ void Foam::UnsortedMeshedSurface<Face>::clear()
{ {
ParentType::clearOut(); ParentType::clearOut();
points().clear(); storedPoints().clear();
faces().clear(); storedFaces().clear();
regions_.clear(); regions_.clear();
patches_.clear(); patches_.clear();
} }
@ -640,7 +647,7 @@ void Foam::UnsortedMeshedSurface<Face>::movePoints(const pointField& newPoints)
ParentType::movePoints(newPoints); ParentType::movePoints(newPoints);
// Copy new points // Copy new points
points() = newPoints; storedPoints() = newPoints;
} }
@ -656,7 +663,7 @@ void Foam::UnsortedMeshedSurface<Face>::scalePoints(const scalar& scaleFactor)
// Adapt for new point position // Adapt for new point position
ParentType::movePoints(pointField()); ParentType::movePoints(pointField());
points() *= scaleFactor; storedPoints() *= scaleFactor;
} }
} }
@ -722,8 +729,8 @@ void Foam::UnsortedMeshedSurface<Face>::transfer
{ {
clear(); clear();
faces().transfer(surf.faces()); storedPoints().transfer(surf.storedPoints());
points().transfer(surf.points()); storedFaces().transfer(surf.storedFaces());
regions_.transfer(surf.regions_); regions_.transfer(surf.regions_);
patches_.transfer(surf.patches_); patches_.transfer(surf.patches_);
@ -742,8 +749,8 @@ void Foam::UnsortedMeshedSurface<Face>::transfer
clear(); clear();
points().transfer(surf.points()); storedPoints().transfer(surf.storedPoints());
faces().transfer(surf.faces()); storedFaces().transfer(surf.storedFaces());
regions_.setSize(size()); regions_.setSize(size());
patches_.setSize(patchLst.size()); patches_.setSize(patchLst.size());
@ -839,8 +846,8 @@ void Foam::UnsortedMeshedSurface<Face>::operator=
) )
{ {
clear(); clear();
faces() = surf.faces(); storedPoints() = surf.points();
points() = surf.points(); storedFaces() = surf.faces();
regions_ = surf.regions_; regions_ = surf.regions_;
patches_ = surf.patches_; patches_ = surf.patches_;
} }

View File

@ -89,17 +89,9 @@ class UnsortedMeshedSurface
{ {
friend class MeshedSurface<Face>; friend class MeshedSurface<Face>;
protected:
// Protected Member Data
//- Typedef for type holding the region (patch) informationm
typedef surfPatchIdentifier PatchRegionType;
private: private:
//- Private typedefs for convenience //- Private typedefs for convenience
typedef UnsortedMeshedSurface<Face> ThisType;
typedef PrimitivePatchExtra typedef PrimitivePatchExtra
< <
Face, Face,
@ -109,6 +101,9 @@ private:
> >
ParentType; ParentType;
//- Typedef for type holding the region (patch) informationm
typedef surfPatchIdentifier PatchRegionType;
// Private Member Data // Private Member Data
//- The regions associated with the faces //- The regions associated with the faces
@ -146,6 +141,25 @@ protected:
//- Sets patch names from hashed values (name -> id) //- Sets patch names from hashed values (name -> id)
void setPatches(const HashTable<label>& groupToPatch); void setPatches(const HashTable<label>& groupToPatch);
//- Return non-const access to global points
pointField& storedPoints()
{
return const_cast<pointField&>(ParentType::points());
}
//- Return non-const access to the faces
List<Face>& storedFaces()
{
return static_cast<List<Face> &>(*this);
}
//- Return non-const access to the faces
List<label>& storedRegions()
{
return regions_;
}
public: public:
//- Runtime type information //- Runtime type information
@ -153,6 +167,9 @@ public:
// Static // Static
//- Only handles triangulated faces
inline static bool isTri();
//- Can we read this file format? //- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false); static bool canRead(const word& ext, const bool verbose=false);
@ -294,7 +311,7 @@ public:
//- Return the number of points //- Return the number of points
label nPoints() const label nPoints() const
{ {
return points().size(); return ParentType::points().size();
} }
//- Return the number of faces //- Return the number of faces
@ -318,51 +335,27 @@ public:
return ParentType::points(); return ParentType::points();
} }
//- Return non-const access to global points
pointField& points()
{
return const_cast<pointField&>(ParentType::points());
}
//- Return const access to the faces //- Return const access to the faces
const List<Face>& faces() const const List<Face>& faces() const
{ {
return static_cast<const List<Face> &>(*this); return static_cast<const List<Face> &>(*this);
} }
//- Return non-const access to the faces
List<Face>& faces()
{
return static_cast<List<Face> &>(*this);
}
//- Return const access to the regions //- Return const access to the regions
const List<label>& regions() const const List<label>& regions() const
{ {
return regions_; return regions_;
} }
//- Return non-const access to the region Ids
List<label>& regions()
{
return regions_;
}
//- Return const access to the patches //- Return const access to the patches
const surfPatchIdentifierList& patches() const const List<surfPatchIdentifier>& patches() const
{
return patches_;
}
//- Return non-const access to the patches
surfPatchIdentifierList& patches()
{ {
return patches_; return patches_;
} }
//- Sort faces according to region. //- Sort faces according to region.
// Returns patch list and sets faceMap to index within faces() // Returns patch list and sets faceMap to index within faces()
surfGroupList sortedRegions(labelList& faceMap) const; List<surfGroup> sortedRegions(labelList& faceMap) const;
// Edit // Edit
@ -446,6 +439,22 @@ public:
}; };
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Specialization for holding triangulated information
template<>
inline bool UnsortedMeshedSurface<triFace>::isTri()
{
return true;
}
//- Specialization for holding triangulated information
template<>
inline label UnsortedMeshedSurface<triFace>::triangulate()
{
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -48,7 +48,7 @@ bool Foam::UnsortedMeshedSurface<Face>::stitchFaces
const bool verbose const bool verbose
) )
{ {
pointField& pointLst = points(); pointField& pointLst = storedPoints();
// Merge points // Merge points
labelList pointMap(pointLst.size()); labelList pointMap(pointLst.size());
@ -70,14 +70,14 @@ bool Foam::UnsortedMeshedSurface<Face>::stitchFaces
// Set the coordinates to the merged ones // Set the coordinates to the merged ones
pointLst.transfer(newPoints); pointLst.transfer(newPoints);
List<Face>& faceLst = faces(); List<Face>& faceLst = storedFaces();
// Reset the point labels to the unique points array // Reset the point labels to the unique points array
label newFaceI = 0; label newFaceI = 0;
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
Face& f = faceLst[faceI]; Face& f = faceLst[faceI];
forAll (f, fp) forAll(f, fp)
{ {
f[fp] = pointMap[f[fp]]; f[fp] = pointMap[f[fp]];
} }
@ -125,14 +125,14 @@ void Foam::UnsortedMeshedSurface<Face>::checkFaces(const bool verbose)
// Simple check on indices ok. // Simple check on indices ok.
const label maxPointI = points().size() - 1; const label maxPointI = points().size() - 1;
List<Face>& faceLst = faces(); List<Face>& faceLst = storedFaces();
// Phase 0: detect badly labelled faces // Phase 0: detect badly labelled faces
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
const Face& f = faceLst[faceI]; const Face& f = faceLst[faceI];
forAll (f, fp) forAll(f, fp)
{ {
if (f[fp] < 0 || f[fp] > maxPointI) if (f[fp] < 0 || f[fp] > maxPointI)
{ {
@ -151,7 +151,7 @@ void Foam::UnsortedMeshedSurface<Face>::checkFaces(const bool verbose)
const labelListList& fFaces = ParentType::faceFaces(); const labelListList& fFaces = ParentType::faceFaces();
label newFaceI = 0; label newFaceI = 0;
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
Face& f = faceLst[faceI]; Face& f = faceLst[faceI];
@ -164,7 +164,7 @@ void Foam::UnsortedMeshedSurface<Face>::checkFaces(const bool verbose)
// Check if faceNeighbours use same points as this face. // Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged. // Note: discards normal information - sides of baffle are merged.
forAll (neighbours, neighI) forAll(neighbours, neighI)
{ {
if (neighbours[neighI] <= faceI) if (neighbours[neighI] <= faceI)
{ {
@ -172,7 +172,7 @@ void Foam::UnsortedMeshedSurface<Face>::checkFaces(const bool verbose)
continue; continue;
} }
const face& nei = faceLst[neighbours[neighI]]; const Face& nei = faceLst[neighbours[neighI]];
if (f == nei) if (f == nei)
{ {
@ -242,10 +242,10 @@ template<class Face>
Foam::label Foam::UnsortedMeshedSurface<Face>::triangulate() Foam::label Foam::UnsortedMeshedSurface<Face>::triangulate()
{ {
label nTri = 0; label nTri = 0;
List<Face>& faceLst = faces(); List<Face>& faceLst = storedFaces();
// determine how many triangles are needed // determine how many triangles are needed
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
nTri += faceLst[faceI].size() - 2; nTri += faceLst[faceI].size() - 2;
} }
@ -264,7 +264,7 @@ Foam::label Foam::UnsortedMeshedSurface<Face>::triangulate()
// Reset the point labels to the unique points array // Reset the point labels to the unique points array
label newFaceI = 0; label newFaceI = 0;
forAll (faceLst, faceI) forAll(faceLst, faceI)
{ {
const Face& f = faceLst[faceI]; const Face& f = faceLst[faceI];
triFace fTri; triFace fTri;

View File

@ -49,18 +49,18 @@ bool Foam::UnsortedMeshedSurface<Face>::read(Istream& is)
List<surfGroup> patchLst(is); List<surfGroup> patchLst(is);
// read points: // read points:
is >> points(); is >> storedPoints();
// read faces: // read faces:
// TODO - specialization to triangulate on-the-fly // TODO - specialization to triangulate on-the-fly
if (mustTriangulate) if (mustTriangulate)
{ {
is >> faces(); is >> storedFaces();
} }
else else
{ {
is >> faces(); is >> storedFaces();
} }
patches_.setSize(patchLst.size()); patches_.setSize(patchLst.size());

View File

@ -38,13 +38,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::AC3DsurfaceFormat<Face>::AC3DsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::AC3DsurfaceFormat<Face>::AC3DsurfaceFormat Foam::fileFormats::AC3DsurfaceFormat<Face>::AC3DsurfaceFormat
( (
@ -65,16 +58,7 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
) )
{ {
ParentType::clear(); ParentType::clear();
const bool mustTriangulate = ParentType::isTri();
// triangulation required?
bool mustTriangulate = false;
{
Face f;
if (f.max_size() == 3)
{
mustTriangulate = true;
}
}
IFstream is(fName); IFstream is(fName);
if (!is.good()) if (!is.good())
@ -296,9 +280,9 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
} }
// transfer to normal lists // transfer to normal lists
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
ParentType::faces().transfer(faceLst); ParentType::storedFaces().transfer(faceLst);
ParentType::regions().transfer(regionLst); ParentType::storedRegions().transfer(regionLst);
ParentType::setPatches(regionNames); ParentType::setPatches(regionNames);
ParentType::stitchFaces(SMALL); ParentType::stitchFaces(SMALL);
@ -339,10 +323,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
labelList pMap; labelList pMap;
labelList fMap; labelList fMap;
ParentType patch = surf.subsetMesh ParentType patch = surf.subsetMesh(include, pMap, fMap);
(
include, pMap, fMap
);
// Now we have triSurface for this patch alone. Write it. // Now we have triSurface for this patch alone. Write it.
os << "numvert " << patch.nPoints() << endl; os << "numvert " << patch.nPoints() << endl;

View File

@ -34,6 +34,8 @@ Note
Since the faces are already organized as patches, the reader could be Since the faces are already organized as patches, the reader could be
optimized for this, but at expense of losing a common reading approach. optimized for this, but at expense of losing a common reading approach.
The output is always sorted by regions.
SourceFiles SourceFiles
AC3DsurfaceFormat.C AC3DsurfaceFormat.C
@ -66,7 +68,6 @@ class AC3DsurfaceFormat
public AC3DsurfaceFormatCore public AC3DsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef AC3DsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -81,9 +82,6 @@ public:
// Constructors // Constructors
//- Construct null
AC3DsurfaceFormat();
//- Construct from file name //- Construct from file name
AC3DsurfaceFormat(const fileName&); AC3DsurfaceFormat(const fileName&);
@ -113,6 +111,7 @@ public:
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is always sorted by regions.
static void write static void write
( (
Ostream&, Ostream&,
@ -120,6 +119,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is always sorted by regions.
static void write static void write
( (
const fileName& fName, const fileName& fName,

View File

@ -55,44 +55,29 @@ namespace fileFormats
class AC3DsurfaceFormatCore class AC3DsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Read a type via IStringStream //- Read a type via IStringStream
template<class Type> template<class Type>
static Type parse(const string&); static Type parse(const string&);
//- Read cmd, args from IFstream //- Read cmd, args from IFstream
static bool readCmd(IFstream&, string& cmd, string& args); static bool readCmd(IFstream&, string& cmd, string& args);
//- Cue up to cmd, reading args //- Cue up to cmd, reading args
static bool cueTo(IFstream&, const string& cmd, string& args); static bool cueTo(IFstream&, const string& cmd, string& args);
//- Cue up to cmd, reading args or exit with a FatalError //- Cue up to cmd, reading args or exit with a FatalError
// returns the command args // returns the command args
static string cueToOrDie static string cueToOrDie
( (
IFstream&, IFstream&,
const string& cmd, const string& cmd,
const string& errorMsg=string::null const string& errorMsg=string::null
); );
//- Write header with materials //- Write header with materials
static void writeHeader(Ostream&, const List<surfGroup>&); static void writeHeader(Ostream&, const List<surfGroup>&);
public:
// Constructors
//- Construct null
AC3DsurfaceFormatCore()
{}
// Destructor
~AC3DsurfaceFormatCore()
{}
// Member Functions
}; };

View File

@ -31,12 +31,6 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::FTRsurfaceFormat<Face>::FTRsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::FTRsurfaceFormat<Face>::FTRsurfaceFormat Foam::fileFormats::FTRsurfaceFormat<Face>::FTRsurfaceFormat
@ -46,7 +40,7 @@ Foam::fileFormats::FTRsurfaceFormat<Face>::FTRsurfaceFormat
: :
ParentType() ParentType()
{ {
ThisType::read(fName); read(fName);
} }
@ -75,13 +69,13 @@ bool Foam::fileFormats::FTRsurfaceFormat<Face>::read
List<point> pointLst(is); List<point> pointLst(is);
// transfer to normal list // transfer to normal list
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
// read faces with keys // read faces with keys
List<Keyed<triFace> > readFaces(is); List<Keyed<triFace> > readFaces(is);
List<Face> faceLst(readFaces.size()); List<Face> faceLst(readFaces.size());
List<label> regionLst(readFaces.size()); List<label> regionLst(readFaces.size());
// disentangle faces/keys - already triangulated // disentangle faces/keys - already triangulated
forAll(readFaces, faceI) forAll(readFaces, faceI)
@ -91,8 +85,8 @@ bool Foam::fileFormats::FTRsurfaceFormat<Face>::read
regionLst[faceI] = readFaces[faceI].key(); regionLst[faceI] = readFaces[faceI].key();
} }
ParentType::faces().transfer(faceLst); ParentType::storedFaces().transfer(faceLst);
ParentType::regions().transfer(regionLst); ParentType::storedRegions().transfer(regionLst);
Map<word> regionNames; Map<word> regionNames;
forAll(readPatches, patchI) forAll(readPatches, patchI)

View File

@ -26,7 +26,7 @@ Class
Foam::fileFormats::FTRsurfaceFormat Foam::fileFormats::FTRsurfaceFormat
Description Description
Reading of Foam Trisurface Format Reading of the (now deprecated) Foam Trisurface Format.
SourceFiles SourceFiles
FTRsurfaceFormat.C FTRsurfaceFormat.C
@ -57,7 +57,6 @@ class FTRsurfaceFormat
public UnsortedMeshedSurface<Face> public UnsortedMeshedSurface<Face>
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef FTRsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -69,13 +68,13 @@ class FTRsurfaceFormat
void operator=(const FTRsurfaceFormat<Face>&); void operator=(const FTRsurfaceFormat<Face>&);
//- read compatibility for ftr format //- read compatibility for ftr patch definitions
class ftrPatch class ftrPatch
{ {
//- Name of patch //- Name of patch
word name_; word name_;
//- Type of patch //- Type of patch (ignored since it is usually "empty")
word type_; word type_;
public: public:
@ -96,9 +95,6 @@ public:
// Constructors // Constructors
//- Construct null
FTRsurfaceFormat();
//- Construct from file name //- Construct from file name
FTRsurfaceFormat(const fileName&); FTRsurfaceFormat(const fileName&);

View File

@ -35,13 +35,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::GTSsurfaceFormat<Face>::GTSsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::GTSsurfaceFormat<Face>::GTSsurfaceFormat Foam::fileFormats::GTSsurfaceFormat<Face>::GTSsurfaceFormat
( (
@ -89,15 +82,14 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
// write directly into the lists: // write directly into the lists:
pointField& pointLst = ParentType::points(); pointField& pointLst = ParentType::storedPoints();
List<Face>& faceLst = ParentType::faces(); List<Face>& faceLst = ParentType::storedFaces();
List<label>& regionLst = ParentType::regions(); List<label>& regionLst = ParentType::storedRegions();
pointLst.setSize(nPoints); pointLst.setSize(nPoints);
faceLst.setSize(nElems); faceLst.setSize(nElems);
regionLst.setSize(nElems); regionLst.setSize(nElems);
// Read points // Read points
forAll(pointLst, pointI) forAll(pointLst, pointI)
{ {
@ -234,8 +226,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
// check if output triangulation would be required // check if output triangulation would be required
// It is too annoying to triangulate on-the-fly // It is too annoying to triangulate on-the-fly
// just issue a warning and get out // just issue a warning and get out
// if (!surf.isTri())
if (faceLst.size() && faceLst[0].max_size() != 3)
{ {
label nNonTris = 0; label nNonTris = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)
@ -337,7 +328,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
// It is too annoying to triangulate on-the-fly // It is too annoying to triangulate on-the-fly
// just issue a warning and get out // just issue a warning and get out
// //
if (faceLst.size() && faceLst[0].max_size() != 3) if (!surf.isTri())
{ {
label nNonTris = 0; label nNonTris = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)

View File

@ -58,7 +58,6 @@ class GTSsurfaceFormat
public UnsortedMeshedSurface<Face> public UnsortedMeshedSurface<Face>
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef GTSsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -73,9 +72,6 @@ public:
// Constructors // Constructors
//- Construct null
GTSsurfaceFormat();
//- Construct from file name //- Construct from file name
GTSsurfaceFormat(const fileName&); GTSsurfaceFormat(const fileName&);
@ -103,6 +99,7 @@ public:
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by regions
static void write static void write
( (
Ostream&, Ostream&,
@ -110,6 +107,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by regions
static void write static void write
( (
const fileName& fName, const fileName& fName,

View File

@ -35,13 +35,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat
( (
@ -50,7 +43,7 @@ Foam::fileFormats::NASsurfaceFormat<Face>::NASsurfaceFormat
: :
ParentType() ParentType()
{ {
ThisType::read(fName); read(fName);
} }
@ -63,16 +56,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
) )
{ {
ParentType::clear(); ParentType::clear();
const bool mustTriangulate = ParentType::isTri();
// triangulation required?
bool mustTriangulate = false;
{
Face f;
if (f.max_size() == 3)
{
mustTriangulate = true;
}
}
IFstream is(fName); IFstream is(fName);
if (!is.good()) if (!is.good())
@ -364,8 +348,8 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// transfer to normal lists // transfer to normal lists
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
ParentType::regions().transfer(regionLst); ParentType::storedRegions().transfer(regionLst);
pointId.shrink(); pointId.shrink();
faceLst.shrink(); faceLst.shrink();
@ -405,7 +389,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
// transfer to normal lists // transfer to normal lists
ParentType::faces().transfer(faceLst); ParentType::storedFaces().transfer(faceLst);
ParentType::setPatches(regionNames); ParentType::setPatches(regionNames);
return true; return true;

View File

@ -68,7 +68,6 @@ class NASsurfaceFormat
public NASsurfaceFormatCore public NASsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef NASsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -83,9 +82,6 @@ public:
// Constructors // Constructors
//- Construct null
NASsurfaceFormat();
//- Construct from file name //- Construct from file name
NASsurfaceFormat(const fileName&); NASsurfaceFormat(const fileName&);

View File

@ -53,24 +53,10 @@ namespace fileFormats
class NASsurfaceFormatCore class NASsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Do weird things to extract number //- Do weird things to extract number
static scalar parseNASCoord(const string&); static scalar parseNASCoord(const string&);
public:
// Constructors
//- Construct null
NASsurfaceFormatCore()
{}
// Destructor
~NASsurfaceFormatCore()
{}
}; };

View File

@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OBJsurfaceFormat.H" #include "OBJsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -33,13 +32,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::OBJsurfaceFormat<Face>::OBJsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::OBJsurfaceFormat<Face>::OBJsurfaceFormat Foam::fileFormats::OBJsurfaceFormat<Face>::OBJsurfaceFormat
( (
@ -48,7 +40,7 @@ Foam::fileFormats::OBJsurfaceFormat<Face>::OBJsurfaceFormat
: :
ParentType() ParentType()
{ {
ThisType::read(fName); read(fName);
} }
@ -61,16 +53,7 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
) )
{ {
ParentType::clear(); ParentType::clear();
const bool mustTriangulate = ParentType::isTri();
// triangulation required?
bool mustTriangulate = false;
{
Face f;
if (f.max_size() == 3)
{
mustTriangulate = true;
}
}
IFstream is(fName); IFstream is(fName);
if (!is.good()) if (!is.good())
@ -215,9 +198,9 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
} }
// transfer to normal lists // transfer to normal lists
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
ParentType::faces().transfer(faceLst); ParentType::storedFaces().transfer(faceLst);
ParentType::regions().transfer(regionLst); ParentType::storedRegions().transfer(regionLst);
ParentType::setPatches(groupToPatch); ParentType::setPatches(groupToPatch);
return true; return true;
@ -250,7 +233,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
os << 'f'; os << 'f';
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp] + 1; os << ' ' << f[fp] + 1;
@ -259,7 +242,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
} }
} }
os << "# </faces>" << endl; os << "# </faces>" << endl;
} }
@ -286,7 +269,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
os << 'f'; os << 'f';
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp] + 1; os << ' ' << f[fp] + 1;
@ -294,7 +277,7 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
os << endl; os << endl;
} }
} }
os << "# </faces>" << endl; os << "# </faces>" << endl;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -62,7 +62,6 @@ class OBJsurfaceFormat
public OBJsurfaceFormatCore public OBJsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef OBJsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -85,9 +84,6 @@ public:
// Constructors // Constructors
//- Construct null
OBJsurfaceFormat();
//- Construct from file name //- Construct from file name
OBJsurfaceFormat(const fileName&); OBJsurfaceFormat(const fileName&);
@ -117,6 +113,7 @@ public:
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by regions
static void write static void write
( (
Ostream&, Ostream&,
@ -124,6 +121,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by regions
static void write static void write
( (
const fileName& fName, const fileName& fName,

View File

@ -49,37 +49,22 @@ namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class AC3DfileFormat Declaration Class OBJsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class OBJsurfaceFormatCore class OBJsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
Ostream&, Ostream&,
const pointField&, const pointField&,
const label nFaces, const label nFaces,
const List<surfGroup>& const List<surfGroup>&
); );
public:
// Constructors
//- Construct null
OBJsurfaceFormatCore()
{}
// Destructor
~OBJsurfaceFormatCore()
{}
// Member Functions
}; };

View File

@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OFFsurfaceFormat.H" #include "OFFsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -35,13 +34,6 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::OFFsurfaceFormat<Face>::OFFsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::OFFsurfaceFormat<Face>::OFFsurfaceFormat Foam::fileFormats::OFFsurfaceFormat<Face>::OFFsurfaceFormat
( (
@ -50,7 +42,7 @@ Foam::fileFormats::OFFsurfaceFormat<Face>::OFFsurfaceFormat
: :
ParentType() ParentType()
{ {
ThisType::read(fName); read(fName);
} }
@ -63,16 +55,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
) )
{ {
ParentType::clear(); ParentType::clear();
const bool mustTriangulate = ParentType::isTri();
// triangulation required?
bool mustTriangulate = false;
{
Face f;
if (f.max_size() == 3)
{
mustTriangulate = true;
}
}
IFstream is(fName); IFstream is(fName);
if (!is.good()) if (!is.good())
@ -167,12 +150,12 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
} }
// transfer to normal lists // transfer to normal lists
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
ParentType::faces().transfer(faceLst); ParentType::storedFaces().transfer(faceLst);
// no region information // no region information
ParentType::regions().setSize(ThisType::size()); ParentType::storedRegions().setSize(ParentType::size());
ParentType::regions() = 0; ParentType::storedRegions() = 0;
ParentType::setPatches(0); ParentType::setPatches(0);
return true; return true;
@ -202,7 +185,7 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size(); os << f.size();
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp]; os << ' ' << f[fp];
@ -213,7 +196,7 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
} }
os << "# </patch>" << endl; os << "# </patch>" << endl;
} }
os << "# </faces>" << endl; os << "# </faces>" << endl;
} }
@ -238,7 +221,7 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
os << f.size(); os << f.size();
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp]; os << ' ' << f[fp];
@ -249,7 +232,7 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
} }
os << "# </patch>" << endl; os << "# </patch>" << endl;
} }
os << "# </faces>" << endl; os << "# </faces>" << endl;
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -70,7 +70,6 @@ class OFFsurfaceFormat
public OFFsurfaceFormatCore public OFFsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef OFFsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -93,9 +92,6 @@ public:
// Constructors // Constructors
//- Construct null
OFFsurfaceFormat();
//- Construct from file name //- Construct from file name
OFFsurfaceFormat(const fileName&); OFFsurfaceFormat(const fileName&);
@ -123,6 +119,7 @@ public:
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by region.
static void write static void write
( (
Ostream&, Ostream&,
@ -130,6 +127,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by region.
static void write static void write
( (
const fileName& fName, const fileName& fName,

View File

@ -55,30 +55,16 @@ namespace fileFormats
class OFFsurfaceFormatCore class OFFsurfaceFormatCore
{ {
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
Ostream&, Ostream&,
const pointField&, const pointField&,
const label nFaces, const label nFaces,
const List<surfGroup>& const List<surfGroup>&
); );
public:
// Constructors
//- Construct null
OFFsurfaceFormatCore()
{}
// Destructor
~OFFsurfaceFormatCore()
{}
// Member Functions
}; };

View File

@ -25,8 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "SMESHsurfaceFormat.H" #include "SMESHsurfaceFormat.H"
#include "clock.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -63,7 +61,7 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size(); os << f.size();
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp]; os << ' ' << f[fp];
@ -95,7 +93,7 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
os << f.size(); os << f.size();
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp]; os << ' ' << f[fp];

View File

@ -67,7 +67,6 @@ class SMESHsurfaceFormat
public SMESHsurfaceFormatCore public SMESHsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef SMESHsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -96,6 +95,7 @@ public:
// Member Functions // Member Functions
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by region.
static void write static void write
( (
Ostream&, Ostream&,
@ -103,6 +103,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by region.
static void write static void write
( (
const fileName& fName, const fileName& fName,

View File

@ -26,7 +26,6 @@ License
#include "SMESHsurfaceFormatCore.H" #include "SMESHsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

View File

@ -36,8 +36,6 @@ SourceFiles
#ifndef SMESHsurfaceFormatCore_H #ifndef SMESHsurfaceFormatCore_H
#define SMESHsurfaceFormatCore_H #define SMESHsurfaceFormatCore_H
#include "IFstream.H"
#include "OFstream.H"
#include "Ostream.H" #include "Ostream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
@ -58,31 +56,16 @@ class SMESHsurfaceFormatCore
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
Ostream&, Ostream&,
const pointField&, const pointField&,
const label nFaces const label nFaces
); );
//- Write tail information //- Write tail information
static void writeTail(Ostream&); static void writeTail(Ostream&);
public:
// Constructors
//- Construct null
SMESHsurfaceFormatCore()
{}
// Destructor
~SMESHsurfaceFormatCore()
{}
// Member Functions
}; };

View File

@ -25,16 +25,13 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "STARCDsurfaceFormat.H" #include "STARCDsurfaceFormat.H"
#include "clock.H"
#include "OSspecific.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Face> template<class Face>
void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
( (
Ostream& os, Ostream& os,
const Face& f, const Face& f,
@ -69,26 +66,6 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat()
:
ParentType()
{}
// .vrt file format:
/*---------------------------------------------------------------------------*\
Line 1:
PROSTAR_VERTEX [newline]
Line 2:
<version> 0 0 0 0 0 0 0 [newline]
Body:
<vertexId> <x> <y> <z> [newline]
\*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
( (
@ -102,7 +79,6 @@ Foam::fileFormats::STARCDsurfaceFormat<Face>::STARCDsurfaceFormat
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face> template<class Face>
bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
( (
@ -110,17 +86,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
) )
{ {
ParentType::clear(); ParentType::clear();
const bool mustTriangulate = ParentType::isTri();
// triangulation required?
bool mustTriangulate = false;
{
Face f;
if (f.max_size() == 3)
{
mustTriangulate = true;
}
}
fileName baseName = fName.lessExt(); fileName baseName = fName.lessExt();
autoPtr<IFstream> isPtr; autoPtr<IFstream> isPtr;
@ -160,7 +126,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
} }
// transfer to normal lists // transfer to normal lists
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
// Build inverse mapping (index to point) // Build inverse mapping (index to point)
pointId.shrink(); pointId.shrink();
@ -294,8 +260,8 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
} }
// transfer to normal lists // transfer to normal lists
ParentType::faces().transfer(faceLst); ParentType::storedFaces().transfer(faceLst);
ParentType::regions().transfer(regionLst); ParentType::storedRegions().transfer(regionLst);
ParentType::setPatches(regionNames); ParentType::setPatches(regionNames);
@ -310,22 +276,16 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf
) )
{ {
const List<Face>& faceLst = surf.faces();
fileName baseName = fName.lessExt(); fileName baseName = fName.lessExt();
autoPtr<OFstream> osPtr;
osPtr.reset(new OFstream(baseName + ".vrt"));
writePoints(osPtr(), surf.points());
writePoints(OFstream(baseName + ".vrt")(), surf.points());
OFstream os(baseName + ".cel");
writeHeader(os, "CELL");
const List<Face>& faceLst = surf.faces();
labelList faceMap; labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap); List<surfGroup> patchLst = surf.sortedRegions(faceMap);
osPtr.reset(new OFstream(baseName + ".cel"));
writeHeader(osPtr(), "CELL");
label faceIndex = 0; label faceIndex = 0;
forAll(patchLst, patchI) forAll(patchLst, patchI)
{ {
@ -334,10 +294,18 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
forAll(patch, patchFaceI) forAll(patch, patchFaceI)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, f, faceIndex, patchI + 1);
writeShell(osPtr(), f, faceIndex, patchI + 1);
} }
} }
// write simple .inp file
writeCase
(
OFstream(baseName + ".inp")(),
surf.points(),
surf.nFaces(),
patchLst
);
} }
@ -348,20 +316,15 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
const MeshedSurface<Face>& surf const MeshedSurface<Face>& surf
) )
{ {
fileName baseName = fName.lessExt();
writePoints(OFstream(baseName + ".vrt")(), surf.points());
OFstream os(baseName + ".cel");
writeHeader(os, "CELL");
const List<Face>& faceLst = surf.faces(); const List<Face>& faceLst = surf.faces();
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
fileName baseName = fName.lessExt();
autoPtr<OFstream> osPtr;
osPtr.reset(new OFstream(baseName + ".vrt"));
writePoints(osPtr(), surf.points());
osPtr.reset(new OFstream(baseName + ".cel"));
writeHeader(osPtr(), "CELL");
label faceIndex = 0; label faceIndex = 0;
forAll(patchLst, patchI) forAll(patchLst, patchI)
{ {
@ -370,9 +333,18 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
forAll(patch, patchFaceI) forAll(patch, patchFaceI)
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
writeShell(osPtr(), f, faceIndex, patchI + 1); writeShell(os, f, faceIndex, patchI + 1);
} }
} }
// write simple .inp file
writeCase
(
OFstream(baseName + ".inp")(),
surf.points(),
surf.nFaces(),
patchLst
);
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -42,7 +42,6 @@ SourceFiles
#ifndef STARCDsurfaceFormat_H #ifndef STARCDsurfaceFormat_H
#define STARCDsurfaceFormat_H #define STARCDsurfaceFormat_H
#include "IFstream.H"
#include "Ostream.H" #include "Ostream.H"
#include "OFstream.H" #include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
@ -67,7 +66,6 @@ class STARCDsurfaceFormat
public STARCDsurfaceFormatCore public STARCDsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef STARCDsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Data // Private Data
@ -79,12 +77,6 @@ class STARCDsurfaceFormat
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&);
//- Disallow default bitwise assignment
void operator=(const STARCDsurfaceFormat<Face>&);
static inline void writeShell static inline void writeShell
( (
Ostream&, Ostream&,
@ -93,13 +85,16 @@ class STARCDsurfaceFormat
const label cellTableId const label cellTableId
); );
//- Disallow default bitwise copy construct
STARCDsurfaceFormat(const STARCDsurfaceFormat<Face>&);
//- Disallow default bitwise assignment
void operator=(const STARCDsurfaceFormat<Face>&);
public: public:
// Constructors // Constructors
//- Construct null
STARCDsurfaceFormat();
//- Construct from file name //- Construct from file name
STARCDsurfaceFormat(const fileName&); STARCDsurfaceFormat(const fileName&);
@ -128,10 +123,19 @@ public:
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
static void write(const fileName&, const UnsortedMeshedSurface<Face>&); // The output is sorted by regions
static void write
(
const fileName&,
const UnsortedMeshedSurface<Face>&
);
//- Write MeshedSurface //- Write MeshedSurface
static void write(const fileName&, const MeshedSurface<Face>&); static void write
(
const fileName&,
const MeshedSurface<Face>&
);
//- Write to Ostream as one large file - not really useful //- Write to Ostream as one large file - not really useful
virtual void write(Ostream&) const virtual void write(Ostream&) const

View File

@ -26,17 +26,10 @@ License
#include "STARCDsurfaceFormatCore.H" #include "STARCDsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
#include "OSspecific.H"
#include "IStringStream.H" #include "IStringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
//! @cond localscope
const int starcdShellShape = 3;
const int starcdShellType = 4;
//! @endcond localscope
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader bool Foam::fileFormats::STARCDsurfaceFormatCore::readHeader
@ -121,6 +114,43 @@ void Foam::fileFormats::STARCDsurfaceFormatCore::writePoints
os.flush(); os.flush();
} }
void Foam::fileFormats::STARCDsurfaceFormatCore::writeCase
(
Ostream& os,
const pointField& pointLst,
const label nFaces,
const List<surfGroup>& patchLst
)
{
word caseName = os.name().lessExt().name();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nFaces << " faces" << nl
<< "! case " << caseName << nl
<< "! ------------------------------" << nl;
forAll(patchLst, patchI)
{
os << "ctable " << patchI + 1 << " shell" << nl
<< "ctname " << patchI + 1 << " " << patchLst[patchI].name() << nl;
}
os << "! ------------------------------" << nl
<< "*set icvo mxv - 1" << nl
<< "vread " << caseName << ".vrt icvo,,,coded" << nl
<< "cread " << caseName << ".cel icvo,,,add,coded" << nl
<< "*set icvo" << nl
<< "! end" << nl;
os.flush();
}
#if 0
#endif
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //

View File

@ -38,7 +38,6 @@ SourceFiles
#include "IFstream.H" #include "IFstream.H"
#include "Ostream.H" #include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
@ -58,25 +57,19 @@ class STARCDsurfaceFormatCore
protected: protected:
// Protected Member Functions // Protected Member Functions
static bool readHeader(IFstream&, const word&); static bool readHeader(IFstream&, const word&);
static void writeHeader(Ostream&, const char* filetype); static void writeHeader(Ostream&, const char* filetype);
static void writePoints(Ostream&, const pointField&); static void writePoints(Ostream&, const pointField&);
public: static void writeCase
(
// Constructors Ostream&,
const pointField&,
//- Construct null const label nFaces,
STARCDsurfaceFormatCore() const List<surfGroup>&
{} );
// Destructor
~STARCDsurfaceFormatCore()
{}
// Member Functions
}; };

View File

@ -59,21 +59,34 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
inline STLpoint(); inline STLpoint()
{}
//- Construct from components //- Construct from components
inline STLpoint(float x, float y, float z); inline STLpoint(float x, float y, float z)
:
Vector<float>(x, y, z)
{}
//- Construct from point //- Construct from point
inline STLpoint(const point&); inline STLpoint(const point& pt)
:
Vector<float>(float(pt.x()), float(pt.y()), float(pt.z()))
{}
//- Construct from istream //- Construct from istream
inline STLpoint(Istream&); inline STLpoint(Istream& is)
:
Vector<float>(is)
{}
// Member Operators // Member Operators
inline operator point() const; inline operator point() const
{
return point(x(), y(), z());
}
}; };
@ -84,10 +97,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "STLpointI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -1,60 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::STLpoint::STLpoint()
{}
inline Foam::STLpoint::STLpoint(float x, float y, float z)
:
Vector<float>(x, y, z)
{}
inline Foam::STLpoint::STLpoint(const point& pt)
:
Vector<float>(float(pt.x()), float(pt.y()), float(pt.z()))
{}
inline Foam::STLpoint::STLpoint(Istream& is)
:
Vector<float>(is)
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::STLpoint::operator point() const
{
return point(x(), y(), z());
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -50,17 +50,14 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
const point& p2 = pointLst[f[fp2]]; const point& p2 = pointLst[f[fp2]];
// write STL triangle // write STL triangle
os << " facet normal " os << " facet normal "
<< norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl << norm.x() << ' ' << norm.y() << ' ' << norm.z() << nl
<< " outer loop\n" << " outer loop\n"
<< " vertex " << " vertex " << p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl
<< p0.x() << ' ' << p0.y() << ' ' << p0.z() << nl << " vertex " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl
<< " vertex " << " vertex " << p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
<< p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl << " endloop\n"
<< " vertex " << " endfacet" << endl;
<< p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl
<< " endloop\n"
<< " endfacet" << endl;
} }
} }
@ -108,24 +105,37 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeASCII
const List<Face>& faceLst = surf.faces(); const List<Face>& faceLst = surf.faces();
const vectorField& normLst = surf.faceNormals(); const vectorField& normLst = surf.faceNormals();
labelList faceMap; if (surf.patches().size() == 1)
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
label faceIndex = 0;
forAll(patchLst, patchI)
{ {
// Print all faces belonging to this region // a single region - we can skip sorting
const surfGroup& patch = patchLst[patchI]; os << "solid " << surf.patches()[0].name() << endl;
forAll(faceLst, faceI)
os << "solid " << patch.name() << endl;
forAll(patch, patchFaceI)
{ {
const label faceI = faceMap[faceIndex++];
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]); writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
} }
os << "endsolid " << surf.patches()[0].name() << endl;
os << "endsolid " << patch.name() << endl;
} }
else
{
labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
label faceIndex = 0;
forAll(patchLst, patchI)
{
// Print all faces belonging to this region
const surfGroup& patch = patchLst[patchI];
os << "solid " << patch.name() << endl;
forAll(patch, patchFaceI)
{
const label faceI = faceMap[faceIndex++];
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
}
os << "endsolid " << patch.name() << endl;
}
}
} }
@ -143,7 +153,6 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeASCII
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
const vectorField& normLst = surf.faceNormals(); const vectorField& normLst = surf.faceNormals();
// force triangulation, but just do the cheapest form possible
label faceIndex = 0; label faceIndex = 0;
forAll(patchLst, patchI) forAll(patchLst, patchI)
{ {
@ -151,13 +160,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeASCII
const surfGroup& patch = patchLst[patchI]; const surfGroup& patch = patchLst[patchI];
os << "solid " << patch.name() << endl; os << "solid " << patch.name() << endl;
forAll(patch, patchFaceI) forAll(patch, patchFaceI)
{ {
const label faceI = faceIndex++; const label faceI = faceIndex++;
writeShell(os, pointLst, faceLst[faceI], normLst[faceI]); writeShell(os, pointLst, faceLst[faceI], normLst[faceI]);
} }
os << "endsolid " << patch.name() << endl; os << "endsolid " << patch.name() << endl;
} }
} }
@ -176,17 +183,22 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
const List<label>& regionLst = surf.regions(); const List<label>& regionLst = surf.regions();
const vectorField& normLst = surf.faceNormals(); const vectorField& normLst = surf.faceNormals();
// Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os);
// force triangulation, but just do the cheapest form possible
unsigned int nTris = 0; unsigned int nTris = 0;
forAll(faceLst, faceI) if (surf.isTri())
{ {
nTris += faceLst[faceI].size() - 2; nTris = faceLst.size();
}
else
{
// count triangles for on-the-fly triangulation
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
} }
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); // Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os, nTris);
// always write unsorted // always write unsorted
forAll(faceLst, faceI) forAll(faceLst, faceI)
@ -215,17 +227,22 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
const vectorField& normLst = surf.faceNormals(); const vectorField& normLst = surf.faceNormals();
const List<surfGroup>& patchLst = surf.patches(); const List<surfGroup>& patchLst = surf.patches();
// Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os);
// force triangulation, but just do the cheapest form possible
unsigned int nTris = 0; unsigned int nTris = 0;
forAll(faceLst, faceI) if (surf.isTri())
{ {
nTris += faceLst[faceI].size() - 2; nTris = faceLst.size();
}
else
{
// count triangles for on-the-fly triangulation
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
} }
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int)); // Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os, nTris);
label faceIndex = 0; label faceIndex = 0;
forAll(patchLst, patchI) forAll(patchLst, patchI)
@ -249,13 +266,6 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::STLsurfaceFormat<Face>::STLsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::STLsurfaceFormat<Face>::STLsurfaceFormat Foam::fileFormats::STLsurfaceFormat<Face>::STLsurfaceFormat
( (
@ -264,7 +274,7 @@ Foam::fileFormats::STLsurfaceFormat<Face>::STLsurfaceFormat
: :
ParentType() ParentType()
{ {
ThisType::read(fName); read(fName);
} }
@ -281,16 +291,13 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
// read in the values // read in the values
STLsurfaceFormatCore reader(fName); STLsurfaceFormatCore reader(fName);
pointField& pointLst = ParentType::points();
List<Face>& faceLst = ParentType::faces();
List<label>& regionLst = ParentType::regions();
// transfer // transfer
pointLst.transfer(reader.points()); ParentType::storedPoints().transfer(reader.points());
regionLst.transfer(reader.regions()); ParentType::storedRegions().transfer(reader.regions());
// assemble the faces: // generate the faces:
faceLst.setSize(regionLst.size()); List<Face>& faceLst = ParentType::storedFaces();
faceLst.setSize(ParentType::regions().size());
label ptI = 0; label ptI = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)

View File

@ -58,7 +58,6 @@ class STLsurfaceFormat
public UnsortedMeshedSurface<Face> public UnsortedMeshedSurface<Face>
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef STLsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private data // Private data
@ -107,9 +106,6 @@ public:
// Constructors // Constructors
//- Construct null
STLsurfaceFormat();
//- Construct from file name //- Construct from file name
STLsurfaceFormat(const fileName&); STLsurfaceFormat(const fileName&);
@ -137,7 +133,7 @@ public:
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface (as ASCII) //- Write UnsortedMeshedSurface (as ASCII) sorted by region
static void write static void write
( (
Ostream&, Ostream&,
@ -152,7 +148,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The ASCII output is sorted by patch, the binary output is unsorted // ASCII output is sorted by region; binary output is unsorted
static void write static void write
( (
const fileName&, const fileName&,
@ -160,7 +156,6 @@ public:
); );
//- Write MeshedSurface //- Write MeshedSurface
// The ASCII output is sorted by patch, the binary output is unsorted
static void write static void write
( (
const fileName&, const fileName&,

View File

@ -149,7 +149,7 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
// Read an STL triangle // Read an STL triangle
STLtriangle stlTri(is); STLtriangle stlTri(is);
// transcript the vertices of the STL triangle -> points // transcribe the vertices of the STL triangle -> points
points_[ptI++] = stlTri.a(); points_[ptI++] = stlTri.a();
points_[ptI++] = stlTri.b(); points_[ptI++] = stlTri.b();
points_[ptI++] = stlTri.c(); points_[ptI++] = stlTri.c();
@ -173,13 +173,13 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
Info<< "solid region" << prevRegion << nl; Info<< "solid region" << prevRegion << nl;
} }
Info<< " facet normal " << stlTri.normal() << nl; Info<< " facet normal " << stlTri.normal() << nl
Info<< " outer loop" << nl; << " outer loop" << nl
Info<< " vertex " << stlTri.a() << nl; << " vertex " << stlTri.a() << nl
Info<< " vertex " << stlTri.b() << nl; << " vertex " << stlTri.b() << nl
Info<< " vertex " << stlTri.c() << nl; << " vertex " << stlTri.c() << nl
Info<< " outer loop" << nl; << " outer loop" << nl
Info<< " endfacet" << endl; << " endfacet" << endl;
#endif #endif
} }
@ -222,7 +222,11 @@ Foam::fileFormats::STLsurfaceFormatCore::~STLsurfaceFormatCore()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::STLsurfaceFormatCore::writeHeaderBINARY(ostream& os) void Foam::fileFormats::STLsurfaceFormatCore::writeHeaderBINARY
(
ostream& os,
unsigned int nTris
)
{ {
// Write the STL header, avoid possible trailing junk // Write the STL header, avoid possible trailing junk
string header("STL binary file", headerSize); string header("STL binary file", headerSize);
@ -231,6 +235,9 @@ void Foam::fileFormats::STLsurfaceFormatCore::writeHeaderBINARY(ostream& os)
header[i] = 0; header[i] = 0;
} }
os.write(header.c_str(), headerSize); os.write(header.c_str(), headerSize);
os.write(reinterpret_cast<char*>(&nTris), sizeof(unsigned int));
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -96,16 +96,13 @@ public:
// Static Member Functions // Static Member Functions
//- Write "STL binary file" to stream //- Write "STL binary file" and number of triangles to stream
static void writeHeaderBINARY(ostream&); static void writeHeaderBINARY(ostream&, unsigned int);
// Constructors // Constructors
//- Read from file, filling in the information //- Read from file, filling in the information
STLsurfaceFormatCore STLsurfaceFormatCore(const fileName&);
(
const fileName&
);
// Destructor // Destructor

View File

@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "TRIsurfaceFormat.H" #include "TRIsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IOmanip.H" #include "IOmanip.H"
#include "IStringStream.H" #include "IStringStream.H"
@ -64,13 +63,6 @@ inline void Foam::fileFormats::TRIsurfaceFormat<Face>::writeShell
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat()
:
ParentType()
{}
template<class Face> template<class Face>
Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat Foam::fileFormats::TRIsurfaceFormat<Face>::TRIsurfaceFormat
( (
@ -190,11 +182,11 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
} }
// transfer to normal list // transfer to normal list
ParentType::points().transfer(pointLst); ParentType::storedPoints().transfer(pointLst);
ParentType::regions().transfer(regionLst); ParentType::storedRegions().transfer(regionLst);
// make our triangles directly // make our triangles directly
List<Face>& faceLst = ParentType::faces(); List<Face>& faceLst = ParentType::storedFaces();
faceLst.setSize(ParentType::regions().size()); faceLst.setSize(ParentType::regions().size());
label ptI = 0; label ptI = 0;
@ -225,16 +217,35 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces(); const List<Face>& faceLst = surf.faces();
labelList faceMap; bool doSort = false;
List<surfGroup> patchLst = surf.sortedRegions(faceMap); // a single region needs no sorting
if (surf.patches().size() == 1)
label faceIndex = 0;
forAll(patchLst, patchI)
{ {
forAll(patchLst[patchI], patchFaceI) doSort = false;
}
if (doSort)
{
labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
label faceIndex = 0;
forAll(patchLst, patchI)
{ {
const Face& f = faceLst[faceMap[faceIndex++]]; forAll(patchLst[patchI], patchFaceI)
writeShell(os, pointLst, f, patchI); {
const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, pointLst, f, patchI);
}
}
}
else
{
const List<label>& regionLst = surf.regions();
forAll(faceLst, faceI)
{
writeShell(os, pointLst, faceLst[faceI], regionLst[faceI]);
} }
} }
} }

View File

@ -58,7 +58,6 @@ class TRIsurfaceFormat
public UnsortedMeshedSurface<Face> public UnsortedMeshedSurface<Face>
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef TRIsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -81,9 +80,6 @@ public:
// Constructors // Constructors
//- Construct null
TRIsurfaceFormat();
//- Construct from file name //- Construct from file name
TRIsurfaceFormat(const fileName&); TRIsurfaceFormat(const fileName&);
@ -111,6 +107,7 @@ public:
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// By default, the output is not sorted by regions
static void write static void write
( (
Ostream&, Ostream&,
@ -118,6 +115,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// By default, the output is not sorted by regions
static void write static void write
( (
const fileName& fName, const fileName& fName,
@ -145,6 +143,7 @@ public:
} }
//- Write object //- Write object
// By default, the output is not sorted by regions
virtual void write(Ostream& os) const virtual void write(Ostream& os) const
{ {
write(os, *this); write(os, *this);

View File

@ -25,9 +25,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "VTKsurfaceFormat.H" #include "VTKsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -75,27 +72,57 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
writeHeader(os, surf.points()); writeHeader(os, surf.points());
writeHeaderPolygons(os, faceLst); writeHeaderPolygons(os, faceLst);
labelList faceMap; bool doSort = false;
List<surfGroup> patchLst = surf.sortedRegions(faceMap); // a single region needs no sorting
if (surf.patches().size() == 1)
label faceIndex = 0;
forAll(patchLst, patchI)
{ {
forAll(patchLst[patchI], patchFaceI) doSort = false;
{
const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
}
} }
// Print region numbers if (doSort)
writeTail(os, patchLst); {
labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
label faceIndex = 0;
forAll(patchLst, patchI)
{
forAll(patchLst[patchI], patchFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
}
}
// Print region numbers
writeTail(os, patchLst);
}
else
{
labelList faceMap;
List<surfGroup> patchLst = surf.sortedRegions(faceMap);
forAll(faceLst, faceI)
{
const Face& f = faceLst[faceI];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
}
// Print region numbers
writeTail(os, surf.regions());
}
} }
@ -119,12 +146,12 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
{ {
const Face& f = faceLst[faceIndex++]; const Face& f = faceLst[faceIndex++];
os << f.size(); os << f.size();
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp]; os << ' ' << f[fp];
} }
os << ' ' << nl; os << ' ' << nl;
} }
} }

View File

@ -60,7 +60,6 @@ class VTKsurfaceFormat
public VTKsurfaceFormatCore public VTKsurfaceFormatCore
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef VTKsurfaceFormat<Face> ThisType;
typedef UnsortedMeshedSurface<Face> ParentType; typedef UnsortedMeshedSurface<Face> ParentType;
// Private Member Functions // Private Member Functions
@ -94,6 +93,7 @@ public:
// Write // Write
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// By default, the output is not sorted by regions.
static void write static void write
( (
Ostream&, Ostream&,
@ -101,6 +101,7 @@ public:
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// By default, the output is not sorted by regions.
static void write static void write
( (
const fileName& fName, const fileName& fName,

View File

@ -26,8 +26,6 @@ License
#include "VTKsurfaceFormatCore.H" #include "VTKsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -84,11 +82,11 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
{ {
if ((patchFaceI % 20) == 0) if ((patchFaceI % 20) == 0)
{ {
os << nl; os << nl;
} }
else else
{ {
os << ' '; os << ' ';
} }
} }
os << patchI + 1; os << patchI + 1;
@ -98,6 +96,38 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
} }
void Foam::fileFormats::VTKsurfaceFormatCore::writeTail
(
Ostream& os,
const List<label>& regionLst
)
{
// Print region numbers
os << nl
<< "CELL_DATA " << regionLst.size() << nl
<< "FIELD attributes 1" << nl
<< "region 1 " << regionLst.size() << " float" << nl;
forAll(regionLst, faceI)
{
if (faceI)
{
if ((faceI % 20) == 0)
{
os << nl;
}
else
{
os << ' ';
}
}
os << regionLst[faceI] + 1;
}
os << nl;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //

View File

@ -57,30 +57,18 @@ class VTKsurfaceFormatCore
protected: protected:
// Protected Member Functions // Protected Member Functions
//- Write header information with points //- Write header information with points
static void writeHeader static void writeHeader
( (
Ostream&, Ostream&,
const pointField& const pointField&
); );
//- Write header information with patch informattion //- Write trailing information with patch information
static void writeTail(Ostream&, const List<surfGroup>&); static void writeTail(Ostream&, const List<surfGroup>&);
public: //- Write trailing information with region information
static void writeTail(Ostream&, const List<label>& regionLst);
// Constructors
//- Construct null
VTKsurfaceFormatCore()
{}
// Destructor
virtual ~VTKsurfaceFormatCore()
{}
// Member Functions
}; };