如何读取 vtkDataArray 中的数据?
How to read data in vtkDataArray?
我是 VTK 的新手。
这是我的代码的一部分:
vtkDataSetReader *rdr = vtkDataSetReader::New();
rdr->SetFileName("proj7b.vtk");
rdr->SetScalarsName("hardyglobal");
rdr->Update();
int dims[3];
vtkRectilinearGrid *rgrid = (vtkRectilinearGrid *) rdr->GetOutput();
rgrid->GetDimensions(dims);
vtkDataArray *dataArray;
dataArray = vtkDoubleArray::New();
dataArray = rgrid->GetPointData()->GetScalars()->GetVoidPointer(0);
for(i=0;i<10;i++)
{
cout<<"here----------"<<endl;
cout<<" "<<dataArray[i]<<" ";
}
我想将数据读入我的 vtkDataArray。但是这段代码无法编译:
proj7b.cxx:525:15: error:
assigning to 'vtkDataArray *' from incompatible type 'void *'
dataArray = rgrid->GetPointData()->GetScalars()->GetVoidPointer(0);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
产生了 1 个错误。
有没有人知道如何将数据读入 vtkDataArray?
Vtk为其提供了方法,你不需要使用"low level"方法:
rgrid->GetPointData()->GetArray(0)
或
rgrid->GetPointData()->GetArray("arrayname")
FieldData 和 CellData 的工作方式相同 (http://www.vtk.org/doc/release/6.2/html/classvtkFieldData.html)
你得到的是一个 vtkArray,而不是一个简单的 c++ 数组,所以你必须像这样阅读它:
cout<<" "<<dataArray->GetValue(i) <<" ";
wiki里有很多例子http://www.vtk.org/Wiki/VTK/Examples/Cxx
请查看此页面:https://cloud.tencent.com/developer/ask/sof/148655
void doSomething(vtkSmartPointer<vtkDataArray> dataArray) { vtkIdType numTuples = dataArray->GetNumberOfTuples(); for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx)
{
double* tuple = dataArray->GetTuple(tupleIdx);
for (int j = 0; j < ¿¿¿???; ++j}
double var = tuple[j];
//Do something with var
//Carefull don't go out of bounds
} }
我是 VTK 的新手。 这是我的代码的一部分:
vtkDataSetReader *rdr = vtkDataSetReader::New();
rdr->SetFileName("proj7b.vtk");
rdr->SetScalarsName("hardyglobal");
rdr->Update();
int dims[3];
vtkRectilinearGrid *rgrid = (vtkRectilinearGrid *) rdr->GetOutput();
rgrid->GetDimensions(dims);
vtkDataArray *dataArray;
dataArray = vtkDoubleArray::New();
dataArray = rgrid->GetPointData()->GetScalars()->GetVoidPointer(0);
for(i=0;i<10;i++)
{
cout<<"here----------"<<endl;
cout<<" "<<dataArray[i]<<" ";
}
我想将数据读入我的 vtkDataArray。但是这段代码无法编译:
proj7b.cxx:525:15: error:
assigning to 'vtkDataArray *' from incompatible type 'void *'
dataArray = rgrid->GetPointData()->GetScalars()->GetVoidPointer(0);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
产生了 1 个错误。 有没有人知道如何将数据读入 vtkDataArray?
Vtk为其提供了方法,你不需要使用"low level"方法:
rgrid->GetPointData()->GetArray(0)
或 rgrid->GetPointData()->GetArray("arrayname")
FieldData 和 CellData 的工作方式相同 (http://www.vtk.org/doc/release/6.2/html/classvtkFieldData.html)
你得到的是一个 vtkArray,而不是一个简单的 c++ 数组,所以你必须像这样阅读它:
cout<<" "<<dataArray->GetValue(i) <<" ";
wiki里有很多例子http://www.vtk.org/Wiki/VTK/Examples/Cxx
请查看此页面:https://cloud.tencent.com/developer/ask/sof/148655
void doSomething(vtkSmartPointer<vtkDataArray> dataArray) { vtkIdType numTuples = dataArray->GetNumberOfTuples(); for (vtkIdType tupleIdx = 0; tupleIdx < numTuples; ++tupleIdx)
{
double* tuple = dataArray->GetTuple(tupleIdx);
for (int j = 0; j < ¿¿¿???; ++j}
double var = tuple[j];
//Do something with var
//Carefull don't go out of bounds
} }