VS2008+QT+VTK编译

所有安装最好不要有中文目录。

1。安装VS2008

2。下载qt-win-opensource-4.6.2-vs2008.exe(http://get.qt.nokia.com/qt/source/qt-win-opensource-4.6.2-vs2008.exe)qt-vs-addin-1.1.4.exe(http://get.qt.nokia.com/vsaddin/qt-vs-addin-1.1.4.exe)先安装qt-win-opensource-4.6.2-vs2008.exe再安装qt-vs-addin-1.1.4.exe。安装完成后启动Visual Studio with Qt 4.6.2如图:

3。启动完成后新建一个项目如下图:
启动编译,如果成功则说明QT嵌入VS2008成功的。
4。下载 vtk-5.6.0-win32.exehttp://www.vtk.org/files/release/5.6/vtk-5.6.0-win32.exe), 5.6/vtk-5.6.0.zip(http://www.vtk.org/files/release/5.6/vtk-5.6.0.zipvtkdata-5.6.0.ziphttp://www.vtk.org/files/release/5.6/vtkdata-5.6.0.zip), cmake-2.8.1-win32-x86.exehttp://www.cmake.org/files/v2.8/cmake-2.8.1-win32-x86.exe)。下载完成后安装cmake-2.8.1-win32-x86.exe (不能有中文路径)再安装 vtk-5.6.0-win32.exe(不能有中文路径,如G:/VTK 5.6)。
安装完成后解压vtk-5.6.0.zip、vtkdata-5.6.0.zip到G:/VTK 5.6。
5。运行Cmake选择源文件路径和生成文件路径:
VS2008+QT+VTK编译 - 200309129 - '∧ ∧︵
 6。再点Add Entry按钮在弹出的对话诓中设置 VTK_USE_GUISUPPORT".设为True:
点OK后选择VS2008的版本显示如下图:
VS2008+QT+VTK编译_第1张图片
 
7。点击 Configure按钮完成后勾选VTK_USE_QT,如果要编译例子请将:BUILD_ EXAMPLES勾选上,再点击 Configure按钮
知道列表中无红色。
 8。在列表无红色的时候点击Generate按钮,生成VS2008工程文件(G:/VTK 5.6/bin/VTK.sln),打开工程文件并且编译
文件很大,编译时间也很长。耐心等待
9。编译通过后,(1)新建一个QT项目。在项目-》属性-》配置属性-》C/C++-》常规中的附加包含目录将头文件目录一个一个的添加进去,G:/VTK 5.6/GenericFiltering,G:/VTK 5.6/Common,G:/VTK 5.6/IO,G:/VTK 5.6/Filtering,G:/VTK 5.6/bin,G:/VTK 5.6/Rendering,G:/VTK 5.6/Graphics,G:/VTK 5.6/VolumeRendering,G:/VTK 5.6/Imaging,G:/VTK 5.6/Hybrid,G:/VTK 5.6/GUISupport,G:/VTK 5.6/include/vtk-5.6,G:/VTK 5.6/Parallel,G:/VTK 5.6/lib,G:/VTK 5.6/bin/Rendering (2)添加完后再 连接器-》输入 选择附加依赖项vtkzlib.lib vtkWidgets.lib vtkVolumeRendering.lib vtkViews.lib vtkverdict.lib vtktiff.lib vtksys.lib vtksqlite.lib vtkRendering.lib vtkQtChart.lib vtkproj4.lib vtkpng.lib vtkNetCDF.lib vtkmyUnsorted.lib vtkmyImaging.lib vtkmyCommon.lib vtkmetaio.lib vtkLocal.lib vtklibxml2.lib vtkjpeg.lib vtkIO.lib vtkInfovis.lib vtkImaging.lib vtkHybrid.lib vtkGraphics.lib  vtkGeovis.lib vtkGenericFiltering.lib vtkftgl.lib  vtkfreetype.lib vtkFiltering.lib vtkexpat.lib vtkexoIIc.lib vtkDICOMParser.lib vtkCommon.lib vtkCharts.lib vtkalglib.lib QVTKWidgetPlugin.lib QVTK.lib mpistubs.lib MapReduceMPI.lib   最后将依赖项的路径添加进 常规-》附加目录(G:/VTK 5.6/bin/bin/Debug)

最后我们需要打开G:/vtk 5.6/bin /bin/debug这个文件夹选择其中所有的DLL 后缀的文件全部复制到c:/windows/system32 

在项目中如果找不到头文件或者链接按(1)(2)的方法将他添加进去。
现在基本工作就算完成了,接下来我们写一小程序测试:
main.cpp:
#include "qtvtk.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
 QApplication a(argc, argv);
 QTVTK w;
 w.show();
 return a.exec();
}
qtvtk.h:
#ifndef QTVTK_H
#define QTVTK_H
#include <QtGui/QWidget>
#include "vtkRenderer.h"
#include "vtkWin32OpenGLRenderWindow.h"
#include "vtkWin32RenderWindowInteractor.h"
class QTVTK: public QWidget
{
 Q_OBJECT
public:
 QTVTK(QWidget* parent = 0);
 ~QTVTK();
protected:
 virtual void paintEvent(QPaintEvent *);
 virtual bool winEvent(MSG *);
private:
 vtkRenderer *Renderer;
 vtkWin32OpenGLRenderWindow *RenderWindow;
 vtkWin32RenderWindowInteractor *Interactor;
};
#endif // QTVTK_H
qtvtk.cpp:
#include "qtvtk.h"
#include "vtkActor2D.h"
#include "vtkTextMapper.h"
#include "vtkTextProperty.h"
#include "vtkDataSetReader.h"
#include "vtkDataSetMapper.h"
#include "vtkCommand.h"
#include "vtkCamera.h"
#include "vtkWin32RenderWindowInteractor.h"
#include "vtkInteractorStyleTrackballCamera.h"
QTVTK::QTVTK(QWidget* parent)
:QWidget(parent)
{
 this->Renderer = vtkRenderer::New();
 this->Renderer->SetBackground(0.3, 0.5, 0.1);
 this->RenderWindow = vtkWin32OpenGLRenderWindow::New();
 this->RenderWindow->AddRenderer(this->Renderer);
 this->Interactor = vtkWin32RenderWindowInteractor::New();
 vtkActor2D *actor2d = vtkActor2D::New();
 vtkTextMapper *txt = vtkTextMapper::New();
 actor2d->SetMapper(txt);
 txt->SetInput("Hello World");
 txt->GetTextProperty()->SetFontSize(24);
 this->Renderer->AddViewProp(actor2d);
 txt->Delete();
 actor2d->Delete();
 vtkActor *actor = vtkActor::New();
 vtkDataSetReader *reader = vtkDataSetReader::New();
 reader->SetFileName("C://Users//LQF//Desktop//QTVTK//QTVTK//Debug//weldedSpheres.vtk");//该文件可以在G:/VTK 5.6/Examples/GUI/Win32/SampleMFC中找到
 vtkDataSetMapper *mapper = vtkDataSetMapper::New();
 mapper->SetInput(reader->GetOutput());
 actor->SetMapper(mapper);
 this->Renderer->AddViewProp(actor);
 mapper->Delete();
 reader->Delete();
 actor->Delete();
}
QTVTK::~QTVTK()
{
 if (this->Interactor) {
  this->Interactor->Delete();
 }
 if (this->Renderer) {
  this->Renderer->SetRenderWindow(NULL);
 }
 if (this->RenderWindow) {
  this->RenderWindow->Delete();
 }
 if (this->Renderer) {
  this->Renderer->Delete();
 }
}
void QTVTK::paintEvent(QPaintEvent *e)
{
 if (! this->Interactor->GetInitialized()) {
  this->RenderWindow->SetWindowId(this->winId());
  this->RenderWindow->WindowInitialize();
  this->Interactor->SetRenderWindow(this->RenderWindow);
  this->Interactor->Initialize();
 }
 this->RenderWindow->Render();
}
bool QTVTK::winEvent(MSG *msg)
{
 switch (msg->message) {
  case WM_LBUTTONDOWN:
  case WM_LBUTTONUP:
  case WM_MBUTTONDOWN:
  case WM_MBUTTONUP:
  case WM_RBUTTONDOWN:
  case WM_RBUTTONUP:
  case WM_MOUSEMOVE:
  case WM_CHAR:
  case WM_TIMER:
   if (this->Interactor->GetInitialized()) {
    vtkHandleMessage2(msg->hwnd, msg->message, msg->lParam, msg->wParam, this->Interactor);
   }
 }
 return false;
}

你可能感兴趣的:(timer,Class,dll,Build,qt,actor)