FMSToSurface.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh 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.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Creates surface patches from surface subsets
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "triSurf.H"
31 #include "triSurfaceCopyParts.H"
32 #include "demandDrivenData.H"
33 #include "OFstream.H"
34 
35 using namespace Foam;
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
40 (
41  const triSurf& origSurf,
42  const fileName& edgeFileName
43 )
44 {
45  OFstream file(edgeFileName);
46 
47  const pointField& points = origSurf.points();
48  labelList newPointLabel(points.size(), -1);
49  label nPoints(0);
50 
51  const edgeLongList& featureEdges = origSurf.featureEdges();
52  forAll(featureEdges, feI)
53  {
54  const edge& e = featureEdges[feI];
55 
56  if( newPointLabel[e[0]] == -1 )
57  newPointLabel[e[0]] = nPoints++;
58  if( newPointLabel[e[1]] == -1 )
59  newPointLabel[e[1]] = nPoints++;
60  }
61 
62  pointField pCopy(nPoints);
63  forAll(newPointLabel, pI)
64  {
65  if( newPointLabel[pI] < 0 )
66  continue;
67 
68  pCopy[newPointLabel[pI]] = points[pI];
69  }
70 
71  //- write the header
72  file << "# vtk DataFile Version 3.0\n";
73  file << "vtk output\n";
74  file << "ASCII\n";
75  file << "DATASET POLYDATA\n";
76 
77  //- write points
78  file << "POINTS " << pCopy.size() << " float\n";
79  forAll(pCopy, pI)
80  {
81  const point& p = pCopy[pI];
82  file << p.x() << ' ' << p.y() << ' ' << p.z() << '\n';
83  }
84 
85  file << "\nLINES " << featureEdges.size()
86  << ' ' << 3*featureEdges.size() << nl;
87  forAll(featureEdges, edgeI)
88  {
89  const edge& e = featureEdges[edgeI];
90  file << "2 " << newPointLabel[e[0]]
91  << token::SPACE << newPointLabel[e[1]] << nl;
92  }
93  file << nl;
94 
95  if( !file )
97  (
98  "void exportFeatureEdges(const triSurf&, const fileName&)"
99  ) << "Writting of feature edges failed!" << exit(FatalError);
100 }
101 
102 int main(int argc, char *argv[])
103 {
105  argList::validArgs.clear();
106 
107  argList::validArgs.append("input surface file");
108  argList::validArgs.append("output surface file");
109  argList::validOptions.insert("exportSubsets", "");
110  argList::validOptions.insert("exportFeatureEdges", "");
111  argList args(argc, argv);
112 
113  fileName inFileName(args.args()[1]);
114  fileName outFileName(args.args()[2]);
115 
116  fileName outFileNoExt = outFileName.lessExt();
117  fileName outExtension = outFileName.ext();
118 
119  Info << "Out file no ext " << outFileNoExt << endl;
120  Info << "Extension " << outExtension << endl;
121 
122  //- read the inout surface
123  triSurf origSurf(inFileName);
124 
125  //- write the surface in the requated format
126  origSurf.writeSurface(outFileName);
127 
128  //- export surface subsets as separate surface meshes
129  if( args.options().found("exportSubsets") )
130  {
131  DynList<label> subsetIDs;
132  origSurf.facetSubsetIndices(subsetIDs);
133 
134  triSurfaceCopyParts copyParts(origSurf);
135 
136  forAll(subsetIDs, subsetI)
137  {
138  //- get the name of the subset
139  triSurf copySurf;
140  wordList subsetName(1);
141  subsetName[0] = origSurf.facetSubsetName(subsetIDs[subsetI]);
142 
143  //- create a surface mesh corresponding to the subset
144  copyParts.copySurface(subsetName, copySurf);
145 
146  //- write the mesh on disk
147  fileName fName = outFileNoExt+"_facetSubset_"+subsetName[0];
148  fName += '.'+outExtension;
149 
150  copySurf.writeSurface(fName);
151  }
152  }
153 
154  if( args.options().found("exportFeatureEdges") )
155  {
156  fileName fName = outFileNoExt+"_featureEdges";
157  fName += ".vtk";
158  exportFeatureEdges(origSurf, fName);
159  }
160 
161  Info << "End\n" << endl;
162  return 0;
163 }
164 
165 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
triSurf.H
p
p
Definition: pEqn.H:62
Foam::argList::args
const stringList & args() const
Return arguments.
Definition: argListI.H:66
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::triSurfPoints::points
const pointField & points() const
access to points
Definition: triSurfPointsI.H:44
Foam::edge
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
Definition: edge.H:58
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:313
Foam::triSurfFeatureEdges::featureEdges
const edgeLongList & featureEdges() const
access to feature edges
Definition: triSurfFeatureEdgesI.H:44
OFstream.H
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::argList::options
const Foam::HashTable< string > & options() const
Return options.
Definition: argListI.H:90
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
main
int main(int argc, char *argv[])
Definition: FMSToSurface.C:102
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
edgeLongList
This is a typedef for LongList<edge>
Foam::argList::validOptions
static HashTable< string > validOptions
A list of valid options.
Definition: argList.H:146
Foam::FatalError
error FatalError
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::DynList< label >
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
Foam::triSurfFacets::facetSubsetIndices
void facetSubsetIndices(DynList< label > &) const
Definition: triSurfFacetsI.H:105
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::triSurfaceCopyParts
Definition: triSurfaceCopyParts.H:49
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
Foam::triSurfFacets::facetSubsetName
word facetSubsetName(const label) const
Definition: triSurfFacets.C:135
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::triSurfaceCopyParts::copySurface
void copySurface(const wordList &, triSurf &) const
copies selected patches/subsets to an already created mesh
Definition: triSurfaceCopyParts.C:285
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
exportFeatureEdges
void exportFeatureEdges(const triSurf &origSurf, const fileName &edgeFileName)
Definition: FMSToSurface.C:40
Foam::triSurf
Definition: triSurf.H:59
triSurfaceCopyParts.H
Foam::token::SPACE
@ SPACE
Definition: token.H:95