[vtkusers] MPI Offscreen Volume Rendering
Kent Williams
kent at psychiatry.uiowa.edu
Fri May 12 15:38:04 EDT 2006
You just need to create an instance of vtkImageData.
The following assumes that you are working with unsigned char data. For
RGB you'd call
ImageFromBuffer(buf,dims,3), where buf is your image data, dims is an
array of dimensions for the image,
and componentCount is the number of scalars per pixel/voxel.
vtkImageData *ImageFromBuffer(char *buffer,int *dims, int componentCount)
{
vtkImageData *rval = vtkImageData::New();
rval->SetScalarTypeToUnsignedChar();
rval->SetDimensions(dims);
rval->SetNumberOfScalarComponents(componentCount);
rval->AllocateScalars();
memcpy(this->GetScalarPointer(), buffer,dims[0] * dims[1] * dims[2]
* componentCount * sizeof(char));
return rval;
}
Kevin H. Hobbs wrote:
>I want to try the vtkParallelRenderManager::GetPixelData method because
>the manual says it's "he most appropriate way to retrieve full size
>image data after a render." The trouble is I can't just plug that
>UnsignedCharArray into an image writer.
>
>How do I set up an image to hold the output of GetPixelData?
>
>
>------------------------------------------------------------------------
>
>#include "vtkGraphicsFactory.h"
>#include "vtkImagingFactory.h"
>
>#include "vtkXMLPPolyDataReader.h"
>#include "vtkSphereSource.h"
>#include "vtkParallelFactory.h"
>#include "vtkCamera.h"
>#include "vtkActor.h"
>#include "vtkMPIController.h"
>#include "vtkMPICommunicator.h"
>#include "vtkObjectFactory.h"
>#include "vtkCompositeRenderManager.h"
>#include "vtkDistributedDataFilter.h"
>#include "vtkDataSetSurfaceFilter.h"
>#include "vtkPieceScalars.h"
>#include "vtkPolyData.h"
>#include "vtkPolyDataMapper.h"
>#include "vtkRenderer.h"
>#include "vtkRenderWindow.h"
>#include "vtkRenderWindowInteractor.h"
>
>struct args_struct
>{
> int argc;
> char** argv;
>};
>
>#define WSIZE 512
>
>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();
>
> // Graphics Factory
> vtkGraphicsFactory * graphics_factory
> = vtkGraphicsFactory::New();
> graphics_factory->SetOffScreenOnlyMode( 1 );
> graphics_factory->SetUseMesaClasses( 1 );
>
> // Imaging Factory
> vtkImagingFactory * imaging_factory
> = vtkImagingFactory::New();
> imaging_factory->SetUseMesaClasses( 1 );
>
>
> // Sphere
> vtkSphereSource * sphere
> = vtkSphereSource::New();
> sphere->SetThetaResolution(16);
> sphere->SetPhiResolution(16);
>
> /*
> vtkXMLPPolyDataReader * reader
> = vtkXMLPPolyDataReader::New();
> reader->SetFileName( in_file_name );
> */
>
> // Distributed Data Filter
> vtkDistributedDataFilter * dist_dat_filter
> = vtkDistributedDataFilter::New();
>
> dist_dat_filter->SetInputConnection
> ( sphere->GetOutputPort() );
> dist_dat_filter->SetController( controller );
>
> dist_dat_filter->SetBoundaryModeToSplitBoundaryCells();
> dist_dat_filter->UseMinimalMemoryOff();
>
> // Color by Piece
> vtkPieceScalars * piece_color = vtkPieceScalars::New();
> piece_color->SetInputConnection
> ( dist_dat_filter->GetOutputPort() );
> piece_color->SetScalarModeToCellData();
>
> // Surface Filter
> vtkDataSetSurfaceFilter * surface
> = vtkDataSetSurfaceFilter::New();
> surface->SetInputConnection
> ( piece_color->GetOutputPort() );
>
> // Mapper
> vtkPolyDataMapper * mapper = vtkPolyDataMapper::New();
> mapper->SetInputConnection( surface->GetOutputPort() );
>
> mapper->SetColorModeToMapScalars();
> mapper->SetScalarModeToUseCellFieldData();
> mapper->SelectColorArray( "Piece" );
> mapper->SetScalarRange( 0, num_procs - 1 );
>
> // Actor
> vtkActor * actor = vtkActor::New();
> actor->SetMapper( mapper );
>
> // Render Manager
> vtkCompositeRenderManager * manager
> = vtkCompositeRenderManager::New();
>
> // Renderer
> vtkRenderer * renderer = manager->MakeRenderer();
> renderer->AddActor( actor );
>
> vtkRenderWindow * render_window
> = manager->MakeRenderWindow();
> 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( 16 );
>
> render_window->Render();
> render_window->Render();
>
> manager->StartInteractor();
>
> manager->StopServices();
> }
> else
> {
>
> manager->StartServices();
> }
>
> // Clean Up
> mapper->Delete();
> actor->Delete();
> renderer->Delete();
> render_window->Delete();
>
> dist_dat_filter->Delete();
> piece_color->Delete();
> surface->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;
>}
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>This is the private VTK discussion list.
>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>
>
More information about the vtkusers
mailing list