- /*******************************************************************************
- Simple VTK Example
- A very simple VTK example - a raw 2D datafile is read
- it's magnified by a factor of 3 and then it's displayed on a window.
- The pipeline:
- vtkImageReader->vtkImageMagnify->vtkRenderWindow
- The p_w_picpath file is a raw file of 64 rows * 64 columns. The values are
- 2 byte (short int) long.
- It's a greyscale dataset (NumberOfScalrComponents = 1)
- *******************************************************************************/
- #include "vtkImageReader.h"
- #include "vtkImageViewer.h"
- #include "vtkImageMagnify.h"
- #include "vtkRenderer.h"
- #include "vtkRenderWindow.h"
- #include "vtkRenderWindowInteractor.h"
- #define IMG_FILE "C:data.raw"
- int main (void)
- {
- vtkImageReader *imgReader = vtkImageReader::New();
- imgReader->SetFileDimensionality(2);
- imgReader->SetFileName(IMG_FILE);
- imgReader->SetNumberOfScalarComponents(1);
- imgReader->SetDataExtent(0,63, 0,63, 0,0);
- vtkImageMagnify *imgMagnify = vtkImageMagnify::New();
- imgMagnify->SetInputConnection(imgReader->GetOutputPort());
- imgMagnify->SetMagnificationFactors(3, 3, 3);
- vtkImageViewer* imgViewer = vtkImageViewer::New();
- imgViewer->SetInputConnection(imgMagnify->GetOutputPort());
- vtkRenderWindow *renWindow = vtkRenderWindow::New();
- renWindow->AddRenderer(imgViewer->GetRenderer());
- renWindow->SetSize(64*3, 64*3);
- vtkRenderWindowInteractor *renWindowInteractor = vtkRenderWindowInteractor::New();
- renWindowInteractor->SetRenderWindow(renWindow);
- renWindowInteractor->Initialize();
- renWindowInteractor->Start();
- return 0;
- }
本文来源: