Skip to content
Snippets Groups Projects
Commit 79b53a9c authored by Mark Olesen's avatar Mark Olesen
Browse files

rename BSplineTest to splineTest and add Catmull-Rom to it

- the current B-Splines deliver rubbish
parent b83e6981
No related branches found
No related tags found
No related merge requests found
BSplineTest.C
EXE = $(FOAM_USER_APPBIN)/BSplineTest
splineTest.C
EXE = $(FOAM_USER_APPBIN)/splineTest
......@@ -28,6 +28,7 @@ License
#include "vector.H"
#include "IFstream.H"
#include "BSpline.H"
#include "CatmullRomSpline.H"
using namespace Foam;
......@@ -38,28 +39,79 @@ int main(int argc, char *argv[])
{
argList::noParallel();
argList::validArgs.insert("file .. fileN");
argList::addBoolOption("B", "B-Spline");
argList::addBoolOption("cmr", "catmull-rom spline (default)");
argList::addOption
(
"n",
"INT",
"number of segments for evaluation - default 20"
);
argList args(argc, argv, false, true);
if (args.additionalArgs().empty())
{
args.printUsage();
}
bool useBSpline = args.optionFound("B");
bool useCatmullRom = args.optionFound("cmr");
label nSeg = args.optionLookupOrDefault<label>("n", 20);
if (!useBSpline && !useCatmullRom)
{
Info<<"defaulting to Catmull-Rom spline" << endl;
useCatmullRom = true;
}
forAll(args.additionalArgs(), argI)
{
const string& srcFile = args.additionalArgs()[argI];
Info<< nl << "reading " << srcFile << nl;
IFstream ifs(srcFile);
List<pointField> splinePointFields(ifs);
List<pointField> pointFields(ifs);
forAll(splinePointFields, splineI)
forAll(pointFields, splineI)
{
Info<<"convert " << splinePointFields[splineI] << " to bspline" << endl;
BSpline spl(splinePointFields[splineI], vector::zero, vector::zero);
Info<< "1/2 = " << spl.position(0.5) << endl;
Info<<"\noriginal points: " << pointFields[splineI] << nl;
if (useBSpline)
{
BSpline spl(pointFields[splineI], vector::zero, vector::zero);
Info<< nl
<< "B-Spline interpolation:" << nl
<< "----------------------" << endl;
for (label segI = 0; segI <= nSeg; ++segI)
{
scalar lambda = scalar(segI)/scalar(nSeg);
Info<< spl.position(lambda) << " // " << lambda << endl;
}
}
if (useCatmullRom)
{
CatmullRomSpline spl
(
pointFields[splineI]
);
Info<< nl
<<"Catmull-Rom interpolation:" << nl
<< "-------------------------" << endl;
for (label segI = 0; segI <= nSeg; ++segI)
{
scalar lambda = scalar(segI)/scalar(nSeg);
Info<< spl.position(lambda) << " // " << lambda << endl;
}
}
}
}
return 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment