[vtkusers] running parts of a pipeline in parallel
Schaap, J.A. (LKEB)
J.A.Schaap at lumc.nl
Mon Sep 2 05:19:49 EDT 2002
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