VTK/Tutorials/VtkIdType: Difference between revisions

From KitwarePublic
< VTK‎ | Tutorials
Jump to navigationJump to search
(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(); ...)
 
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
Here is an example:
Here is an example:
<source lang="cpp">
<source lang="cpp">
  vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
   
   
  for ( unsigned int i = 0; i < Polydata->GetNumberOfPoints(); ++i )
for ( unsigned int i = 0; i < polydata->GetNumberOfPoints(); ++i )
   {  
   {  
    Vertices->InsertNextCell(1,i);
  vertices->InsertNextCell(1,i);
   }
   }
</source>
</source>
Line 18: Line 18:
To fix this, you need to put the value into a vtkIdType object, as follows:
To fix this, you need to put the value into a vtkIdType object, as follows:
<source lang="cpp">
<source lang="cpp">
  vtkSmartPointer<vtkCellArray> Vertices = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkCellArray> vertices = vtkSmartPointer<vtkCellArray>::New();
   
   
  for ( unsigned int i = 0; i < Polydata->GetNumberOfPoints(); ++i )
for ( unsigned int i = 0; i < polydata->GetNumberOfPoints(); ++i )
   {  
   {  
    vtkIdType id[1];
  vtkIdType id[1];
    id[0] = i;
  id[0] = i;
   
  vertices->InsertNextCell(1,id);
    Vertices->InsertNextCell(1,id);
   }
   }
</source>
</source>

Latest revision as of 16:03, 22 January 2010

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>