VTK系列51_VTK三维平面(点)法向量计算

实例51:三维平面(点)法向量计算

#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);

#include 
#include  
#include  //计算法向量
#include 
#include 
#include 
#include 
#include 
//
#include 
#include 
#include 
#include 
#include 

int main()
{
	vtkSmartPointer plyReader =
		vtkSmartPointer::New();
	plyReader->SetFileName("C:\\Users\\Administrator\\Desktop\\VTK2\\hellovtk\\vtk_图像处理学习\\第六章_图像处理\\data\\fran_cut.vtk");
	plyReader->Update();

	vtkSmartPointer normFilter =
		vtkSmartPointer::New();
	normFilter->SetInputData(plyReader->GetOutput());
	normFilter->SetComputePointNormals(1);//开启点法向量计算
	normFilter->SetComputeCellNormals(0); //关闭单元法向量计算
	normFilter->SetAutoOrientNormals(1);
	normFilter->SetSplitting(0);
	normFilter->Update();

	vtkSmartPointer mask =
		vtkSmartPointer::New();
	mask->SetInputData(normFilter->GetOutput());
	mask->SetMaximumNumberOfPoints(300);
	mask->RandomModeOn();
	mask->Update();

	vtkSmartPointer arrow =
		vtkSmartPointer::New();
	arrow->Update(); //一定要更新 否则数据没有添加进来,程序会报错

	vtkSmartPointer glyph =
		vtkSmartPointer::New();
	glyph->SetInputData(mask->GetOutput());
	glyph->SetSourceData(arrow->GetOutput());//每一点用箭头代替
	glyph->SetVectorModeToUseNormal();//设置向量显示模式和法向量一致
	glyph->SetScaleFactor(0.01); //设置伸缩比例
	glyph->Update();
	
	vtkSmartPointer mapper =
		vtkSmartPointer::New();
	mapper->SetInputData(plyReader->GetOutput());
	vtkSmartPointer normMapper =
		vtkSmartPointer::New();
	normMapper->SetInputData(normFilter->GetOutput());
	vtkSmartPointer glyphMapper =
		vtkSmartPointer::New();
	glyphMapper->SetInputData(glyph->GetOutput());

	vtkSmartPointer actor =
		vtkSmartPointer::New();
	actor->SetMapper(mapper);
	vtkSmartPointer normActor =
		vtkSmartPointer::New();
	normActor->SetMapper(normMapper);
	vtkSmartPointer glyphActor =
		vtkSmartPointer::New();
	glyphActor->SetMapper(glyphMapper);
	glyphActor->GetProperty()->SetColor(1, 0, 0);
	
	double origView[4] = { 0, 0, 0.33, 1 };
	double normView[4] = { 0.33, 0, 0.66, 1 };
	double glyphView[4] = { 0.66, 0, 1, 1 };
	vtkSmartPointer origRender =
		vtkSmartPointer::New();
	origRender->SetViewport(origView);
	origRender->AddActor(actor);
	origRender->SetBackground(1, 0, 0);
	vtkSmartPointer normRender =
		vtkSmartPointer::New();
	normRender->SetViewport(normView);
	normRender->AddActor(normActor);
	normRender->SetBackground(0, 1, 0);
	vtkSmartPointer glyphRender =
		vtkSmartPointer::New();
	glyphRender->SetViewport(glyphView);
	glyphRender->AddActor(glyphActor);
	glyphRender->AddActor(normActor);
	glyphRender->SetBackground(0, 0, 1);
	
	vtkSmartPointer rw =
		vtkSmartPointer::New();
	rw->AddRenderer(origRender);
	rw->AddRenderer(normRender);
	rw->AddRenderer(glyphRender);
	rw->SetWindowName("Calculating Point Norm & Cell Norm");
	rw->SetSize(960, 320);
	rw->Render();

	vtkSmartPointer rwi =
		vtkSmartPointer::New();
	rwi->SetRenderWindow(rw);
	rwi->Initialize();
	rwi->Start();

	return 0;
}

VTK系列目录:

1 VTK基本概念

2 VTK图像处理

3 VTK图形处理

4 VTK体绘制

你可能感兴趣的:(VTK学习笔记,openCV,vtk)