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;
}
![](https://img.laitimes.com/img/9ZDMuAjOiMmIsIjOiQnIsIiNx8FesU2cfdGLwczX0xiRGZkRGZ0Xy9GbvNGL38VZ6l2cskmNhVTYykVNFFXN1cVYhVjQDlkN4dkY1IVdiZTQClGVF5UMR9Fd4VGdsATNfd3bkFGazxycykFaKdkYzZUbapXNXlleSdVY2pESa9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnLhVGNkNWOykDMmhTNmFWYiFTNwQzM4IGOkRjZmhjN2UzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
茶壺資料-點顯示
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;
}