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