Install vs2015 and qt-5.7.1
- download and installVS2015qt-opensource-windows-x86-msvc2015-5.7.1.exe
- Configure QT environment variable
- Installation
QT-VS-TOOLS
and select QT versionC:\Qt\Qt5.7.1\5.7\msvc2015_64
Install VTK
- The file directory is as follows,
VTK-src
Place the source code,VTK-bin
Place the file compiled by CMAKE,VTK
Place the final file, the corresponding download URLVTK
- cmake compilation
- Configure once
BUILD_EXAMPLES
: Indicates whether to compile the example in VTK. If not activated, the compilation time can be reduced, and it can be compiled separately afterwards. We are placed here as OFF.
BUILD_TESTING
— indicates whether to compile the test code in VTK. If not activated, the compilation time can be reduced, and it can be compiled separately afterwards. We are placed here as OFF.
BUILD_SHARED_LIBS
—— indicate whether to create a shared library. If activated, the DLL or sharing library will be created, so that the VTK applications generated later will be relatively small and can save a lot of space; if not activated, the static library will be created. We are placed here.
CMAKE_INSTALL_PREFIX
-VTK generation path, modify as follows
The next settings are related to QT, search QT and check all
After configure againVTK_QT_VERSION
Change to 5
CONFIGURE again, the position of the QT will be automatically detected (you need to shut down after changing the QT environment variable)
HereQt5WebKitWidgets_DIR
Can’t find it, let’s get rid of itMoudule_vtkGUISupportQtWebkit
Configure
After no red clickGenerate
, then clickOpen Project
, you can also find vtk.sln to open
- vs2015 compilation:
ALL_BUILD
–. After no problem, then
INSTALL
–only for projects
–Only generate Install
Change toRe -compilation
QVTKWidgetPlugin.dll
Copy to the designer of Qt, the corresponding directory is as follows
like thisVS2015
OpenQt designer
will be more outQVTKWidget
*VTK test
: Use CMAKE to establish a project, the directory is as follows
cmakelists.txt content
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0020 NEW)
project(Cylinder)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(Cylinder Cylinder.cxx)
if(VTK_LIBRARIES)
target_link_libraries(Cylinder ${VTK_LIBRARIES})
else()
target_link_libraries(Cylinder vtkHybrid vtkWigets)
endif(VTK_LIBRARIES)
Here you need to enterVTK_DIR
(If the system environment variable configuration is configuredD:\Kitware\VTK\VTK\debug\bin
, will be searched automatically here), he containsUseVTK.cmake
Folder
and thenConfigure
After no redGenerate
After no problemOpen Project
Open VS2015 in
Enter the following code inCylinder.cxx
#include "vtkCylinderSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkProperty.h"
#include "vtkSmartPointer.h"
int main() {
vtkSmartPointer<vtkCylinderSource> cylinder = vtkSmartPointer<vtkCylinderSource>::New();
cylinder->SetResolution(8);
vtkSmartPointer<vtkPolyDataMapper> cylinderMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
cylinderMapper->SetInputConnection(cylinder->GetOutputPort());
vtkSmartPointer<vtkActor> cylinderActor = vtkSmartPointer<vtkActor>::New();
cylinderActor->SetMapper(cylinderMapper);
cylinderActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);
cylinderActor->RotateX(30.0);
cylinderActor->RotateY(-45.0);
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(cylinderActor);
renderer->SetBackground(0, 0, 1);//RGB
renderer->ResetCamera();
renderer->GetActiveCamera()->Zoom(0.3);
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderWindow->SetSize(200, 200);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Start();
return 0;
}
ALL-BUILD
–Open cylinder.exe
Install ITK
ITK downloadITK_src
, hereInsightToolkit-4.11.0
version, here isITK examples, the installation is consistent with the above, pay attention to hook upMoudule_ITKVtkGlue
- ITK test
CMakeLists.cxx
cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8)
project(HelloWorld)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
add_executable(HelloWorld HelloWorld.cxx)
target_link_libraries(HelloWorld ${ITK_LIBRARIES})
HelloWorld.cxx
#include"itkImage.h"
#include<iostream>
int main(){
typedef itk::Image<unsigned short,3> ImageType;
ImageType::Pointer image=ImageType::New();
std::cout<<"hello world"<<std::endl;
system("pause");
return 0;
}
result
VTK, ITK hybrid test
We read the picture with ITK and then VTK display
CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0020 NEW)
project(ImageToVTKImageFilter)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
else()
find_package(ItkVtkGlue REQUIRED)
include(${ItkVtkGlue_USE_FILE})
set(Glue ItkVtkGlue)
endif()
add_executable(ImageToVTKImageFilter ImageToVTKImageFilter.cxx)
target_link_libraries(ImageToVTKImageFilter
${Glue} ${VTK_LIBRARIES} ${ITK_LIBRARIES})
ImageToVTKImageFilter.cxx
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkGDCMImageIO.h"
#include "itkImageToVTKImageFilter.h"
#include "vtkSmartPointer.h"
#include "vtkImageFlip.h"
#include "vtkImageViewer.h"
#include "vtkRenderWindowInteractor.h"
int main()
{
typedef signed short PixelType;
const unsigned int Dimension = 2;
typedef itk::Image<PixelType, Dimension> ImageType;
typedef itk::GDCMImageIO ImageIOType;
ImageIOType::Pointer imageIO = ImageIOType::New();
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("E:/22");
reader->SetImageIO(imageIO);
reader->Update();
typedef itk::ImageToVTKImageFilter<ImageType> ImageToVTKImageFilterType;
ImageToVTKImageFilterType::Pointer itkToVtk = ImageToVTKImageFilterType::New();
itkToVtk->SetInput(reader->GetOutput());
itkToVtk->Update();
vtkSmartPointer<vtkImageFlip> imageFlip = vtkSmartPointer<vtkImageFlip>::New();
imageFlip->SetInputData(itkToVtk->GetOutput());
imageFlip->SetFilteredAxes(1);
imageFlip->Update();
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkImageViewer> imageViewer = vtkSmartPointer<vtkImageViewer>::New();
imageViewer->SetInputData(imageFlip->GetOutput());
imageViewer->SetColorLevel(300);
imageViewer->SetColorWindow(2000);
imageViewer->SetupInteractor(interactor);
imageViewer->Render();
system("pause");
return 0;
}