1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 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, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Transform (scale/rotate) a surface. Like transformPoints but then for
29 The rollPitchYaw option takes three angles (degrees):
30 - roll (rotation about x) followed by
31 - pitch (rotation about y) followed by
32 - yaw (rotation about z)
34 The yawPitchRoll does yaw followed by pitch followed by roll.
36 \*---------------------------------------------------------------------------*/
38 #include "triSurface.H"
43 #include "transformField.H"
45 #include "quaternion.H"
48 using namespace Foam::mathematicalConstant;
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 int main(int argc, char *argv[])
56 argList::noParallel();
57 argList::validArgs.clear();
59 argList::validArgs.append("surface file");
60 argList::validArgs.append("output surface file");
61 argList::validOptions.insert("translate", "vector");
62 argList::validOptions.insert("rotate", "(vector vector)");
63 argList::validOptions.insert("scale", "vector");
64 argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
65 argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
66 argList args(argc, argv);
68 fileName surfFileName(args.additionalArgs()[0]);
70 Info<< "Reading surf from " << surfFileName << " ..." << endl;
72 fileName outFileName(args.additionalArgs()[1]);
74 Info<< "Writing surf to " << outFileName << " ..." << endl;
77 if (args.options().empty())
79 FatalErrorIn(args.executable())
80 << "No options supplied, please use one or more of "
81 "-translate, -rotate or -scale options."
85 triSurface surf1(surfFileName);
87 pointField points(surf1.points());
89 if (args.optionFound("translate"))
91 vector transVector(args.optionLookup("translate")());
93 Info<< "Translating points by " << transVector << endl;
95 points += transVector;
98 if (args.optionFound("rotate"))
100 Pair<vector> n1n2(args.optionLookup("rotate")());
101 n1n2[0] /= mag(n1n2[0]);
102 n1n2[1] /= mag(n1n2[1]);
104 tensor T = rotationTensor(n1n2[0], n1n2[1]);
106 Info<< "Rotating points by " << T << endl;
108 points = transform(T, points);
110 else if (args.optionFound("rollPitchYaw"))
112 vector v(args.optionLookup("rollPitchYaw")());
114 Info<< "Rotating points by" << nl
115 << " roll " << v.x() << nl
116 << " pitch " << v.y() << nl
117 << " yaw " << v.z() << endl;
120 // Convert to radians
123 quaternion R(v.x(), v.y(), v.z());
125 Info<< "Rotating points by quaternion " << R << endl;
126 points = transform(R, points);
128 else if (args.optionFound("yawPitchRoll"))
130 vector v(args.optionLookup("yawPitchRoll")());
132 Info<< "Rotating points by" << nl
133 << " yaw " << v.x() << nl
134 << " pitch " << v.y() << nl
135 << " roll " << v.z() << endl;
138 // Convert to radians
142 scalar pitch = v.y();
145 quaternion R = quaternion(vector(0, 0, 1), yaw);
146 R *= quaternion(vector(0, 1, 0), pitch);
147 R *= quaternion(vector(1, 0, 0), roll);
149 Info<< "Rotating points by quaternion " << R << endl;
150 points = transform(R, points);
153 if (args.optionFound("scale"))
155 vector scaleVector(args.optionLookup("scale")());
157 Info<< "Scaling points by " << scaleVector << endl;
159 points.replace(vector::X, scaleVector.x()*points.component(vector::X));
160 points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
161 points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
164 triSurface surf2(surf1, surf1.patches(), points);
166 surf2.write(outFileName);
168 Info << "End\n" << endl;
174 // ************************************************************************* //