VTK的编译和部署,配合c++和visual studio2022,VTK开发环境的配置

1.下载

在官网选择最新的版本

Download | VTK

下载之后进行解压,然后再里面创建build目录,方便后面使用cmake进行编译

2.对源码进行编译

打卡Cmake,如图操作

可以看到点击configure之后,cmake对我们的代码在进行处理

处理完成之后会看到很多的红色,提示

多点几次configure这些红色警告就会消失

看到没有红色警告之后,点击Generate来生成VS的项目文件。

然后再build目录下能看到VS项目文件

打开项目文件,使用VS2022,选择ALL_BUILD项目进行编译,debug,release版本根据个人的需要

然后再选择INSTALL项目进行生成

然后会遇到一个问题,报错Setlocal,这是因为没有把Visual studio 以管理员的身份打开,

编译INSTALL是为了,生成对应的include文件和lib 文件。方便其他程序引用VTK库

最终再C盘下生成了对应的文件

3.在项目中使用VTK库。VTK开发环境的配置

1.在Visual studio中创建控制台应用程序。

2.右键点击项目属性,选择vc++目录,配置库目录和包含目录

填写我们之前编译INSTALL生成的相关内容,

VTK\lib,和VTK\include\vtk-9.3

3.配置附加依赖项,将VTK目录下面的lib中,所有的lib的名字都写入到附加依赖项中。

快捷方法,通过cmd进入我们的lib目录下面

输入命令 DIR *.lib*/B>LIST.TXT

就能在LIST.txt文件中看到所有的lib的名字。

把所有的文件名拷贝进入附加依赖项中。

示例代码,拷贝下面的代码例子运行,如果能跑起来,说明成功运行了。

#include <vtkCamera.h>
#include <vtkDataSetAttributes.h>
#include <vtkGraphLayoutView.h>
#include <vtkIntArray.h>
#include <vtkLookupTable.h>
#include <vtkMutableDirectedGraph.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkViewTheme.h>

int main(int, char* [])
{
	vtkNew<vtkNamedColors> colors;

	vtkNew<vtkMutableDirectedGraph> graph;

	// Create a graph.
	vtkIdType v1 = graph->AddVertex();
	vtkIdType v2 = graph->AddVertex();
	vtkIdType v3 = graph->AddVertex();
	graph->AddEdge(v1, v2);
	graph->AddEdge(v2, v3);

	// Create the color array.
	vtkNew<vtkIntArray> edgeColors;
	edgeColors->SetNumberOfComponents(1);
	edgeColors->SetName("Color");

	vtkNew<vtkLookupTable> lookupTable;
	lookupTable->SetNumberOfTableValues(2);
	lookupTable->SetTableValue(0, colors->GetColor4d("Red").GetData());
	lookupTable->SetTableValue(1, colors->GetColor4d("Lime").GetData());
	lookupTable->Build();

	edgeColors->InsertNextValue(0);
	edgeColors->InsertNextValue(1);

	// Add the color array to the graph.
	graph->GetEdgeData()->AddArray(edgeColors);

	vtkNew<vtkGraphLayoutView> graphLayoutView;
	graphLayoutView->AddRepresentationFromInput(graph);
	// Needs VTK::InfovisBoostGraphAlgorithms.
	// graphLayoutView->SetLayoutStrategyToTree();
	graphLayoutView->SetLayoutStrategy("Simple 2D");

	graphLayoutView->SetEdgeColorArrayName("Color");
	graphLayoutView->ColorEdgesOn();

	vtkNew<vtkViewTheme> theme;
	theme->SetCellLookupTable(lookupTable);

	graphLayoutView->ApplyViewTheme(theme);
	graphLayoutView->ResetCamera();
	// graphLayoutView->GetRenderer()->SetBackground(
	//    colors->GetColor3d("Navy").GetData());
	// graphLayoutView->GetRenderer()->SetBackground2(
	//    colors->GetColor3d("MidnightBlue").GetData());
	graphLayoutView->GetRenderer()->GetActiveCamera()->Zoom(0.8);
	graphLayoutView->GetRenderWindow()->SetWindowName("ColorEdges");
	graphLayoutView->GetInteractor()->Initialize();
	graphLayoutView->GetInteractor()->Start();

	return EXIT_SUCCESS;
}

输出结果:

记得一定要把这个目录下的文件拷贝到编译结果目录下

相关推荐

  1. VTK中GetOutputPort()GetOutput()区别

    2024-03-10 12:12:03       47 阅读
  2. VTK----VTK事件机制

    2024-03-10 12:12:03       39 阅读
  3. VTK交互器

    2024-03-10 12:12:03       38 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-10 12:12:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-10 12:12:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-10 12:12:03       87 阅读
  4. Python语言-面向对象

    2024-03-10 12:12:03       96 阅读

热门阅读

  1. websocket前端应用

    2024-03-10 12:12:03       42 阅读
  2. RLAIF在提升大型语言模型训练中的应用

    2024-03-10 12:12:03       49 阅读
  3. 关于Spring Boot的配置文件

    2024-03-10 12:12:03       43 阅读
  4. 在Elasticsearch IK分词器中更新、停用某些专有名词

    2024-03-10 12:12:03       37 阅读
  5. Vue3搭建后台管理系统模板

    2024-03-10 12:12:03       35 阅读
  6. 事件委托,数组去重

    2024-03-10 12:12:03       48 阅读
  7. Word Game

    Word Game

    2024-03-10 12:12:03      43 阅读
  8. kafka集成外部系统

    2024-03-10 12:12:03       39 阅读
  9. sql执行计划需要关注那些内容?

    2024-03-10 12:12:03       43 阅读
  10. rust的 || 是什么,怎么使用?

    2024-03-10 12:12:03       47 阅读