surfaceOrient.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  surfaceOrient
26 
27 Description
28  Set normal consistent with respect to a user provided 'outside' point.
29  If the -inside option is used the point is considered inside.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "argList.H"
34 #include "triSurfaceSearch.H"
35 #include "orientedSurface.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 
42 int main(int argc, char *argv[])
43 {
45  (
46  "set face normals consistent with a user-provided 'outside' point"
47  );
48 
50  argList::validArgs.append("surfaceFile");
51  argList::validArgs.append("visiblePoint");
52  argList::validArgs.append("output surfaceFile");
54  (
55  "inside",
56  "treat provided point as being inside"
57  );
59  (
60  "usePierceTest",
61  "determine orientation by counting number of intersections"
62  );
63 
64  argList args(argc, argv);
65 
66  const fileName surfFileName = args[1];
67  const point visiblePoint = args.argRead<point>(2);
68  const fileName outFileName = args[3];
69 
70  const bool orientInside = args.optionFound("inside");
71  const bool usePierceTest = args.optionFound("usePierceTest");
72 
73  Info<< "Reading surface from " << surfFileName << nl
74  << "Orienting surface such that visiblePoint " << visiblePoint
75  << " is ";
76 
77  if (orientInside)
78  {
79  Info<< "inside" << endl;
80  }
81  else
82  {
83  Info<< "outside" << endl;
84  }
85 
86 
87 
88  // Load surface
89  triSurface surf(surfFileName);
90 
91 
92  bool anyFlipped = false;
93 
94  if (usePierceTest)
95  {
96  triSurfaceSearch surfSearches(surf);
97 
98  anyFlipped = orientedSurface::orient
99  (
100  surf,
101  surfSearches,
102  visiblePoint,
103  !orientInside
104  );
105  }
106  else
107  {
108  anyFlipped = orientedSurface::orient
109  (
110  surf,
111  visiblePoint,
112  !orientInside
113  );
114  }
115 
116  if (anyFlipped)
117  {
118  Info<< "Flipped orientation of (part of) surface." << endl;
119  }
120  else
121  {
122  Info<< "Did not flip orientation of any triangle of surface." << endl;
123  }
124 
125  Info<< "Writing new surface to " << outFileName << endl;
126 
127  surf.write(outFileName);
128 
129  Info<< "End\n" << endl;
130 
131  return 0;
132 }
133 
134 
135 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:69
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static bool orient(triSurface &, const point &, const bool orientOutside)
Flip faces such that normals are consistent with point:
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
Helper class to search on triSurface.
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
static const char nl
Definition: Ostream.H:262
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:177
messageStream Info
virtual Ostream & write(const token &)=0
Write next token to stream.
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:83
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
Triangulated surface description with patch information.
Definition: triSurface.H:65
Foam::argList args(argc, argv)
Namespace for OpenFOAM.