2014-11-09 00:10:28 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
|
|
|
\\ / O peration | Version: 3.2
|
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2014-11-09 00:10:28 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2015-05-17 13:32:07 +00:00
|
|
|
This file is part of foam-extend.
|
2014-11-09 00:10:28 +00:00
|
|
|
|
2015-05-17 13:32:07 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2014-11-09 00:10:28 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2015-05-17 13:32:07 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2014-11-09 00:10:28 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2015-05-17 13:32:07 +00:00
|
|
|
foam-extend 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.
|
2014-11-09 00:10:28 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2015-05-17 13:32:07 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-09 00:10:28 +00:00
|
|
|
|
|
|
|
Description
|
|
|
|
Creates surface patches from surface subsets
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "argList.H"
|
2015-08-06 22:56:00 +00:00
|
|
|
#include "objectRegistry.H"
|
2015-06-17 13:53:59 +00:00
|
|
|
#include "foamTime.H"
|
2014-11-09 00:10:28 +00:00
|
|
|
#include "triSurf.H"
|
|
|
|
#include "triSurfaceCopyParts.H"
|
|
|
|
#include "demandDrivenData.H"
|
|
|
|
#include "OFstream.H"
|
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
void exportFeatureEdges
|
|
|
|
(
|
|
|
|
const triSurf& origSurf,
|
|
|
|
const fileName& edgeFileName
|
|
|
|
)
|
|
|
|
{
|
|
|
|
OFstream file(edgeFileName);
|
|
|
|
|
|
|
|
const pointField& points = origSurf.points();
|
|
|
|
labelList newPointLabel(points.size(), -1);
|
|
|
|
label nPoints(0);
|
|
|
|
|
|
|
|
const edgeLongList& featureEdges = origSurf.featureEdges();
|
|
|
|
forAll(featureEdges, feI)
|
|
|
|
{
|
|
|
|
const edge& e = featureEdges[feI];
|
|
|
|
|
|
|
|
if( newPointLabel[e[0]] == -1 )
|
|
|
|
newPointLabel[e[0]] = nPoints++;
|
|
|
|
if( newPointLabel[e[1]] == -1 )
|
|
|
|
newPointLabel[e[1]] = nPoints++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pointField pCopy(nPoints);
|
|
|
|
forAll(newPointLabel, pI)
|
|
|
|
{
|
|
|
|
if( newPointLabel[pI] < 0 )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
pCopy[newPointLabel[pI]] = points[pI];
|
|
|
|
}
|
|
|
|
|
|
|
|
//- write the header
|
|
|
|
file << "# vtk DataFile Version 3.0\n";
|
|
|
|
file << "vtk output\n";
|
|
|
|
file << "ASCII\n";
|
|
|
|
file << "DATASET POLYDATA\n";
|
|
|
|
|
|
|
|
//- write points
|
|
|
|
file << "POINTS " << pCopy.size() << " float\n";
|
|
|
|
forAll(pCopy, pI)
|
|
|
|
{
|
|
|
|
const point& p = pCopy[pI];
|
|
|
|
file << p.x() << ' ' << p.y() << ' ' << p.z() << '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
file << "\nLINES " << featureEdges.size()
|
|
|
|
<< ' ' << 3*featureEdges.size() << nl;
|
|
|
|
forAll(featureEdges, edgeI)
|
|
|
|
{
|
|
|
|
const edge& e = featureEdges[edgeI];
|
|
|
|
file << "2 " << newPointLabel[e[0]]
|
|
|
|
<< token::SPACE << newPointLabel[e[1]] << nl;
|
|
|
|
}
|
|
|
|
file << nl;
|
|
|
|
|
|
|
|
if( !file )
|
|
|
|
FatalErrorIn
|
|
|
|
(
|
|
|
|
"void exportFeatureEdges(const triSurf&, const fileName&)"
|
|
|
|
) << "Writting of feature edges failed!" << exit(FatalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
argList::noParallel();
|
|
|
|
argList::validArgs.clear();
|
|
|
|
|
|
|
|
argList::validArgs.append("input surface file");
|
|
|
|
argList::validArgs.append("output surface file");
|
|
|
|
argList::validOptions.insert("exportSubsets", "");
|
|
|
|
argList::validOptions.insert("exportFeatureEdges", "");
|
|
|
|
argList args(argc, argv);
|
|
|
|
|
|
|
|
fileName inFileName(args.args()[1]);
|
|
|
|
fileName outFileName(args.args()[2]);
|
|
|
|
|
|
|
|
fileName outFileNoExt = outFileName.lessExt();
|
|
|
|
fileName outExtension = outFileName.ext();
|
|
|
|
|
|
|
|
Info << "Out file no ext " << outFileNoExt << endl;
|
|
|
|
Info << "Extension " << outExtension << endl;
|
|
|
|
|
|
|
|
//- read the inout surface
|
|
|
|
triSurf origSurf(inFileName);
|
|
|
|
|
|
|
|
//- write the surface in the requated format
|
|
|
|
origSurf.writeSurface(outFileName);
|
|
|
|
|
|
|
|
//- export surface subsets as separate surface meshes
|
|
|
|
if( args.options().found("exportSubsets") )
|
|
|
|
{
|
|
|
|
DynList<label> subsetIDs;
|
|
|
|
origSurf.facetSubsetIndices(subsetIDs);
|
|
|
|
|
|
|
|
triSurfaceCopyParts copyParts(origSurf);
|
|
|
|
|
|
|
|
forAll(subsetIDs, subsetI)
|
|
|
|
{
|
|
|
|
//- get the name of the subset
|
|
|
|
triSurf copySurf;
|
|
|
|
wordList subsetName(1);
|
|
|
|
subsetName[0] = origSurf.facetSubsetName(subsetIDs[subsetI]);
|
|
|
|
|
|
|
|
//- create a surface mesh corresponding to the subset
|
|
|
|
copyParts.copySurface(subsetName, copySurf);
|
|
|
|
|
|
|
|
//- write the mesh on disk
|
|
|
|
fileName fName = outFileNoExt+"_facetSubset_"+subsetName[0];
|
|
|
|
fName += '.'+outExtension;
|
|
|
|
|
|
|
|
copySurf.writeSurface(fName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( args.options().found("exportFeatureEdges") )
|
|
|
|
{
|
|
|
|
fileName fName = outFileNoExt+"_featureEdges";
|
|
|
|
fName += ".vtk";
|
|
|
|
exportFeatureEdges(origSurf, fName);
|
|
|
|
}
|
|
|
|
|
|
|
|
Info << "End\n" << endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ************************************************************************* //
|