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-2024 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 "MeshedSurfaces.H"
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 int main(int argc, char *argv[])
70 {
71  #include "removeCaseOptions.H"
72 
74  (
75  "Transforms a surface geometry "
76  "by translation, rotation and/or scaling.\n"
77  "The <transformations> are listed comma-separated in a string "
78  "and executed in sequence.\n\n"
79  "transformations:\n"
80  " translate=<vector> "
81  "translation by vector, e.g. (1 2 3)\n"
82  " rotate=(<n1> <n2>) "
83  "rotation from unit vector n1 to n2\n"
84  " Rx=<angle> "
85  "rotation by given angle [deg], e.g. 90, about x-axis\n"
86  " Ry=<angle> "
87  "rotation by given angle [deg] about y-axis\n"
88  " Rz=<angle> "
89  "rotation by given angle [deg] about z-axis\n"
90  " Ra=<axis vector> <angle> "
91  "rotation by given angle [deg] about specified axis\n"
92  " scale=<vector> "
93  "scale by factors from vector in x, y, z directions,\n"
94  " "
95  "e.g. (0.001 0.001 0.001) to scale from mm to m\n\n"
96  "example:\n"
97  " surfaceTransformPoints \"translate=(1.2 0 0), Rx=90\" "
98  "in.stl out.obj"
99  );
100 
102  argList::validArgs.append("transformations");
103  argList::validArgs.append("surface file");
104  argList::validArgs.append("output surface file");
105 
106  argList args(argc, argv);
107 
108  const string transformationString(args[1]);
109  const fileName surfFileName(args[2]);
110  const fileName outFileName(args[3]);
111 
112  #include "createTransforms.H"
113 
114  Info<< "Reading surf from " << surfFileName << " ..." << nl
115  << "Writing surf to " << outFileName << " ..." << endl;
116 
117  meshedSurface surf1(surfFileName);
118  pointField points(surf1.points());
120  surf1.setPoints(points);
121  surf1.write(outFileName);
122 
123  Info<< "End\n" << endl;
124 
125  return 0;
126 }
127 
128 
129 // ************************************************************************* //
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:257
messageStream Info
static const char nl
Definition: Ostream.H:266
Foam::argList args(argc, argv)