[vtk-developers] Handling invalid vtp files

Berk Geveci berk.geveci at kitware.com
Sun Feb 14 13:56:30 EST 2010


> Here is the type of check I was thinking of:
>
>   for(vtkIdType cellId = 0; cellId < numCells; cellId++)
>     {
>     vtkSmartPointer<vtkIdList> pointList =
>         vtkSmartPointer<vtkIdList>::New();
>     data->GetCellPoints(cellId, pointList);
>
>     for(vtkIdType p = 0; p < pointList->GetNumberOfIds(); p++)
>       {
>       vtkIdType id = pointList->GetId(p);
>       if(id < 0 || id >= numPoints)
>         {
>         cout << "The data contains a cell which is defined on invalid
> geometry!" << endl;
>         cout << "In particular, cell " << cellId << " tries to reference
> point " << id <<
>             ", but there are only " << numPoints << " points." << endl;
>         return EXIT_FAILURE;
>         }
>       }
>     }
>

This is too inefficient. You should directly walk over the cell connectivity
arrays (Verts, Lines, Polys, Strips) and check the point ids there.


> In vtkXMLReader::RequestData, we have a vtkDataObject, so I guess we would
> just cast it to a vtkDataSet and if the cast passes then we could use the
> above function?
>

You can't always cast to vtkDataSet. vtkXMLReaders can produce other types.
I would add a pure virtual method to vtkDataObject called something like
SanityCheck() or VerifyXXX() and implement it in subclasses. vtkDataSet
would also call CheckAttributes() in this function. Then in vtkXMLReader,
you can have something like

if (this->VerifyOutput && !this->SanityCheck())
   {
   vtkErrorMacro
   return empty output
   }

I would have this flag set to off by default in the class but to on in
ParaView.

-berk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20100214/846fdb75/attachment.html>


More information about the vtk-developers mailing list