ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file

Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
Henry Weller
2016-05-30 21:20:56 +01:00
parent 1cce60aa78
commit eba760a6d6
24640 changed files with 6366069 additions and 0 deletions

View File

@ -0,0 +1,2 @@
ADD_SUBDIRECTORY(Cxx)

View File

@ -0,0 +1,26 @@
INCLUDE_REGULAR_EXPRESSION("^(lex|vtk|png|j|Task|Pipe).*$")
IF (VTK_USE_MPI)
find_package(MPI REQUIRED)
INCLUDE_DIRECTORIES(${MPI_C_INCLUDE_PATH})
# Needed for mpich 2
ADD_DEFINITIONS("-DMPICH_IGNORE_CXX_SEEK")
IF (VTK_USE_RENDERING)
ADD_EXECUTABLE(ParallelIso ParallelIso.cxx)
TARGET_LINK_LIBRARIES(ParallelIso vtkParallel vtkHybrid
${MPI_C_LIBRARIES})
if (MPI_CXX_LIBRARIES)
TARGET_LINK_LIBRARIES(ParallelIso ${MPI_CXX_LIBRARIES})
endif()
ENDIF ()
SET(TaskPara_SRCS TaskParallelism.cxx task1.cxx task2.cxx)
ADD_EXECUTABLE(TaskParallelism ${TaskPara_SRCS})
TARGET_LINK_LIBRARIES (TaskParallelism vtkParallel)
# ADD_EXECUTABLE(SimpleBenchmark SimpleBenchmark.cxx)
# TARGET_LINK_LIBRARIES(SimpleBenchmark vtkParallel ${MPI_LIBRARIES} )
ENDIF ()

View File

