| [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 | 
|---|
| [5c8592] | 37 | tesselpoints[0] = new TesselPoint; | 
|---|
|  | 38 | tesselpoints[0]->node = new Vector(0., 0., 0.); | 
|---|
| [68f03d] | 39 | tesselpoints[0]->setName("1"); | 
|---|
| [5c8592] | 40 | tesselpoints[0]->nr = 1; | 
|---|
|  | 41 | points[0] = new BoundaryPointSet(tesselpoints[0]); | 
|---|
|  | 42 | tesselpoints[1] = new TesselPoint; | 
|---|
|  | 43 | tesselpoints[1]->node = new Vector(0., 1., 0.); | 
|---|
| [68f03d] | 44 | tesselpoints[1]->setName("2"); | 
|---|
| [5c8592] | 45 | tesselpoints[1]->nr = 2; | 
|---|
|  | 46 | points[1] = new BoundaryPointSet(tesselpoints[1]); | 
|---|
|  | 47 | tesselpoints[2] = new TesselPoint; | 
|---|
| [68f03d] | 48 | tesselpoints[2]->node = new Vector(1., 0., 0.); | 
|---|
|  | 49 | tesselpoints[2]->setName("3"); | 
|---|
|  | 50 | tesselpoints[2]->nr = 3; | 
|---|
| [5c8592] | 51 | points[2] = new BoundaryPointSet(tesselpoints[2] ); | 
|---|
| [e9c677] | 52 |  | 
|---|
|  | 53 | // create line | 
|---|
|  | 54 | lines[0] = new BoundaryLineSet(points[0], points[1], 0); | 
|---|
|  | 55 | lines[1] = new BoundaryLineSet(points[1], points[2], 1); | 
|---|
|  | 56 | lines[2] = new BoundaryLineSet(points[0], points[2], 2); | 
|---|
|  | 57 |  | 
|---|
|  | 58 | // create triangle | 
|---|
|  | 59 | triangle = new BoundaryTriangleSet(lines, 0); | 
|---|
|  | 60 | triangle->GetNormalVector(Vector(0.,0.,1.)); | 
|---|
|  | 61 | }; | 
|---|
|  | 62 |  | 
|---|
|  | 63 |  | 
|---|
|  | 64 | void TesselationBoundaryTriangleTest::tearDown() | 
|---|
|  | 65 | { | 
|---|
|  | 66 | delete(triangle); | 
|---|
| [5c8592] | 67 | for (int i=0;i<3;++i) { | 
|---|
|  | 68 | // TesselPoint does not delete its vector as it only got a reference | 
|---|
|  | 69 | delete tesselpoints[i]->node; | 
|---|
|  | 70 | delete tesselpoints[i]; | 
|---|
|  | 71 | } | 
|---|
| [e9c677] | 72 | MemoryUsageObserver::purgeInstance(); | 
|---|
|  | 73 | logger::purgeInstance(); | 
|---|
|  | 74 | errorLogger::purgeInstance(); | 
|---|
|  | 75 | }; | 
|---|
|  | 76 |  | 
|---|
|  | 77 | /** UnitTest for Tesselation::IsInnerPoint() | 
|---|
|  | 78 | */ | 
|---|
|  | 79 | void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest() | 
|---|
|  | 80 | { | 
|---|
|  | 81 | Vector TestIntersection; | 
|---|
|  | 82 | Vector Point; | 
|---|
|  | 83 |  | 
|---|
|  | 84 | // simple test on y line | 
|---|
| [1bd79e] | 85 | Point = Vector(-1.,0.5,0.); | 
|---|
| [e9c677] | 86 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 87 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 88 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 89 | Point = Vector(-4.,0.5,0.); | 
|---|
| [e9c677] | 90 | CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 91 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 92 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 93 |  | 
|---|
|  | 94 | // simple test on x line | 
|---|
| [1bd79e] | 95 | Point = Vector(0.5,-1.,0.); | 
|---|
| [e9c677] | 96 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 97 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 98 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 99 | Point = Vector(0.5,-6.,0.); | 
|---|
| [e9c677] | 100 | CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 101 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 102 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 103 |  | 
|---|
|  | 104 | // simple test on slanted line | 
|---|
| [1bd79e] | 105 | Point = Vector(1.,1.,0.); | 
|---|
| [e9c677] | 106 | CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 107 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 108 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 109 | Point = Vector(5.,5.,0.); | 
|---|
| [e9c677] | 110 | CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 111 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 112 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 113 |  | 
|---|
|  | 114 | // simple test on first node | 
|---|
| [1bd79e] | 115 | Point = Vector(-1.,-1.,0.); | 
|---|
| [e9c677] | 116 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 117 | Point = Vector(0.,0.,0.); | 
|---|
| [e9c677] | 118 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 119 |  | 
|---|
|  | 120 | // simple test on second node | 
|---|
| [1bd79e] | 121 | Point = Vector(0.,2.,0.); | 
|---|
| [e9c677] | 122 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 123 | Point = Vector(0.,1.,0.); | 
|---|
| [e9c677] | 124 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 125 |  | 
|---|
|  | 126 | // simple test on third node | 
|---|
| [1bd79e] | 127 | Point = Vector(2.,0.,0.); | 
|---|
| [e9c677] | 128 | CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 129 | Point = Vector(1.,0.,0.); | 
|---|
| [e9c677] | 130 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 131 | }; | 
|---|
|  | 132 |  | 
|---|
|  | 133 | /** UnitTest for Tesselation::IsInnerPoint() | 
|---|
|  | 134 | */ | 
|---|
|  | 135 | void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest() | 
|---|
|  | 136 | { | 
|---|
|  | 137 | Vector TestIntersection; | 
|---|
|  | 138 | Vector Point; | 
|---|
|  | 139 |  | 
|---|
|  | 140 | // straight down/up | 
|---|
| [1bd79e] | 141 | Point = Vector(1./3.,1./3.,+5.); | 
|---|
| [e9c677] | 142 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 143 | Point = Vector(1./3.,1./3.,0.); | 
|---|
| [e9c677] | 144 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 145 | Point = Vector(1./3.,1./3.,-5.); | 
|---|
| [e9c677] | 146 | CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 147 | Point = Vector(1./3.,1./3.,0.); | 
|---|
| [e9c677] | 148 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 149 |  | 
|---|
|  | 150 | // simple test on y line | 
|---|
| [1bd79e] | 151 | Point = Vector(-1.,0.5,+2.); | 
|---|
| [e9c677] | 152 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 153 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 154 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 155 | Point = Vector(-1.,0.5,-3.); | 
|---|
| [e9c677] | 156 | CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 157 | Point = Vector(0.,0.5,0.); | 
|---|
| [e9c677] | 158 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 159 |  | 
|---|
|  | 160 | // simple test on x line | 
|---|
| [1bd79e] | 161 | Point = Vector(0.5,-1.,+1.); | 
|---|
| [e9c677] | 162 | CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 163 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 164 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 165 | Point = Vector(0.5,-1.,-2.); | 
|---|
| [e9c677] | 166 | CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 167 | Point = Vector(0.5,0.,0.); | 
|---|
| [e9c677] | 168 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 169 |  | 
|---|
|  | 170 | // simple test on slanted line | 
|---|
| [1bd79e] | 171 | Point = Vector(1.,1.,+3.); | 
|---|
| [e9c677] | 172 | CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 173 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 174 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
| [1bd79e] | 175 | Point = Vector(1.,1.,-4.); | 
|---|
| [e9c677] | 176 | CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 177 | Point = Vector(0.5,0.5,0.); | 
|---|
| [e9c677] | 178 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 179 |  | 
|---|
|  | 180 | // simple test on first node | 
|---|
| [1bd79e] | 181 | Point = Vector(-1.,-1.,5.); | 
|---|
| [e9c677] | 182 | CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 183 | Point = Vector(0.,0.,0.); | 
|---|
| [e9c677] | 184 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 185 |  | 
|---|
|  | 186 | // simple test on second node | 
|---|
| [1bd79e] | 187 | Point = Vector(0.,2.,5.); | 
|---|
| [e9c677] | 188 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 189 | Point = Vector(0.,1.,0.); | 
|---|
| [e9c677] | 190 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 191 |  | 
|---|
|  | 192 | // simple test on third node | 
|---|
| [1bd79e] | 193 | Point = Vector(2.,0.,5.); | 
|---|
| [e9c677] | 194 | CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); | 
|---|
| [1bd79e] | 195 | Point = Vector(1.,0.,0.); | 
|---|
| [e9c677] | 196 | CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); | 
|---|
|  | 197 | }; | 
|---|