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;
}