1.两点连线
Line()
{
vtkLineSource lineSource = vtkLineSource.New();
double[] p0 = new double[] {1.0,0.0,0.0}
double[] p1 = new double[]{0.0,1.0,0.0}
lineSource.SetPoint1(p0[0],p0[1],p0[2]);
lineSource.SetPoint2(p1[0],p0[1],p0[2]);
actor.GetProperty().SetLineWidth(4);
}
2.多点连线
LongLine()
{
double[,] p=new double[,]{
{0.0,0.0,0.0},
{1.0,0.0,0.0},
{0.0,1.0,0.0},
{0.0,1.0,2.0},
{1.0,2.0,3.0}
};
定义5*3数组
vtkPoints points = vtkPoints.New();
for(int i=0;i<5;i++)
points.InsertNextPoint(p[i,0],p[i,1],p[i,2]);
vtkCellArray lines = vtkCellArray.New();
for(int i=0;i<4;i++)
{
vtkLine line = vtkLine.New();
line.GetPointIds().SetId(0,i);
line.GetPointIds().SetId(1,i+1);
lines.InsertNextCell(line);
}
vtkPolyData linesPolyData = vtkPolyData.New();
linesPolyData.SetPoints(points);
linesPolyData.SetLines(lines);
actor.GetProperty().SetLineWidth(4);
}
3.点线赋值
double[] origin = new double[] { 0.0,0.0,0.0};
double[] p0 = new double[] { 1.0,0.0,0.0};
double[] p1 = new double[] { 0.0,1.0,0.0};
vtkPoints pts = vtkPoints.New();
pts.InsertNextPoint(origin[0],origin[1],origin[2]);
pts.InsertNextPoint(p0[0],p0[1],p0[2]);
pts.InsertNextPoint(p1[0],p1[1],p1[2]);
byte[] red = new byte[] { 255,0,0};
byte[] green = new byte[] { 0,255,0};
vtkUnsignedCharArray colors = vtkUnsignedCharArray.New();
colors.SetNumberOfComponents(3);
colors.SetName("Colors");
colors.InsertNextValue(red[0]);
colors.InsertNextValue(red[1]);
colors.InsertNextValue(red[2]);
colors.InsertNextValue(green[0]);
colors.InsertNextValue(green[1]);
colors.InsertNextValue(green[2]);
vtkLine line0 = vtkLine.New();
line0.GetPointIds().SetId(0,0);
line0.GetPointIds().SetId(1,1);
vtkLine line1 = vtkLine.New();
line1.GetPointIds().SetId(0,0);
line1.GetPointIds().SetId(1,2);
vtkCellArray lines = vtkCellArray.New();
lines.InsertNextCell(line0);
lines.InsertNextCell(line1);
vtkPolyData linesPolyData = vtkPolyData.New();
linesPolyData.SetPoints(pts);
linesPolyData.SetLines(lines);
linesPolyData.GetCellData().SetScalars(colors);