上篇文章(VTK----VTK数据结构详解(计算机篇)-CSDN博客)从计算机数据结构(数组、链表等)的角度对数据数组、数据对象、数据属性的实现原理进行了说明,下面从代码的层面详细说明它们的使用及相关实现逻辑。
1 数据数组
以vtkFloatArray为例,下面是它的使用及其VTK内部实现的代码:
vtkNew<vtkFloatArray> scalars;
scalars->InsertTuple1(0, 1);
void vtkDataArray::InsertTuple1(vtkIdType i, double value)
{
int numComp = this->GetNumberOfComponents();
if (numComp != 1)
{
vtkErrorMacro(
"The number of components do not match the number requested: " << numComp << " != 1");
}
this->InsertTuple(i, &value);
}
template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>::InsertTupl