[vtkusers] Traversing vtkPolyData returns incorrect number of points

David Edmunds David.Edmunds at icr.ac.uk
Thu May 26 09:07:40 EDT 2016


Hi Andrew and Dan,

Thanks very much for your help and the useful Python script.

I have now fixed the problem, it was related to a bug in the way I generate my vtkPolyData objects from my input data.

For future reference, my input data consists of a set of closed loops consisting of 3D points, stored in a vector<vector<double>>.
I now successfully convert this to vtkPolyData using the following two functions:

vtkSmartPointer<vtkPolyData> convertContourToPolyData(vector<double> c) {
  auto points = vtkSmartPointer<vtkPoints>::New();
  for (auto i = 0; i < c.size(); i += 3) {
    auto id = points->InsertNextPoint(c[i], c[i + 1], c[i + 2]);
  }

  auto poly_line = vtkSmartPointer<vtkPolyLine>::New();
  poly_line->GetPointIds()->SetNumberOfIds(points->GetNumberOfPoints());
  for (auto i = 0; i < points->GetNumberOfPoints(); i++) {
    poly_line->GetPointIds()->SetId(i, i);
  }

  auto cells = vtkSmartPointer<vtkCellArray>::New();
  cells->InsertNextCell(poly_line);

  auto poly_data = vtkSmartPointer<vtkPolyData>::New();
  poly_data->SetPoints(points);
  poly_data->SetLines(cells);

  return poly_data;
}

vtkSmartPointer<vtkPolyData> convertContoursToPolyData(vector<vector<double>> contours) {
  auto append_filter = vtkSmartPointer<vtkAppendPolyData>::New();

  for (auto c : contours) {
    append_filter->AddInputData(convertContourToPolyData(c));
  }
  append_filter->Update();

  return append_filter->GetOutput();
}

Kind regards,

Dave

On 26 May 2016, at 03:12, Andrew Maclean <andrew.amaclean at gmail.com<mailto:andrew.amaclean at gmail.com>> wrote:

Hi David and Dan,

I had a little look at the data using Dan's python script.

Line 29 needs to be changed from:
points.InsertPoint(currentPointId, d.GetPoint(pointIds[i]))
to:
points.InsertPoint(currentPointId, d.GetPoint(i))

When this is done, out.vtp has the points that are not associated with the cells in the original data in it.

Now, if you change line 28 to:
if pointIds[i] == 1 and i > 0:
This will select all points associated with the cells. The extra i > 0 condition is needed as point 0 in cell 0 lies way outside the boundary of all the other points for some reason, yet is associated with a cell. This one point has a value of: (0, 3.6e19, -5.2e27), whilst the dimensions of the polygonal mesh are:
X-range: -195 to 193 (delta: 389)
Y-range: -45.2 to 242 (delta: 287)
Z-range: -583 to 362 (delta: 945)

This is a nice little script Dan for filtering out points not associated with cells, I'll add it to my list of useful scripts, thanks.


Regards
   Andrew




---------- Forwarded message ----------
From: David Edmunds <David.Edmunds at icr.ac.uk<mailto:David.Edmunds at icr.ac.uk>>
To: Dan Lipsa <dan.lipsa at kitware.com<mailto:dan.lipsa at kitware.com>>
Cc: "vtkusers at vtk.org<mailto:vtkusers at vtk.org>" <vtkusers at vtk.org<mailto:vtkusers at vtk.org>>, David Edmunds <David.Edmunds at icr.ac.uk<mailto:David.Edmunds at icr.ac.uk>>
Date: Wed, 25 May 2016 14:51:14 +0100
Subject: Re: [vtkusers] Traversing vtkPolyData returns incorrect number of points
Hi,

Sorry for the late reply but I couldn’t send attachments to the mailing list. My input file can be found at http://www.filedropper.com/organbody.

Kind regards,

Dave

On 23 May 2016, at 18:20, Dan Lipsa <dan.lipsa at kitware.com<mailto:dan.lipsa at kitware.com>> wrote:

I see,
Well, in this case, you may have points that are not part of any cells. Can you share your data file?

On Mon, May 23, 2016 at 12:16 PM, David Edmunds <David.Edmunds at icr.ac.uk<mailto:David.Edmunds at icr.ac.uk>> wrote:
Hi Dan,

Thanks, but I actually get a much smaller number when I count all the points from cells. Also, in my input dataset the cells are disjoint, i.e. no points are shared between multiple cells.

Kind regards,

Dave

On 23 May 2016, at 16:51, Dan Lipsa <dan.lipsa at kitware.com<mailto:dan.lipsa at kitware.com>> wrote:

Hi David,
You have shared points between cells so it is normal you'll get a bigger number when you count all the points from cells.

On Mon, May 23, 2016 at 10:01 AM, David Edmunds <David.Edmunds at icr.ac.uk<mailto:David.Edmunds at icr.ac.uk>> wrote:
Dear all,

I am traversing a vtkPolyData object which is read in from a file using vtkXMLPolyDataReader. I access the number of points in the vtkPolyData in two different ways, here is my source code:

  vtkSmartPointer<vtkXMLPolyDataReader> reader = vtkSmartPointer<vtkXMLPolyDataReader>::New();
  reader->SetFileName("/Users/dedmunds/Desktop/organ_Body.vtp");
  reader->Update();
  vtkSmartPointer<vtkPolyData> poly_data = reader->GetOutput();

  cout << "Number of points: " << poly_data->GetNumberOfPoints() << endl;

  int traversal_points = 0;
  for (int i=0; i<poly_data->GetNumberOfCells(); i++) {
    traversal_points += poly_data->GetCell(i)->GetNumberOfPoints();
  }
  cout << "Traversal number of points: " << traversal_points << endl;

Here is the output:

Number of points: 286402
Traversal number of points: 143204

Why do I get two different answers? The second number is approximately half the first. What am I doing wrong?

Thanks for your help,

Kind regards,

Dave

The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only.  If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer and network.
_______________________________________________
Powered by www.kitware.com<http://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:
http://public.kitware.com/mailman/listinfo/vtkusers



The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer and network.



The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only. If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer and network.


The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP.

This e-mail message is confidential and for use by the addressee only.  If the message is received by anyone other than the addressee, please return the message to the sender by replying to it and then delete the message from your computer and network.
--
___________________________________________
Andrew J. P. Maclean

___________________________________________

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160526/6465cf91/attachment-0001.html>


More information about the vtkusers mailing list