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-------------------------------------------------------------------------------
11License
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
27Application
28 surfaceOrient
29
30Group
31 grpSurfaceUtilities
32
33Description
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
43using namespace Foam;
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47
48int main(int argc, char *argv[])
49{
50 argList::addNote
51 (
52 "Set face normals consistent with a user-provided 'outside' point"
53 );
54
55 argList::noParallel();
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
60 argList::addBoolOption
61 (
62 "inside",
63 "Treat provided point as being inside"
64 );
65 argList::addBoolOption
66 (
67 "usePierceTest",
68 "Determine orientation by counting number of intersections"
69 );
70 argList::addOption
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// ************************************************************************* //
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:124
T get(const label index) const
Get a value from the argument at index.
Definition: argListI.H:278
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:178
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
Definition: argListI.H:307
A class for handling file names.
Definition: fileName.H:76
Helper class to search on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:79
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
Foam::argList args(argc, argv)