VTK 中主要包括点属性数据和单元属性数据,在 VTK 中,属性数据和数据集的结构可以被许多过滤器处理,并且产生新的结构和属性,
---------------------------------------------------------------------------------------------------------------------------------
1.vtkObject
---> unsigned char Debug; // enable debug message
vtkTimeStamp MTime; // Keep track of modification time
int ReferenceCount; // Number of uses of this object by other objects, 引用本对象的对象数
vtkSubjectHelper * SubjectHelper;
其中:class vtkTimeStamp中包含了一个时间戳成员,标记变量被修改的时间:
unsigned long ModifiedTime;
vtk中经常用这个时间戳确定是否需要更新类。
---------------------------------------------------------------------------------------------------------------------------------
2. vtkAttributeData : public vtkObject //
成员:
--> vtkDataArray *Data; // Array which represents data
---------------------------------------------------------------------------------------------------------------------------------
3. vtkDataArray
---> int size, int maxID; // already allocated size of data, and max index
----> Extend; // grow array by this amount
----> int NumberOfComponents; // the number of components per tuple
virtual void GetTuple(const int i, double * tuple);
virtual void SetTuple(const int i, const double * tuple);
virtual void InsertTuple(const int i, const double * tuple);
virtual int InsertNextTuple(const double * tuple);
可以用 vtkDataArray 的子类存储不同类型的属性数据,比如
vtkFloatArray //
vtkIntArray // 类存储浮点型、整型数据
vtkIntArry *justArry=vtkIntArry::New();
justArry->SetNumberOfComponents(2); // 每个单元有两个成员
justArry->SetNumberOfTuples(100); // 分配100个单元 ,100*2 = 200数据
justArry->setTuple2(0,1,2); // 第0个数据
justArry->setTuple2(1,3,4); // 第1个数据
// 另外一个例子
vtkFloatArray *vector=vtkFloatArray::New();
vector->SetNumberOfComponents(3); //设置组元的大小 ,即每个单元3个数据
vector->insertTuple3(0, 1.0 ,2.0 ,3.0); // 插入第0个数据
vector->insertTuple3(1, 1.0, 4.0 ,5.0); // 插入第一个数据
//下面代码展示——标量属性数据和点数据对象关联
vtkPolyDataSet *polyData=vtkPolyDataSet::New();
......
polyData->GetPointData()->SetScalars(scalar);
//矢量属性数据和单元数据对象关联
polyData->GetCellData()->SetVectors(vector);
述代码将属性数据数组和数据对象关联。
【特别说明】当我们将属性数据数组和数据对象相关联时,要注意属性数据标注的是标量还是矢量,如果是标量使用方法 SetScalars()方法,如果是矢量使用 SetVectors()方法。
类似的,我们可以使用下述方法访问属性数据:
Scalars=polyData->GetPointData()->GetScalars(); //得到标量
Vectors=polyData->GetCellData()->GetVectors(); //得到矢量
在 VTK 中,许多过滤器只接收特定形式的属性数据作为输入,例如:vtkElevationFilter过滤器接收在指定方向上的高程值作为输入并且生成新的标量值
vtkPointDataToCellData 和 vtkCellDataToPointData 这两个类为我们提供了在不同的属性数据之间进行互相转换的方法(在点属性数据和单元属性数据之间相互转换)
---------------------------------------------------------------------------------------------------------------------------------
4.vtkPoints : public vtkAttributeData -----> 存储点集数据,一堆点!!!
成员:
----> float Bounds[6] ; //点集的边界
----> vtkTimeStamp ComputeTime; // Time at which bounds computed
方法:
intGetNumberOfPoints(){returnthis->Data->GetNumberOfTuples();};
float*GetPoint(intid){returnthis->Data->GetTuple(id);};
voidGetPoint(intid,floatx[3]){this->Data->GetTuple(id,x);};
voidGetPoint(intid,doublex[3]){this->Data->GetTuple(id,x);};
voidSetPoint(intid,constfloatx[3]){this->Data->SetTuple(id,x);};
voidSetPoint(intid,constdoublex[3]){this->Data->SetTuple(id,x);};
voidSetPoint(intid,doublex,doubley,doublez);
voidInsertPoint(intid,constfloatx[3]){this->Data->InsertTuple(id,x);};
voidInsertPoint(intid,constdoublex[3]){this->Data->InsertTuple(id,x);};
voidInsertPoint(intid,doublex,doubley,doublez);
intInsertNextPoint(constfloatx[3]){
returnthis->Data->InsertNextTuple(x);};
intInsertNextPoint(constdoublex[3]){
returnthis->Data->InsertNextTuple(x);};
intInsertNextPoint(doublex,doubley,doublez);
voidSetNumberOfPoints(intnumber);
voidGetPoints(vtkIdList*ptId,vtkPoints*fp);
virtualvoidComputeBounds();
float*GetBounds();
voidGetBounds(floatbounds[6]);
3.2.1 手动创建 vtkPolyData
有几种不同的方式来构造多边形数据,一般的情况下首先创建一个 vtkPoints 类型的对
象存储点,然后创建 vtkCellArrays 类型的对象存储单元,下面的示例程序用一个三角带创
建了一个 vtkPolyData,程序运行结果如下:
程序示例代码(Examp313):
VTK 用户手册
第 73 页
//定义定点
vtkPoints *points = vtkPoints::New();
points->InsertPoint(0, 0.0, 0.0, 0.0);
points->InsertPoint(1, 0.0, 1.0, 0.0);
points->InsertPoint(2, 1.0, 0.0, 0.0);
points->InsertPoint(3, 1.0, 1.0, 0.0);
points->InsertPoint(4, 2.0, 0.0, 0.0);
points->InsertPoint(5, 2.0, 1.0, 0.0);
points->InsertPoint(6, 3.0, 0.0, 0.0);
points->InsertPoint(7, 3.0, 1.0, 0.0);
//构建组成多边形数据的单元
vtkCellArray *strips = vtkCellArray::New();
//插入一个单元,该单元由 8 个顶点组成
strips->InsertNextCell(8);
strips->InsertCellPoint(0); //id of point!!!!!!!!!!!!!!!!!!!!!!!
strips->InsertCellPoint(1);
strips->InsertCellPoint(2);
strips->InsertCellPoint(3);
strips->InsertCellPoint(4);
strips->InsertCellPoint(5);
strips->InsertCellPoint(6);
strips->InsertCellPoint(7);
//构建多边形数据
vtkPolyData *profile = vtkPolyData::New();
//设定组成多边形数据的点
profile->SetPoints(points);
//设定单元的组成方式,三角条带
profile->SetStrips(strips);
//数据映射
vtkPolyDataMapper *map = vtkPolyDataMapper::New();
map->SetInput(profile);
//创建角色
vtkActor *strip = vtkActor::New();
strip->SetMapper(map);
下面给出一个创建立方体的例子,这次我们创建六个四边形并且用立方体顶点处的标量
值作为颜色映色绘制立方体,示例程序运行结果如下:
---------------------------------------------------------------------------------------------------------------------------------
5. vtkDataSet 类 -
vtkDataSet 是所有数据集类的父类,是一个抽象的不能实例化的类,,所有将 vtkDataSet 做为输入的过滤器也可以接收
vtkPolyData、
vtkImageData、
vtkStructuredGrid、
vtkRectilinearGri
和
vtkUnstructuredGrid 等类型做为输入。
--------------------------------------------------------------------------------------------------------------------------------------
5.vtkCell
vtkCell 是 VTK 中数据类型的基础,通常对图形数据的操作都是对单元的操作,如进行插值、坐标变换、坐标搜索、图形的几何变换等,从一个图形数据中提取单元可以用方法 GetCell(int cellID)来实现。
单元是由一种确定类型的一系列顶点组成的基本图元,具有二维(对于面)或三维(对于体)的维度,它是组成其他复杂图形的基础。