VTK_开发环境搭建(VTK-9.3.0,WIN11,MSVC_X64)

1. 编译环境

  • Visual Studio 2022(VS 17);
  • QT(MSVC 2019,X64,默认支持源码调试);
  • CMake(3.29);
  • VTK(9.3.0);

2. 编译配置(CMake)

CMAKE_BUILD_TYPE        Debug;Release;MinSizeRel;RelWithDebInfo
CMAKE_INSTALL_PREFIX        C:/VTK/VTK-9.3.0-release
VTK_GROUP_Qt        YES
Qt6_DIR        C:/Qt/6.7.0/msvc2019_64/lib/cmake/Qt6
Qt6QmlTools_Dir        C:/Qt/6.7.0/msvc2019_64/lib/cmake/Qt6QmlTools

3. 编译安装

3.1 编译Release版本
# 1. VS打开工程VTK.sln;
# 2. 选中项目"ALL_BUILD",保持编译配置为“Release x64”,右键“生成”,编译代码;
# 3. 选中项目"INSTALL",保持编译配置为“Release x64”,右键“生成”,安装程序;
3.2 编译Debug版本
# 1. VS打开工程VTK.sln;
# 2. 选中项目"ALL_BUILD",保持编译配置为“Release x64”,右键“生成”,编译代码;
# 3. 选中项目"INSTALL",保持编译配置为“Release x64”,右键“生成”,安装程序;

4. 错误处理

4.1 Debug版编译错误(error LNK1169: one or more multiply defined symbols found);
错误信息:

vtkCommonCore-9.3d.lib(vtkCommonCore-9.3d.dll) : error LNK2005: "public: __cdecl vtkConstantImplicitBackend<unsigned __int64>::vtkConstantImplicitBackend<unsigned __int64>(unsigned __int64)" (??0?$vtkConstantImplicitBackend@_K@@QEAA@_K@Z) already defined in vtkToImplicitRamerDouglasPeuckerStrategy.cxx.obj
Creating library lib\Debug\vtkFiltersReduction-9.3d.lib and object lib\Debug\vtkFiltersReduction-9.3d.exp
bin\Debug\vtkFiltersReduction-9.3d.dll : fatal error LNK1169: one or more multiply defined symbols found
解决方法:

定位源文件,并修改代码:
VTK-9.3.0/Common/Core/vtkConstantImplicitBackend.h

修改前:
struct VTKCOMMONCORE_EXPORT vtkConstantImplicitBackend final

修改后:
struct vtkConstantImplicitBackend final
4.2 Debug版运行错误(开发调试时,弹出信息窗口并卡死);
解决方法(源文件中增加如下代码,用于关闭vtkOutputWindow):

#include <vtkOutputWindow.h>
vtkOutputWindow::SetGlobalWarningDisplay(0);
4.3 Release/Debug版运行错误(意外退出);
错误信息:

13:10:55: Starting D:\Codes\QT\02_HelloWorld\build\Desktop_Qt_6_7_0_MSVC2019_64bit-Release\release\02_HelloWorld.exe...
13:10:55: D:\Codes\QT\02_HelloWorld\build\Desktop_Qt_6_7_0_MSVC2019_64bit-Release\release\02_HelloWorld.exe exited with code 0
解决方法(源文件中增加如下代码,用于初始化VTK环境):

#include <vtkAutoInit.h>

VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)
注:确保路径“C:\VTK\VTK-9.3.0-release\bin”和“C:\VTK\VTK-9.3.0-debug\bin”,已经添加到系统环境变量$PATH。

5. 测试代码

#include <vtkAutoInit.h>
#include <vtkOutputWindow.h>
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCylinderSource.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <array>

VTK_MODULE_INIT(vtkRenderingOpenGL2)
VTK_MODULE_INIT(vtkInteractionStyle)

