实时绘制VTK点

时间:2018-06-05 14:33:36

标签: c# vtk

我想使用VTK库实时绘制一个点。不过,我在做这件事时遇到了一些问题。我的程序正在阐明这一点,但在我点击我的窗口控件之前我无法看到它,该点代表磁力的协调x。

这是我的代码:

 private void Pointdessinateur()
    {

        // Create the geometry of the points (the coordinate)
        vtkPoints points = vtkPoints.New();

        List<double> X = new List<double>(); // création de la liste
        List<double> Y = new List<double>();
        List<double> Z = new List<double>();
        // Create topology of the points (a vertex per point)
        vtkCellArray vertices = vtkCellArray.New();
        int i = 0;

        X.Add(XCnorm);
        Y.Add(YCnorm);
        Z.Add(ZCnorm);

        int[] ids = new int[X.Count];
        for (i = 0; i < X.Count; i++)
            ids[i] = points.InsertNextPoint(X[i], Y[i], Z[i]);

        int size = Marshal.SizeOf(typeof(int)) * X.Count;
        IntPtr pIds = Marshal.AllocHGlobal(size);
        Marshal.Copy(ids, 0, pIds, X.Count);
        vertices.InsertNextCell(X.Count, pIds);
        Marshal.FreeHGlobal(pIds);

        // Create a polydata object
        vtkPolyData pointPoly = vtkPolyData.New();

        // Set the points and vertices we created as the geometry and topology of the polydata
        pointPoly.SetPoints(points);
        pointPoly.SetVerts(vertices);

        // Visualize
        vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
        mapper.SetInput(pointPoly);
        vtkActor actor = vtkActor.New();
        actor.SetMapper(mapper);
        actor.GetProperty().SetPointSize(3);
        actor.GetProperty().SetColor(0.25, 0.0, 0.0);
        vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
        vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
        renderer.AddActor(actor); 
    }

1 个答案:

答案 0 :(得分:0)

问题解决。

我只是在我的VTKRenderWindow

上调用渲染
renderWindow.Render();