[Insight-developers] Backward compatibility worst practices

Bill Lorensen bill.lorensen at gmail.com
Tue Aug 25 13:36:42 EDT 2009


Folks,

Here is a recent e-mail from the vtk users list. It illustrates an
issue regarding backward compatibility. This fellow is probably trying
to get a former colleague's working. Granted the pain could be less if
there was a documented description on what to do.

I searched google and the vtk wiki and could not find a description on
how to change the user's code.

FYI: vtk 4.2 is 5 years old.

Bill


---------- Forwarded message ----------
From: Kernel Blaha <kernelblaha at gmail.com>
Date: Mon, Aug 24, 2009 at 3:12 PM
Subject: [vtkusers] Legacy interactor code
To: vtkusers at vtk.org


Hi,

I'm a relative new user of VTK and I've inherited some code which
works fine with VTK 4.2.
I've now upgraded to 5.4 and have gotten stuck.

On compiling (in MS Visual Studio 2008) I get the following error:

'SetTimerMethod' : is not a member of 'vtkInteractorStyleUser'

The offending bit of code is the following:

DWORD WINAPI OnRunning(LPVOID){
       int i;
       // interact with data
       renderer = vtkRenderer::New();          // create renderer
       renderer->SetBackground(1,1,1); // set background to white
       renWin = vtkRenderWindow::New();                // create window
       renWin->AddRenderer(renderer);                          //
attach renderer to window
       renWin->SetSize(700,700);
// set size of window
       iren = vtkRenderWindowInteractor::New();        // create
interactor  (for mouse interaction)
       iren->SetRenderWindow(renWin);                  // attach
interactor to main window
       vtkInteractorStyleUser  *myint= vtkInteractorStyleUser::New();
// my settings for interaction
       myint->SetInteractor(iren);                             //
attach my interactor settings to windows interactor
       myint->SetTimerMethod(&animation,NULL); //      set timer
method to use animation function


       axes = vtkAxes::New(); // add axes
       axes->SetScaleFactor(1.0);      // scale factor of axes
       vtkPolyDataMapper *axesMapper = vtkPolyDataMapper::New(); //
create axes DataMapper (points to be drawn)
       axesMapper->SetInput(axes->GetOutput());        //give the data
mapper some date (about the axes)
       vtkActor *axesActor = vtkActor::New();          //axes actor,
the actual thing to pass to the renderer
       axesActor->SetMapper(axesMapper);                       // pass
the mapper to the actor

       camera = vtkCamera::New();
       camera->SetPosition(0.55,-1.75,-0.5);
       camera->SetFocalPoint(0.55,0,0.5);
       camera->Roll(180);

       renderer->SetActiveCamera(camera);
       renderer->ResetCamera();
//      renderer->AddActor(axesActor ); // actually send axes Actor to
the renderer.
       for(i=0;i<=vtknet_nnodes;i++)
               renderer->AddActor(nodesActor[i]); // actually send the
points to the renderer

       renWin->Render();                               // Render in Window

       myint->StartAnimate();                  //Start animation using
interactor and renderer
       iren->Start();
       return 0;
}


The above calls the animation function below, which uses mutex to stop
multiple access of cylx, cyly, cylz in another thread.


void animation(void *)
{
       int i;
       int scale=60;
       char str[20];

       WaitForSingleObject(m_mutex, INFINITE);

       for(i=0;i<vtknet_ncyls;i++)
       {

               nodesActor[trans2i[i]]->SetScale(1,cyly[i]*(float)scale,1);
               nodesActor[trans2i[i]]->SetPosition(cylx[i],-cyly[i]/((float)2000/scale),cylz[i]);
//cyly[i]*(float)scale/2
               nodesActor[trans2i[i]]->GetProperty()->SetColor(cylcolour[i]);

       }

       vtknet_ncyls_old=vtknet_ncyls;

       ReleaseMutex(m_mutex);
       Sleep(1);

}


I've had a look through (some of) the online resources and found that
this is an obsolete way of doing things.

Would anyone be kind enough to point me in the right direction as to
how it should be done now?
Any help would be greatly appreciated!!
Thanks in advance
Leon


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at:
http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers


More information about the Insight-developers mailing list