[vtkusers] How to check input data is proper?

rakesh patil prakeshofficial at gmail.com
Wed Jan 4 01:10:09 EST 2012


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 *
*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120104/0e6c9ab7/attachment.htm>


More information about the vtkusers mailing list