surfaceFeatureEdges.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  Finds feature edges and corners of a triangulated surface
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "IFstream.H"
31 #include "fileName.H"
32 #include "triSurf.H"
33 #include "OFstream.H"
34 #include "OSspecific.H"
35 #include "demandDrivenData.H"
36 #include <cstdlib>
37 #include <sstream>
38 
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // Main program:
44 using namespace Foam;
45 
46 int main(int argc, char *argv[])
47 {
49  argList::validArgs.clear();
50  argList::validArgs.append("input surface file");
51  argList::validArgs.append("output surface file");
52  argList::validOptions.insert("angle", "scalar");
53  argList args(argc, argv);
54 
55  fileName inFileName(args.args()[1]);
56  fileName outFileName(args.args()[2]);
57 
58  if (outFileName == inFileName)
59  {
61  << "Output file " << outFileName
62  << " would overwrite the input file."
63  << exit(FatalError);
64  }
65 
66  scalar tol(45.0);
67  if( args.options().found("angle") )
68  {
69  const scalar ang = readScalar(IStringStream(args.options()["angle"])());
70  tol = ang;
71  }
72  else
73  {
74  Info << "Using 45 deg as default angle!" << endl;
75  }
76 
77  triSurf originalSurface(inFileName);
78 
79  triSurfaceDetectFeatureEdges edgeDetector(originalSurface, tol);
80  edgeDetector.detectFeatureEdges();
81 
82  if( outFileName.ext() == "fms" || outFileName.ext() == "FMS" )
83  {
84  Info << "Writing : " << outFileName << endl;
85  originalSurface.writeSurface(outFileName);
86  }
87  else
88  {
89  triSurfacePatchManipulator manipulator(originalSurface);
90  const triSurf* newSurfPtr = manipulator.surfaceWithPatches();
91 
92  Info << "Writing : " << outFileName << endl;
93  newSurfPtr->writeSurface(outFileName);
94 
95  deleteDemandDrivenData(newSurfPtr);
96  }
97 
98  Info << "End\n" << endl;
99 
100  return 0;
101 }
102 
103 
104 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
OSspecific.H
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
triSurf.H
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
triSurfacePatchManipulator.H
Foam::triSurfaceDetectFeatureEdges::detectFeatureEdges
void detectFeatureEdges()
store regions in a graph
Definition: triSurfaceDetectFeatureEdges.C:62
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
triSurfaceDetectFeatureEdges.H
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::triSurfaceDetectFeatureEdges
Definition: triSurfaceDetectFeatureEdges.H:50
OFstream.H
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::argList::options
const Foam::HashTable< string > & options() const
Return options.
Definition: argListI.H:90
Foam::argList::executable
const word & executable() const
Name of executable without the path.
Definition: argListI.H:30
Foam::Info
messageStream Info
argList.H
fileName.H
Foam::triSurfacePatchManipulator::surfaceWithPatches
const triSurf * surfaceWithPatches(IOdictionary *meshDictPtr=NULL, const word prefix="patch_", const bool forceOverwrite=false) const
store regions into subsets with a given prefix
Definition: triSurfacePatchManipulator.C:86
IFstream.H
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::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Foam::triSurfacePatchManipulator
Definition: triSurfacePatchManipulator.H:52
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
main
int main(int argc, char *argv[])
Definition: surfaceFeatureEdges.C:46
Foam::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::triSurf
Definition: triSurf.H:59