vtkPointSource & vtkPoints

Hi,
I’m working on a tool to select points, using the rubberband interactor.

However, question is about basic vtk data types.

In the vtkRubberband select example, the data is generated like this

 vtkNew<vtkPointSource> pointSource;
 pointSource->SetNumberOfPoints(2000);
 pointSource->Update();

 vtkNew<vtkIdFilter> idFilter;
 idFilter->SetInputConnection(pointSource->GetOutputPort());
 idFilter->SetCellIdsArrayName("OriginalIds");
 idFilter->SetPointIdsArrayName("OriginalIds");
 idFilter->Update();

Our data is stored using vtkPoints.

What I’m struggling with is, how do I create the input to the IdFilter, starting from vtkPoints?

I found (one) answer from another post here: How to create a mesh data from vtkPoints? - #4 by Charles_Gueunet

  // vtk data set to fill
  vtkNew<vtkPolyData> myPolyData;

   // compute a vtkIdList that contains ids of each points 
 vtkIdType numPoints = points->GetNumberOfPoints();  
 vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
 pointIds->SetNumberOfIds(numPoints);
 for (vtkIdType i = 0; i < numPoints; ++i)
 {
    pointIds->SetId(i, i);
 }

   // create a vtkCellArray from this list
  vtkSmartPointer<vtkCellArray> polyPoint = vtkSmartPointer<vtkCellArray>::New();
  polyPoint->InsertNextCell(pointIds);
 
   // give the points and cells to the final poly data
  myPolyData->SetPoints(points);
  myPolyData->SetVerts(polyPoint);

So, the points are used to construct the cell(s). It seems all points are “within” one cell. But not sure if that is proper semantics.

I believe I read somewhere that in order to render any data, the data need to be in “cells”.

I guess this small example goes to the core of how primitive data is represented in vtk, in order to be visualized, so, time to read the manual(!)

1 Like

Hello,

Please:

  1. Post the link to the original post as additional info there may benefit others;

  2. Enclose the code between two ``` to have it appropriately formatted by the markdown engine;

  3. Mark the solution as solution so others with the same problem as yours promptly find the answer to their needs.

thanks,

PC

2 Likes

Thanks Paulo, I cleaned up the question/answer.

1 Like

@totte_karlsson glad you found this answer. I would like to complete a bit, because since then VTK has evolved.
If memory is important to you, it is now possible to instantiate a vtkPointSet instead of a vtkPolyData, see the related discussion here

1 Like