surfaceOrient.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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 {
44  #include "removeCaseOptions.H"
45 
47  (
48  "set face normals consistent with a user-provided 'outside' point"
49  );
50 
51  argList::validArgs.append("surface file");
52  argList::validArgs.append("output surface file");
53  argList::validArgs.append("visiblePoint");
55  (
56  "inside",
57  "treat provided point as being inside"
58  );
60  (
61  "usePierceTest",
62  "determine orientation by counting number of intersections"
63  );
64 
65  argList args(argc, argv);
66 
67  const fileName surfFileName = args[1];
68  const fileName outFileName = args[2];
69  const point visiblePoint = args.argRead<point>(3);
70 
71  const bool orientInside = args.optionFound("inside");
72  const bool usePierceTest = args.optionFound("usePierceTest");
73 
74  Info<< "Reading surface from " << surfFileName << nl
75  << "Orienting surface such that visiblePoint " << visiblePoint
76  << " is ";
77 
78  if (orientInside)
79  {
80  Info<< "inside" << endl;
81  }
82  else
83  {
84  Info<< "outside" << endl;
85  }
86 
87 
88 
89  // Load surface
90  triSurface surf(surfFileName);
91 
92 
93  bool anyFlipped = false;
94 
95  if (usePierceTest)
96  {
97  triSurfaceSearch surfSearches(surf);
98 
99  anyFlipped = orientedSurface::orient
100  (
101  surf,
102  surfSearches,
103  visiblePoint,
104  !orientInside
105  );
106  }
107  else
108  {
109  anyFlipped = orientedSurface::orient
110  (
111  surf,
112  visiblePoint,
113  !orientInside
114  );
115  }
116 
117  if (anyFlipped)
118  {
119  Info<< "Flipped orientation of (or part of) surface." << endl;
120  }
121  else
122  {
123  Info<< "Did not flip orientation of any triangle of surface." << endl;
124  }
125 
126  Info<< "Writing new surface to " << outFileName << endl;
127 
128  surf.write(outFileName);
129 
130  Info<< "End\n" << endl;
131 
132  return 0;
133 }
134 
135 
136 // ************************************************************************* //
virtual Ostream & write(const char)=0
Write character.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
T argRead(const label index) const
Read a value from the argument at index.
Definition: argListI.H:183
A class for handling file names.
Definition: fileName.H:82
static bool orient(triSurface &, const point &, const bool orientOutside)
Flip faces such that normals are consistent with point:
Helper class to search on triSurface.
Triangulated surface description with patch information.
Definition: triSurface.H:69
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
static const char nl
Definition: Ostream.H:260
Foam::argList args(argc, argv)