2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2018-05-29 07:35:20 +00:00
|
|
|
\\ / O peration | Version: 4.1
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
General Public License for more details.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Description
|
|
|
|
Transform (scale/rotate) a surface. Like transformPoints but then for
|
|
|
|
surfaces.
|
|
|
|
|
|
|
|
The rollPitchYaw option takes three angles (degrees):
|
|
|
|
- roll (rotation about x) followed by
|
|
|
|
- pitch (rotation about y) followed by
|
|
|
|
- yaw (rotation about z)
|
|
|
|
|
2016-03-14 11:22:06 +00:00
|
|
|
or -rotateAlongVector (vector and angle in degrees)
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
The yawPitchRoll does yaw followed by pitch followed by roll.
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "triSurface.H"
|
|
|
|
#include "argList.H"
|
|
|
|
#include "OFstream.H"
|
|
|
|
#include "IFstream.H"
|
|
|
|
#include "boundBox.H"
|
|
|
|
#include "transformField.H"
|
|
|
|
#include "Pair.H"
|
|
|
|
#include "quaternion.H"
|
2016-03-14 11:22:06 +00:00
|
|
|
#include "RodriguesRotation.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
using namespace Foam;
|
|
|
|
using namespace Foam::mathematicalConstant;
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
// Main program:
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
argList::noParallel();
|
|
|
|
argList::validArgs.clear();
|
|
|
|
|
|
|
|
argList::validArgs.append("surface file");
|
|
|
|
argList::validArgs.append("output surface file");
|
|
|
|
argList::validOptions.insert("translate", "vector");
|
|
|
|
argList::validOptions.insert("rotate", "(vector vector)");
|
2016-03-14 11:22:06 +00:00
|
|
|
argList::validOptions.insert("rotateAlongVector", "(vector angleInDegree)");
|
2010-05-12 13:27:55 +00:00
|
|
|
argList::validOptions.insert("scale", "vector");
|
|
|
|
argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
|
|
|
|
argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
|
|
|
|
argList args(argc, argv);
|
|
|
|
|
|
|
|
fileName surfFileName(args.additionalArgs()[0]);
|
|
|
|
|
|
|
|
Info<< "Reading surf from " << surfFileName << " ..." << endl;
|
|
|
|
|
|
|
|
fileName outFileName(args.additionalArgs()[1]);
|
|
|
|
|
|
|
|
Info<< "Writing surf to " << outFileName << " ..." << endl;
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.options().empty())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
FatalErrorIn(args.executable())
|
|
|
|
<< "No options supplied, please use one or more of "
|
|
|
|
"-translate, -rotate or -scale options."
|
|
|
|
<< exit(FatalError);
|
|
|
|
}
|
|
|
|
|
|
|
|
triSurface surf1(surfFileName);
|
|
|
|
|
|
|
|
pointField points(surf1.points());
|
|
|
|
|
2016-03-14 11:22:06 +00:00
|
|
|
// Translation options
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("translate"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
vector transVector(args.optionLookup("translate")());
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Translating points by " << transVector << endl;
|
|
|
|
|
|
|
|
points += transVector;
|
|
|
|
}
|
|
|
|
|
2016-03-14 11:22:06 +00:00
|
|
|
// Rotation options
|
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("rotate"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
Pair<vector> n1n2(args.optionLookup("rotate")());
|
2010-05-12 13:27:55 +00:00
|
|
|
n1n2[0] /= mag(n1n2[0]);
|
|
|
|
n1n2[1] /= mag(n1n2[1]);
|
|
|
|
|
|
|
|
tensor T = rotationTensor(n1n2[0], n1n2[1]);
|
|
|
|
|
|
|
|
Info<< "Rotating points by " << T << endl;
|
|
|
|
|
|
|
|
points = transform(T, points);
|
|
|
|
}
|
2010-08-25 21:42:57 +00:00
|
|
|
else if (args.optionFound("rollPitchYaw"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
vector v(args.optionLookup("rollPitchYaw")());
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Rotating points by" << nl
|
|
|
|
<< " roll " << v.x() << nl
|
|
|
|
<< " pitch " << v.y() << nl
|
|
|
|
<< " yaw " << v.z() << endl;
|
|
|
|
|
|
|
|
|
|
|
|
// Convert to radians
|
|
|
|
v *= pi/180.0;
|
|
|
|
|
|
|
|
quaternion R(v.x(), v.y(), v.z());
|
|
|
|
|
|
|
|
Info<< "Rotating points by quaternion " << R << endl;
|
|
|
|
points = transform(R, points);
|
|
|
|
}
|
2010-08-25 21:42:57 +00:00
|
|
|
else if (args.optionFound("yawPitchRoll"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
vector v(args.optionLookup("yawPitchRoll")());
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Rotating points by" << nl
|
|
|
|
<< " yaw " << v.x() << nl
|
|
|
|
<< " pitch " << v.y() << nl
|
|
|
|
<< " roll " << v.z() << endl;
|
|
|
|
|
|
|
|
// Convert to radians
|
|
|
|
v *= pi/180.0;
|
|
|
|
|
|
|
|
scalar yaw = v.x();
|
|
|
|
scalar pitch = v.y();
|
|
|
|
scalar roll = v.z();
|
|
|
|
|
|
|
|
quaternion R = quaternion(vector(0, 0, 1), yaw);
|
|
|
|
R *= quaternion(vector(0, 1, 0), pitch);
|
|
|
|
R *= quaternion(vector(1, 0, 0), roll);
|
|
|
|
|
|
|
|
Info<< "Rotating points by quaternion " << R << endl;
|
|
|
|
points = transform(R, points);
|
|
|
|
}
|
2016-03-14 11:22:06 +00:00
|
|
|
else if (args.optionFound("rotateAlongVector"))
|
|
|
|
{
|
|
|
|
vector rotationAxis;
|
|
|
|
scalar rotationAngle;
|
|
|
|
|
|
|
|
args.optionLookup("rotateAlongVector")()
|
|
|
|
>> rotationAxis
|
|
|
|
>> rotationAngle;
|
|
|
|
|
|
|
|
tensor T = RodriguesRotation(rotationAxis, rotationAngle);
|
|
|
|
|
|
|
|
Info << "Rotating points by " << T << endl;
|
|
|
|
points = transform(T, points);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Scale options
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2010-08-25 21:42:57 +00:00
|
|
|
if (args.optionFound("scale"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2010-08-25 21:42:57 +00:00
|
|
|
vector scaleVector(args.optionLookup("scale")());
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Info<< "Scaling points by " << scaleVector << endl;
|
|
|
|
|
|
|
|
points.replace(vector::X, scaleVector.x()*points.component(vector::X));
|
|
|
|
points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
|
|
|
|
points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
|
|
|
|
}
|
|
|
|
|
|
|
|
triSurface surf2(surf1, surf1.patches(), points);
|
|
|
|
|
|
|
|
surf2.write(outFileName);
|
|
|
|
|
|
|
|
Info << "End\n" << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|