1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
24 \*---------------------------------------------------------------------------*/
31 #include "CatmullRomSpline.H"
35 inline Ostream& printPoint(Ostream& os, const point& p)
37 os << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 int main(int argc, char *argv[])
47 argList::noParallel();
48 argList::validArgs.insert("file .. fileN");
49 argList::addBoolOption("B", "B-Spline implementation");
50 argList::addBoolOption("CMR", "catmull-rom spline (default)");
55 "number of segments for evaluation - default 20"
58 argList args(argc, argv, false, true);
65 bool useBSpline = args.optionFound("B");
66 bool useCatmullRom = args.optionFound("CMR");
67 label nSeg = args.optionLookupOrDefault<label>("n", 20);
69 if (!useCatmullRom && !useBSpline)
71 Info<<"defaulting to Catmull-Rom spline" << endl;
75 for (label argI=1; argI < args.size(); ++argI)
77 const string& srcFile = args[argI];
78 Info<< nl << "reading " << srcFile << nl;
79 IFstream ifs(srcFile);
81 List<pointField> pointFields(ifs);
84 forAll(pointFields, splineI)
86 Info<<"\n# points:" << endl;
87 forAll(pointFields[splineI], ptI)
89 printPoint(Info, pointFields[splineI][ptI]);
94 BSpline spl(pointFields[splineI]);
96 Info<< nl << "# B-Spline" << endl;
98 for (label segI = 0; segI <= nSeg; ++segI)
100 scalar lambda = scalar(segI)/scalar(nSeg);
101 printPoint(Info, spl.position(lambda));
107 CatmullRomSpline spl(pointFields[splineI]);
109 Info<< nl <<"# Catmull-Rom" << endl;
111 for (label segI = 0; segI <= nSeg; ++segI)
113 scalar lambda = scalar(segI)/scalar(nSeg);
114 printPoint(Info, spl.position(lambda));
119 polyLine pl(pointFields[splineI]);
121 Info<< nl <<"# polyList" << endl;
123 for (label segI = 0; segI <= nSeg; ++segI)
125 scalar lambda = scalar(segI)/scalar(nSeg);
126 printPoint(Info, pl.position(lambda));
136 // ************************************************************************* //