Confusion about splitting classes to allow sharing of resources
- From: "m.a.stijnman@xxxxxxxxxxxxxx" <m.a.stijnman@xxxxxxxxxxxxxx>
- Date: 20 Apr 2005 06:44:54 -0700
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
.
- Follow-Ups:
- Re: Confusion about splitting classes to allow sharing of resources
- From: H. S. Lahman
- Re: Confusion about splitting classes to allow sharing of resources
- From: Hang Dog
- Re: Confusion about splitting classes to allow sharing of resources
- Prev by Date: Re: a UML tool light on resources
- Next by Date: Re: Confusion about splitting classes to allow sharing of resources
- Previous by thread: responsibilites - 'active' and 'passive' classes
- Next by thread: Re: Confusion about splitting classes to allow sharing of resources
- Index(es):
Relevant Pages
|