surfaceTransformPoints.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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
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
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
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