image

Add references: Kitware.mymmy.Runtime.dll and KitwareVTK.dll

image

==============================================

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Kitware.VTK;

namespace SimplePointsReader
{
public partial class Form1 : Form
{
private Kitware.VTK.RenderWindowControl renderWindowControl1;
public Form1()
{
InitializeComponent();
renderWindowControl1 = new RenderWindowControl();
this.Controls.Add(renderWindowControl1);
renderWindowControl1.Show();
renderWindowControl1.Dock = DockStyle.Fill;
}

==============================================

private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofd = new OpenFileDialog())
{
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{

SimplePointsReader(ofd.FileName);
}
}
}
private void SimplePointsReader(string fileName)
{
// Path to vtk data must be set as an environment variable
// VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0"
vtkTesting test = vtkTesting.New();
string root = test.GetDataRoot();
string filePath = System.IO.Path.Combine(root, fileName);

vtkSimplePointsReader reader = vtkSimplePointsReader.New();
reader.SetFileName(filePath);
reader.Update();
// Visualize
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(reader.GetOutputPort());
vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetPointSize(4);
vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
renderer.SetBackground(.3, .6, .3);
renderer.AddActor(actor);
//renderer.ResetCamera();
}

載入C:\VTK 5.6\vtkdata\Data\points.txt

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

image

加入第九點[0.5 0.5 0]

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
0.5 0.5 0

image

參考資料:

http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/SimplePointsReader

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 me1237guy 的頭像
    me1237guy

    天天向上

    me1237guy 發表在 痞客邦 留言(0) 人氣()