VTK_9.0.0 空间两点间的点云距离距离计算

长度测量

其中新建项目配置好VTK所需的环境,运行程序报错,Error: no override found for 'vtkPolyDataMapper2D'.

This initializes the specified VTK modules. CMake includes these by default, but other compilers such as VS do not.

解决办法:在头文件前面加入

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)

或者

若是通过visual studio编译而不是cmake编译的的话需要添加代码:

#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);

当然出现下列问题:

Error LNK1120 1 unresolved externals

Error LNK2019 unresolved external symbol "void __cdecl vtkRenderingOpenGL_AutoInit_Construct(void)" (?vtkRenderingOpenGL_AutoInit_Construct@@YAXXZ) referenced in function "public: __cdecl `anonymous namespace'::vtkRenderingOpenGL_ModuleInit::vtkRenderingOpenGL_ModuleInit(void)" (??0vtkRenderingOpenGL_ModuleInit@?A0xb422abed@@QEAA@XZ)

多半是在头文件中添加这句

#include "vtkAutoInit.h"
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);

解决方法:将其换成下列这代码并将其放在头文件前面

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)

代码如下:

#define vtkRenderingCore_AUTOINIT 2(vtkRenderingOpenGL2, vtkInteractionStyle)
#include 
#include 
#include 
#include 
#include 
#include 

int main(int, char *[])
{
	// A renderer and render window
	vtkSmartPointer renderer =
		vtkSmartPointer::New();
	vtkSmartPointer renderWindow =
		vtkSmartPointer::New();
	renderWindow->AddRenderer(renderer);

	// An interactor
	vtkSmartPointer renderWindowInteractor =
		vtkSmartPointer::New();
	renderWindowInteractor->SetRenderWindow(renderWindow);

	vtkSmartPointer distanceWidget =
		vtkSmartPointer::New();
	distanceWidget->SetInteractor(renderWindowInteractor);
	distanceWidget->CreateDefaultRepresentation();
	static_cast(distanceWidget->GetRepresentation())
		->SetLabelFormat("%-#6.3g mm");

	// Render an image (lights and cameras are created automatically)
	renderWindow->Render();

	renderWindowInteractor->Initialize();
	renderWindow->Render();
	distanceWidget->On();

	// Begin mouse interaction
	renderWindowInteractor->Start();

	return EXIT_SUCCESS;
}

计算效果

VTK_9.0.0 空间两点间的点云距离距离计算_第1张图片

本文VTK版本为VTK_9.0.0 ,本文项目程序下载链接:

链接:https://pan.baidu.com/s/1jw0wLh4GOz_Ct9uEP_WzPA 
提取码:zkq8

参考博文:

1、http://www.voidcn.com/article/p-qynbbhui-da.html

2、https://lorensen.github.io/VTKExamples/site/Cxx/Widgets/DistanceWidget/

 

 

 

你可能感兴趣的:(VTK_9.0.0,c++)