Remove legacy splines code and use CatmullRomSpline as 'spline'

- compatibility:
  * 'polySpline' and 'simpleSpline' accepted
  * detect and discard end tangent specifications

- a BSpline is also included (eg, for future support of NURBS), but is
  not selectable from blockMesh since it really isn't as nice as the
  Catmull-Rom (ie, doesn't *exactly* go through each point).
This commit is contained in:
Mark Olesen
2009-12-07 06:54:06 +01:00
parent 1b0cf102cc
commit 73f9f7f780
19 changed files with 235 additions and 1136 deletions

View File

@ -1,4 +1,4 @@
curvedEdges/BSpline2.C
curvedEdges/BSpline.C
curvedEdges/CatmullRomSpline.C
curvedEdges/polyLine.C
@ -9,11 +9,6 @@ curvedEdges/polyLineEdge.C
curvedEdges/lineDivide.C
curvedEdges/splineEdge.C
curvedEdges/legacy/spline.C
curvedEdges/legacy/BSpline.C
curvedEdges/legacy/simpleSplineEdge.C
curvedEdges/legacy/polySplineEdge.C
blockDescriptor/blockDescriptor.C
blockDescriptor/blockDescriptorEdges.C

View File

@ -25,24 +25,23 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BSpline2.H"
#include "BSpline.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::BSpline2::BSpline2
Foam::BSpline::BSpline
(
const pointField& Knots,
const vector&,
const vector&
const pointField& knots,
const bool closed
)
:
polyLine(Knots)
polyLine(knots, closed)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::BSpline2::position(const scalar mu) const
Foam::point Foam::BSpline::position(const scalar mu) const
{
// endpoints
if (mu < SMALL)
@ -60,25 +59,36 @@ Foam::point Foam::BSpline2::position(const scalar mu) const
}
Foam::point Foam::BSpline2::position
Foam::point Foam::BSpline::position
(
const label segment,
const scalar mu
) const
{
// out-of-bounds
if (segment < 0)
{
return points().first();
}
else if (segment > nSegments())
{
return points().last();
}
const point& p0 = points()[segment];
const point& p1 = points()[segment+1];
// special cases - no calculation needed
if (segment < 0 || mu < 0.0)
if (mu <= 0.0)
{
return p0;
}
else if (segment > nSegments() || mu >= 1.0)
else if (mu >= 1.0)
{
return p1;
}
// determine the end points
point e0;
point e1;
@ -86,7 +96,7 @@ Foam::point Foam::BSpline2::position
if (segment == 0)
{
// end: simple reflection
e0 = 2.0 * p0 - p1;
e0 = 2*p0 - p1;
}
else
{
@ -96,7 +106,7 @@ Foam::point Foam::BSpline2::position
if (segment+1 == nSegments())
{
// end: simple reflection
e1 = 2.0 * p1 - p0;
e1 = 2*p1 - p0;
}
else
{
@ -121,9 +131,9 @@ Foam::point Foam::BSpline2::position
}
Foam::scalar Foam::BSpline2::length() const
Foam::scalar Foam::BSpline::length() const
{
notImplemented("BSpline2::length() const");
notImplemented("BSpline::length() const");
return 1.0;
}

View File

@ -23,13 +23,13 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::BSpline2
Foam::BSpline
Description
An implementation of B-splines.
In this implementation, the end tangents are created
automatically by reflection.
In this implementation, the end tangents are created automatically
by reflection.
In matrix form, the @e local interpolation on the interval t=[0..1] is
described as follows:
@ -40,28 +40,27 @@ Description
[ 1 4 1 0 ] [ P2 ]
@endverbatim
Where P-1 and P2 represent the neighbouring points or the
extrapolated end points. Simple reflection is used to
automatically create the end points.
Where P-1 and P2 represent the neighbouring points or the extrapolated
end points. Simple reflection is used to automatically create the end
points.
The spline is discretized based on the chord length of the
individual segments. In rare cases (sections with very high
curvatures), the resulting distribution may be sub-optimal.
The spline is discretized based on the chord length of the individual
segments. In rare cases (sections with very high curvatures), the
resulting distribution may be sub-optimal.
SeeAlso
CatmullRomSpline
ToDo
A future implementation could also handle closed splines - either
when the start/end points are identically or when specified.
A future implementation could also handle closed splines.
SourceFiles
BSpline2.C
BSpline.C
\*---------------------------------------------------------------------------*/
#ifndef BSpline2_H
#define BSpline2_H
#ifndef BSpline_H
#define BSpline_H
#include "polyLine.H"
@ -71,20 +70,20 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BSpline2 Declaration
Class BSpline Declaration
\*---------------------------------------------------------------------------*/
class BSpline2
class BSpline
:
public polyLine
{
// Private Member Functions
//- Disallow default bitwise copy construct
BSpline2(const BSpline2&);
BSpline(const BSpline&);
//- Disallow default bitwise assignment
void operator=(const BSpline2&);
void operator=(const BSpline&);
public:
@ -92,11 +91,10 @@ public:
// Constructors
//- Construct from components
BSpline2
BSpline
(
const pointField& knots,
const vector& begTangentNotImplemented = vector::zero,
const vector& endTangentNotImplemented = vector::zero
const bool notImplementedClosed = false
);

View File

@ -31,12 +31,11 @@ License
Foam::CatmullRomSpline::CatmullRomSpline
(
const pointField& Knots,
const vector&,
const vector&
const pointField& knots,
const bool closed
)
:
polyLine(Knots)
polyLine(knots, closed)
{}
@ -66,19 +65,30 @@ Foam::point Foam::CatmullRomSpline::position
const scalar mu
) const
{
// out-of-bounds
if (segment < 0)
{
return points().first();
}
else if (segment > nSegments())
{
return points().last();
}
const point& p0 = points()[segment];
const point& p1 = points()[segment+1];
// special cases - no calculation needed
if (segment < 0 || mu < 0.0)
if (mu <= 0.0)
{
return p0;
}
else if (segment > nSegments() || mu >= 1.0)
else if (mu >= 1.0)
{
return p1;
}
// determine the end points
point e0;
point e1;
@ -86,7 +96,7 @@ Foam::point Foam::CatmullRomSpline::position
if (segment == 0)
{
// end: simple reflection
e0 = 2.0 * p0 - p1;
e0 = 2*p0 - p1;
}
else
{
@ -96,7 +106,7 @@ Foam::point Foam::CatmullRomSpline::position
if (segment+1 == nSegments())
{
// end: simple reflection
e1 = 2.0 * p1 - p0;
e1 = 2*p1 - p0;
}
else
{

View File

@ -26,36 +26,35 @@ Class
Foam::CatmullRomSpline
Description
An implementation of Catmull-Rom splines (sometime as known as
Overhauser splines).
An implementation of Catmull-Rom splines
(sometimes known as Overhauser splines).
In this implementation, the end tangents are created
automatically by reflection.
In this implementation, the end tangents are created automatically
by reflection.
In matrix form, the @e local interpolation on the interval t=[0..1] is
described as follows:
@verbatim
P(t) = 0.5 * [ t^3 t^2 t 1 ] * [ -1 3 -3 1 ] * [ P-1 ]
P(t) = 1/2 * [ t^3 t^2 t 1 ] * [ -1 3 -3 1 ] * [ P-1 ]
[ 2 -5 4 -1 ] [ P0 ]
[ -1 0 1 0 ] [ P1 ]
[ 0 2 0 0 ] [ P2 ]
@endverbatim
Where P-1 and P2 represent the neighbouring points or the
extrapolated end points. Simple reflection is used to
automatically create the end points.
Where P-1 and P2 represent the neighbouring points or the extrapolated
end points. Simple reflection is used to automatically create the end
points.
The spline is discretized based on the chord length of the
individual segments. In rare cases (sections with very high
curvatures), the resulting distribution may be sub-optimal.
The spline is discretized based on the chord length of the individual
segments. In rare cases (sections with very high curvatures), the
resulting distribution may be sub-optimal.
SeeAlso
http://www.algorithmist.net/catmullrom.html provides a nice
introduction
ToDo
A future implementation could also handle closed splines - either
when the start/end points are identically or when specified.
A future implementation could also handle closed splines.
SourceFiles
CatmullRomSpline.C
@ -97,8 +96,7 @@ public:
CatmullRomSpline
(
const pointField& knots,
const vector& begTangentNotImplemented = vector::zero,
const vector& endTangentNotImplemented = vector::zero
const bool notImplementedClosed = false
);

View File

@ -1,137 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "BSpline.H"
#include "simpleMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::pointField Foam::BSpline::findKnots
(
const pointField& allknots,
const vector& fstend,
const vector& sndend
)
{
const label NKnots = allknots.size();
// set up 1/6 and 2/3 which are the matrix elements throughout most
// of the matrix
register const scalar oneSixth = 1.0/6.0;
register const scalar twoThird = 2.0/3.0;
simpleMatrix<vector> M(NKnots+2, 0, vector::zero);
// set up the matrix
M[0][0] = -0.5*scalar(NKnots - 1);
M[0][2] = 0.5*scalar(NKnots - 1);
for (register label i = 1; i <= NKnots; i++)
{
M[i][i-1] = oneSixth;
M[i][i] = twoThird;
M[i][i+1] = oneSixth;
}
M[NKnots+1][NKnots-1] = -0.5*scalar(NKnots - 1);
M[NKnots+1][NKnots+1] = 0.5*scalar(NKnots - 1);
// set up the vector
for (register label i = 1; i <= NKnots; i++)
{
M.source()[i] = allknots[i-1];
}
// set the gradients at the ends:
if (mag(fstend) < 1e-8)
{
// default : forward differences on the end knots
M.source()[0] = allknots[1] - allknots[0];
M.source()[0] /= mag(M.source()[0]);
}
else
{
// use the gradient vector provided
M.source()[0] = fstend/mag(fstend);
}
if (mag(sndend)<1e-8)
{
// default : forward differences on the end knots
M.source()[NKnots+1] = M.source()[NKnots-1] - M.source()[NKnots];
M.source()[NKnots+1] /= mag(M.source()[NKnots+1]);
}
else
{
// use the gradient vector provided
M.source()[NKnots+1] = sndend/mag(sndend);
}
// invert the equation to find the control knots
return M.solve();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::BSpline::BSpline
(
const pointField& Knots,
const vector& fstend,
const vector& sndend
)
:
spline(findKnots(Knots, fstend, sndend))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::BSpline::realPosition(const scalar mu) const
{
return spline::position(mu);
}
Foam::point Foam::BSpline::position(const scalar mu) const
{
return spline::position((1.0/(nKnots() - 1))*(1.0 + mu*(nKnots() - 3)));
}
Foam::scalar Foam::BSpline::length() const
{
notImplemented("BSpline::length() const");
return 1.0;
}
// ************************************************************************* //

View File

@ -1,106 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::BSpline
Description
A cubic spline going through all the knots
SourceFiles
BSpline.C
\*---------------------------------------------------------------------------*/
#ifndef BSpline_H
#define BSpline_H
#include "spline.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class BSpline Declaration
\*---------------------------------------------------------------------------*/
class BSpline
:
public spline
{
// Private Member Functions
pointField findKnots
(
const pointField&,
const vector& fstend,
const vector& sndend
);
//- Disallow default bitwise copy construct
BSpline(const BSpline&);
//- Disallow default bitwise assignment
void operator=(const BSpline&);
public:
// Constructors
//- Construct from components
BSpline
(
const pointField& knots,
const vector& fstend = vector::zero,
const vector& sndend = vector::zero
);
// Member Functions
//- Return the real point position corresponding to the curve parameter
// 0 <= lambda <= 1
point realPosition(const scalar lambda) const;
//- Return the point position corresponding to the curve parameter
// 0 <= lambda <= 1
point position(const scalar lambda) const;
//- Return the length of the curve
scalar length() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,150 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "polySplineEdge.H"
#include "BSpline.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(polySplineEdge, 0);
addToRunTimeSelectionTable(curvedEdge, polySplineEdge, Istream);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// intervening : returns a list of the points making up the polyLineEdge
// which describes the spline. nBetweenKnots is the number of points
// placed between each knot : this ensures that the knot locations
// are retained as a subset of the polyLine points.
// note that the points are evenly spaced in the parameter mu, not
// in real space
Foam::pointField Foam::polySplineEdge::intervening
(
const pointField& otherknots,
const label nBetweenKnots,
const vector& fstend,
const vector& sndend
)
{
BSpline spl
(
appendEndPoints(curvedEdge::points_, start_, end_, otherknots),
fstend,
sndend
);
const label nSize
(
otherknots.size() * (1 + nBetweenKnots) + nBetweenKnots + 2
);
const label NKnots = spl.nKnots();
const scalar init = 1.0/(NKnots - 1);
scalar interval = (NKnots - scalar(3.0))/NKnots;
interval /= otherknots.size() + 1;
interval /= nBetweenKnots + 1;
pointField ans(nSize);
ans[0] = curvedEdge::points_[start_];
register scalar index(init);
for (register label i=1; i<nSize-1; i++)
{
index += interval;
ans[i] = spl.realPosition(index);
}
ans[nSize-1] = curvedEdge::points_[end_];
return ans;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polySplineEdge::polySplineEdge
(
const pointField& points,
const label start,
const label end,
const pointField& otherknots,
const label nInterKnots
)
:
curvedEdge(points, start, end),
polyLine
(
intervening
(
otherknots,
nInterKnots,
vector::zero,
vector::zero
)
),
otherKnots_(otherknots)
{}
Foam::polySplineEdge::polySplineEdge
(
const pointField& points,
Istream& is
)
:
curvedEdge(points, is),
polyLine(pointField(0)),
otherKnots_(is)
{
label nInterKnots(20);
vector fstend(is);
vector sndend(is);
polyLine::points_ = intervening(otherKnots_, nInterKnots, fstend, sndend);
calcParam();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::polySplineEdge::position(const scalar mu) const
{
return polyLine::position(mu);
}
Foam::scalar Foam::polySplineEdge::length() const
{
return polyLine::length();
}
// ************************************************************************* //

View File

@ -1,117 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::polySplineEdge
Description
A curvedEdge interface for B-splines.
SourceFiles
polySplineEdge.C
\*---------------------------------------------------------------------------*/
#ifndef polySplineEdge_H
#define polySplineEdge_H
#include "curvedEdge.H"
#include "polyLine.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class polySplineEdge Declaration
\*---------------------------------------------------------------------------*/
class polySplineEdge
:
public curvedEdge,
public polyLine
{
// Private data
pointField otherKnots_;
// Private member functions
pointField intervening
(
const pointField& otherKnots,
const label nBetweenKnots,
const vector&,
const vector&
);
public:
//- Runtime type information
TypeName("polySpline");
// Constructors
//- Construct from components
polySplineEdge
(
const pointField&,
const label start,
const label end,
const pointField& otherKnots,
const label nInterKnots = 20
);
//- Construct from Istream setting pointsList
polySplineEdge(const pointField&, Istream&);
//- Destructor
virtual ~polySplineEdge()
{}
// Member Functions
//- Return the point position corresponding to the curve parameter
// 0 <= lambda <= 1
point position(const scalar mu) const;
//- Return the length of the curve
scalar length() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,92 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "simpleSplineEdge.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(simpleSplineEdge, 0);
addToRunTimeSelectionTable(curvedEdge, simpleSplineEdge, Istream);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::simpleSplineEdge::simpleSplineEdge
(
const pointField& points,
const label start,
const label end,
const pointField& otherknots
)
:
curvedEdge(points, start, end),
BSpline(appendEndPoints(points, start, end, otherknots))
{}
Foam::simpleSplineEdge::simpleSplineEdge
(
const pointField& points,
const label start,
const label end,
const pointField& otherknots,
const vector& fstend,
const vector& sndend
)
:
curvedEdge(points, start, end),
BSpline(appendEndPoints(points, start, end, otherknots), fstend, sndend)
{}
Foam::simpleSplineEdge::simpleSplineEdge(const pointField& points, Istream& is)
:
curvedEdge(points, is),
BSpline(appendEndPoints(points, start_, end_, pointField(is)))
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::simpleSplineEdge::position(const scalar mu) const
{
return BSpline::position(mu);
}
Foam::scalar Foam::simpleSplineEdge::length() const
{
notImplemented("simpleSplineEdge::length() const");
return 1.0;
}
// ************************************************************************* //

View File

@ -1,122 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::simpleSplineEdge
Description
A curvedEdge interface for B-splines.
SourceFiles
simpleSplineEdge.C
\*---------------------------------------------------------------------------*/
#ifndef simpleSplineEdge_H
#define simpleSplineEdge_H
#include "curvedEdge.H"
#include "BSpline.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class simpleSplineEdge Declaration
\*---------------------------------------------------------------------------*/
class simpleSplineEdge
:
public curvedEdge,
public BSpline
{
// Private Member Functions
//- Disallow default bitwise copy construct
simpleSplineEdge(const simpleSplineEdge&);
//- Disallow default bitwise assignment
void operator=(const simpleSplineEdge&);
public:
//- Runtime type information
TypeName("simpleSpline");
// Constructors
//- Construct from components
simpleSplineEdge
(
const pointField&,
const label start,
const label end,
const pointField& otherKnots
);
//- Construct from components
simpleSplineEdge
(
const pointField&,
const label start,
const label end,
const pointField& otherKnots,
const vector& fstend,
const vector& sndend
);
//- Construct from Istream setting pointsList
simpleSplineEdge(const pointField&, Istream&);
// Destructor
virtual ~simpleSplineEdge()
{}
// Member Functions
//- Return the point position corresponding to the curve parameter
// 0 <= lambda <= 1
point position(const scalar) const;
//- Return the length of the simple spline curve
scalar length() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,95 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "spline.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::scalar Foam::spline::B(const scalar tau)
{
if (tau <= -2.0 || tau >= 2.0)
{
return 0.0;
}
else if (tau <= -1.0)
{
return pow((2.0 + tau), 3.0)/6.0;
}
else if (tau <= 0.0)
{
return (4.0 - 6.0*tau*tau - 3.0*tau*tau*tau)/6.0;
}
else if (tau <= 1.0)
{
return (4.0 - 6.0*tau*tau + 3.0*tau*tau*tau)/6.0;
}
else if (tau <= 2.0)
{
return pow((2.0 - tau), 3.0)/6.0;
}
else
{
FatalErrorIn("spline::B(const scalar)")
<< "Programming error???, "
<< "tau = " << tau
<< abort(FatalError);
}
return 0.0;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::spline::spline(const pointField& knotPoints)
:
knots_(knotPoints)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::spline::position(const scalar mu) const
{
point loc(point::zero);
for (register label i=0; i < knots_.size(); i++)
{
loc += B((knots_.size() - 1)*mu - i)*knots_[i];
}
return loc;
}
Foam::scalar Foam::spline::length() const
{
notImplemented("spline::length() const");
return 1.0;
}
// ************************************************************************* //

View File

@ -1,115 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::spline
Description
Define a basic spline on nKnots knots.
The spline does not go anywhere near these knots
(will act as a base type for various splines that will have real uses)
SourceFiles
spline.C
\*---------------------------------------------------------------------------*/
#ifndef spline_H
#define spline_H
#include "pointField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class spline Declaration
\*---------------------------------------------------------------------------*/
class spline
{
// Private data
//- The knots defining the spline
pointField knots_;
// Private Member Functions
//- Blending function for constructing spline
static scalar B(const scalar);
//- Disallow default bitwise copy construct
spline(const spline&);
//- Disallow default bitwise assignment
void operator=(const spline&);
public:
// Constructors
//- Construct from components
spline(const pointField&);
// Member Functions
// Access
//- Return the knot points in the spline
const pointField& knotPoints() const
{
return knots_;
}
//- Return the number of knots in the spline
label nKnots() const
{
return knots_.size();
}
//- Return the point position corresponding to the curve parameter
// 0 <= lambda <= 1
point position(const scalar) const;
//- Return the length of the spline curve
scalar length() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -60,7 +60,7 @@ void Foam::polyLine::calcParam()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polyLine::polyLine(const pointField& ps)
Foam::polyLine::polyLine(const pointField& ps, const bool)
:
points_(ps),
lineLength_(0.0),
@ -86,15 +86,6 @@ Foam::label Foam::polyLine::nSegments() const
Foam::label Foam::polyLine::localParameter(scalar& lambda) const
{
// check range of lambda
if (lambda < 0 || lambda > 1)
{
FatalErrorIn("polyLine::localParameter(scalar&)")
<< "Parameter out-of-range, "
<< "lambda = " << lambda
<< abort(FatalError);
}
// check endpoints
if (lambda < SMALL)
{
@ -128,47 +119,58 @@ Foam::label Foam::polyLine::localParameter(scalar& lambda) const
}
Foam::point Foam::polyLine::position(const scalar lambda) const
Foam::point Foam::polyLine::position(const scalar mu) const
{
// check range of lambda
if (lambda < 0 || lambda > 1)
{
FatalErrorIn("polyLine::position(const scalar)")
<< "Parameter out of range, "
<< "lambda = " << lambda
<< abort(FatalError);
}
// check endpoints
if (lambda < SMALL)
if (mu < SMALL)
{
return points_[0];
return points_.first();
}
else if (lambda > 1 - SMALL)
else if (mu > 1 - SMALL)
{
return points_.last();
}
// search table of cumulative distances to find which line-segment
// we are on. Check the upper bound.
scalar lambda = mu;
label segment = localParameter(lambda);
return position(segment, lambda);
}
label segmentI = 1;
while (param_[segmentI] < lambda)
Foam::point Foam::polyLine::position
(
const label segment,
const scalar mu
) const
{
// out-of-bounds
if (segment < 0)
{
++segmentI;
return points_.first();
}
else if (segment > nSegments())
{
return points_.last();
}
--segmentI; // we now want the lower bound
const point& p0 = points()[segment];
const point& p1 = points()[segment+1];
// linear interpolation
return
(
points_[segmentI]
+ ( points_[segmentI+1] - points_[segmentI] )
* ( lambda - param_[segmentI] )
/ ( param_[segmentI+1] - param_[segmentI] )
);
// special cases - no calculation needed
if (mu <= 0.0)
{
return p0;
}
else if (mu >= 1.0)
{
return p1;
}
else
{
// linear interpolation
return points_[segment] + mu * (p1 - p0);
}
}

View File

@ -29,6 +29,9 @@ Description
A series of straight line segments, which can also be interpreted as
a series of control points for splines, etc.
ToDo
A future implementation could also handle a closed polyLine.
SourceFiles
polyLine.C
@ -89,7 +92,11 @@ public:
// Constructors
//- Construct from components
polyLine(const pointField&);
polyLine
(
const pointField&,
const bool notImplementedClosed = false
);
// Member Functions
@ -104,6 +111,10 @@ public:
// 0 <= lambda <= 1
point position(const scalar) const;
//- Return the point position corresponding to the local parameter
// 0 <= lambda <= 1 on the given segment
point position(const label segment, const scalar) const;
//- Return the length of the curve
scalar length() const;
};

View File

@ -33,7 +33,32 @@ License
namespace Foam
{
defineTypeNameAndDebug(splineEdge, 0);
addToRunTimeSelectionTable(curvedEdge, splineEdge, Istream);
addToRunTimeSelectionTable
(
curvedEdge,
splineEdge,
Istream
);
// compatibility with old names
addNamedToRunTimeSelectionTable
(
curvedEdge,
splineEdge,
Istream,
simpleSpline
);
// compatibility with old names
addNamedToRunTimeSelectionTable
(
curvedEdge,
splineEdge,
Istream,
polySpline
);
}
@ -44,11 +69,11 @@ Foam::splineEdge::splineEdge
const pointField& points,
const label start,
const label end,
const pointField& otherknots
const pointField& internalPoints
)
:
curvedEdge(points, start, end),
CatmullRomSpline(appendEndPoints(points, start, end, otherknots))
CatmullRomSpline(appendEndPoints(points, start, end, internalPoints))
{}
@ -60,15 +85,21 @@ Foam::splineEdge::splineEdge(const pointField& points, Istream& is)
token t(is);
is.putBack(t);
// might have start/end tangents that we currently ignore
// compatibility - might also have start/end tangents - discard them
if (t == token::BEGIN_LIST)
{
vector fstend(is);
vector sndend(is);
vector tangent0Ignored(is);
vector tangent1Ignored(is);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::splineEdge::~splineEdge()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::splineEdge::position(const scalar mu) const

View File

@ -28,6 +28,10 @@ Class
Description
A curvedEdge interface for Catmull-Rom splines.
Note
For compatibility, also accepts the type names 'polySpline' and
'simpleSpline'.
SourceFiles
splineEdge.C
@ -76,17 +80,15 @@ public:
const pointField&,
const label start,
const label end,
const pointField& otherKnots
const pointField& internalPoints
);
//- Construct from Istream setting pointsList
//- Construct from Istream, setting pointsList
splineEdge(const pointField&, Istream&);
// Destructor
virtual ~splineEdge()
{}
//- Destructor
virtual ~splineEdge();
// Member Functions
@ -95,7 +97,7 @@ public:
// 0 <= lambda <= 1
virtual point position(const scalar) const;
//- Return the length of the simple spline curve
//- Return the length of the spline curve (not implemented)
virtual scalar length() const;
};