VTK/Tutorials/VtkIdType

From KitwarePublic
< VTK‎ | Tutorials
Revision as of 15:20, 20 October 2009 by Daviddoria (talk | contribs) (New page: Confused why you can't use ints or unsigned ints in some places? Here is an example: <source lang="cpp"> vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New(); ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Confused why you can't use ints or unsigned ints in some places?

Here is an example: <source lang="cpp">

 vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();

 for ( unsigned int i = 0; i < Polydata->GetNumberOfPoints(); ++i )
 { 
   Vertices->InsertNextCell(1,i);
 }

</source>

The error generated is: <source lang="text"> error: invalid conversion from 'unsigned int' to 'const vtkIdType*' </source>

To fix this, you need to put the value into a vtkIdType object, as follows: <source lang="cpp">

 vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();

 for ( unsigned int i = 0; i < Polydata->GetNumberOfPoints(); ++i )
 { 
   vtkIdType id[1];
   id[0] = i;
   
   Vertices->InsertNextCell(1,id);
 }

</source>