使用Visual Studio创建新的VTK项目

时间:2016-04-12 13:24:46

标签: c++ windows visual-studio-2013 cmake vtk

我正在尝试创建一个在Visual Studio中使用VTK的新C ++项目。

我按照说明如何使用CMake在Windows上下载,访问和构建VTK,这似乎没问题。然后我尝试创建一个包含VTK功能和可视化的新项目,但是它生成了无法打开任何VTK头文件的错误(可能是由于项目属性中的其他依赖项,但我不确定要更改或更新的内容)使这项工作)。

有谁知道如何解决这个问题? (目前我正在尝试使用以下代码查看简单的多维数据集):

#include <vtkSmartPointer.h>
#include <vtkActor.h>
#include <vtkCubeSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <cmath>
#include <algorithm>


int   main(int t) {
if (t==1) {
vtkSmartPointer<vtkCubeSource> cubeSource =
    vtkSmartPointer<vtkCubeSource>::New();

// Create a mapper and actor.
vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(cubeSource->GetOutputPort());

vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);

// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

// Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(.3, .2, .1);

// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();

        actor->Delete();
        mapper->Delete();
        renderer->Delete();
        renderWindow->Delete();
        renderWindowInteractor->Delete();

    }

  return 0;
 }

另外,我的CMakeLists文件是:

cmake_minimum_required(VERSION 2.8)

PROJECT(karman)

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

add_executable(karman MACOSX_BUNDLE karman)

if(VTK_LIBRARIES)
   target_link_libraries(karman ${VTK_LIBRARIES})
else()
     target_link_libraries(karman vtkHybrid vtkWidgets)
endif()

0 个答案:

没有答案