OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceTransformPoints.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Description
00026     Transform (scale/rotate) a surface. Like transformPoints but then for
00027     surfaces.
00028 
00029     The rollPitchYaw option takes three angles (degrees):
00030     - roll (rotation about x) followed by
00031     - pitch (rotation about y) followed by
00032     - yaw (rotation about z)
00033 
00034     The yawPitchRoll does yaw followed by pitch followed by roll.
00035 
00036 \*---------------------------------------------------------------------------*/
00037 
00038 #include "triSurface.H"
00039 #include "argList.H"
00040 #include "OFstream.H"
00041 #include "IFstream.H"
00042 #include "boundBox.H"
00043 #include "transformField.H"
00044 #include "Pair.H"
00045 #include "quaternion.H"
00046 
00047 using namespace Foam;
00048 using namespace Foam::mathematicalConstant;
00049 
00050 
00051 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 // Main program:
00053 
00054 int main(int argc, char *argv[])
00055 {
00056     argList::noParallel();
00057     argList::validArgs.clear();
00058 
00059     argList::validArgs.append("surface file");
00060     argList::validArgs.append("output surface file");
00061     argList::validOptions.insert("translate", "vector");
00062     argList::validOptions.insert("rotate", "(vector vector)");
00063     argList::validOptions.insert("scale", "vector");
00064     argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
00065     argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
00066     argList args(argc, argv);
00067 
00068     fileName surfFileName(args.additionalArgs()[0]);
00069 
00070     Info<< "Reading surf from " << surfFileName << " ..." << endl;
00071 
00072     fileName outFileName(args.additionalArgs()[1]);
00073 
00074     Info<< "Writing surf to " << outFileName << " ..." << endl;
00075 
00076 
00077     if (args.options().empty())
00078     {
00079         FatalErrorIn(args.executable())
00080             << "No options supplied, please use one or more of "
00081                "-translate, -rotate or -scale options."
00082             << exit(FatalError);
00083     }
00084 
00085     triSurface surf1(surfFileName);
00086 
00087     pointField points(surf1.points());
00088 
00089     if (args.optionFound("translate"))
00090     {
00091         vector transVector(args.optionLookup("translate")());
00092 
00093         Info<< "Translating points by " << transVector << endl;
00094 
00095         points += transVector;
00096     }
00097 
00098     if (args.optionFound("rotate"))
00099     {
00100         Pair<vector> n1n2(args.optionLookup("rotate")());
00101         n1n2[0] /= mag(n1n2[0]);
00102         n1n2[1] /= mag(n1n2[1]);
00103 
00104         tensor T = rotationTensor(n1n2[0], n1n2[1]);
00105 
00106         Info<< "Rotating points by " << T << endl;
00107 
00108         points = transform(T, points);
00109     }
00110     else if (args.optionFound("rollPitchYaw"))
00111     {
00112         vector v(args.optionLookup("rollPitchYaw")());
00113 
00114         Info<< "Rotating points by" << nl
00115             << "    roll  " << v.x() << nl
00116             << "    pitch " << v.y() << nl
00117             << "    yaw   " << v.z() << endl;
00118 
00119 
00120         // Convert to radians
00121         v *= pi/180.0;
00122 
00123         quaternion R(v.x(), v.y(), v.z());
00124 
00125         Info<< "Rotating points by quaternion " << R << endl;
00126         points = transform(R, points);
00127     }
00128     else if (args.optionFound("yawPitchRoll"))
00129     {
00130         vector v(args.optionLookup("yawPitchRoll")());
00131 
00132         Info<< "Rotating points by" << nl
00133             << "    yaw   " << v.x() << nl
00134             << "    pitch " << v.y() << nl
00135             << "    roll  " << v.z() << endl;
00136 
00137 
00138         // Convert to radians
00139         v *= pi/180.0;
00140 
00141         scalar yaw = v.x();
00142         scalar pitch = v.y();
00143         scalar roll = v.z();
00144 
00145         quaternion R = quaternion(vector(0, 0, 1), yaw);
00146         R *= quaternion(vector(0, 1, 0), pitch);
00147         R *= quaternion(vector(1, 0, 0), roll);
00148 
00149         Info<< "Rotating points by quaternion " << R << endl;
00150         points = transform(R, points);
00151     }
00152 
00153     if (args.optionFound("scale"))
00154     {
00155         vector scaleVector(args.optionLookup("scale")());
00156 
00157         Info<< "Scaling points by " << scaleVector << endl;
00158 
00159         points.replace(vector::X, scaleVector.x()*points.component(vector::X));
00160         points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
00161         points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
00162     }
00163 
00164     triSurface surf2(surf1, surf1.patches(), points);
00165 
00166     surf2.write(outFileName);
00167 
00168     Info << "End\n" << endl;
00169 
00170     return 0;
00171 }
00172 
00173 
00174 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd