From 53e91f12db934845353b36f61f5865dece9ccfff Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 18 Aug 2022 11:43:18 +0200 Subject: [PATCH] BUG: incorrect order for output scaling (transformPoints, ...) - the output write scaling should be applied *after* undoing the effects of the specified rotation centre. Fixes #2566 ENH: update option names for transformPoints and surfaceTransformPoints - prefer '-auto-centre' and '-centre', but also accept the previous options '-auto-origin' and '-origin' as aliases. Changing to '-centre' avoids possible confusion with coordinate system origin(). --- .../transformPoints/transformPoints.C | 45 ++++++++++++------- .../surfaceTransformPoints.C | 42 +++++++++++------ 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C index 7f695abffb..c3e692077e 100644 --- a/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C +++ b/applications/utilities/mesh/manipulation/transformPoints/transformPoints.C @@ -169,14 +169,22 @@ int main(int argc, char *argv[]) ( "translate", "vector", - "Translate by specified - eg, '(1 0 0)' before rotations" + "Translate by specified before rotations" + ); + argList::addBoolOption + ( + "auto-centre", + "Use bounding box centre as centre for rotations" ); argList::addOption ( - "origin", + "centre", "point", - "Use specified as origin for rotations" + "Use specified as centre for rotations" ); + argList::addOptionCompat("auto-centre", {"auto-origin", 2206}); + argList::addOptionCompat("centre", {"origin", 2206}); + argList::addOption ( "rotate", @@ -290,18 +298,24 @@ int main(int argc, char *argv[]) if (args.readIfPresent("translate", v)) { Info<< "Translating points by " << v << endl; - points += v; } - vector origin; - const bool useOrigin = args.readIfPresent("origin", origin); - if (useOrigin) + vector rotationCentre; + bool useRotationCentre = args.readIfPresent("centre", rotationCentre); + if (args.found("auto-centre") && !useRotationCentre) { - Info<< "Set origin for rotations to " << origin << endl; - points -= origin; + useRotationCentre = true; + rotationCentre = boundBox(points).centre(); } + if (useRotationCentre) + { + Info<< "Set centre of rotation to " << rotationCentre << endl; + points -= rotationCentre; + } + + if (args.found("rotate")) { Pair n1n2 @@ -380,6 +394,13 @@ int main(int argc, char *argv[]) } } + if (useRotationCentre) + { + Info<< "Unset centre of rotation from " << rotationCentre << endl; + points += rotationCentre; + } + + List scaling; if (args.readListIfPresent("scale", scaling)) { @@ -410,12 +431,6 @@ int main(int argc, char *argv[]) } } - if (useOrigin) - { - Info<< "Unset origin for rotations from " << origin << endl; - points += origin; - } - // Set the precision of the points data to 10 IOstream::defaultPrecision(max(10u, IOstream::defaultPrecision())); diff --git a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C index a3ba6687bc..369e4587f0 100644 --- a/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C +++ b/applications/utilities/surface/surfaceTransformPoints/surfaceTransformPoints.C @@ -112,12 +112,20 @@ int main(int argc, char *argv[]) "vector", "Translate by specified - eg, '(1 0 0)' before rotations" ); + argList::addBoolOption + ( + "auto-centre", + "Use bounding box centre as centre for rotations" + ); argList::addOption ( - "origin", + "centre", "point", - "Use specified as origin for rotations" + "Use specified as centre for rotations" ); + argList::addOptionCompat("auto-centre", {"auto-origin", 2206}); + argList::addOptionCompat("centre", {"origin", 2206}); + argList::addOption ( "rotate", @@ -229,18 +237,24 @@ int main(int argc, char *argv[]) if (args.readIfPresent("translate", v)) { Info<< "Translating points by " << v << endl; - points += v; } - vector origin(Zero); - const bool useOrigin = args.readIfPresent("origin", origin); - if (useOrigin) + vector rotationCentre; + bool useRotationCentre = args.readIfPresent("centre", rotationCentre); + if (args.found("auto-centre") && !useRotationCentre) { - Info<< "Set origin for rotations to " << origin << endl; - points -= origin; + useRotationCentre = true; + rotationCentre = boundBox(points).centre(); } + if (useRotationCentre) + { + Info<< "Set centre of rotation to " << rotationCentre << endl; + points -= rotationCentre; + } + + if (args.found("rotate")) { Pair n1n2 @@ -299,6 +313,13 @@ int main(int argc, char *argv[]) points = transform(rot, points); } + if (useRotationCentre) + { + Info<< "Unset centre of rotation from " << rotationCentre << endl; + points += rotationCentre; + } + + List scaling; if (args.readListIfPresent("scale", scaling)) { @@ -338,11 +359,6 @@ int main(int argc, char *argv[]) } } - if (useOrigin) - { - Info<< "Unset origin for rotations from " << origin << endl; - points += origin; - } surf1.movePoints(points); surf1.write(exportName, writeFileType);