我正在学习VTK,正在阅读VTKTextBook。 我尝试执行Cone示例。
当我运行它时,我有一个奇怪的行为,很难解释 带有单词,但您可以在以下链接的gif中看到它: https://imgur.com/lJigYGu
我使用的代码与的代码略有不同 例子,但是他们两个都有相同的问题。
这是我的cube.cpp文件的代码:
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkConeSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
int main(int, char* []) {
vtkNew<vtkNamedColors> colors;
vtkNew<vtkConeSource> cone;
cone->SetHeight(3.0);
cone->SetRadius(1.0);
cone->SetResolution(10);
vtkNew<vtkPolyDataMapper> coneMapper;
coneMapper->SetInputConnection(cone->GetOutputPort());
vtkNew<vtkActor> coneActor;
coneActor->SetMapper(coneMapper);
vtkNew<vtkRenderer> ren1;
ren1->AddActor(coneActor);
ren1->SetBackground(
colors->GetColor3d("MidnightBlue").GetData());
vtkNew<vtkRenderWindow> renWin;
renWin->AddRenderer(ren1);
renWin->SetSize(300, 300);
vtkNew<vtkRenderWindowInteractor> interactor;
interactor->SetRenderWindow(renWin);
interactor->Start();
for (auto i = 0; i < 360; ++i) {
// render the image
renWin->Render();
// rotate the active camera by one degree
ren1->GetActiveCamera()->Azimuth(1);
}
return EXIT_SUCCESS;
}
这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(Cone)
set(VTK_USE_CARBON ON)
find_package(VTK COMPONENTS
vtkCommonCore
vtkCommonDataModel
vtkFiltersSources
vtkInteractionStyle
vtkRenderingCore
vtkRenderingFreeType
vtkRenderingOpenGL2 QUIET)
if (NOT VTK_FOUND)
message("Skipping Cone: ${VTK_NOT_FOUND_MESSAGE}")
return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
# old system
include(${VTK_USE_FILE})
add_executable(Cone Cone.cpp)
target_link_libraries(Cone PRIVATE ${VTK_LIBRARIES})
else ()
# include all components
add_executable(Cone Cone.cxx )
target_link_libraries(Cone PRIVATE ${VTK_LIBRARIES})
# vtk_module_autoinit is needed
vtk_module_autoinit(
TARGETS Cone
MODULES ${VTK_LIBRARIES}
)
endif ()
我已经在vtk用户的邮件列表和vtk forum中进行了询问,但没有得到任何答复。
我已经尝试过安装了自制软件的vtk版本8.1.2和在github的master分支中从源代码编译的8.90.0版本。