wpf使用Kitware.VTK画线

使用

wpf,C#,Kitware.VTK

实现

有两个点,画出这两点之间的一条直线

  • 第一次实现时,画面只显示两个点,没有显示直线,如下代码
private void DrawGlueWidth()
{
    List<double[]> Points = new List<double[]>();
    Points.Add(new double[] { 100, 100, 100 });
    Points.Add(new double[] { 50, 50, 50 });

    // Create a points array
    vtkPoints points = vtkPoints.New();

    // Create a cell array to store the lines
    vtkCellArray lines = vtkCellArray.New();
    vtkCellArray ps = vtkCellArray.New();
    for (int i = 0; i < Points.Count; i++)
    {
        points.InsertNextPoint(Points[i][0], Points[i][1], Points[i][2]);
        if (i == 0 || i % 2 == 0)
		{
		    // Create a line between the points
		    vtkLine line = vtkLine.New();
		    line.GetPointIds().SetId(0, i);
		    line.GetPointIds().SetId(1, i + 1);
		    
    		lines.InsertNextCell(line);
		}
    }
    vtkLine line = vtkLine.New();
    line.GetPointIds().SetId(0, 0);
    line.GetPointIds().SetId(1, 1);
    lines.InsertNextCell(line);

    // Create a polyline data structure
    vtkPolyData polyData = vtkPolyData.New();
    polyData.SetPoints(points);
    polyData.SetLines(lines);


    // Create a mapper and actor
    vtkVertexGlyphFilter glyphFilter = vtkVertexGlyphFilter.New();
    glyphFilter.SetInputConnection(polyData.GetProducerPort());

    vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
    mapper.SetInputConnection(glyphFilter.GetOutputPort());

    vtkActor actor = vtkActor.New();
    actor.SetMapper(mapper);
    actor.GetProperty().SetColor(1, 0, 0);
    actor.GetProperty().SetPointSize(5);
    actor.GetProperty().SetLineStipplePattern(15);
    actor.GetProperty().SetLineWidth(15);

    // Add the actor to the renderer
    vtkRenderer renderer = renderControl.RenderWindow.GetRenderers().GetFirstRenderer();
    renderer.AddActor(actor);
	renderControl.RenderWindow.Render();
  • 第二次更改后, 可以了,如下代码
private void DrawGlueWidth()
{
    List<double[]> Points = new List<double[]>();
    Points.Add(new double[] { 58.9000015258789, -11.6255941390991, 56.7488250732422 });
    Points.Add(new double[] { 63.7000007629395, -11.7111196517944, 56.80859375 });

    // Create a points array
    vtkPoints points = vtkPoints.New();

    // Create a cell array to store the lines
    vtkCellArray lines = vtkCellArray.New();

    for (int i = 0; i < Points.Count; i++)
    {
        points.InsertNextPoint(Points[i][0], Points[i][1], Points[i][2]);
        if (i == 0 || i % 2 == 0)
        {
            // Create a line between the points
            vtkLine line = vtkLine.New();
            line.GetPointIds().SetId(0, i);
            line.GetPointIds().SetId(1, i + 1);

            lines.InsertNextCell(line);
        }
    }

    // 创建一个PolyData对象来存储点和线
    vtkPolyData polyData = vtkPolyData.New();
    polyData.SetPoints(points);
    polyData.SetLines(lines);

    // 创建一个Mapper和Actor来渲染点和线
    vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
    mapper.SetInputConnection(polyData.GetProducerPort());

    vtkActor actor = vtkActor.New();
    actor.SetMapper(mapper);
    actor.GetProperty().SetColor(0, 0, 1);
    actor.GetProperty().SetLineWidth(2);

    // Add the actor to the renderer
    vtkRenderer renderer = renderControl.RenderWindow.GetRenderers().GetFirstRenderer();
    renderer.AddActor(actor);

    renderControl.RenderWindow.Render();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值