[e9c677] | 1 | /*
|
---|
| 2 | * tesselation_boundarytriangleunittest.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Jan 13, 2010
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | using namespace std;
|
---|
| 9 |
|
---|
| 10 | #include <cppunit/CompilerOutputter.h>
|
---|
| 11 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 12 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 13 |
|
---|
| 14 | #include <cstring>
|
---|
| 15 |
|
---|
| 16 | #include "defs.hpp"
|
---|
| 17 | #include "tesselation.hpp"
|
---|
| 18 | #include "tesselation_boundarytriangleunittest.hpp"
|
---|
| 19 |
|
---|
[9b6b2f] | 20 | #ifdef HAVE_TESTRUNNER
|
---|
| 21 | #include "UnitTestMain.hpp"
|
---|
| 22 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 23 |
|
---|
[e9c677] | 24 | #define SPHERERADIUS 2.
|
---|
| 25 |
|
---|
| 26 | /********************************************** Test classes **************************************/
|
---|
| 27 |
|
---|
| 28 | // Registers the fixture into the 'registry'
|
---|
| 29 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
|
---|
| 30 |
|
---|
| 31 |
|
---|
| 32 | void TesselationBoundaryTriangleTest::setUp()
|
---|
| 33 | {
|
---|
| 34 | setVerbosity(5);
|
---|
| 35 |
|
---|
| 36 | // create nodes
|
---|
| 37 | TesselPoint *Walker = NULL;
|
---|
| 38 | Walker = new TesselPoint;
|
---|
| 39 | Walker->node = new Vector(0., 0., 0.);
|
---|
| 40 | Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
|
---|
| 41 | strcpy(Walker->Name, "1");
|
---|
| 42 | Walker->nr = 1;
|
---|
| 43 | points[0] = new BoundaryPointSet(Walker);
|
---|
| 44 | Walker = new TesselPoint;
|
---|
| 45 | Walker->node = new Vector(0., 1., 0.);
|
---|
| 46 | Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
|
---|
| 47 | strcpy(Walker->Name, "2");
|
---|
| 48 | Walker->nr = 2;
|
---|
| 49 | points[1] = new BoundaryPointSet(Walker);
|
---|
| 50 | Walker = new TesselPoint;
|
---|
| 51 | Walker->node = new Vector(1., 0., 0.);
|
---|
| 52 | Walker->Name = Malloc<char>(3, "TesselationBoundaryTriangleTest::setUp - *Name");
|
---|
| 53 | strcpy(Walker->Name, "3");
|
---|
| 54 | Walker->nr = 3;
|
---|
| 55 | points[2] = new BoundaryPointSet(Walker);
|
---|
| 56 |
|
---|
| 57 | // create line
|
---|
| 58 | lines[0] = new BoundaryLineSet(points[0], points[1], 0);
|
---|
| 59 | lines[1] = new BoundaryLineSet(points[1], points[2], 1);
|
---|
| 60 | lines[2] = new BoundaryLineSet(points[0], points[2], 2);
|
---|
| 61 |
|
---|
| 62 | // create triangle
|
---|
| 63 | triangle = new BoundaryTriangleSet(lines, 0);
|
---|
| 64 | triangle->GetNormalVector(Vector(0.,0.,1.));
|
---|
| 65 | };
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | void TesselationBoundaryTriangleTest::tearDown()
|
---|
| 69 | {
|
---|
| 70 | delete(triangle);
|
---|
| 71 | MemoryUsageObserver::purgeInstance();
|
---|
| 72 | logger::purgeInstance();
|
---|
| 73 | errorLogger::purgeInstance();
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | /** UnitTest for Tesselation::IsInnerPoint()
|
---|
| 77 | */
|
---|
| 78 | void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
|
---|
| 79 | {
|
---|
| 80 | Vector TestIntersection;
|
---|
| 81 | Vector Point;
|
---|
| 82 |
|
---|
| 83 | // simple test on y line
|
---|
| 84 | Point.Init(-1.,0.5,0.);
|
---|
| 85 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 86 | Point.Init(0.,0.5,0.);
|
---|
| 87 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 88 | Point.Init(-4.,0.5,0.);
|
---|
| 89 | CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 90 | Point.Init(0.,0.5,0.);
|
---|
| 91 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 92 |
|
---|
| 93 | // simple test on x line
|
---|
| 94 | Point.Init(0.5,-1.,0.);
|
---|
| 95 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 96 | Point.Init(0.5,0.,0.);
|
---|
| 97 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 98 | Point.Init(0.5,-6.,0.);
|
---|
| 99 | CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 100 | Point.Init(0.5,0.,0.);
|
---|
| 101 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 102 |
|
---|
| 103 | // simple test on slanted line
|
---|
| 104 | Point.Init(1.,1.,0.);
|
---|
| 105 | CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 106 | Point.Init(0.5,0.5,0.);
|
---|
| 107 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 108 | Point.Init(5.,5.,0.);
|
---|
| 109 | CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 110 | Point.Init(0.5,0.5,0.);
|
---|
| 111 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 112 |
|
---|
| 113 | // simple test on first node
|
---|
| 114 | Point.Init(-1.,-1.,0.);
|
---|
| 115 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 116 | Point.Init(0.,0.,0.);
|
---|
| 117 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 118 |
|
---|
| 119 | // simple test on second node
|
---|
| 120 | Point.Init(0.,2.,0.);
|
---|
| 121 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 122 | Point.Init(0.,1.,0.);
|
---|
| 123 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 124 |
|
---|
| 125 | // simple test on third node
|
---|
| 126 | Point.Init(2.,0.,0.);
|
---|
| 127 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 128 | Point.Init(1.,0.,0.);
|
---|
| 129 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 130 | };
|
---|
| 131 |
|
---|
| 132 | /** UnitTest for Tesselation::IsInnerPoint()
|
---|
| 133 | */
|
---|
| 134 | void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
|
---|
| 135 | {
|
---|
| 136 | Vector TestIntersection;
|
---|
| 137 | Vector Point;
|
---|
| 138 |
|
---|
| 139 | // straight down/up
|
---|
| 140 | Point.Init(1./3.,1./3.,+5.);
|
---|
| 141 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 142 | Point.Init(1./3.,1./3.,0.);
|
---|
| 143 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 144 | Point.Init(1./3.,1./3.,-5.);
|
---|
| 145 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 146 | Point.Init(1./3.,1./3.,0.);
|
---|
| 147 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 148 |
|
---|
| 149 | // simple test on y line
|
---|
| 150 | Point.Init(-1.,0.5,+2.);
|
---|
| 151 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 152 | Point.Init(0.,0.5,0.);
|
---|
| 153 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 154 | Point.Init(-1.,0.5,-3.);
|
---|
| 155 | CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 156 | Point.Init(0.,0.5,0.);
|
---|
| 157 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 158 |
|
---|
| 159 | // simple test on x line
|
---|
| 160 | Point.Init(0.5,-1.,+1.);
|
---|
| 161 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 162 | Point.Init(0.5,0.,0.);
|
---|
| 163 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 164 | Point.Init(0.5,-1.,-2.);
|
---|
| 165 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 166 | Point.Init(0.5,0.,0.);
|
---|
| 167 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 168 |
|
---|
| 169 | // simple test on slanted line
|
---|
| 170 | Point.Init(1.,1.,+3.);
|
---|
| 171 | CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 172 | Point.Init(0.5,0.5,0.);
|
---|
| 173 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 174 | Point.Init(1.,1.,-4.);
|
---|
| 175 | CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 176 | Point.Init(0.5,0.5,0.);
|
---|
| 177 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 178 |
|
---|
| 179 | // simple test on first node
|
---|
| 180 | Point.Init(-1.,-1.,5.);
|
---|
| 181 | CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 182 | Point.Init(0.,0.,0.);
|
---|
| 183 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 184 |
|
---|
| 185 | // simple test on second node
|
---|
| 186 | Point.Init(0.,2.,5.);
|
---|
| 187 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 188 | Point.Init(0.,1.,0.);
|
---|
| 189 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 190 |
|
---|
| 191 | // simple test on third node
|
---|
| 192 | Point.Init(2.,0.,5.);
|
---|
| 193 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) );
|
---|
| 194 | Point.Init(1.,0.,0.);
|
---|
| 195 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
|
---|
| 196 | };
|
---|