Skip to content
Snippets Groups Projects
Commit 9aa2546e authored by Cory Quammen's avatar Cory Quammen Committed by Kitware Robot
Browse files

Merge topic 'FixFindTriangle'


9aa13b4c Modify the CMakeLists
3c4ad8f2 Add a test for FindTriangle
26fc6af6 Fix occasional failure of testing if a point is in or out of a triangle

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Reviewed-by: Cory Quammen's avatarCory Quammen <cory.quammen@kitware.com>
Merge-request: !762
parents 190d119d 9aa13b4c
Branches
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests
TestDecimatePolylineFilter.cxx
TestDecimatePro.cxx,NO_VALID
TestDelaunay2D.cxx
TestDelaunay2DFindTriangle.cxx,NO_VALID
TestDelaunay3D.cxx,NO_VALID
TestExecutionTimer.cxx,NO_VALID
TestFeatureEdges.cxx,NO_VALID
......
/*=========================================================================
Program: Visualization Toolkit
Module: TestDelaunay2D_FindTriangle.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkDelaunay2D.h"
#include "vtkCellArray.h"
int TestDelaunay2DFindTriangle( int vtkNotUsed(argc), char* vtkNotUsed(argv)[] )
{
vtkPoints *newPts = vtkPoints::New();
newPts->InsertNextPoint(0.650665, -0.325333, 0);
newPts->InsertNextPoint(-0.325333, 0.650665, 0);
newPts->InsertNextPoint(-0.325333, -0.325333, 0);
newPts->InsertNextPoint(0.283966, 0.0265961, 0);
newPts->InsertNextPoint(0.373199, -0.0478668, 0);
newPts->InsertNextPoint(-0.325333, 0.535065, 0);
vtkCellArray* cells = vtkCellArray::New();
vtkIdType pts[2];
pts[0] = 3;
pts[1] = 4;
cells->InsertNextCell(2, pts);
pts[0] = 5;
pts[1] = 3;
cells->InsertNextCell(2, pts);
pts[0] = 5;
pts[1] = 1;
cells->InsertNextCell(2, pts);
pts[0] = 1;
pts[1] = 4;
cells->InsertNextCell(2, pts);
pts[0] = 4;
pts[1] = 0;
cells->InsertNextCell(2, pts);
pts[0] = 0;
pts[1] = 2;
cells->InsertNextCell(2, pts);
pts[0] = 2;
pts[1] = 5;
cells->InsertNextCell(2, pts);
vtkPolyData *poly = vtkPolyData::New();
poly->SetPoints(newPts);
poly->SetLines(cells);
newPts->Delete();
cells->Delete();
vtkDelaunay2D *del2D = vtkDelaunay2D::New();
del2D->SetInputData(poly);
del2D->SetSourceData(poly);
del2D->SetTolerance(0.0);
del2D->SetAlpha(0.0);
del2D->SetOffset(10);
del2D->BoundingTriangulationOff();
poly->Delete();
del2D->Update();
vtkPolyData *out = del2D->GetOutput();
vtkIdType numFaces = out->GetNumberOfCells();
if (numFaces!=5)
{
del2D->Delete();
return EXIT_FAILURE;
}
int expected[5][3] = {{4,2,0},{4,3,2},{5,3,1},{4,1,3},{5,3,2}};
int face[3] = {0,0,0};
for (int i=0; i<numFaces; ++i)
{
vtkCell* cell = out->GetCell(i);
face[0] = cell->GetPointId(0);
face[1] = cell->GetPointId(1);
face[2] = cell->GetPointId(2);
if (face[0]!=expected[i][0] || face[1]!=expected[i][1] || face[2]!=expected[i][2])
{
del2D->Delete();
return EXIT_FAILURE;
}
}
del2D->Delete();
return EXIT_SUCCESS;
}
\ No newline at end of file
......@@ -134,7 +134,7 @@ vtkIdType vtkDelaunay2D::FindTriangle(double x[3], vtkIdType ptIds[3],
srand(tri);
ir = rand() % 3;
// evaluate in/out of each edge
for (inside=1, minProj=0.0, ic=0; ic<3; ic++)
for (inside=1, minProj=VTK_DEL2D_TOLERANCE, ic=0; ic<3; ic++)
{
i = (ir+ic) % 3;
i2 = (i+1) % 3;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment