[vtkusers] Parallel Volume Rendering
polittico
polittico at libero.it
Wed Dec 6 09:25:14 EST 2006
Thank You so much Kevin,
but I want that my vtk application do it...
I found the following code on the list, it compile, I see the render window but there's nothing in it. What's wrong?
#include "vtkXMLUnstructuredGridReader.h"
#include "vtkParallelFactory.h"
#include "vtkCamera.h"
#include "vtkMPIController.h"
#include "vtkMPICommunicator.h"
#include "vtkObjectFactory.h"
#include "vtkCompositeRenderManager.h"
#include "vtkDistributedDataFilter.h"
#include "vtkUnstructuredGrid.h"
#include "vtkDataSetTriangleFilter.h"
#include "vtkPiecewiseFunction.h"
#include "vtkColorTransferFunction.h"
#include "vtkVolumeProperty.h"
#include "vtkUnstructuredGridVolumeRayCastMapper.h"
#include "vtkVolume.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
struct args_struct
{
int argc;
char** argv;
};
#define WSIZE 864
static void Run(vtkMultiProcessController * controller, void *arg)
{
args_struct * args = reinterpret_cast<args_struct *>(arg);
char* in_file_name = args->argv[1];
int myid = controller->GetLocalProcessId();
int num_procs = controller->GetNumberOfProcesses();
// Reader
vtkXMLUnstructuredGridReader * reader
= vtkXMLUnstructuredGridReader::New();
reader->SetFileName( in_file_name );
/*
// Distributed Data Filter
vtkDistributedDataFilter * dist_dat_filter
= vtkDistributedDataFilter::New();
dist_dat_filter->SetController( controller );
//dist_dat_filter->SetBoundaryModeToSplitBoundaryCells();
dist_dat_filter->UseMinimalMemoryOff();
dist_dat_filter->SetInputConnection
( reader->GetOutputPort() );
*/
// Triangle Filter
vtkDataSetTriangleFilter * triangle_filter
= vtkDataSetTriangleFilter::New();
triangle_filter->SetInputConnection
( reader->GetOutputPort() );
// Opacity
vtkPiecewiseFunction * opacity
= vtkPiecewiseFunction::New();
opacity->AddPoint( 5500, 0.0 );
opacity->AddPoint( 26158, 1.0 );
// Color
vtkColorTransferFunction * color
= vtkColorTransferFunction::New();
color->AddRGBPoint( 5500, 0.0, 0.0, 0.0 );
color->AddRGBPoint( 10665, 0.0, 0.0, 1.0 );
color->AddRGBPoint( 15829, 1.0, 0.0, 0.0 );
color->AddRGBPoint( 20994, 0.0, 1.0, 0.0 );
color->AddRGBPoint( 26158, 0.0, 1.0, 1.0 );
// Volume Property
vtkVolumeProperty * vol_prop = vtkVolumeProperty::New();
vol_prop->SetColor( color );
vol_prop->SetScalarOpacity( opacity );
vol_prop->ShadeOff();
vol_prop->SetInterpolationTypeToLinear();
// Mapper
vtkUnstructuredGridVolumeRayCastMapper * mapper
= vtkUnstructuredGridVolumeRayCastMapper::New();
mapper->SetInputConnection( triangle_filter->GetOutputPort() );
mapper->SetScalarModeToUsePointData();
mapper->SelectScalarArray( "Scalars_" );
// Volume
vtkVolume * volume = vtkVolume::New();
volume->SetMapper( mapper );
volume->SetProperty( vol_prop );
// Render Manager
vtkCompositeRenderManager * manager
= vtkCompositeRenderManager::New();
// Renderer
vtkRenderer * renderer = manager->MakeRenderer();
renderer->AddVolume( volume );
vtkRenderWindow * render_window
= manager->MakeRenderWindow();
render_window->SetOffScreenRendering(1);
render_window->AddRenderer( renderer );
renderer->SetBackground( 0, 0, 0 );
render_window->SetSize( WSIZE, WSIZE );
int wp = WSIZE - WSIZE * (double) myid / num_procs;
render_window->SetPosition( wp, wp);
manager->SetRenderWindow( render_window );
manager->SetController( controller );
manager->InitializeOffScreen();
//mapper->SetPiece( myid );
//mapper->SetNumberOfPieces( num_procs );
mapper->Update();
// Interactor
vtkRenderWindowInteractor * interactor
= vtkRenderWindowInteractor::New();
interactor->SetRenderWindow( render_window );
if ( myid == 0 )
{
renderer->ResetCamera();
vtkCamera * camera
= renderer->GetActiveCamera();
camera->UpdateViewport(renderer);
camera->ParallelProjectionOn();
camera->SetParallelScale( 14 );
render_window->Render();
render_window->Render();
manager->StartInteractor();
manager->StopServices();
}
else
{
manager->StartServices();
}
// Clean Up
mapper->Delete();
triangle_filter->Delete();
opacity->Delete();
color->Delete();
vol_prop->Delete();
volume->Delete();
renderer->Delete();
render_window->Delete();
//dist_dat_filter->Delete();
manager->Delete();
}
int main(int argc, char **argv)
{
//char* in_file_name = argv[1];
//int pieces = atoi( argv[2] );
// Controller
vtkMPIController * controller
= vtkMPIController::New();
controller->Initialize(&argc, &argv);
vtkMultiProcessController::SetGlobalController
(controller);
args_struct args;
args.argc = argc;
args.argv = argv;
controller->SetSingleMethod(Run, &args);
controller->SingleMethodExecute();
controller->Finalize();
controller->Delete();
return 0;
}
------------------------------------------------------
Ordina subito la scintillante lampada a forma di Renna di Babbo Natale: lascerai i tuoi ospiti... a bocca aperta !
http://click.libero.it/dmail06dic06
More information about the vtkusers
mailing list