PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://gitlab.com/johnvarv/OpenFOAM-3.0.x
C | 198 lines | 124 code | 32 blank | 42 comment | 8 complexity | 428ca8b48b59fbb69dc84d22368d2fa6 MD5 | raw file
  1. /*---------------------------------------------------------------------------*\
  2. ========= |
  3. \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
  4. \\ / O peration |
  5. \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
  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. Application
  21. surfaceTransformPoints
  22. Description
  23. Transform (scale/rotate) a surface.
  24. Like transformPoints but for surfaces.
  25. The rollPitchYaw option takes three angles (degrees):
  26. - roll (rotation about x) followed by
  27. - pitch (rotation about y) followed by
  28. - yaw (rotation about z)
  29. The yawPitchRoll does yaw followed by pitch followed by roll.
  30. \*---------------------------------------------------------------------------*/
  31. #include "argList.H"
  32. #include "OFstream.H"
  33. #include "IFstream.H"
  34. #include "boundBox.H"
  35. #include "transformField.H"
  36. #include "Pair.H"
  37. #include "quaternion.H"
  38. #include "mathematicalConstants.H"
  39. #include "MeshedSurfaces.H"
  40. using namespace Foam;
  41. using namespace Foam::constant::mathematical;
  42. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  43. int main(int argc, char *argv[])
  44. {
  45. argList::addNote
  46. (
  47. "Transform (scale/rotate) a surface. "
  48. "Like transformPoints but for surfaces."
  49. );
  50. argList::noParallel();
  51. argList::validArgs.append("surfaceFile");
  52. argList::validArgs.append("output surfaceFile");
  53. argList::addOption
  54. (
  55. "translate",
  56. "vector",
  57. "translate by the specified <vector> - eg, '(1 0 0)'"
  58. );
  59. argList::addOption
  60. (
  61. "rotate",
  62. "(vectorA vectorB)",
  63. "transform in terms of a rotation between <vectorA> and <vectorB> "
  64. "- eg, '( (1 0 0) (0 0 1) )'"
  65. );
  66. argList::addOption
  67. (
  68. "scale",
  69. "vector",
  70. "scale by the specified amount - eg, '(0.001 0.001 0.001)' for a "
  71. "uniform [mm] to [m] scaling"
  72. );
  73. argList::addOption
  74. (
  75. "rollPitchYaw",
  76. "vector",
  77. "transform in terms of '( roll pitch yaw )' in degrees"
  78. );
  79. argList::addOption
  80. (
  81. "yawPitchRoll",
  82. "vector",
  83. "transform in terms of '( yaw pitch roll )' in degrees"
  84. );
  85. argList args(argc, argv);
  86. const fileName surfFileName = args[1];
  87. const fileName outFileName = args[2];
  88. Info<< "Reading surf from " << surfFileName << " ..." << nl
  89. << "Writing surf to " << outFileName << " ..." << endl;
  90. if (args.options().empty())
  91. {
  92. FatalErrorIn(args.executable())
  93. << "No options supplied, please use one or more of "
  94. "-translate, -rotate or -scale options."
  95. << exit(FatalError);
  96. }
  97. meshedSurface surf1(surfFileName);
  98. pointField points(surf1.points());
  99. vector v;
  100. if (args.optionReadIfPresent("translate", v))
  101. {
  102. Info<< "Translating points by " << v << endl;
  103. points += v;
  104. }
  105. if (args.optionFound("rotate"))
  106. {
  107. Pair<vector> n1n2
  108. (
  109. args.optionLookup("rotate")()
  110. );
  111. n1n2[0] /= mag(n1n2[0]);
  112. n1n2[1] /= mag(n1n2[1]);
  113. tensor T = rotationTensor(n1n2[0], n1n2[1]);
  114. Info<< "Rotating points by " << T << endl;
  115. points = transform(T, points);
  116. }
  117. else if (args.optionReadIfPresent("rollPitchYaw", v))
  118. {
  119. Info<< "Rotating points by" << nl
  120. << " roll " << v.x() << nl
  121. << " pitch " << v.y() << nl
  122. << " yaw " << v.z() << nl;
  123. // Convert to radians
  124. v *= pi/180.0;
  125. quaternion R(v.x(), v.y(), v.z());
  126. Info<< "Rotating points by quaternion " << R << endl;
  127. points = transform(R, points);
  128. }
  129. else if (args.optionReadIfPresent("yawPitchRoll", v))
  130. {
  131. Info<< "Rotating points by" << nl
  132. << " yaw " << v.x() << nl
  133. << " pitch " << v.y() << nl
  134. << " roll " << v.z() << nl;
  135. // Convert to radians
  136. v *= pi/180.0;
  137. scalar yaw = v.x();
  138. scalar pitch = v.y();
  139. scalar roll = v.z();
  140. quaternion R = quaternion(vector(0, 0, 1), yaw);
  141. R *= quaternion(vector(0, 1, 0), pitch);
  142. R *= quaternion(vector(1, 0, 0), roll);
  143. Info<< "Rotating points by quaternion " << R << endl;
  144. points = transform(R, points);
  145. }
  146. if (args.optionReadIfPresent("scale", v))
  147. {
  148. Info<< "Scaling points by " << v << endl;
  149. points.replace(vector::X, v.x()*points.component(vector::X));
  150. points.replace(vector::Y, v.y()*points.component(vector::Y));
  151. points.replace(vector::Z, v.z()*points.component(vector::Z));
  152. }
  153. surf1.movePoints(points);
  154. surf1.write(outFileName);
  155. Info<< "End\n" << endl;
  156. return 0;
  157. }
  158. // ************************************************************************* //