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
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
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
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
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
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