78static bool hasReadWriteTypes(
const word& readType,
const word& writeType)
80 volatile bool good =
true;
82 if (!meshedSurface::canReadType(readType,
true))
87 if (!meshedSurface::canWriteType(writeType,
true))
108 if (scaling.
size() == 1)
112 else if (scaling.
size() == 3)
117 equal(scaling[0], scaling[1])
118 &&
equal(scaling[0], scaling[2])
124 else if (!scaling.
empty())
127 <<
"Incorrect number of components, must be 1 or 3." <<
nl
128 <<
" -" << optName <<
' ' <<
args[optName].c_str() <<
endl
132 if (scaling.
size() == 1 &&
equal(scaling[0], 1))
146 if (scaling.
size() == 1)
148 Info<<
"Scaling points uniformly by " << scaling[0] <<
nl;
151 else if (scaling.
size() == 3)
153 Info<<
"Scaling points by ("
156 << scaling[2] <<
')' <<
nl;
167int main(
int argc,
char *argv[])
171 "Transform (translate / rotate / scale) surface points.\n"
172 "Like transformPoints but for surfaces.\n"
173 "Note: roll=rotate about x, pitch=rotate about y, yaw=rotate about z"
175 argList::noParallel();
176 argList::addArgument(
"input",
"The input surface file");
177 argList::addArgument(
"output",
"The output surface file");
178 argList::addBoolOption
181 "Recentre the bounding box before other operations"
187 "Translate by specified <vector> before rotations"
189 argList::addBoolOption
192 "Use bounding box centre as origin for rotations"
198 "Use specified <point> as origin for rotations"
204 "Rotate from <vectorA> to <vectorB> - eg, '((1 0 0) (0 0 1))'"
210 "Rotate <angle> degrees about <vector> - eg, '((1 0 0) 45)'"
215 "Rotate (degrees) about x-axis"
220 "Rotate (degrees) about y-axis"
225 "Rotate (degrees) about z-axis"
231 "Rotate by '(roll pitch yaw)' degrees"
237 "Rotate by '(yaw pitch roll)' degrees"
243 "Uniform or non-uniform input scaling"
249 "Uniform or non-uniform output scaling"
255 "Input format (default: use file extension)"
261 "Output format (default: use file extension)"
265 argList::addOptionCompat(
"write-scale", {
"scale", -2006});
289 <<
"No operation supplied, "
290 <<
"use at least one of the following:" <<
nl
293 for (
const auto& opName : operationNames)
300 <<
nl <<
exit(FatalError);
307 const word readFileType
312 const word writeFileType
319 if (!hasReadWriteTypes(readFileType, writeFileType))
322 <<
"Unsupported file format(s)" <<
nl
327 Info<<
"Reading surf from " << importName <<
" ..." <<
nl
328 <<
"Writing surf to " << exportName <<
" ..." <<
endl;
339 applyScaling(
points, getScalingOpt(
"read-scale",
args));
345 Info<<
"Adjust centre " << v <<
" -> (0 0 0)" <<
endl;
351 Info<<
"Translating points by " << v <<
endl;
357 if (
args.
found(
"auto-origin") && !useOrigin)
365 Info<<
"Set origin for rotations to " << origin <<
endl;
373 bool useRotation(
false);
394 const vector& axis = rotAxisAngle.first();
395 const scalar angle = rotAxisAngle.second();
397 Info<<
"Rotating points " <<
nl
398 <<
" about " << axis <<
nl
399 <<
" angle " << angle <<
nl;
401 rot = axisAngle::rotation(axis, angle,
true);
406 const scalar angle =
args.
get<scalar>(
"rotate-x");
408 Info<<
"Rotating points about x-axis: " << angle <<
nl;
410 rot = axisAngle::rotation(
vector::X, angle,
true);
415 const scalar angle =
args.
get<scalar>(
"rotate-y");
417 Info<<
"Rotating points about y-axis: " << angle <<
nl;
419 rot = axisAngle::rotation(
vector::Y, angle,
true);
424 const scalar angle =
args.
get<scalar>(
"rotate-z");
426 Info<<
"Rotating points about z-axis: " << angle <<
nl;
428 rot = axisAngle::rotation(
vector::Z, angle,
true);
433 Info<<
"Rotating points by" <<
nl
434 <<
" roll " << v.x() <<
nl
435 <<
" pitch " << v.y() <<
nl
436 <<
" yaw " << v.z() <<
nl;
438 rot = euler::rotation(euler::eulerOrder::ROLL_PITCH_YAW, v,
true);
443 Info<<
"Rotating points by" <<
nl
444 <<
" yaw " << v.x() <<
nl
445 <<
" pitch " << v.y() <<
nl
446 <<
" roll " << v.z() <<
nl;
448 rot = euler::rotation(euler::eulerOrder::YAW_PITCH_ROLL, v,
true);
454 Info<<
"Rotating points by " << rot <<
endl;
459 applyScaling(
points, getScalingOpt(
"write-scale",
args));
463 Info<<
"Unset origin for rotations from " << origin <<
endl;
468 surf1.write(exportName, writeFileType);
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
void resize(const label len)
Adjust allocated size of list.
void clear()
Clear the list, i.e. set size to zero.
An ordered pair of two objects of type <T> with first() and second() elements.
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
bool empty() const noexcept
True if the UList is empty (ie, size() is zero)
void size(const label n)
Older name for setAddressableSize.
Extract command arguments and options from the supplied argc and argv parameters.
T get(const label index) const
Get a value from the argument at index.
bool readListIfPresent(const word &optName, List< T > &list) const
label count(const UList< word > &optionNames) const
Return how many of the specified options were used.
bool found(const word &optName) const
Return true if the named option is found.
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
ITstream lookup(const word &optName) const
Return an input stream from the named option.
T getOrDefault(const word &optName, const T &deflt) const
Get a value from the named option if present, or return default.
A bounding box defined in terms of min/max extrema points.
point centre() const
The centre (midpoint) of the bounding box.
A class for handling file names.
Tensor of scalars, i.e. Tensor<scalar>.
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
A class for handling words, derived from Foam::string.
word ext() const
Return file name extension (part after last .)
word lessExt() const
Return word without extension (part before last .)
Namespace for coordinate system rotations.
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
tensor rotationTensor(const vector &n1, const vector &n2)
Rotational transformation tensor from vector n1 to n2.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a)
Foam::argList args(argc, argv)