Thread View: cvnet.c++
2 messages
2 total messages
Started by Ronald van Loon
Mon, 16 Nov 1992 16:08
Real life problem: what is the proper way of subclassing this ?
Author: Ronald van Loon
Date: Mon, 16 Nov 1992 16:08
Date: Mon, 16 Nov 1992 16:08
68 lines
2650 bytes
2650 bytes
The problem is the following:
consider a basic graphics class, called 'point3d' encapsulating the concept of
a 3D-point in a coordinate-system. Mind you, the coordinate system is
important, every point has one. A number of operations are defined on those
points, like multiplication (inproduct), adding (translation) etc. etc.
Everytime two points are incompatible, ie. are in different coordinatesystem,
one of the two is forced in the coordinatesystem by a coordinate
transformation.
Now, for efficiency reasons, the check whether points are in the same
coordinatesystem needs to be removed, as it turns out that most of the time
points are already in the same coordinatesystem, hence testing is not needed.
Two approaches can now be taken:
1. The original 3-dimensional point in coordinatesystem concept is a special
case of a normal 3-dimensional point:
class point_3d
{
// baseclass
... operations ...
};
class point_3d_with_coordinate_system
: public point_3d
{
// subclass
};
additional advantage:
all code for point_3d_with_coordinate_system is very straightforward:
point_3d_wc::function(point_3d& point2)
if (point1 not in same coordinate system as point 2)
force point2 in same coordinate system as point1
execute equivalent code in baseclass (as coordinate systems are the same)
2. The 3 dimensional point without checks for coordinate systems is a special
case of the normal case.
class point_3d_with_coordinate_system
{
// different baseclass
};
class point_3d_with_no_coordinate_system_check
: public point_3d_with_coordinate_system
obvious disadvantage:
all code from the base-class needs to be duplicated (as the code from
the baseclass contains the check for coordinate systems).
Any and all opinions from the net appreciated
--
+--- Ronald van Loon ---+
| (rvloon@cv.ruu.nl) |
| 3DCV Group, Utrecht |
+--- The Netherlands ---+ This part of .signature intentionally left blank.
Re: Real life problem: what is the proper way of subclassing this ?
Author: Doug Morgan
Date: Mon, 16 Nov 1992 23:24
Date: Mon, 16 Nov 1992 23:24
70 lines
3753 bytes
3753 bytes
In article <1992Nov16.160806.29351@cv.ruu.nl> rvloon@cv.ruu.nl (Ronald van Loon) writes:
[... two ways of handling point_3d and
point_3d_with_coordinate_system so that the test for equal
coordinate system can be bypassed ...]
--
+--- Ronald van Loon ---+
| (rvloon@cv.ruu.nl) |
| 3DCV Group, Utrecht |
+--- The Netherlands ---+ This part of .signature intentionally left blank.
How about just one class with two sets of operations? One set has the
test for equal coordinate systems. The other does not. The functions
in the second set all assume a precondition that the coordinate
systems are be equal. If coordinate systems are unequal, the results
are undefined (even if something is dutifully computed).
Also, here is a discussion of how coordinate system organization.
This is not directly applicable to your question, but pretty much is
the general starting point for deriving more specialized coordinate
system implementations. A point with coordinate system is
conceptually a pair:
[abstract point (p in P), coordinate system (S : P => R^n)].
Notice,
O a coordinate systems is a mapping
O there is no explicit vector of coefficients. However, such a
vector can still be obtained as S(p) (or S().apply(p) in C++).
O the coordinate system frame can be obtained from the tuple of
abstract points:
[S.inverse().apply([0 0 0])
S.inverse().apply([1 0 0])
S.inverse().apply([0 1 0])
S.inverse().apply([0 0 1))].
Other important objects are:
O coordinate transformations, such as
T = S1.inverse().compose(S2) : R^n1 => R^n2
O mappings between abstract spaces, such a M : P1 => P2
O associated coordinate mappings, such as
T = S1.inverse().compose(M).compose(S2) : R^n1 => R^n2
O network (or set) of mapping between abstract spaces and coordinate
transformations/mappings.
All operations on points with coordinate systems eventually decompose
into operations on points in R^n which themselves decompose into
operations on things like arrays of floats. The multitude of design
choices include:
O going straight to representations of things like arrays of floats
and making all the rest implicit. Within certain scopes of a
graphics application (e.g. inside a graphics server, a graphics
engine, or a third party graphics routine) this can be manditory.
O disallowing all user access to the abstract point objects or even
the coordinate system objects, so they needn't be explicit in the
final software design
O caching intermediate interesting information. Caching the
coordinate tuple (S(p)) or an array of floats on the
point_3d_with_coordinate_system is the most common type of cache.
Another type caches composed coordinate transformations on the
network object or in some local variable.
doug
--------------------------------------------------------------------
Doug Morgan, doug@ads.com, (415) 960-7300
Advanced Decision Systems (a division of Booz-Allen & Hamilton Inc.)
1500 Plymouth St., Mountain View, CA 94043-1230
--------------------------------------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads