FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Application
00025     surfaceTransformPoints
00026 
00027 Description
00028     Transform (scale/rotate) a surface.
00029 
00030     Like transformPoints but then for surfaces. The rollPitchYaw option takes
00031     three angles (degrees):
00032     - roll (rotation about x) followed by
00033     - pitch (rotation about y) followed by
00034     - yaw (rotation about z)
00035 
00036     The yawPitchRoll does yaw followed by pitch followed by roll.
00037 
00038 Usage
00039 
00040     - surfaceTransformPoints [OPTIONS] <Foam surface file> <surface output file>
00041 
00042     @param <Foam surface file> \n
00043     @todo Detailed description of argument.
00044 
00045     @param <surface output file> \n
00046     @todo Detailed description of argument.
00047 
00048     @param -translate <vector>\n
00049     Translation vector.
00050 
00051     @param -rollPitchYaw <(roll pitch yaw)>\n
00052     Rotation angles.
00053 
00054     @param -yawPitchRoll <(yaw pitch roll)>\n
00055     Rotation angles.
00056 
00057     @param -rotate <(vector vector)>\n
00058     Rotate from first to second direction.
00059 
00060     @param -scale <vector (sx sy sz)>\n
00061     Scaling factors in x, y and z direction.
00062 
00063     @param -case <dir>\n
00064     Case directory.
00065 
00066     @param -help \n
00067     Display help message.
00068 
00069     @param -doc \n
00070     Display Doxygen API documentation page for this application.
00071 
00072     @param -srcDoc \n
00073     Display Doxygen source documentation page for this application.
00074 
00075 \*---------------------------------------------------------------------------*/
00076 
00077 #include <triSurface/triSurface.H>
00078 #include <OpenFOAM/argList.H>
00079 #include <OpenFOAM/OFstream.H>
00080 #include <OpenFOAM/IFstream.H>
00081 #include <OpenFOAM/boundBox.H>
00082 #include <OpenFOAM/transformField.H>
00083 #include <OpenFOAM/Pair.H>
00084 #include <OpenFOAM/quaternion.H>
00085 
00086 using namespace Foam;
00087 using namespace Foam::mathematicalConstant;
00088 
00089 
00090 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00091 // Main program:
00092 
00093 int main(int argc, char *argv[])
00094 {
00095     argList::noParallel();
00096     argList::validArgs.clear();
00097 
00098     argList::validArgs.append("surface file");
00099     argList::validArgs.append("output surface file");
00100     argList::validOptions.insert("translate", "vector");
00101     argList::validOptions.insert("rotate", "(vector vector)");
00102     argList::validOptions.insert("scale", "vector");
00103     argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
00104     argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
00105     argList args(argc, argv);
00106 
00107     fileName surfFileName(args.additionalArgs()[0]);
00108 
00109     Info<< "Reading surf from " << surfFileName << " ..." << endl;
00110 
00111     fileName outFileName(args.additionalArgs()[1]);
00112 
00113     Info<< "Writing surf to " << outFileName << " ..." << endl;
00114 
00115 
00116     if (args.options().empty())
00117     {
00118         FatalErrorIn(args.executable())
00119             << "No options supplied, please use one or more of "
00120                "-translate, -rotate or -scale options."
00121             << exit(FatalError);
00122     }
00123 
00124     triSurface surf1(surfFileName);
00125 
00126     pointField points(surf1.points());
00127 
00128     if (args.optionFound("translate"))
00129     {
00130         vector transVector(args.optionLookup("translate")());
00131 
00132         Info<< "Translating points by " << transVector << endl;
00133 
00134         points += transVector;
00135     }
00136 
00137     if (args.optionFound("rotate"))
00138     {
00139         Pair<vector> n1n2(args.optionLookup("rotate")());
00140         n1n2[0] /= mag(n1n2[0]);
00141         n1n2[1] /= mag(n1n2[1]);
00142 
00143         tensor T = rotationTensor(n1n2[0], n1n2[1]);
00144 
00145         Info<< "Rotating points by " << T << endl;
00146 
00147         points = transform(T, points);
00148     }
00149     else if (args.optionFound("rollPitchYaw"))
00150     {
00151         vector v(args.optionLookup("rollPitchYaw")());
00152 
00153         Info<< "Rotating points by" << nl
00154             << "    roll  " << v.x() << nl
00155             << "    pitch " << v.y() << nl
00156             << "    yaw   " << v.z() << endl;
00157 
00158 
00159         // Convert to radians
00160         v *= pi/180.0;
00161 
00162         quaternion R(v.x(), v.y(), v.z());
00163 
00164         Info<< "Rotating points by quaternion " << R << endl;
00165         points = transform(R, points);
00166     }
00167     else if (args.optionFound("yawPitchRoll"))
00168     {
00169         vector v(args.optionLookup("yawPitchRoll")());
00170 
00171         Info<< "Rotating points by" << nl
00172             << "    yaw   " << v.x() << nl
00173             << "    pitch " << v.y() << nl
00174             << "    roll  " << v.z() << endl;
00175 
00176 
00177         // Convert to radians
00178         v *= pi/180.0;
00179 
00180         scalar yaw = v.x();
00181         scalar pitch = v.y();
00182         scalar roll = v.z();
00183 
00184         quaternion R = quaternion(vector(0, 0, 1), yaw);
00185         R *= quaternion(vector(0, 1, 0), pitch);
00186         R *= quaternion(vector(1, 0, 0), roll);
00187 
00188         Info<< "Rotating points by quaternion " << R << endl;
00189         points = transform(R, points);
00190     }
00191 
00192     if (args.optionFound("scale"))
00193     {
00194         vector scaleVector(args.optionLookup("scale")());
00195 
00196         Info<< "Scaling points by " << scaleVector << endl;
00197 
00198         points.replace(vector::X, scaleVector.x()*points.component(vector::X));
00199         points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
00200         points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
00201     }
00202 
00203     triSurface surf2(surf1, surf1.patches(), points);
00204 
00205     surf2.write(outFileName);
00206 
00207     Info << "End\n" << endl;
00208 
00209     return 0;
00210 }
00211 
00212 
00213 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines