[vtkusers] How to check input data is proper?

Bryn Lloyd lloyd at itis.ethz.ch
Wed Jan 4 09:13:24 EST 2012


Hi

I would suggest to set the locator for you dataset.

By default the locator is a vtkMergePoints locator, which might not be 
setup to work well for large data.
To check if this is the case, you could call Print(cout) on the locator 
after running the clean filter.

If the parameters (Divisions) are the same, then it is not trying to 
compute good parameters for the dataset.
The number of divisions controls how many bins there are to put the 
points in each dimenions.
In my experience you will get good performance if you have around 120 
points per bin. You can try to set the divisions based on the bounding 
box of your dataset.

If your data is not sampled very evenly spaced you might want to use an 
octree point locator:
http://www.vtk.org/doc/nightly/html/classvtkIncrementalOctreePointLocator.html

e.g. something like this:

loc = vtkIncrementalOctreePointLocator::New();
loc->SetMaxPointsPerLeaf 
<classvtkIncrementalOctreePointLocator.html#acba69b2b6f98df7dd733bcea37e2b953>(128);
loc->BuildLocator();
clean->SetLocator(loc);



On 1/4/2012 7:10 AM, rakesh patil wrote:
> Hello,
>
> I am facing problem in triangulation for few datasets. I have VTK 
> compiled for 64-bit machine and some datasets get triangulated and 
> some do not. I went through the doxygen help for vtkDelaunay2D which 
> says that
>
> *The Delaunay triangulation can be numerically sensitive in some 
> cases. To prevent problems, try to avoid injecting points that will 
> result in triangles with bad aspect ratios (1000:1 or greater). In 
> practice this means inserting points that are "widely dispersed", and 
> enables smooth transition of triangle sizes throughout the mesh. (You 
> may even want to add extra points to create a better point 
> distribution.) If numerical problems are present, you will see a 
> warning message to this effect at the end of the triangulation process.
>
> *Now how can I verify or make sure that there are no numerical 
> problems in the input dataset? I am reading input dataset from a file. 
> Is there any direct or indirect way to remove such problems if they 
> exists?
>
> At very first point I thought of vtkCleanPolyData filter to use. But 
> this takes very long time for large data. If this is the only way to 
> remove numerical problems, then can vtkCleanPolyData filter be made to 
> execute faster?
>
> Please suggest me something. Below is the code I am using
>
> #include <iostream>
> #include <vtkPoints.h>
> #include <vtkDoubleArray.h>
> #include <vtkPointData.h>
> #include <vtkPolyData.h>
> #include <vtkDelaunay2D.h>
> #include <vtkCellArray.h>
> #include <vtkSmartPointer.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkRenderWindow.h>
> #include <vtkCleanPolyData.h>
>
> int main()
> {
>     vtkPoints *points = vtkPoints::New();
>     vtkDoubleArray *scalarArray = vtkDoubleArray::New();
>     vtkCellArray *polyVertex = vtkCellArray::New();
>
>     std::string filename="carto-gebco.pts";
>
>     FILE *fp = fopen(filename.c_str(), "r");
>     if(!fp){
>         std::cout << "Unable to open file" << std::endl;
>         return -1 ;
>     }
>
>     char buffer[256];
>     char str[256];
>     double xval, yval, zval;
>     vtkIdType i = 0;
>
>     while(fgets(buffer, 256, fp)) //return false;
>     {
>         str[0]='\0';
>         sscanf(buffer, "%lf%lf%lf", &xval, &yval, &zval);
>
>         points->InsertPoint(i, xval,
>             yval,0);
>         scalarArray->InsertTuple1(i, zval);
>         polyVertex->InsertNextCell(1, &i);
>
>         i++;
>     }
>     std::cout << "Completed reading input data" << std::endl;
>     points->Modified();
>     scalarArray->Modified();
>     polyVertex->Modified();
>
>     vtkPolyData *pd = vtkPolyData::New();
>     pd->SetPoints(points);
>     pd->GetPointData()->SetScalars(scalarArray);
>     pd->SetVerts(polyVertex);
>
>     points->Delete();
>     scalarArray->Delete();
>     polyVertex->Delete();
>
>     std::cout << "Checking duplicate points" << std::endl;
>     vtkSmartPointer<vtkCleanPolyData> cpd = 
> vtkSmartPointer<vtkCleanPolyData>::New();
>     cpd->SetInput(pd);
>     pd->Delete();
>     cpd->SetTolerance(0.00001);
>     cpd->Update();
>
>     std::cout << "Triangulating data" << std::endl;
>     vtkDelaunay2D *del = vtkDelaunay2D::New();
>     del->SetInputConnection(cpd->GetOutputPort());
>     del->SetTolerance(0.00001);
>     del->Update();
>
>     std::cout << "Completed triangulation" << std::endl;
>     vtkSmartPointer<vtkPolyDataMapper> triangulatedMapper =
>     vtkSmartPointer<vtkPolyDataMapper>::New();
>   triangulatedMapper->SetInputConnection(del->GetOutputPort());
>   del->Delete();
>   vtkSmartPointer<vtkActor> triangulatedActor =
>     vtkSmartPointer<vtkActor>::New();
>   triangulatedActor->SetMapper(triangulatedMapper);
>
>   // Create a renderer, render window, and interactor
>   vtkSmartPointer<vtkRenderer> renderer =
>     vtkSmartPointer<vtkRenderer>::New();
>   vtkSmartPointer<vtkRenderWindow> renderWindow =
>     vtkSmartPointer<vtkRenderWindow>::New();
>   renderWindow->AddRenderer(renderer);
>   vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
>     vtkSmartPointer<vtkRenderWindowInteractor>::New();
>   renderWindowInteractor->SetRenderWindow(renderWindow);
>
>   // Add the actor to the scene
>   renderer->AddActor(triangulatedActor);
>  // renderer->AddActor(triangulatedActor);
>   renderer->SetBackground(.3, .6, .3); // Background color green
>
>   // Render and interact
>   renderWindow->Render();
>   renderWindowInteractor->Start();
>
>     fclose(fp);
>
>     return 0;
> }
>
> Here is a sample input data
>
> http://www.fileflyer.com/view/dkhbrBR
>
> Thanks
>
> Regards
> Rakesh Patil *
> *
>
>
> _______________________________________________
> Powered by 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120104/ddd39c0e/attachment.htm>


More information about the vtkusers mailing list