[vtkusers] Changing/setting the extent of an image for a custom reader
kalin
kalin at cs.jhu.edu
Tue Jan 21 17:31:35 EST 2014
Hi there,
I have a questions about changing the extents of an image in VTK. I
have followed the examples to create a reader for my data files. What I
have so far seems to work OK, the reader subclasses vtkImageAlgorithm
and produces an image. What I would like to know is if I can change the
extents of the image to be rendered before my reader reads the entire
file. Let's say that I want to look at only a small part of the image
and I provide the extent as input to the reader. I have a test harness
that I'm using for the reader, which is below (which will use the reader
to read all of the data and then display it as an image).
// Read the file
vtkSmartPointer<MyReader> reader =
vtkSmartPointer<MyReader>::New();
reader->SetFileName ( argv[1] );
reader->Update();
//TODO: Figure out how to set the extent.
vtkImageData* output = reader->GetOutput();
// Convert the image to a polydata
vtkSmartPointer<vtkImageDataGeometryFilter> imageDataGeometryFilter =
vtkSmartPointer<vtkImageDataGeometryFilter>::New();
imageDataGeometryFilter->SetInputConnection(reader->GetOutputPort());
imageDataGeometryFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(imageDataGeometryFilter->GetOutputPort());
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetPointSize(3);
// Setup rendering
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->SetBackground(1,1,1);
renderer->ResetCamera();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
Any suggestions as to the best way to do this? I am not quite sure if I
should be implementing the RequestUpdateExtent method or something else.
Thanks,
Kalin
More information about the vtkusers
mailing list