[vtkusers] Help with MultiThreading

Peter Wallin petwa055 at student.liu.se
Thu Nov 4 07:44:58 EST 2004


Hello there experts!,

I have an animation method in my vtk application. Its called be a simple "play" button but now I want to be able to use a "stop" botton to stop it.

I tried to run the animation on a seperate thread. But I dont get it to work. It doesnt seem to listen for my button clicks. Im not sure if I use it the right way.I only found a single example in (vtkFiniteDifferenceGradientEstimator.cxx) on how to use vtkMultiThreader.

Im using MFC and have implememted my vtk Code into the ViewDoc.
Below is my threading function and the functions that are linked with the buttons.
By pressing the buttons one just set a varibale to 1 or 0, and I want the thread to run the animation as long as the value is 1 and that it stops when its 0. 

I would really be happy with any help because I have been stuck on this for a long while! 

Regards
Peter


///////////////////////////////////
vtkView.cpp
////////


static VTK_THREAD_RETURN_TYPE Simulation( void *arg) // Single
{ 

sim = ((vtkViewDoc *)arg)->simulation;
steps = ((vtkViewDoc *)arg)->timesteps;

while(sim) {

for (int i=0;i<=steps;i++) {

		//updating updateVectorScaleFactor and updateScalarScaleFactor....
               
		((vtkView *)arg)->warp->SetScaleFactor(updateVectorScaleFactor);
		((vtkView *)arg)->scalars->SetScaleFactor(updateScalarScaleFactor);
		((vtkView *)arg)->actor->SetMapper(((vtkView*)arg)->pMapper);
		((vtkView *)arg)->renWin->Render();
	}

}
  return VTK_THREAD_RETURN_VALUE;

}




//Methods linked with play and stop button.


void VtkView::StartAnim() {   
multiThreader->SetSingleMethod( Simulation,(CVtkSDIView *) this );                               
multiThreader->SingleMethodExecute();
simulation=1;

}

void VtkView::StopAnim() {

simulation=0;

}


 




More information about the vtkusers mailing list