mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: additional options for transformPoints and surfaceRefineRedGreen
- add -recentre option to shift points according to the bounding box centre before performing other operations - add -auto-origin to use the bounding box centre as the origin for rotations. Has lower priority than the -origin option. - surfaceTransformPoints now has distinct -read-scale, -write-scale options (as per surfaceMeshConvert). Silently accepts -scale as equivalent to -write-scale, for backwards compatibility and similarity with transformPoints - add -steps option for surfaceRefineRedGreen for successive refinement
This commit is contained in:
@ -41,11 +41,14 @@ Usage
|
||||
Specify the time to search from and apply the transformation
|
||||
(default is latest)
|
||||
|
||||
-recentre
|
||||
Recentre using the bounding box centre before other operations
|
||||
|
||||
-translate vector
|
||||
Translates the points by the given vector before rotations
|
||||
Translate the points by the given vector before rotations
|
||||
|
||||
-rotate (vector vector)
|
||||
Rotates the points from the first vector to the second,
|
||||
Rotate the points from the first vector to the second
|
||||
|
||||
-rotate-angle (vector angle)
|
||||
Rotate angle degrees about vector axis.
|
||||
@ -54,7 +57,7 @@ Usage
|
||||
or -rollPitchYaw (rolldegrees pitchdegrees yawdegrees)
|
||||
|
||||
-scale scalar|vector
|
||||
Scales the points by the given scalar or vector.
|
||||
Scale the points by the given scalar or vector on output.
|
||||
|
||||
The any or all of the three options may be specified and are processed
|
||||
in the above order.
|
||||
@ -150,6 +153,85 @@ void rotateFields(const argList& args, const Time& runTime, const tensor& T)
|
||||
}
|
||||
|
||||
|
||||
// Retrieve scaling option
|
||||
// - size 0 : no scaling
|
||||
// - size 1 : uniform scaling
|
||||
// - size 3 : non-uniform scaling
|
||||
List<scalar> getScalingOpt(const word& optName, const argList& args)
|
||||
{
|
||||
// readListIfPresent handles single or multiple values
|
||||
// - accept 1 or 3 values
|
||||
|
||||
List<scalar> scaling;
|
||||
args.readListIfPresent(optName, scaling);
|
||||
|
||||
if (scaling.size() == 1)
|
||||
{
|
||||
// Uniform scaling
|
||||
}
|
||||
else if (scaling.size() == 3)
|
||||
{
|
||||
// Non-uniform, but may actually be uniform
|
||||
if
|
||||
(
|
||||
equal(scaling[0], scaling[1])
|
||||
&& equal(scaling[0], scaling[2])
|
||||
)
|
||||
{
|
||||
scaling.resize(1);
|
||||
}
|
||||
}
|
||||
else if (!scaling.empty())
|
||||
{
|
||||
FatalError
|
||||
<< "Incorrect number of components, must be 1 or 3." << nl
|
||||
<< " -" << optName << ' ' << args[optName].c_str() << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (scaling.size() == 1 && equal(scaling[0], 1))
|
||||
{
|
||||
// Scale factor 1 == no scaling
|
||||
scaling.clear();
|
||||
}
|
||||
|
||||
for (const scalar scale : scaling)
|
||||
{
|
||||
if (scale <= 0)
|
||||
{
|
||||
FatalError
|
||||
<< "Invalid scaling value, must be positive." << nl
|
||||
<< " -" << optName << ' ' << args[optName].c_str() << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
return scaling;
|
||||
}
|
||||
|
||||
|
||||
void applyScaling(pointField& points, const List<scalar>& scaling)
|
||||
{
|
||||
if (scaling.size() == 1)
|
||||
{
|
||||
Info<< "Scaling points uniformly by " << scaling[0] << nl;
|
||||
points *= scaling[0];
|
||||
}
|
||||
else if (scaling.size() == 3)
|
||||
{
|
||||
Info<< "Scaling points by ("
|
||||
<< scaling[0] << ' '
|
||||
<< scaling[1] << ' '
|
||||
<< scaling[2] << ')' << nl;
|
||||
|
||||
points.replace(vector::X, scaling[0]*points.component(vector::X));
|
||||
points.replace(vector::Y, scaling[1]*points.component(vector::Y));
|
||||
points.replace(vector::Z, scaling[2]*points.component(vector::Z));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -165,11 +247,21 @@ int main(int argc, char *argv[])
|
||||
"Specify the time to search from and apply the transformation"
|
||||
" (default is latest)"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"recentre",
|
||||
"Recentre the bounding box before other operations"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
"translate",
|
||||
"vector",
|
||||
"Translate by specified <vector> - eg, '(1 0 0)' before rotations"
|
||||
"Translate by specified <vector> before rotations"
|
||||
);
|
||||
argList::addBoolOption
|
||||
(
|
||||
"auto-origin",
|
||||
"Use bounding box centre as origin for rotations"
|
||||
);
|
||||
argList::addOption
|
||||
(
|
||||
@ -214,6 +306,9 @@ int main(int argc, char *argv[])
|
||||
"use either '(0.001 0.001 0.001)' or simply '0.001'"
|
||||
);
|
||||
|
||||
// Compatibility with surfaceTransformPoints
|
||||
argList::addOptionCompat("scale", {"write-scale", 0});
|
||||
|
||||
#include "addRegionOption.H"
|
||||
#include "setRootCase.H"
|
||||
|
||||
@ -223,6 +318,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
const List<word> operationNames
|
||||
{
|
||||
"recentre",
|
||||
"translate",
|
||||
"rotate",
|
||||
"rotate-angle",
|
||||
@ -286,16 +382,31 @@ int main(int argc, char *argv[])
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
// Begin operations
|
||||
|
||||
vector v;
|
||||
if (args.found("recentre"))
|
||||
{
|
||||
v = boundBox(points).centre();
|
||||
Info<< "Adjust centre " << v << " -> (0 0 0)" << endl;
|
||||
points -= v;
|
||||
}
|
||||
|
||||
if (args.readIfPresent("translate", v))
|
||||
{
|
||||
Info<< "Translating points by " << v << endl;
|
||||
|
||||
points += v;
|
||||
}
|
||||
|
||||
vector origin;
|
||||
const bool useOrigin = args.readIfPresent("origin", origin);
|
||||
bool useOrigin = args.readIfPresent("origin", origin);
|
||||
if (args.found("auto-origin") && !useOrigin)
|
||||
{
|
||||
useOrigin = true;
|
||||
origin = boundBox(points).centre();
|
||||
}
|
||||
|
||||
if (useOrigin)
|
||||
{
|
||||
Info<< "Set origin for rotations to " << origin << endl;
|
||||
@ -328,8 +439,8 @@ int main(int argc, char *argv[])
|
||||
args.lookup("rotate-angle")()
|
||||
);
|
||||
|
||||
const vector& axis = rotAxisAngle.first();
|
||||
const scalar& angle = rotAxisAngle.second();
|
||||
const vector& axis = rotAxisAngle.first();
|
||||
const scalar angle = rotAxisAngle.second();
|
||||
|
||||
Info<< "Rotating points " << nl
|
||||
<< " about " << axis << nl
|
||||
@ -380,35 +491,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
List<scalar> scaling;
|
||||
if (args.readListIfPresent("scale", scaling))
|
||||
{
|
||||
// readListIfPresent handles single or multiple values
|
||||
|
||||
if (scaling.size() == 1)
|
||||
{
|
||||
Info<< "Scaling points uniformly by " << scaling[0] << nl;
|
||||
points *= scaling[0];
|
||||
}
|
||||
else if (scaling.size() == 3)
|
||||
{
|
||||
Info<< "Scaling points by ("
|
||||
<< scaling[0] << " "
|
||||
<< scaling[1] << " "
|
||||
<< scaling[2] << ")" << nl;
|
||||
|
||||
points.replace(vector::X, scaling[0]*points.component(vector::X));
|
||||
points.replace(vector::Y, scaling[1]*points.component(vector::Y));
|
||||
points.replace(vector::Z, scaling[2]*points.component(vector::Z));
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalError
|
||||
<< "-scale with 1 or 3 components only" << nl
|
||||
<< "given: " << args["scale"] << endl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
// Output scaling
|
||||
applyScaling(points, getScalingOpt("scale", args));
|
||||
|
||||
if (useOrigin)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user