/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C

https://github.com/xyuan/OpenFOAM-1.7.x · C · 173 lines · 92 code · 41 blank · 40 comment · 8 complexity · efbf78f2748d75a42eb6d80b765a6eec MD5 · raw file

  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
  6. \\/ M anipulation |
  7. -------------------------------------------------------------------------------
  8. License
  9. This file is part of OpenFOAM.
  10. OpenFOAM is free software: you can redistribute it and/or modify it
  11. under the terms of the GNU General Public License as published by
  12. the Free Software Foundation, either version 3 of the License, or
  13. (at your option) any later version.
  14. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
  15. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  17. for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
  20. Description
  21. Transform (scale/rotate) a surface. Like transformPoints but then for
  22. surfaces.
  23. The rollPitchYaw option takes three angles (degrees):
  24. - roll (rotation about x) followed by
  25. - pitch (rotation about y) followed by
  26. - yaw (rotation about z)
  27. The yawPitchRoll does yaw followed by pitch followed by roll.
  28. \*---------------------------------------------------------------------------*/
  29. #include "triSurface.H"
  30. #include "argList.H"
  31. #include "OFstream.H"
  32. #include "IFstream.H"
  33. #include "boundBox.H"
  34. #include "transformField.H"
  35. #include "Pair.H"
  36. #include "quaternion.H"
  37. using namespace Foam;
  38. using namespace Foam::mathematicalConstant;
  39. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  40. // Main program:
  41. int main(int argc, char *argv[])
  42. {
  43. argList::noParallel();
  44. argList::validArgs.clear();
  45. argList::validArgs.append("surface file");
  46. argList::validArgs.append("output surface file");
  47. argList::validOptions.insert("translate", "vector");
  48. argList::validOptions.insert("rotate", "(vector vector)");
  49. argList::validOptions.insert("scale", "vector");
  50. argList::validOptions.insert("rollPitchYaw", "(roll pitch yaw)");
  51. argList::validOptions.insert("yawPitchRoll", "(yaw pitch roll)");
  52. argList args(argc, argv);
  53. fileName surfFileName(args.additionalArgs()[0]);
  54. Info<< "Reading surf from " << surfFileName << " ..." << endl;
  55. fileName outFileName(args.additionalArgs()[1]);
  56. Info<< "Writing surf to " << outFileName << " ..." << endl;
  57. if (args.options().empty())
  58. {
  59. FatalErrorIn(args.executable())
  60. << "No options supplied, please use one or more of "
  61. "-translate, -rotate or -scale options."
  62. << exit(FatalError);
  63. }
  64. triSurface surf1(surfFileName);
  65. pointField points(surf1.points());
  66. if (args.optionFound("translate"))
  67. {
  68. vector transVector(args.optionLookup("translate")());
  69. Info<< "Translating points by " << transVector << endl;
  70. points += transVector;
  71. }
  72. if (args.optionFound("rotate"))
  73. {
  74. Pair<vector> n1n2(args.optionLookup("rotate")());
  75. n1n2[0] /= mag(n1n2[0]);
  76. n1n2[1] /= mag(n1n2[1]);
  77. tensor T = rotationTensor(n1n2[0], n1n2[1]);
  78. Info<< "Rotating points by " << T << endl;
  79. points = transform(T, points);
  80. }
  81. else if (args.optionFound("rollPitchYaw"))
  82. {
  83. vector v(args.optionLookup("rollPitchYaw")());
  84. Info<< "Rotating points by" << nl
  85. << " roll " << v.x() << nl
  86. << " pitch " << v.y() << nl
  87. << " yaw " << v.z() << endl;
  88. // Convert to radians
  89. v *= pi/180.0;
  90. quaternion R(v.x(), v.y(), v.z());
  91. Info<< "Rotating points by quaternion " << R << endl;
  92. points = transform(R, points);
  93. }
  94. else if (args.optionFound("yawPitchRoll"))
  95. {
  96. vector v(args.optionLookup("yawPitchRoll")());
  97. Info<< "Rotating points by" << nl
  98. << " yaw " << v.x() << nl
  99. << " pitch " << v.y() << nl
  100. << " roll " << v.z() << endl;
  101. // Convert to radians
  102. v *= pi/180.0;
  103. scalar yaw = v.x();
  104. scalar pitch = v.y();
  105. scalar roll = v.z();
  106. quaternion R = quaternion(vector(0, 0, 1), yaw);
  107. R *= quaternion(vector(0, 1, 0), pitch);
  108. R *= quaternion(vector(1, 0, 0), roll);
  109. Info<< "Rotating points by quaternion " << R << endl;
  110. points = transform(R, points);
  111. }
  112. if (args.optionFound("scale"))
  113. {
  114. vector scaleVector(args.optionLookup("scale")());
  115. Info<< "Scaling points by " << scaleVector << endl;
  116. points.replace(vector::X, scaleVector.x()*points.component(vector::X));
  117. points.replace(vector::Y, scaleVector.y()*points.component(vector::Y));
  118. points.replace(vector::Z, scaleVector.z()*points.component(vector::Z));
  119. }
  120. triSurface surf2(surf1, surf1.patches(), points);
  121. surf2.write(outFileName);
  122. Info << "End\n" << endl;
  123. return 0;
  124. }
  125. // ************************************************************************* //