[vtkusers] running parts of a pipeline in parallel

Andrew J. P. Maclean a.maclean at acfr.usyd.edu.au
Mon Sep 2 19:18:16 EDT 2002


Here are some general observations:
1) Create a shared memory object in which the mappers and possibly the
image source are stored. Access to these objects is protected by
mutexes.
2) Remove the actors from the threads.
3) Start off the two threads and make sure that they deep copy their
mappers to shared memory upon termination of these threads.
4)
   Either a) Have a third thread that waits on the availability of the
mappers and when available deep copies them and processes them through
the actor and renderer. 

   Or b) Or just do a join on the first two threads in main process an
process them as you do below.

This may give you some hints on parallelizing.

Hope this helps.


___________________________________________
Andrew J. P. Maclean
Postal:
Australian Centre for Field Robotics
The Rose Street Building J04
The University of Sydney  2006  NSW
AUSTRALIA
 
Room:  106
Phone: +61 2 9351 3283
Fax:   +61 2 9351 7474
       http://www.acfr.usyd.edu.au/

___________________________________________


-----Original Message-----
From: vtkusers-admin at public.kitware.com
[mailto:vtkusers-admin at public.kitware.com] On Behalf Of Schaap, J.A.
(LKEB)
Sent: Monday, 2 September 2002 19:20
To: vtk mailing list
Subject: [vtkusers] running parts of a pipeline in parallel

Hi guru's,

I'm looking into parallelizing my vtk based programs.
Below you can find a very simple example of one source that is used by
two parallel pieces of pipeline, that generate two actors, which are
displayed in one renderer. Very simple isn't it?

What I would like to do is to execute the pieces denoted as pipe1 and
pipe2 in two seperate threads.

I have looked at the documentation of vtkMultiProcessController,
vtkInputPort, vtkOutputPort and at the examples, but I still can't
figure out how to do this.

Could anybody modify my example below so that the two pipe's run in two
seperate threads?

Thanx, Jorrit




//Begin of example code

#include "vtkImageEllipsoidSource.h"
#include "vtkProperty.h"
#include "vtkImageGaussianSmooth.h"
#include "vtkImageGradientMagnitude.h"
#include "vtkContourFilter.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"

int main()
{
//setup renderer, renderwindow and renderwindowinteractor
	vtkRenderWindow *renWin = vtkRenderWindow::New();
	renWin->MakeRenderWindowInteractor()->Initialize();

	vtkRenderer *ren = vtkRenderer::New();
	renWin->AddRenderer(ren);
//end of setup


//source
	vtkImageEllipsoidSource *ies = vtkImageEllipsoidSource::New();
	ies->SetWholeExtent(0, 63, 0, 63, 0, 63);
	ies->SetOutputScalarTypeToUnsignedChar();
	ies->SetOutValue(0);
	ies->SetInValue(60);
	ies->SetRadius(32, 32, 32);
	ies->SetCenter(0, 32, 32);
//source


//begin of pipe 1
	vtkImageGaussianSmooth *igs = vtkImageGaussianSmooth::New();
	igs->SetInput(ies->GetOutput());
	
	vtkContourFilter *cf1 = vtkContourFilter::New();
	cf1->SetInput(igs->GetOutput());
	cf1->SetValue(0, 30);
	cf1->ComputeScalarsOff();
	cf1->ComputeNormalsOn();

	vtkPolyDataMapper *pdMapper1 = vtkPolyDataMapper::New();
	pdMapper1->SetInput(cf1->GetOutput());

	vtkActor *actor1 = vtkActor::New();
	actor1->SetMapper(pdMapper1);
	actor1->GetProperty()->SetColor(1, 0, 0);
	ren->AddActor(actor1);
//end of pipe 1


	
//begin of pipe 2
	vtkImageGradientMagnitude *igm =
vtkImageGradientMagnitude::New();
	igm->SetInput(ies->GetOutput());
	
	vtkImageGaussianSmooth *igs2 = vtkImageGaussianSmooth::New();
	igs2->SetInput(igm->GetOutput());
	
	vtkContourFilter *cf2 = vtkContourFilter::New();
	cf2->SetInput(igs2->GetOutput());
	cf2->SetValue(0, 2);
	cf2->ComputeScalarsOff();
	cf2->ComputeNormalsOn();

	vtkPolyDataMapper *pdMapper2 = vtkPolyDataMapper::New();
	pdMapper2->SetInput(cf2->GetOutput());

	vtkActor *actor2 = vtkActor::New();
	actor2->SetMapper(pdMapper2);
	actor2->GetProperty()->SetColor(0, 1, 0);
	ren->AddActor(actor2);
//end of pipe 2


//start interaction
	renWin->GetInteractor()->Start();


//cleanup after interaction has ended
	renWin->Delete();
	ren->Delete();
	ies->Delete();
	igs->Delete();
	cf1->Delete();
	pdMapper1->Delete();
	actor1->Delete();
	igm->Delete();
	igs2->Delete();
	cf2->Delete();
	pdMapper2->Delete();
	actor2->Delete();

//exit
	return 0;
}







More information about the vtkusers mailing list