surfaceTransformPoints.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-2021 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  surfaceTransformPoints
26 
27 Description
28  Transform (translate, rotate, scale) a surface.
29 
30 Usage
31  \b surfaceTransformPoints "<transformations>" <input> <output>
32  Supported transformations:
33  - \par translate=<translation vector>
34  Translational transformation by given vector
35  - \par rotate=(<n1 vector> <n2 vector>)
36  Rotational transformation from unit vector n1 to n2
37  - \par Rx=<angle [deg] about x-axis>
38  Rotational transformation by given angle about x-axis
39  - \par Ry=<angle [deg] about y-axis>
40  Rotational transformation by given angle about y-axis
41  - \par Rz=<angle [deg] about z-axis>
42  Rotational transformation by given angle about z-axis
43  - \par Ra=<axis vector> <angle [deg] about axis>
44  Rotational transformation by given angle about given axis
45  - \par scale=<x-y-z scaling vector>
46  Anisotropic scaling by the given vector in the x, y, z
47  coordinate directions
48 
49  Example usage:
50  surfaceTransformPoints \
51  "translate=(-0.586 0 -0.156), \
52  Ry=3.485, \
53  translate=(0.586 0 0.156)" \
54  constant/geometry/w3_orig.stl constant/geometry/w3.stl
55 
56 See also
57  Foam::transformer
58  transformPoints
59 
60 \*---------------------------------------------------------------------------*/
61 
62 #include "argList.H"
63 #include "unitConversion.H"
64 #include "MeshedSurfaces.H"
65 
66 using namespace Foam;
67 
68 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 
70 int main(int argc, char *argv[])
71 {
72  #include "removeCaseOptions.H"
73 
75  (
76  "Transforms a surface geometry "
77  "by translation, rotation and/or scaling.\n"
78  "The <transformations> are listed comma-separated in a string "
79  "and executed in sequence.\n\n"
80  "transformations:\n"
81  " translate=<vector> "
82  "translation by vector, e.g. (1 2 3)\n"
83  " rotate=(<n1> <n2>) "
84  "rotation from unit vector n1 to n2\n"
85  " Rx=<angle> "
86  "rotation by given angle [deg], e.g. 90, about x-axis\n"
87  " Ry=<angle> "
88  "rotation by given angle [deg] about y-axis\n"
89  " Rz=<angle> "
90  "rotation by given angle [deg] about z-axis\n"
91  " Ra=<axis vector> <angle> "
92  "rotation by given angle [deg] about specified axis\n"
93  " scale=<vector> "
94  "scale by factors from vector in x, y, z directions,\n"
95  " "
96  "e.g. (0.001 0.001 0.001) to scale from mm to m\n\n"
97  "example:\n"
98  " surfaceTransformPoints \"translate=(1.2 0 0), Rx=90\" "
99  "in.stl out.obj"
100  );
101 
103  argList::validArgs.append("transformations");
104  argList::validArgs.append("surface file");
105  argList::validArgs.append("output surface file");
106 
107  argList args(argc, argv);
108 
109  const string transformationString(args[1]);
110  const fileName surfFileName(args[2]);
111  const fileName outFileName(args[3]);
112 
113  #include "createTransforms.H"
114 
115  Info<< "Reading surf from " << surfFileName << " ..." << nl
116  << "Writing surf to " << outFileName << " ..." << endl;
117 
118  meshedSurface surf1(surfFileName);
119  pointField points(surf1.points());
121  surf1.movePoints(points);
122  surf1.write(outFileName);
123 
124  Info<< "End\n" << endl;
125 
126  return 0;
127 }
128 
129 
130 // ************************************************************************* //
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 noParallel()
Remove the parallel options.
Definition: argList.C:175
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
A class for handling file names.
Definition: fileName.H:82
vector transformPosition(const vector &v) const
Transform the given position.
Definition: transformerI.H:153
transformer transforms
int main(int argc, char *argv[])
Definition: financialFoam.C:44
const pointField & points
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)
Unit conversion functions.