[vtkusers] socket communication

Clinton Stimpson clinton at elemtech.com
Wed Feb 2 11:21:49 EST 2005


>
> Message: 13
> Date: Wed, 2 Feb 2005 15:28:59 +0100
> From: jean-michel.rouet at philips.com
> Subject: [vtkusers] socket communication
> To: vtkusers at vtk.org
> Message-ID:
> 	<OF7AB17334.94A8669E-ONC1256F9C.004EDB96-C1256F9C.004FAC3C at philips.com>
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi all,
>
> I'm trying to do the following.
>
> A vtk application A (the server) that renders a scene and has an
> interactor
> an other vtk application B (the client) that renders an onther scene and
> has also an interactor
>
> (in fact A and B are the same program ran twice)
>
> What I'd like to achieve is this:
> Whenever the user changes the camera in application A, the camera of the
> application B is updated accordingly.
> but when the user moves the camera in B, the camera is not changed in A.
>
> I managed to do almost what I want using a socket communication.
> a callback that reacts on camera modifed events in A sends through the
> socket the position of the camera, the focal point and the viewup vector.
>
> application B listens to the socket and updates its own camera.
> Unfortunately, this listening is blocking the interface of B.
>
> Then I tried to set the socket listenner of B in a spawned thread so that
> the main interaction loop continues to occur.
> But then, the renderer->Render() call in the thread fails saying that: "
> vtkWin32OpenGLRenderWindow (018F0F40): wglMakeCurrent failed in
> MakeCurrent(), error: resource in use" (translation from french La
> ressource demandée est en cours d'utilisation).
>
> What is the solution then ?
>

You'll probably find it easier to *not* make a new thread, overload the
vtk*RenderWindowInteractor::Start method and add your socket(s) to the main
event loop.  You won't have to worry about doing inter-thread
communication, locking/unlocking etc.. and you also won't have to worry
about those video drivers that don't support multiple threads.

Here's an example:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/waiting_in_a_message_loop.asp

You may want to tweak it a bit for yourself.
Just pass your socket in as on of the handle objects to be waited on.
If you need Carbon or X11 equivalents, I can give you those if you need
them.  If you are using a GUI toolkit, there are usually ways to do this
without threading.

Clint




More information about the vtkusers mailing list