#include "vtkBMPReader.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageMagnify.h"
#include "vtkTransform.h"
int main()
{
vtkBMPReader *reader= vtkBMPReader::New();
reader->SetDataByteOrderToLittleEndian();
reader->SetFileName("mm.bmp"); //程序当前目录中有这个文件
reader->SetDataOrigin(0,0,0.0);
vtkTransform *t1=vtkTransform::New();
t1->RotateZ(0);
reader->SetTransform(t1); //控制图像的旋转
vtkImageMagnify *scale=vtkImageMagnify::New();
scale->SetInputConnection(reader->GetOutputPort());
scale->SetMagnificationFactors(2,2,2); //图像各个维度的维放
vtkImageViewer *viewer = vtkImageViewer::New();
viewer->SetInput(scale->GetOutput());
viewer->SetColorWindow(1000);
viewer->SetColorLevel(200);
viewer->SetPosition(0,0);
viewer->Render();
vtkRenderWindowInteractor *viewerinter = vtkRenderWindowInteractor::New();
viewer->SetupInteractor(viewerinter);
vtkImageViewer *viewer2 = vtkImageViewer::New(); //没有缩放的原图,以作对比
viewer2->SetInput(reader->GetOutput());
viewer2->SetColorWindow(256);
viewer2->SetColorLevel(200);
viewer2->SetPosition(0,100);
viewer2->Render();
vtkRenderWindowInteractor *viewerinter2 = vtkRenderWindowInteractor::New();
viewer2->SetupInteractor(viewerinter2);
viewerinter->Initialize();
viewerinter->Start();
scale->Delete();
viewer->Delete();
viewerinter->Delete();
viewer2->Delete();
viewerinter2->Delete();
return 0;
}
保存以上代码为文件:ImageScale.cxx
以下是CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
PROJECT (ImageScale)
IF(NOT VTK_BINARY_DIR)
FIND_PACKAGE(VTK REQUIRED)
IF(NOT VTK_USE_RENDERING)
MESSAGE(FATAL_ERROR "${PROJECT_NAME} requires VTK_USE_RENDERING.")
ENDIF(NOT VTK_USE_RENDERING)
INCLUDE(${VTK_USE_FILE})
ENDIF(NOT VTK_BINARY_DIR)
ADD_EXECUTABLE(ImageScale ImageScale.cxx)
TARGET_LINK_LIBRARIES(ImageScale vtkRendering vtkIO)
附程序原图:
贴个图(好漂漂的mm ):
本文来源:http://www.vislab.cn/bbs/viewthread.php?tid=3075&extra=page%3D17