@ -0,0 +1,267 @@
/*=========================================================================
Program: Visualization Toolkit
Module: ParallelIso.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This example demonstrates the use of data parallelism in VTK. The
// pipeline ( vtkImageReader -> vtkContourFilter -> vtkElevationFilter )
// is created in parallel and each process is assigned 1 piece to process.
// All satellite processes send the result to the first process which
// collects and renders them.
#include "vtkActor.h"
#include "vtkAppendPolyData.h"
#include "vtkCamera.h"
#include "vtkConeSource.h"
#include "vtkContourFilter.h"
#include "vtkDataSet.h"
#include "vtkElevationFilter.h"
#include "vtkImageReader.h"
#include "vtkMath.h"
#include "vtkMPIController.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkTestUtilities.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkWindowToImageFilter.h"
#include "vtkImageData.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformation.h"
#include "vtkDebugLeaks.h"
#include <mpi.h>
static const float ISO_START=4250.0;
static const float ISO_STEP=-1250.0;
static const int ISO_NUM=3;
// Just pick a tag which is available
static const int ISO_VALUE_RMI_TAG=300;
static const int ISO_OUTPUT_TAG=301;
struct ParallelIsoArgs_tmp
{
int* retVal;
int argc;
char** argv;
};
struct ParallelIsoRMIArgs_tmp
{
vtkContourFilter* ContourFilter;
vtkMultiProcessController* Controller;
vtkElevationFilter* Elevation;
};
// call back to set the iso surface value.
void SetIsoValueRMI(void *localArg, void* vtkNotUsed(remoteArg),
int vtkNotUsed(remoteArgLen), int vtkNotUsed(id))
{
ParallelIsoRMIArgs_tmp* args = (ParallelIsoRMIArgs_tmp*)localArg;
float val;
vtkContourFilter *iso = args->ContourFilter;
val = iso->GetValue(0);
iso->SetValue(0, val + ISO_STEP);
args->Elevation->Update();
vtkMultiProcessController* contrl = args->Controller;
contrl->Send(args->Elevation->GetOutput(), 0, ISO_OUTPUT_TAG);
}
// This will be called by all processes
void MyMain( vtkMultiProcessController *controller, void *arg )
{
vtkImageReader *reader;
vtkContourFilter *iso;
vtkElevationFilter *elev;
int myid, numProcs;
float val;
ParallelIsoArgs_tmp* args = reinterpret_cast<ParallelIsoArgs_tmp*>(arg);
// Obtain the id of the running process and the total
// number of processes
myid = controller->GetLocalProcessId();
numProcs = controller->GetNumberOfProcesses();
// Create the reader, the data file name might have
// to be changed depending on where the data files are.
char* fname = vtkTestUtilities::ExpandDataFileName(args->argc, args->argv,
"Data/headsq/quarter");
reader = vtkImageReader::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetDataExtent(0, 63, 0, 63, 1, 93);
reader->SetFilePrefix(fname);
reader->SetDataSpacing(3.2, 3.2, 1.5);
delete[] fname;
// Iso-surface.
iso = vtkContourFilter::New();
iso->SetInputConnection(reader->GetOutputPort());
iso->SetValue(0, ISO_START);
iso->ComputeScalarsOff();
iso->ComputeGradientsOff();
// Compute a different color for each process.
elev = vtkElevationFilter::New();
elev->SetInputConnection(iso->GetOutputPort());
val = (myid+1) / static_cast<float>(numProcs);
elev->SetScalarRange(val, val+0.001);
// Tell the pipeline which piece we want to update.
vtkStreamingDemandDrivenPipeline* exec =
vtkStreamingDemandDrivenPipeline::SafeDownCast(elev->GetExecutive());
exec->SetUpdateNumberOfPieces(exec->GetOutputInformation(0), numProcs);
exec->SetUpdatePiece(exec->GetOutputInformation(0), myid);
if (myid != 0)
{
// If I am not the root process
ParallelIsoRMIArgs_tmp args2;
args2.ContourFilter = iso;
args2.Controller = controller;
args2.Elevation = elev;
// Last, set up a RMI call back to change the iso surface value.
// This is done so that the root process can let this process
// know that it wants the contour value to change.
controller->AddRMI(SetIsoValueRMI, (void *)&args2, ISO_VALUE_RMI_TAG);
controller->ProcessRMIs();
}
else
{
// Create the rendering part of the pipeline
vtkAppendPolyData *app = vtkAppendPolyData::New();
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renWindow = vtkRenderWindow::New();
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
vtkActor *actor = vtkActor::New();
vtkCamera *cam = vtkCamera::New();
renWindow->AddRenderer(ren);
iren->SetRenderWindow(renWindow);
ren->SetBackground(0.9, 0.9, 0.9);
renWindow->SetSize( 400, 400);
mapper->SetInputConnection(app->GetOutputPort());
actor->SetMapper(mapper);
ren->AddActor(actor);
cam->SetFocalPoint(100, 100, 65);
cam->SetPosition(100, 450, 65);
cam->SetViewUp(0, 0, -1);
cam->SetViewAngle(30);
cam->SetClippingRange(177.0, 536.0);
ren->SetActiveCamera(cam);
// loop through some iso surface values.
for (int j = 0; j < ISO_NUM; ++j)
{
// set the local value
iso->SetValue(0, iso->GetValue(0) + ISO_STEP);
elev->Update();
for (int i = 1; i < numProcs; ++i)
{
// trigger the RMI to change the iso surface value.
controller->TriggerRMI(i, ISO_VALUE_RMI_TAG);
}
for (int i = 1; i < numProcs; ++i)
{
vtkPolyData* pd = vtkPolyData::New();
controller->Receive(pd, i, ISO_OUTPUT_TAG);
if (j == ISO_NUM - 1)
{
app->AddInputData(pd);
}
pd->Delete();
}
}
// Tell the other processors to stop processing RMIs.
for (int i = 1; i < numProcs; ++i)
{
controller->TriggerRMI(i, vtkMultiProcessController::BREAK_RMI_TAG);
}
vtkPolyData* outputCopy = vtkPolyData::New();
outputCopy->ShallowCopy(elev->GetOutput());
app->AddInputData(outputCopy);
outputCopy->Delete();
app->Update();
renWindow->Render();
*(args->retVal) =
vtkRegressionTester::Test(args->argc, args->argv, renWindow, 10);
if ( *(args->retVal) == vtkRegressionTester::DO_INTERACTOR)
{
iren->Start();
}
// Clean up
app->Delete();
ren->Delete();
renWindow->Delete();
iren->Delete();
mapper->Delete();
actor->Delete();
cam->Delete();
}
// clean up objects in all processes.
reader->Delete();
iso->Delete();
elev->Delete();
}
int main( int argc, char* argv[] )
{
// This is here to avoid false leak messages from vtkDebugLeaks when
// using mpich. It appears that the root process which spawns all the
// main processes waits in MPI_Init() and calls exit() when
// the others are done, causing apparent memory leaks for any objects
// created before MPI_Init().
MPI_Init(&argc, &argv);
// Note that this will create a vtkMPIController if MPI
// is configured, vtkThreadedController otherwise.
vtkMPIController* controller = vtkMPIController::New();
controller->Initialize(&argc, &argv, 1);
// Added for regression test.
// ----------------------------------------------
int retVal = 1;
ParallelIsoArgs_tmp args;
args.retVal = &retVal;
args.argc = argc;
args.argv = argv;
// ----------------------------------------------
controller->SetSingleMethod(MyMain, &args);
controller->SingleMethodExecute();
controller->Finalize();
controller->Delete();
return !retVal;
}

View File

@ -0,0 +1,75 @@
/*=========================================================================
Program: Visualization Toolkit
Module: PipelineParallelism.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This example demonstrates how to write a pipeline parallel application
// with VTK. It creates two parts of a pipeline on a two different
// processors and connects them with ports. The two processes can then
// process the data in a pipeline mode, i.e:
// 1. Consumer asks the producer to start producing data,
// 2. Consumer receives data and starts processing it,
// 3. Producer starts producing new data,
// 4. Goto 2 unless done.
// The pipeline used in this example is as follows:
// rtSource -> OutputPort --- InputPort -> contour -> Render
// process 0 process 1
// See pipe1.cxx and pipe2.cxx for the pipelines.
#include "PipelineParallelism.h"
int main( int argc, char* argv[] )
{
// Note that this will create a vtkMPIController if MPI
// is configured, vtkThreadedController otherwise.
vtkMultiProcessController* controller = vtkMultiProcessController::New();
controller->Initialize(&argc, &argv);
// When using MPI, the number of processes is determined
// by the external program which launches this application.
// However, when using threads, we need to set it ourselves.
if (controller->IsA("vtkThreadedController"))
{
// Set the number of processes to 2 for this example.
controller->SetNumberOfProcesses(2);
}
int numProcs = controller->GetNumberOfProcesses();
if (numProcs != 2)
{
cerr << "This example requires two processes." << endl;
controller->Finalize();
controller->Delete();
return 1;
}
// Assign the functions and execute them
controller->SetMultipleMethod(0, pipe1, 0);
controller->SetMultipleMethod(1, pipe2, 0);
controller->MultipleMethodExecute();
// Clean-up and exit
controller->Finalize();
controller->Delete();
return 0;
}

View File

@ -0,0 +1,18 @@
/*=========================================================================
Program: Visualization Toolkit
Module: PipelineParallelism.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkMultiProcessController.h"
void pipe1(vtkMultiProcessController* controller, void* arg);
void pipe2(vtkMultiProcessController* controller, void* arg);

View File

@ -0,0 +1,132 @@
/*=========================================================================
Program: Visualization Toolkit
Module: TaskParallelism.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This example demonstrates how to write a task parallel application
// with VTK. It creates two different pipelines and assigns each to
// one processor. These pipelines are:
// 1. rtSource -> contour -> probe
// \ /
// -> gradient magnitude
// 2. rtSource -> gradient -> shrink -> glyph3D
// See task1.cxx and task2.cxx for the pipelines.
#include "TaskParallelism.h"
#include "vtkCompositeRenderManager.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
// This function sets up properties common to both processes
// and executes the task corresponding to the current process
void process(vtkMultiProcessController* controller, void* vtkNotUsed(arg))
{
taskFunction task;
int myId = controller->GetLocalProcessId();
// Chose the appropriate task (see task1.cxx and task2.cxx)
if ( myId == 0 )
{
task = task1;
}
else
{
task = task2;
}
// Setup camera
vtkCamera* cam = vtkCamera::New();
cam->SetPosition( -0.6105, 1.467, -6.879 );
cam->SetFocalPoint( -0.0617558, 0.127043, 0 );
cam->SetViewUp( -0.02, 0.98, 0.193 );
cam->SetClippingRange( 3.36, 11.67);
cam->Dolly(0.8);
// Create the render objects
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->SetSize( WINDOW_WIDTH, WINDOW_HEIGHT );
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// This class allows all processes to composite their images.
// The root process then displays it in it's render window.
vtkCompositeRenderManager* tc = vtkCompositeRenderManager::New();
tc->SetRenderWindow(renWin);
// Generate the pipeline see task1.cxx and task2.cxx)
vtkPolyDataMapper* mapper = (*task)(renWin, EXTENT, cam);
// Only the root process will have an active interactor. All
// the other render windows will be slaved to the root.
tc->StartInteractor();
// Clean-up
iren->Delete();
if (mapper)
{
mapper->Delete();
}
renWin->Delete();
cam->Delete();
}
int main( int argc, char* argv[] )
{
// Note that this will create a vtkMPIController if MPI
// is configured, vtkThreadedController otherwise.
vtkMPIController* controller = vtkMPIController::New();
controller->Initialize(&argc, &argv);
// When using MPI, the number of processes is determined
// by the external program which launches this application.
// However, when using threads, we need to set it ourselves.
if (controller->IsA("vtkThreadedController"))
{
// Set the number of processes to 2 for this example.
controller->SetNumberOfProcesses(2);
}
int numProcs = controller->GetNumberOfProcesses();
if (numProcs != 2)
{
cerr << "This example requires two processes." << endl;
controller->Finalize();
controller->Delete();
return 1;
}
// Execute the function named "process" on both processes
controller->SetSingleMethod(process, 0);
controller->SingleMethodExecute();
// Clean-up and exit
controller->Finalize();
controller->Delete();
return 0;
}

View File

@ -0,0 +1,51 @@
/*=========================================================================
Program: Visualization Toolkit
Module: TaskParallelism.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef __TASKPARA_H
#define __TASKPARA_H
#include "vtkMPIController.h"
#include "vtkRTAnalyticSource.h"
#include "vtkFieldDataToAttributeDataFilter.h"
#include "vtkAttributeDataToFieldDataFilter.h"
#include "vtkImageShrink3D.h"
#include "vtkGlyph3D.h"
#include "vtkGlyphSource2D.h"
#include "vtkImageGradient.h"
#include "vtkImageGradientMagnitude.h"
#include "vtkImageGaussianSmooth.h"
#include "vtkProbeFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkContourFilter.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkCamera.h"
#include "vtkAssignAttribute.h"
typedef vtkPolyDataMapper* (*taskFunction)(vtkRenderWindow* renWin,
double data, vtkCamera* cam);
vtkPolyDataMapper* task1(vtkRenderWindow* renWin, double data,vtkCamera* cam);
vtkPolyDataMapper* task2(vtkRenderWindow* renWin, double data,vtkCamera* cam);
static const double EXTENT = 20;
static const int WINDOW_WIDTH = 400;
static const int WINDOW_HEIGHT = 300;
#endif

View File

@ -0,0 +1,93 @@
/*=========================================================================
Program: Visualization Toolkit
Module: TaskParallelismWithPorts.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// This example demonstrates how to write a task parallel application
// with VTK. It creates two different pipelines and assigns each to
// one processor. These pipelines are:
// 1. rtSource -> contour -> probe .-> append
// \ / port
// -> gradient magnitude /
// 2. rtSource -> gradient -> shrink -> glyph3D -> port
// See task3.cxx and task4.cxx for the pipelines.
#include "TaskParallelismWithPorts.h"
// This function sets up properties common to both processes
// and executes the task corresponding to the current process
void process(vtkMultiProcessController* controller, void* vtkNotUsed(arg))
{
taskFunction task;
int myId = controller->GetLocalProcessId();
// Chose the appropriate task (see task3.cxx and task4.cxx)
if ( myId == 0 )
{
task = task3;
}
else
{
task = task4;
}
// Run the tasks (see task3.cxx and task4.cxx)
(*task)(EXTENT);
}
int main( int argc, char* argv[] )
{
// Note that this will create a vtkMPIController if MPI
// is configured, vtkThreadedController otherwise.
vtkMultiProcessController* controller = vtkMultiProcessController::New();
controller->Initialize(&argc, &argv);
// When using MPI, the number of processes is determined
// by the external program which launches this application.
// However, when using threads, we need to set it ourselves.
if (controller->IsA("vtkThreadedController"))
{
// Set the number of processes to 2 for this example.
controller->SetNumberOfProcesses(2);
}
int numProcs = controller->GetNumberOfProcesses();
if (numProcs != 2)
{
cerr << "This example requires two processes." << endl;
controller->Finalize();
controller->Delete();
return 1;
}
// Execute the function named "process" on both processes
controller->SetSingleMethod(process, 0);
controller->SingleMethodExecute();
// Clean-up and exit
controller->Finalize();
controller->Delete();
return 0;
}

View File

@ -0,0 +1,49 @@
/*=========================================================================
Program: Visualization Toolkit
Module: TaskParallelismWithPorts.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#ifndef __TASKPARA_H
#define __TASKPARA_H
#include "vtkMultiProcessController.h"
#include "vtkRTAnalyticSource.h"
#include "vtkFieldDataToAttributeDataFilter.h"
#include "vtkAttributeDataToFieldDataFilter.h"
#include "vtkImageShrink3D.h"
#include "vtkGlyph3D.h"
#include "vtkGlyphSource2D.h"
#include "vtkImageGradient.h"
#include "vtkImageGradientMagnitude.h"
#include "vtkImageGaussianSmooth.h"
#include "vtkProbeFilter.h"
#include "vtkDataSetMapper.h"
#include "vtkContourFilter.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkAssignAttribute.h"
typedef void (*taskFunction)(double data);
void task3(double data);
void task4(double data);
static const double EXTENT = 20;
static const int WINDOW_WIDTH = 400;
static const int WINDOW_HEIGHT = 300;
#endif

View File

@ -0,0 +1,80 @@
/*=========================================================================
Program: Visualization Toolkit
Module: pipe1.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkCallbackCommand.h"
#include "vtkImageData.h"
#include "vtkOutputPort.h"
#include "vtkRTAnalyticSource.h"
#include "PipelineParallelism.h"
static float XFreq = 60;
// Increments XFreq of the synthetic source
static void IncrementXFreq(vtkObject *vtkNotUsed( caller ),
unsigned long vtkNotUsed(eventId),
void *sr, void *)
{
vtkRTAnalyticSource* source1 = reinterpret_cast<vtkRTAnalyticSource*>(sr);
XFreq = XFreq + 10;
source1->SetXFreq(XFreq);
}
// Pipe 1 for PipelineParallelism.
// See PipelineParallelism.cxx for more information.
void pipe1(vtkMultiProcessController* vtkNotUsed(controller),
void* vtkNotUsed(arg))
{
double extent = 20;
int iextent = static_cast<int>(extent);
// Synthetic image source.
vtkRTAnalyticSource* source1 = vtkRTAnalyticSource::New();
source1->SetWholeExtent (-1*iextent, iextent, -1*iextent, iextent,
-1*iextent, iextent );
source1->SetCenter(0, 0, 0);
source1->SetStandardDeviation( 0.5 );
source1->SetMaximum( 255.0 );
source1->SetXFreq( XFreq );
source1->SetXMag( 10 );
source1->SetYFreq( 30 );
source1->SetYMag( 18 );
source1->SetZFreq( 40 );
source1->SetZMag( 5 );
source1->GetOutput()->SetSpacing(2.0/extent,2.0/extent,2.0/extent);
// Output port
vtkOutputPort* op = vtkOutputPort::New();
op->SetInputConnection(source1->GetOutputPort());
op->SetTag(11);
// Called every time data is requested from the output port
vtkCallbackCommand *cbc = vtkCallbackCommand::New();
cbc->SetCallback(IncrementXFreq);
cbc->SetClientData((void *)source1);
op->AddObserver(vtkCommand::EndEvent,cbc);
cbc->Delete();
// Process requests
op->WaitForUpdate();
// Cleanup
op->Delete();
source1->Delete();
}

View File

@ -0,0 +1,95 @@
/*=========================================================================
Program: Visualization Toolkit
Module: pipe2.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkActor.h"
#include "vtkContourFilter.h"
#include "vtkImageData.h"
#include "vtkInputPort.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "PipelineParallelism.h"
// Pipe 2 for PipelineParallelism.
// See PipelineParallelism.cxx for more information.
void pipe2(vtkMultiProcessController* vtkNotUsed(controller),
void* vtkNotUsed(arg))
{
// Input port
vtkInputPort* ip = vtkInputPort::New();
ip->SetRemoteProcessId(0);
ip->SetTag(11);
// Iso-surface
vtkContourFilter* cf = vtkContourFilter::New();
cf->SetInput(ip->GetImageDataOutput());
cf->SetNumberOfContours(1);
cf->SetValue(0, 220);
// Rendering objects
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(cf->GetOutputPort());
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
vtkRenderer* ren = vtkRenderer::New();
ren->AddActor(actor);
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
// Normally, the Render() call on a RenderWindow() calls
// update on it's actors two times. This is not appropriate
// for this example because with each Update(), the data
// changes. For this reason, we will use a separate PolyData
// object and (shallow) copy the data to it.
vtkPolyData* pd = vtkPolyData::New();
mapper->SetInput(pd);
// Prime the pipeline. Tell the producer to start computing.
ip->Update();
// Get the first data, adjust camera appropriatly
cf->GetOutput()->Update();
pd->ShallowCopy(cf->GetOutput());
ren->ResetCamera();
// Display data
renWin->Render();
// Get more data. With every update the XFreq of the rtSource
// is increased.
for (int i=0; i<17; i++)
{
cf->GetOutput()->Update();
pd->ShallowCopy(cf->GetOutput());
// Display
renWin->Render();
}
// Tell the producer that we are done.
ip->GetController()->TriggerRMI(0, vtkMultiProcessController::BREAK_RMI_TAG);
pd->Delete();
ip->Delete();
cf->Delete();
mapper->Delete();
actor->Delete();
ren->Delete();
renWin->Delete();
}

View File

@ -0,0 +1,89 @@
/*=========================================================================
Program: Visualization Toolkit
Module: task1.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "TaskParallelism.h"
#include "vtkImageData.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
// Task 1 for TaskParallelism.
// See TaskParallelism.cxx for more information.
vtkPolyDataMapper* task1(vtkRenderWindow* renWin, double data,
vtkCamera* cam)
{
double extent = data;
int iextent = static_cast<int>(data);
// The pipeline
// Synthetic image source.
vtkRTAnalyticSource* source1 = vtkRTAnalyticSource::New();
source1->SetWholeExtent (-1*iextent, iextent, -1*iextent, iextent,
-1*iextent, iextent );
source1->SetCenter(0, 0, 0);
source1->SetStandardDeviation( 0.5 );
source1->SetMaximum( 255.0 );
source1->SetXFreq( 60 );
source1->SetXMag( 10 );
source1->SetYFreq( 30 );
source1->SetYMag( 18 );
source1->SetZFreq( 40 );
source1->SetZMag( 5 );
source1->GetOutput()->SetSpacing(2.0/extent,2.0/extent,2.0/extent);
// Iso-surfacing.
vtkContourFilter* contour = vtkContourFilter::New();
contour->SetInputConnection(source1->GetOutputPort());
contour->SetNumberOfContours(1);
contour->SetValue(0, 220);
// Magnitude of the gradient vector.
vtkImageGradientMagnitude* magn = vtkImageGradientMagnitude::New();
magn->SetDimensionality(3);
magn->SetInputConnection(source1->GetOutputPort());
// Probe magnitude with iso-surface.
vtkProbeFilter* probe = vtkProbeFilter::New();
probe->SetInputConnection(contour->GetOutputPort());
probe->SetSourceConnection(magn->GetOutputPort());
probe->SpatialMatchOn();
// Rendering objects.
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInputData(probe->GetPolyDataOutput());
mapper->SetScalarRange(50, 180);
mapper->ImmediateModeRenderingOn();
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
vtkRenderer* ren = vtkRenderer::New();
renWin->AddRenderer(ren);
ren->AddActor(actor);
ren->SetActiveCamera( cam );
// Cleanup
source1->Delete();
contour->Delete();
magn->Delete();
probe->Delete();
actor->Delete();
ren->Delete();
return mapper;
}

View File

@ -0,0 +1,106 @@
/*=========================================================================
Program: Visualization Toolkit
Module: task2.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "TaskParallelism.h"
#include "vtkImageData.h"
#include "vtkPolyDataMapper.h"
// Task 2 for TaskParallelism.
// See TaskParallelism.cxx for more information.
vtkPolyDataMapper* task2(vtkRenderWindow* renWin, double data,
vtkCamera* cam)
{
double extent = data;
int iextent = static_cast<int>(data);
// The pipeline
// Synthetic image source.
vtkRTAnalyticSource* source1 = vtkRTAnalyticSource::New();
source1->SetWholeExtent (-1*iextent, iextent, -1*iextent, iextent,
-1*iextent, iextent );
source1->SetCenter(0, 0, 0);
source1->SetStandardDeviation( 0.5 );
source1->SetMaximum( 255.0 );
source1->SetXFreq( 60 );
source1->SetXMag( 10 );
source1->SetYFreq( 30 );
source1->SetYMag( 18 );
source1->SetZFreq( 40 );
source1->SetZMag( 5 );
source1->GetOutput()->SetSpacing(2.0/extent,2.0/extent,2.0/extent);
// Gradient vector.
vtkImageGradient* grad = vtkImageGradient::New();
grad->SetDimensionality( 3 );
grad->SetInputConnection(source1->GetOutputPort());
vtkImageShrink3D* mask = vtkImageShrink3D::New();
mask->SetInputConnection(grad->GetOutputPort());
mask->SetShrinkFactors(5, 5, 5);
// Label the scalar field as the active vectors.
vtkAssignAttribute* aa = vtkAssignAttribute::New();
aa->SetInputConnection(mask->GetOutputPort());
aa->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS,
vtkAssignAttribute::POINT_DATA);
vtkGlyphSource2D* arrow = vtkGlyphSource2D::New();
arrow->SetGlyphTypeToArrow();
arrow->SetScale(0.2);
arrow->FilledOff();
// Glyph the gradient vector (with arrows)
vtkGlyph3D* glyph = vtkGlyph3D::New();
glyph->SetInputConnection(aa->GetOutputPort());
glyph->SetSourceConnection(arrow->GetOutputPort());
glyph->ScalingOff();
glyph->OrientOn();
glyph->SetVectorModeToUseVector();
glyph->SetColorModeToColorByVector();
// Rendering objects.
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(glyph->GetOutputPort());
mapper->SetScalarRange(50, 180);
mapper->ImmediateModeRenderingOn();
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
vtkRenderer* ren = vtkRenderer::New();
renWin->AddRenderer(ren);
ren->AddActor(actor);
ren->SetActiveCamera( cam );
// Cleanup
source1->Delete();
grad->Delete();
aa->Delete();
mask->Delete();
glyph->Delete();
arrow->Delete();
actor->Delete();
ren->Delete();
return mapper;
}

View File

@ -0,0 +1,119 @@
/*=========================================================================
Program: Visualization Toolkit
Module: task3.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "TaskParallelismWithPorts.h"
#include "vtkAppendPolyData.h"
#include "vtkImageData.h"
#include "vtkInputPort.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
// Task 3 for TaskParallelismWithPorts.
// See TaskParallelismWithPorts.cxx for more information.
void task3(double data)
{
double extent = data;
int iextent = static_cast<int>(data);
// The pipeline
// Synthetic image source.
vtkRTAnalyticSource* source1 = vtkRTAnalyticSource::New();
source1->SetWholeExtent (-1*iextent, iextent, -1*iextent, iextent,
-1*iextent, iextent );
source1->SetCenter(0, 0, 0);
source1->SetStandardDeviation( 0.5 );
source1->SetMaximum( 255.0 );
source1->SetXFreq( 60 );
source1->SetXMag( 10 );
source1->SetYFreq( 30 );
source1->SetYMag( 18 );
source1->SetZFreq( 40 );
source1->SetZMag( 5 );
source1->GetOutput()->SetSpacing(2.0/extent,2.0/extent,2.0/extent);
// Iso-surfacing.
vtkContourFilter* contour = vtkContourFilter::New();
contour->SetInputConnection(source1->GetOutputPort());
contour->SetNumberOfContours(1);
contour->SetValue(0, 220);
// Magnitude of the gradient vector.
vtkImageGradientMagnitude* magn = vtkImageGradientMagnitude::New();
magn->SetDimensionality(3);
magn->SetInputConnection(source1->GetOutputPort());
// Probe magnitude with iso-surface.
vtkProbeFilter* probe = vtkProbeFilter::New();
probe->SetInputConnection(contour->GetOutputPort());
probe->SetSource(magn->GetOutput());
probe->SpatialMatchOn();
// Input port
vtkInputPort* ip = vtkInputPort::New();
ip->SetRemoteProcessId(1);
ip->SetTag(11);
// Append the local and remote data
vtkAppendPolyData* append = vtkAppendPolyData::New();
append->AddInput(ip->GetPolyDataOutput());
append->AddInput(probe->GetPolyDataOutput());
// Rendering objects.
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(append->GetOutputPort());
mapper->SetScalarRange(50, 180);
mapper->ImmediateModeRenderingOn();
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
// Create the render objects
vtkRenderWindow* renWin = vtkRenderWindow::New();
renWin->SetSize( WINDOW_WIDTH, WINDOW_HEIGHT );
vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkRenderer* ren = vtkRenderer::New();
renWin->AddRenderer(ren);
ren->AddActor(actor);
iren->Initialize();
iren->Start();
// Tell the other process we are done
ip->GetController()->TriggerRMI(1,
vtkMultiProcessController::BREAK_RMI_TAG);
// Cleanup
iren->Delete();
renWin->Delete();
ip->Delete();
append->Delete();
source1->Delete();
contour->Delete();
magn->Delete();
probe->Delete();
actor->Delete();
ren->Delete();
mapper->Delete();
}

View File

@ -0,0 +1,97 @@
/*=========================================================================
Program: Visualization Toolkit
Module: task4.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "TaskParallelismWithPorts.h"
#include "vtkImageData.h"
#include "vtkOutputPort.h"
#include "vtkPolyData.h"
// Task 4 for TaskParallelism.
// See TaskParallelismWithPorts.cxx for more information.
void task4(double data)
{
double extent = data;
int iextent = static_cast<int>(data);
// The pipeline
// Synthetic image source.
vtkRTAnalyticSource* source1 = vtkRTAnalyticSource::New();
source1->SetWholeExtent (-1*iextent, iextent, -1*iextent, iextent,
-1*iextent, iextent );
source1->SetCenter(0, 0, 0);
source1->SetStandardDeviation( 0.5 );
source1->SetMaximum( 255.0 );
source1->SetXFreq( 60 );
source1->SetXMag( 10 );
source1->SetYFreq( 30 );
source1->SetYMag( 18 );
source1->SetZFreq( 40 );
source1->SetZMag( 5 );
source1->GetOutput()->SetSpacing(2.0/extent,2.0/extent,2.0/extent);
// Gradient vector.
vtkImageGradient* grad = vtkImageGradient::New();
grad->SetDimensionality( 3 );
grad->SetInputConnection(source1->GetOutputPort());
vtkImageShrink3D* mask = vtkImageShrink3D::New();
mask->SetInputConnection(grad->GetOutputPort());
mask->SetShrinkFactors(5, 5, 5);
// Label the scalar field as the active vectors.
vtkAssignAttribute* aa = vtkAssignAttribute::New();
aa->SetInputConnection(mask->GetOutputPort());
aa->Assign(vtkDataSetAttributes::SCALARS, vtkDataSetAttributes::VECTORS,
vtkAssignAttribute::POINT_DATA);
vtkGlyphSource2D* arrow = vtkGlyphSource2D::New();
arrow->SetGlyphTypeToArrow();
arrow->SetScale(0.2);
arrow->FilledOff();
// Glyph the gradient vector (with arrows)
vtkGlyph3D* glyph = vtkGlyph3D::New();
glyph->SetInputConnection(aa->GetOutputPort());
glyph->SetSource(arrow->GetOutput());
glyph->ScalingOff();
glyph->OrientOn();
glyph->SetVectorModeToUseVector();
glyph->SetColorModeToColorByVector();
// Output port
vtkOutputPort* op = vtkOutputPort::New();
op->SetInputConnection(glyph->GetOutputPort());
op->SetTag(11);
// Process requests
op->WaitForUpdate();
// Cleanup
op->Delete();
source1->Delete();
grad->Delete();
aa->Delete();
mask->Delete();
glyph->Delete();
arrow->Delete();
}