Confusion about splitting classes to allow sharing of resources



Hi all,

I've been confusing myself with this problem for a bit, and I'm
wondering if I'm going about this the right way. Let me describe my
problem first:

I'm using cubic splines to model two-dimensional parametric curves
(x(t),y(t)) to interpolate between nodes. I have a working Spline class
that does cubic spline interpolation of function values f[i] that are
defined at knot positions t[i]. I use this in my current Curve class.
Along with the splines for x and y, the Curve class also has one for
any other values (say p and q) that need to be interpolated along the
curve. I expect subclasses of Curve to add new interpolated parameters
along the curve. All Splines x, y, p and q currently have their own
knot vector t[i] and the Curve class provides functions that ensure a
certain t[i] of all splines only get changed all at once (in my app the
t[i] sometimes need to change to enhance the parameter mapping of the
curve). This is done by providing a virtual SetKnot function that a
Curve implementation should override. To me, the logical next step
would be, to change the spline class so it supports sharing a knot
vector between splines - it will save storage and will guarantee all
Splines stay in sync. For this, I would add a class KnotVector and give
the Spline class a reference to a (possibly) external knot vector.
Adding new interpolation variables in subclasses of Curve will then
just be a matter to linking that spline to the same knot vector as
well.

Now for my dilemma: my current spline class supports a public member
mySpline.Add(t_new, f_new) to add a new interpolation value at the end,
so splines can be built one point at a time. Similarly, the curve class
supports myCurve.Add(t_new, x_new,y_new,p_new,q_new) and will just add
the new data to the corresponding splines. This also provides an
interface to build the curve one point at a time. I still want to
provide this functionality in the new Spline class (with the shared
knot vector) and obviously retain it for the Curve class. But what
should the behaviour of
mySpline.Add(...) be if mySpline uses a shared knot vector? Ideally,

x.Add(t_new, x_new); y.Add(t_new, y_new);

probably should behave the same, whether x and y share a knot vector or
just have a knot vector with equal values. However,

x.Add(t_new, x_new); y.Add(t_alternate, y_new);

probably should generate an error when the knot vectors are shared. I
imagine further that any spline that share a knot vector that is not
explicitly expanded (such as Splines for p and q) gets expanded with a
default value - or it might be better to require all splines to be
given a new value explicitely
before more points can be added.

There are a few more issues, but they all seem to boil down to similar
problems: how do you keep the splines in sync, how do you guarantee
that splines and knotvectors contain the same number of elements, etc.
Like I said, I'm starting to wonder whether I'm going about this the
right way, like I'm approaching design issues from the wrong angle. Can
anyone point me back in the right direction?

best regards Mark

.



Relevant Pages

  • Re: solving the equation [ spline way ]
    ... Information about the location of its endpoints ... Information about the slope of the fitted curve ... At the end Tis not a single cubic curve, ... the complications of cubic splines. ...
    (sci.math)
  • Re: Confusion about splitting classes to allow sharing of resources
    ... I think you are confusing Curves and Splines here, but beyond that, it ... Unless you can share vast numbers of KVs the amount of memory saving will be fairly minimal. ... guarantees that the knot vectors stay in sync at all times. ... interpolate a method on Curve, ...
    (comp.object)
  • Re: Confusion about splitting classes to allow sharing of resources
    ... imagine further that any spline that share a knot vector that is not explicitly expanded (such as Splines for p and q) gets expanded with a default value - or it might be better to require all splines to be given a new value explicitely before more points can be added. ... reference count is not one when adding a point to a curve then copy the KnotVector and replace the reference pointer in the curve with the copy. ...
    (comp.object)
  • Re: Confusion about splitting classes to allow sharing of resources
    ... >> probably should generate an error when the knot vectors are shared. ... >> default value - or it might be better to require all splines to be ... > Share the KnotVector class via reference counted pointers. ... > reference count is not one when adding a point to a curve then copy ...
    (comp.object)
  • Re: Getting smooth Bezier curves in SVG
    ... open source library that can convert clothoid splines into bezier ... splines: libsprio. ... So you could calculate just a bunch of points on your curve (probably ... that into a bezier spline for output into SVG. ...
    (comp.graphics.algorithms)