vtkDoubleArray(vtkFloatArray) vtkIntArray使用

下面是vtk的一段示例代码:

vtkFloatArray* pcoords = vtkFloatArray::New();

  // Note that by default, an array has 1 component.
  // We have to change it to 3 for points
  pcoords->SetNumberOfComponents(3);
  // We ask pcoords to allocate room for at least 4 tuples
  // and set the number of tuples to 4.
  pcoords->SetNumberOfTuples(4);
  // Assign each tuple. There are 5 specialized versions of SetTuple:
  // SetTuple1 SetTuple2 SetTuple3 SetTuple4 SetTuple9
  // These take 1, 2, 3, 4 and 9 components respectively.
  float pts[4][3] = { {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0},
                      {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0} };
  for (i=0; i<4; i++)
    {
    pcoords->SetTuple(i, pts[i]);
    }

  // Create vtkPoints and assign pcoords as the internal data array.
  vtkPoints* points = vtkPoints::New();
  points->SetData(pcoords);


对于vtkXXXArray的类来说,其中的tuples指的是含有元素的个数,而其中的components指的是每个元素用几个元组组成,如对于法向量来说,是N个三元组组成。

上面的例子中指出了pcoord中一共有4个点,每个点包含x,y,z三个方向坐标。

使用points->SetData可以将vtkFloatArray的数组传递给点集合。

更常用的是对于点集的属性集操作,模型的属性信息都保存在其PointData中,通过GetPointData获得其点属性数据,而后可以进行修改更新:

    vtkDoubleArray * src_attris =(    vtkDoubleArray * ) src_ug->GetPointData()->GetScalars();
    vtkDoubleArray * dst_attris = vtkDoubleArray::New();

    pts_num = dst_ug->GetNumberOfPoints();
    attri_num = src_attris->GetNumberOfComponents();
    dst_attris->SetNumberOfTuples(pts_num);
    dst_attris->SetNumberOfComponents(attri_num);

    attri = new double[attri_num];
    null_atrri = new double[attri_num];
    for (i=0;i<attri_num;i++)
    {
        null_atrri[i] = 0.0;
    }
   
    for (ptid =0 ;ptid<pts_num;ptid++)
    {
        dst_ug->GetPoint(ptid,pt);
        pos = src_ug->FindPoint(pt);
        if (pos == -1)
        {
            null_count ++;
            dst_attris->SetTupleValue(ptid,null_atrri);
            continue;
        }
        src_attris->GetTupleValue(pos,attri);
        dst_attris->SetTupleValue(ptid,attri);

    }
    dst_ug->GetPointData()->SetScalars(dst_attris);
    dst_ug->Modified();

 

注意的是在vtkIntArray中,只实现了GetTupleValue, SetTupleValue两个操作,所以在vtkIntArray中,不同通过 SetTuple来设置其中的元素,只能通过GetTupleValue, SetTupleValue.

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值