VTK笔记-使用vtkVertexGlyphFilter类绘制点/点云绘制

vtkVertexGlyphFilter

  vtkVertexGlyphFilter类的功能是创建一个多边形数据vtkPolyData,其中每个点都被创建了一个顶点Vertex
  vtkVertexGlyphFilter类将丢弃输入数据中的所有单元,取而代之的是在每个点上创建一个顶点。此过滤器的预期用途大致相当于vtkGlyph3D类,但此过滤器专门用于具有多个顶点的数据,使渲染结果比glyph过滤器更快、更不混乱。此过滤器可以将图形或点集作为输入。
  vtkVertexGlyphFilter类的接口基本上是使用继承自vtkPolyDataAlgorithm类的接口;

class VTKFILTERSGENERAL_EXPORT vtkVertexGlyphFilter : public vtkPolyDataAlgorithm
{
public:
   vtkTypeMacro(vtkVertexGlyphFilter, vtkPolyDataAlgorithm);
   void PrintSelf(ostream& os, vtkIndent indent) override;
   static vtkVertexGlyphFilter* New();
  
protected:
   vtkVertexGlyphFilter();
   ~vtkVertexGlyphFilter() override;
  
   int RequestData(vtkInformation*, vtkInformationVector**, vtkInformationVector*) override;
   int FillInputPortInformation(int, vtkInformation*) override;
  
private:
   vtkVertexGlyphFilter(const vtkVertexGlyphFilter&) = delete;
   void operator=(const vtkVertexGlyphFilter&) = delete;
};  

脸数据-点显示

  代码目标:从vtk文件中读取离散点集合并展示;
  步骤:
    1.读取fran_cut.vtk文件,获取其中的点数据,不要线和单元信息;
    2.使用vtkVertexGlyphFilter在每个点创建一个顶点Vertex
    3.使用渲染管线渲染绘制;

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

#include <vtkPolyDataReader.h>
#include <vtkVertexGlyphFilter.h>
using namespace std;
int main() {
	vtkNew<vtkPolyDataReader> reader;
	reader->SetFileName("C:\\Data\\VTK\\fran_cut.vtk");
	reader->Update();

	vtkNew<vtkPolyData> points;
	points->SetPoints(reader->GetOutput()->GetPoints());
	vtkNew<vtkVertexGlyphFilter> vertexGlyphFilter;
	vertexGlyphFilter->AddInputData(points);
	vertexGlyphFilter->Update();
	
	vtkNew<vtkPolyDataMapper> pointMapper;
	pointMapper->SetInputData(vertexGlyphFilter->GetOutput());
	pointMapper->ScalarVisibilityOff();

	vtkNew<vtkActor> pointActor;
	pointActor->SetMapper(pointMapper);
	pointActor->GetProperty()->SetColor(1, 1, 1);
	pointActor->GetProperty()->SetPointSize(3);
	
	vtkNew<vtkRenderer> render;
	render->AddActor(pointActor);
	render->SetBackground(0.2, 0.3, 0.4);

	vtkNew<vtkRenderWindow> ren_win;
	ren_win->AddRenderer(render);

	vtkNew<vtkRenderWindowInteractor> iren;
	iren->SetRenderWindow(ren_win);
	iren->Initialize();
	iren->Start();
	return 0; 
}

在这里插入图片描述

茶壶数据-点显示

  TeapotPoints.txt文件中每行有三个浮点型的数,表示了一个点的坐标(x,y,z);如下图:
在这里插入图片描述
  步骤:
    1.从TeapotPoints.txt文件中遍历所有点,放入vtkPoints
    2.创建一个vtkPolyData多边形数据,将vtkPoints点集合放入其中;
    3.使用vtkVertexGlyphFilter在每个点创建一个顶点Vertex
    4.使用渲染管线渲染绘制;

int main() {
	std::string filename = "C:\\Data\\VTK\\TeapotPoints.txt";
	std::ifstream filestream(filename.c_str());

	std::string line;
	vtkNew<vtkPoints> points;

	while (std::getline(filestream, line))
	{
		double x, y, z;
		std::stringstream linestream;
		linestream << line;
		linestream >> x >> y >> z;

		points->InsertNextPoint(x, y, z);
	}
	vtkNew<vtkPolyData> pointsPolydata;
	pointsPolydata->SetPoints(points);

	vtkNew<vtkVertexGlyphFilter> vertexGlyphFilter;
	vertexGlyphFilter->AddInputData(pointsPolydata);
	vertexGlyphFilter->Update();
	vtkNew<vtkPolyDataMapper> pointMapper;
	pointMapper->SetInputData(vertexGlyphFilter->GetOutput());
	//pointMapper->ScalarVisibilityOff();

	vtkNew<vtkActor> pointActor;
	pointActor->SetMapper(pointMapper);
	pointActor->GetProperty()->SetColor(1, 1, 1);
	pointActor->GetProperty()->SetPointSize(3);
	
	vtkNew<vtkRenderer> render;
	render->AddActor(pointActor);
	render->SetBackground(0.2, 0.3, 0.4);

	vtkNew<vtkRenderWindow> ren_win;
	ren_win->AddRenderer(render);

	vtkNew<vtkRenderWindowInteractor> iren;
	iren->SetRenderWindow(ren_win);
	iren->Initialize();
	iren->Start();
	return 0; 
}

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

黑山老妖的笔记本

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

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

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

打赏作者

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

抵扣说明:

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

余额充值