int main(int, char*[])
{

    vtkOutputWindow::SetGlobalWarningDisplay(0);
    vtkNew<vtkNamedColors> colors;

    // Set the background color.
    std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};
    colors->SetColor("BkgColor", bkg.data());

    // This creates a polygonal cylinder model with eight circumferential facets
    // (i.e, in practice an octagonal prism).
    vtkNew<vtkCylinderSource> cylinder;
    cylinder->SetResolution(8);

    // The mapper is responsible for pushing the geometry into the graphics
    // library. It may also do color mapping, if scalars or other attributes are
    // defined.
    vtkNew<vtkPolyDataMapper> cylinderMapper;
    cylinderMapper->SetInputConnection(cylinder->GetOutputPort());

    // The actor is a grouping mechanism: besides the geometry (mapper), it
    // also has a property, transformation matrix, and/or texture map.
    // Here we set its color and rotate it around the X and Y axes.
    vtkNew<vtkActor> cylinderActor;
    cylinderActor->SetMapper(cylinderMapper);
    cylinderActor->GetProperty()->SetColor(
        colors->GetColor4d("Tomato").GetData());
    cylinderActor->RotateX(30.0);
    cylinderActor->RotateY(-45.0);

    // The renderer generates the image
    // which is then displayed on the render window.
    // It can be thought of as a scene to which the actor is added
    vtkNew<vtkRenderer> renderer;
    renderer->AddActor(cylinderActor);
    renderer->SetBackground(colors->GetColor3d("BkgColor").GetData());
    // Zoom in a little by accessing the camera and invoking its "Zoom" method.
    renderer->ResetCamera();
    renderer->GetActiveCamera()->Zoom(1.5);

    // The render window is the actual GUI window
    // that appears on the computer screen
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->SetSize(300, 300);
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("Cylinder");

    // The render window interactor captures mouse events
    // and will perform appropriate camera or actor manipulation
    // depending on the nature of the events.
    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
    renderWindowInteractor->SetRenderWindow(renderWindow);

    // This starts the event loop and as a side effect causes an initial render.
    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据提供的引用内容,你遇到的错误是"No such file or directory",意味着系统无法找到指定的文件或目录。具体来说,系统无法找到路径为'D:\\pythonProject\\build\\exe.win-amd64-3.6\\lib\\vtk.libs\\.load-order-vtk-9.3.0'的文件或目录。 这个错误通常发生在以下几种情况下: 1. 文件或目录不存在:请确保指定的文件或目录路径是正确的,并且确保文件或目录确实存在于指定的位置。 2. 权限问题:如果你没有足够的权限访问该文件或目录,系统也会报错。请确保你具有足够的权限来访问该文件或目录。 3. 环境变量配置错误:有时候,系统需要通过环境变量来找到特定的文件或目录。如果环境变量配置错误或缺失,系统也会报错。请检查你的环境变量配置是否正确。 为了解决这个问题,你可以尝试以下几个步骤: 1. 确认文件或目录是否存在:请检查路径'D:\\pythonProject\\build\\exe.win-amd64-3.6\\lib\\vtk.libs\\.load-order-vtk-9.3.0'是否正确,并确保该文件或目录确实存在。 2. 检查权限:如果文件或目录存在,但你无法访问它,可能是因为你没有足够的权限。请确保你具有足够的权限来访问该文件或目录。 3. 检查环境变量配置:如果你的系统需要通过环境变量来找到文件或目录,你需要确保环境变量配置正确。根据提供的引用内容,你可以尝试设置LD_LIBRARY_PATH环境变量来指定库文件的路径。 以下是一个示例,演示如何设置LD_LIBRARY_PATH环境变量: ```shell export LD_LIBRARY_PATH=/usr/local/lib/python3.6/dist-packages/torch/lib:"${LD_LIBRARY_PATH}" ``` 请注意,这只是一个示例,你需要根据你的具体情况来设置正确的环境变量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

勇敢小觉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值