[vtkusers] Extract csv row and column into points

Polly Pui polly_sukting at hotmail.com
Fri Nov 9 01:13:58 EST 2018


Hi,
Is there any clue that i can extract the row and column data from a csv file and read them as points?
Currently I am using vtkpoints to read points by inserting points manually to my .cpp .
Is it possible for me to call the csv directly and read the data (eg. column 3-5, row 2-10)?

I attach my code here.
......
int main(int, char*[])
{

vtkSmartPointer<vtkPoints> points =
 vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(8.4312, -36.489, -1500.7);
points->InsertNextPoint(8.8408, -37.726, -1500.4);
points->InsertNextPoint(11.372, -37.787, -1501.5);
points->InsertNextPoint(11.263, -36.384, -1501.9);
points->InsertNextPoint(9.3914, -40.819, -1500.8);
points->InsertNextPoint(11.685, -42.482, -1502.7);
points->InsertNextPoint(14.235, -38.096, -1503.5);
points->InsertNextPoint(13.972, -43.051, -1504.2);
points->InsertNextPoint(9.22, -43.904, -1504);

vtkSmartPointer<vtkTable> inputData =
 vtkSmartPointer<vtkTable>::New();
for (int c = 0; c < 3; ++c)
{
 std::stringstream colName;
 colName << "coord " << c;
 vtkSmartPointer<vtkDoubleArray> doubleArray =
  vtkSmartPointer<vtkDoubleArray>::New();
 doubleArray->SetNumberOfComponents(1);
 doubleArray->SetName(colName.str().c_str());
 doubleArray->SetNumberOfTuples(points->GetNumberOfPoints());

 for (int r = 0; r < points->GetNumberOfPoints(); ++r)
 {
  double p[3];
  points->GetPoint(r, p);
  doubleArray->SetValue(r, p[c]);
 }
 inputData->AddColumn(doubleArray);
}

Thank you very much.

Regards,
Polly
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181109/74f75317/attachment.html>


More information about the vtkusers mailing list