[vtkusers] Dynamically connected points

Obada Mahdi omahdi at gmx.de
Tue Oct 24 13:26:15 EDT 2006


Hi Nelson!

On 10/24/06, nelson - <nelson1977 at gmail.com> wrote:
> hi all,
>   i'm coding an interactive geomertry program in python using VTK. I
> can't figure out how to make a Point that is dependant from the
> position of the other points. I can to explain myself by an example.
>
> If i wanto conconstruct the middle point of two points in the space i
> have to build the middle point that change its position when i move
> the two points... can i make it in vtl. I see vtkAssembly but i don't
> understand if it is the right choice.

If I understand your problem correctly, you want to construct a middle
point from two other points that can be moved independently; in other
words, have an object whose position is given implicitly by two other
objects and some kind of operation.

vtkAssembly is useful for compound geometry, i.e. objects consisting
of multiple parts, organized in a hierarchical tree, that should be
affected simultaneously by transformations.  It does not, however,
provide a means to express and maintain object properties that are
calculated from other data sources and a given operation.

I guess there are two possible approaches to your problem--here are some ideas:
(1) Event-driven design: Monitor interactions that change positions
and update the "middle point" accordingly.  I suppose this is what you
already had in mind:

On 10/19/06, nelson - <nelson1977 at gmail.com> wrote:
> I can do it implementing my own observer pattern like
> framework or there is something already esisting in VTK i can use?

An observer like vtkCallbackCommand can be used to have a custom
function called on an event like "InteractionEvent" or
"EndInteractionEvent" for a given object, which can in turn
re-calculate point positions.  If modifications are not only initiated
by keyboard or mouse interaction but also programmatically, observing
the less specific "Modified" event instead might help.

The advantage of this approach is simplicity--the whole update logic
is part of an event handler, and there is no need for affected objects
(like vtkActor) to know about how their properties depend on other
objects.

(2) Demand-driven design: If you would rather like to have a more
general way of expressing dependencies for calculated properties, as
opposed to hard-coding the information flow into an event handler, you
could create a custom subclass of e.g. vtkCoordinate that knows how to
compute its position as "middle point" from other positions given upon
initialization, maybe as instances of vtkCoordinate or vtkActor.  This
custom class could then be used to maintain the calculated position,
by checking its own modification time against the input when being
accessed, and re-calculating theposition if needed.

In order to automatically update an actor's position based on such a
computed coordinate, one would either have to use a customized
vtkActor that maintains its position as a vtkCoordinate-compatible
class, or link them by observing the "Modified" event of the
coordinate object.

I apologize for not being more specific--I have not done something
like this before, so this is all more of a wild guess, and the details
of such an implementation largely depend on the specifics of your
application.


Hope it helps (and does not cause too much confusion :-)

Obada



More information about the vtkusers mailing list