vtk中点线处理汇总

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);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值