Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
applications
utilities
surface
surfaceTransformPoints
surfaceTransformPoints.C
Go to the documentation of this 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
11
OpenFOAM is free software: you can redistribute it and/or modify it
12
under the terms of the GNU General Public License as published by
13
the Free Software Foundation, either version 3 of the License, or
14
(at your option) any later version.
15
16
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19
for more details.
20
21
You should have received a copy of the GNU General Public License
22
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23
24
Application
25
surfaceTransformPoints
26
27
Description
28
Transform (scale/rotate) a surface.
29
30
Like transformPoints but then for surfaces. The rollPitchYaw option takes
31
three angles (degrees):
32
- roll (rotation about x) followed by
33
- pitch (rotation about y) followed by
34
- yaw (rotation about z)
35
36
The yawPitchRoll does yaw followed by pitch followed by roll.
37
38
Usage
39
40
- surfaceTransformPoints [OPTIONS] <Foam surface file> <surface output file>
41
42
@param <Foam surface file> \n
43
@todo Detailed description of argument.
44
45
@param <surface output file> \n
46
@todo Detailed description of argument.
47
48
@param -translate <vector>\n
49
Translation vector.
50
51
@param -rollPitchYaw <(roll pitch yaw)>\n
52
Rotation angles.
53
54
@param -yawPitchRoll <(yaw pitch roll)>\n
55
Rotation angles.
56
57
@param -rotate <(vector vector)>\n
58
Rotate from first to second direction.
59
60
@param -scale <vector (sx sy sz)>\n
61
Scaling factors in x, y and z direction.
62
63
@param -case <dir>\n
64
Case directory.
65
66
@param -help \n
67
Display help message.
68
69
@param -doc \n
70
Display Doxygen API documentation page for this application.
71
72
@param -srcDoc \n
73
Display Doxygen source documentation page for this application.
74
75
\*---------------------------------------------------------------------------*/
76
77
#include <
triSurface/triSurface.H
>
78
#include <
OpenFOAM/argList.H
>
79
#include <
OpenFOAM/OFstream.H
>
80
#include <
OpenFOAM/IFstream.H
>
81
#include <
OpenFOAM/boundBox.H
>
82
#include <
OpenFOAM/transformField.H
>
83
#include <
OpenFOAM/Pair.H
>
84
#include <
OpenFOAM/quaternion.H
>
85
86
using namespace
Foam;
87
using namespace
Foam::mathematicalConstant;
88
89
90
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91
// Main program:
92
93
int
main
(
int
argc,
char
*argv[])
94
{
95
argList::noParallel
();
96
argList::validArgs
.
clear
();
97
98
argList::validArgs
.
append
(
"surface file"
);
99
argList::validArgs
.
append
(
"output surface file"
);
100
argList::validOptions
.
insert
(
"translate"
,
"vector"
);
101
argList::validOptions
.
insert
(
"rotate"
,
"(vector vector)"
);
102
argList::validOptions
.
insert
(
"scale"
,
"vector"
);
103
argList::validOptions
.
insert
(
"rollPitchYaw"
,
"(roll pitch yaw)"
);
104
argList::validOptions
.
insert
(
"yawPitchRoll"
,
"(yaw pitch roll)"
);
105
argList
args
(argc, argv);
106
107
fileName
surfFileName(
args
.
additionalArgs
()[0]);
108
109
Info
<<
"Reading surf from "
<< surfFileName <<
" ..."
<<
endl
;
110
111
fileName
outFileName(
args
.
additionalArgs
()[1]);
112
113
Info
<<
"Writing surf to "
<< outFileName <<
" ..."
<<
endl
;
114
115
116
if
(
args
.
options
().
empty
())
117
{
118
FatalErrorIn
(
args
.
executable
())
119
<<
"No options supplied, please use one or more of "
120
"-translate, -rotate or -scale options."
121
<<
exit
(
FatalError
);
122
}
123
124
triSurface
surf1(surfFileName);
125
126
pointField
points
(surf1.points());
127
128
if
(
args
.
optionFound
(
"translate"
))
129
{
130
vector
transVector(
args
.
optionLookup
(
"translate"
)());
131
132
Info
<<
"Translating points by "
<< transVector <<
endl
;
133
134
points
+= transVector;
135
}
136
137
if
(
args
.
optionFound
(
"rotate"
))
138
{
139
Pair<vector>
n1n2(
args
.
optionLookup
(
"rotate"
)());
140
n1n2[0] /=
mag
(n1n2[0]);
141
n1n2[1] /=
mag
(n1n2[1]);
142
143
tensor
T
=
rotationTensor
(n1n2[0], n1n2[1]);
144
145
Info
<<
"Rotating points by "
<< T <<
endl
;
146
147
points
=
transform
(T,
points
);
148
}
149
else
if
(
args
.
optionFound
(
"rollPitchYaw"
))
150
{
151
vector
v(
args
.
optionLookup
(
"rollPitchYaw"
)());
152
153
Info
<<
"Rotating points by"
<<
nl
154
<<
" roll "
<< v.x() <<
nl
155
<<
" pitch "
<< v.y() <<
nl
156
<<
" yaw "
<< v.z() <<
endl
;
157
158
159
// Convert to radians
160
v *=
pi
/180.0;
161
162
quaternion
R
(v.x(), v.y(), v.z());
163
164
Info
<<
"Rotating points by quaternion "
<<
R
<<
endl
;
165
points
=
transform
(R,
points
);
166
}
167
else
if
(
args
.
optionFound
(
"yawPitchRoll"
))
168
{
169
vector
v(
args
.
optionLookup
(
"yawPitchRoll"
)());
170
171
Info
<<
"Rotating points by"
<<
nl
172
<<
" yaw "
<< v.x() <<
nl
173
<<
" pitch "
<< v.y() <<
nl
174
<<
" roll "
<< v.z() <<
endl
;
175
176
177
// Convert to radians
178
v *=
pi
/180.0;
179
180
scalar yaw = v.x();
181
scalar pitch = v.y();
182
scalar roll = v.z();
183
184
quaternion
R
=
quaternion
(
vector
(0, 0, 1), yaw);
185
R *=
quaternion
(
vector
(0, 1, 0), pitch);
186
R *=
quaternion
(
vector
(1, 0, 0), roll);
187
188
Info
<<
"Rotating points by quaternion "
<< R <<
endl
;
189
points
=
transform
(R,
points
);
190
}
191
192
if
(
args
.
optionFound
(
"scale"
))
193
{
194
vector
scaleVector(
args
.
optionLookup
(
"scale"
)());
195
196
Info
<<
"Scaling points by "
<< scaleVector <<
endl
;
197
198
points
.
replace
(
vector::X
, scaleVector.x()*
points
.
component
(
vector::X
));
199
points
.
replace
(
vector::Y
, scaleVector.y()*
points
.
component
(
vector::Y
));
200
points
.
replace
(
vector::Z
, scaleVector.z()*
points
.
component
(
vector::Z
));
201
}
202
203
triSurface
surf2(surf1, surf1.patches(),
points
);
204
205
surf2.write(outFileName);
206
207
Info
<<
"End\n"
<<
endl
;
208
209
return
0;
210
}
211
212
213
// ************************ vim: set sw=4 sts=4 et: ************************ //