1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
25 Transform (scale/rotate) a surface.
26 Like transformPoints but for surfaces.
28 The rollPitchYaw option takes three angles (degrees):
29 - roll (rotation about x) followed by
30 - pitch (rotation about y) followed by
31 - yaw (rotation about z)
33 The yawPitchRoll does yaw followed by pitch followed by roll.
35 \*---------------------------------------------------------------------------*/
41 #include "transformField.H"
43 #include "quaternion.H"
44 #include "mathematicalConstants.H"
46 #include "MeshedSurfaces.H"
49 using namespace Foam::constant::mathematical;
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 int main(int argc, char *argv[])
59 "Transform (scale/rotate) a surface. "
60 "Like transformPoints but for surfaces."
62 argList::noParallel();
63 argList::validArgs.append("surfaceFile");
64 argList::validArgs.append("output surfaceFile");
69 "translate by the specified <vector> - eg, '(1 0 0)'"
75 "transform in terms of a rotation between <vectorA> and <vectorB> "
76 "- eg, '( (1 0 0) (0 0 1) )'"
82 "scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
83 "uniform [mm] to [m] scaling"
89 "transform in terms of '( roll pitch yaw )' in degrees"
95 "transform in terms of '( yaw pitch roll )' in degrees"
97 argList args(argc, argv);
99 const fileName surfFileName = args[1];
100 const fileName outFileName = args[2];
102 Info<< "Reading surf from " << surfFileName << " ..." << nl
103 << "Writing surf to " << outFileName << " ..." << endl;
105 if (args.options().empty())
107 FatalErrorIn(args.executable())
108 << "No options supplied, please use one or more of "
109 "-translate, -rotate or -scale options."
113 meshedSurface surf1(surfFileName);
115 pointField points(surf1.points());
118 if (args.optionReadIfPresent("translate", v))
120 Info<< "Translating points by " << v << endl;
125 if (args.optionFound("rotate"))
129 args.optionLookup("rotate")()
131 n1n2[0] /= mag(n1n2[0]);
132 n1n2[1] /= mag(n1n2[1]);
134 tensor T = rotationTensor(n1n2[0], n1n2[1]);
136 Info<< "Rotating points by " << T << endl;
138 points = transform(T, points);
140 else if (args.optionReadIfPresent("rollPitchYaw", v))
142 Info<< "Rotating points by" << nl
143 << " roll " << v.x() << nl
144 << " pitch " << v.y() << nl
145 << " yaw " << v.z() << nl;
147 // Convert to radians
150 quaternion R(v.x(), v.y(), v.z());
152 Info<< "Rotating points by quaternion " << R << endl;
153 points = transform(R, points);
155 else if (args.optionReadIfPresent("yawPitchRoll", v))
157 Info<< "Rotating points by" << nl
158 << " yaw " << v.x() << nl
159 << " pitch " << v.y() << nl
160 << " roll " << v.z() << nl;
163 // Convert to radians
167 scalar pitch = v.y();
170 quaternion R = quaternion(vector(0, 0, 1), yaw);
171 R *= quaternion(vector(0, 1, 0), pitch);
172 R *= quaternion(vector(1, 0, 0), roll);
174 Info<< "Rotating points by quaternion " << R << endl;
175 points = transform(R, points);
178 if (args.optionReadIfPresent("scale", v))
180 Info<< "Scaling points by " << v << endl;
182 points.replace(vector::X, v.x()*points.component(vector::X));
183 points.replace(vector::Y, v.y()*points.component(vector::Y));
184 points.replace(vector::Z, v.z()*points.component(vector::Z));
187 surf1.movePoints(points);
188 surf1.write(outFileName);
190 Info<< "End\n" << endl;
196 // ************************************************************************* //