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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2013 OpenFOAM Foundation
9  Copyright (C) 2020-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Application
28  surfaceOrient
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
34  Set normal consistent with respect to a user provided 'outside' point.
35  If the -inside option is used the point is considered inside.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "argList.H"
40 #include "triSurfaceSearch.H"
41 #include "orientedSurface.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 
48 int main(int argc, char *argv[])
49 {
51  (
52  "Set face normals consistent with a user-provided 'outside' point"
53  );
54 
56  argList::addArgument("input", "The input surface file");
57  argList::addArgument("point", "The visible 'outside' point");
58  argList::addArgument("output", "The output surface file");
59 
61  (
62  "inside",
63  "Treat provided point as being inside"
64  );
66  (
67  "usePierceTest",
68  "Determine orientation by counting number of intersections"
69  );
71  (
72  "scale",
73  "factor",
74  "Input geometry scaling factor"
75  );
76 
77  argList args(argc, argv);
78 
79  const auto surfFileName = args.get<fileName>(1);
80  const auto visiblePoint = args.get<point>(2);
81  const auto outFileName = args.get<fileName>(3);
82 
83  const bool orientInside = args.found("inside");
84  const bool usePierceTest = args.found("usePierceTest");
85 
86  Info<< "Reading surface from " << surfFileName << nl
87  << "Orienting surface such that visiblePoint " << visiblePoint
88  << " is ";
89 
90  if (orientInside)
91  {
92  Info<< "inside" << endl;
93  }
94  else
95  {
96  Info<< "outside" << endl;
97  }
98 
99  const scalar scaling = args.getOrDefault<scalar>("scale", -1);
100  if (scaling > 0)
101  {
102  Info<< "Input scaling: " << scaling << nl;
103  }
104 
105  // Load surface
106  triSurface surf(surfFileName, scaling);
107 
108  bool anyFlipped = false;
109 
110  if (usePierceTest)
111  {
112  triSurfaceSearch surfSearches(surf);
113 
114  anyFlipped = orientedSurface::orient
115  (
116  surf,
117  surfSearches,
118  visiblePoint,
119  !orientInside
120  );
121  }
122  else
123  {
124  anyFlipped = orientedSurface::orient
125  (
126  surf,
127  visiblePoint,
128  !orientInside
129  );
130  }
131 
132  if (anyFlipped)
133  {
134  Info<< "Flipped orientation of (part of) surface." << nl;
135  }
136  else
137  {
138  Info<< "Did not flip orientation of any triangle of surface." << nl;
139  }
140 
141  Info<< "Writing new surface to " << outFileName << endl;
142 
143  surf.write(outFileName);
144 
145  Info<< "End\n" << endl;
146 
147  return 0;
148 }
149 
150 
151 // ************************************************************************* //
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
A class for handling file names.
Definition: fileName.H:72
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static bool orient(triSurface &, const point &, const bool orientOutside)
Flip faces such that normals are consistent with point:
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:300
Helper class to search on triSurface.
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:118
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition: argList.C:385
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:271
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:351
messageStream Info
Information stream (stdout output on master, null elsewhere)
Triangulated surface description with patch information.
Definition: triSurface.H:71
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.