vtkFloatArray 继承了vtkDataArray
vtkDataArray存放了连续元素,每components个连续元素组成一个tuple
?
vtkFloatArray可以作为vtkPoints的内部实际存放数据的载体
#include <vtkSmartPointer.h>
#include <vtkPoints.h>
#include <vtkFloatArray.h>
#include <vtkNew.h>
#include <iostream>
int main(int argc, char* argv[])
{
vtkNew<vtkFloatArray> pcoords;
// 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 (int i = 0; i < 4; i++)
{
pcoords->SetTuple(i, pts[i]);
}
// Create vtkPoints and assign pcoords as the internal data array.
vtkNew<vtkPoints> points;
points->SetData(pcoords);
for (int i = 0; i < points->GetNumberOfPoints(); i++)
{
auto p = points->GetPoint(i);
std::cout<<"point["<<i<<"]= ("
<< p[0] << ", "
<< p[1] << ", "
<< p[2] << ")"
<<std::endl;
}
return EXIT_SUCCESS;
}
point[0]= (0, 0, 0)
point[1]= (0, 1, 0)
point[2]= (1, 0, 0)
point[3]= (1, 1, 0)
参考:vtkDoubleArray(vtkFloatArray) vtkIntArray使用_leemengfei的博客-CSDN博客
|