1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: TestTriangle.cxx,v $
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.
=========================================================================*/
// .NAME
// .SECTION Description
// this program tests the Triangle
#include "vtkTriangle.h"
int TestTriangle(int,char *[])
{
// three vertices making a triangle
double pnt0[3] = { 0, 2, 0 };
double pnt1[3] = { 4, 2, 0 };
double pnt2[3] = { 0, 6, 0 };
// points to be tested against the triangle
double pnts[][3] = {
// squared error tolerance
// = 0.0001 * 0.0001 = 0.00000001
// outside the triangle
{ 0, 1.999, 0 },
{ -0.001, 2, 0 },
{ 4, 1.999, 0 },
{ 4, 2.001, 0 },
{ 4.001, 2, 0 },
{ 0, 6.001, 0 },
{ 0.001, 6, 0 },
{ -0.001, 6, 0 },
{ -0.001, 2.001, 0 },
{ -0.001, 1.999, 0 },
{ 0.001, 1.999, 0 },
{ 4.001, 2.001, 0 },
{ 4.001, 1.999, 0 },
{ 3.999, 1.999, 0 },
{ -0.001, 5.999, 0 },
{ -0.001, 6.001, 0 },
{ 0.001, 6.001, 0 },
// inside the triangle
{ 0, 2.001, 0 },
{ 0.001, 2, 0 },
{ 0.001, 2.001, 0 },
{ 3.999, 2.001, 0 },
{ 3.999, 2, 0 },
{ 0, 5.999, 0 },
{ 0.001, 5.999, 0 },
{ 0, 2, 0 },
{ 4, 2, 0 },
{ 0, 6, 0 },
{ 2, 2, 0 },
{ 2, 4, 0 },
{ 0, 4, 0 },
{ 1.333, 3.333, 0 }
};
int inside;
for ( int i = 0; i < 31; i ++ )
{
inside = vtkTriangle::PointInTriangle( pnts[i], pnt0, pnt1, pnt2, 0.00000001 );
if ( inside && i < 17 )
{
cerr << "ERROR: point #" << i << ", an outside-point, considered to be inside the triangle!!!" << endl;
cerr << "Squared error tolerance: 0.00000001" << endl;
return 1;
}
else
if ( !inside && i > 16 )
{
cerr << "ERROR: point #" << i << ", an inside-point, considered to be outside the triangle!!!" << endl;
cerr << "Squared error tolerance: 0.00000001" << endl;
return 1;
}
}
cout << "Passed: 17 points outside and 14 points inside the triangle." << endl;
return 0;
}
|