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