1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Creates surface patches from surface subsets
27 \*---------------------------------------------------------------------------*/
30 #include "objectRegistry.H"
33 #include "triSurfaceCopyParts.H"
34 #include "demandDrivenData.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 void exportFeatureEdges
43 const triSurf& origSurf,
44 const fileName& edgeFileName
47 OFstream file(edgeFileName);
49 const pointField& points = origSurf.points();
50 labelList newPointLabel(points.size(), -1);
53 const edgeLongList& featureEdges = origSurf.featureEdges();
54 forAll(featureEdges, feI)
56 const edge& e = featureEdges[feI];
58 if( newPointLabel[e[0]] == -1 )
59 newPointLabel[e[0]] = nPoints++;
60 if( newPointLabel[e[1]] == -1 )
61 newPointLabel[e[1]] = nPoints++;
64 pointField pCopy(nPoints);
65 forAll(newPointLabel, pI)
67 if( newPointLabel[pI] < 0 )
70 pCopy[newPointLabel[pI]] = points[pI];
74 file << "# vtk DataFile Version 3.0\n";
75 file << "vtk output\n";
77 file << "DATASET POLYDATA\n";
80 file << "POINTS " << pCopy.size() << " float\n";
83 const point& p = pCopy[pI];
84 file << p.x() << ' ' << p.y() << ' ' << p.z() << '\n';
87 file << "\nLINES " << featureEdges.size()
88 << ' ' << 3*featureEdges.size() << nl;
89 forAll(featureEdges, edgeI)
91 const edge& e = featureEdges[edgeI];
92 file << "2 " << newPointLabel[e[0]]
93 << token::SPACE << newPointLabel[e[1]] << nl;
100 "void exportFeatureEdges(const triSurf&, const fileName&)"
101 ) << "Writting of feature edges failed!" << exit(FatalError);
104 int main(int argc, char *argv[])
106 argList::noParallel();
107 argList::validArgs.clear();
109 argList::validArgs.append("input surface file");
110 argList::validArgs.append("output surface file");
111 argList::validOptions.insert("exportSubsets", "");
112 argList::validOptions.insert("exportFeatureEdges", "");
113 argList args(argc, argv);
115 fileName inFileName(args.args()[1]);
116 fileName outFileName(args.args()[2]);
118 fileName outFileNoExt = outFileName.lessExt();
119 fileName outExtension = outFileName.ext();
121 Info << "Out file no ext " << outFileNoExt << endl;
122 Info << "Extension " << outExtension << endl;
124 //- read the inout surface
125 triSurf origSurf(inFileName);
127 //- write the surface in the requated format
128 origSurf.writeSurface(outFileName);
130 //- export surface subsets as separate surface meshes
131 if( args.options().found("exportSubsets") )
133 DynList<label> subsetIDs;
134 origSurf.facetSubsetIndices(subsetIDs);
136 triSurfaceCopyParts copyParts(origSurf);
138 forAll(subsetIDs, subsetI)
140 //- get the name of the subset
142 wordList subsetName(1);
143 subsetName[0] = origSurf.facetSubsetName(subsetIDs[subsetI]);
145 //- create a surface mesh corresponding to the subset
146 copyParts.copySurface(subsetName, copySurf);
148 //- write the mesh on disk
149 fileName fName = outFileNoExt+"_facetSubset_"+subsetName[0];
150 fName += '.'+outExtension;
152 copySurf.writeSurface(fName);
156 if( args.options().found("exportFeatureEdges") )
158 fileName fName = outFileNoExt+"_featureEdges";
160 exportFeatureEdges(origSurf, fName);
163 Info << "End\n" << endl;
167 // ************************************************************************* //