[vtkusers] Extract csv row and column into points

Cory Quammen cory.quammen at kitware.com
Fri Nov 9 09:07:52 EST 2018


vtkDelimitedTextReader -> vtkTableToPolyData is a pipeline that should make
this much simpler.

On Fri, Nov 9, 2018 at 1:14 AM Polly Pui <polly_sukting at hotmail.com> wrote:

> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>


-- 
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20181109/0d535561/attachment.html>


More information about the vtkusers mailing list