[d04966] | 1 | /*
|
---|
| 2 | * tesselationunittest.cpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 26, 2009
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 |
|
---|
| 9 | using namespace std;
|
---|
| 10 |
|
---|
| 11 | #include <cppunit/CompilerOutputter.h>
|
---|
| 12 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 13 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 14 |
|
---|
[49e1ae] | 15 | #include <cstring>
|
---|
| 16 |
|
---|
[d04966] | 17 | #include "defs.hpp"
|
---|
| 18 | #include "tesselation.hpp"
|
---|
| 19 | #include "tesselationunittest.hpp"
|
---|
| 20 |
|
---|
[9b6b2f] | 21 | #ifdef HAVE_TESTRUNNER
|
---|
| 22 | #include "UnitTestMain.hpp"
|
---|
| 23 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 24 |
|
---|
[d04966] | 25 | #define SPHERERADIUS 2.
|
---|
| 26 |
|
---|
| 27 | /********************************************** Test classes **************************************/
|
---|
| 28 |
|
---|
| 29 | // Registers the fixture into the 'registry'
|
---|
| 30 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | void TesselationTest::setUp()
|
---|
| 34 | {
|
---|
| 35 | // create corners
|
---|
| 36 | class TesselPoint *Walker;
|
---|
| 37 | Walker = new TesselPoint;
|
---|
[c15ca2] | 38 | Walker->node = new Vector(1., 0., -1.);
|
---|
[68f03d] | 39 | Walker->setName("1");
|
---|
[d04966] | 40 | Walker->nr = 1;
|
---|
| 41 | Corners.push_back(Walker);
|
---|
| 42 | Walker = new TesselPoint;
|
---|
[c15ca2] | 43 | Walker->node = new Vector(-1., 1., -1.);
|
---|
[68f03d] | 44 | Walker->setName("2");
|
---|
[d04966] | 45 | Walker->nr = 2;
|
---|
| 46 | Corners.push_back(Walker);
|
---|
| 47 | Walker = new TesselPoint;
|
---|
[c15ca2] | 48 | Walker->node = new Vector(-1., -1., -1.);
|
---|
[68f03d] | 49 | Walker->setName("3");
|
---|
[d04966] | 50 | Walker->nr = 3;
|
---|
| 51 | Corners.push_back(Walker);
|
---|
| 52 | Walker = new TesselPoint;
|
---|
| 53 | Walker->node = new Vector(-1., 0., 1.);
|
---|
[68f03d] | 54 | Walker->setName("4");
|
---|
[d04966] | 55 | Walker->nr = 4;
|
---|
| 56 | Corners.push_back(Walker);
|
---|
| 57 |
|
---|
| 58 | // create linkedcell
|
---|
| 59 | LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
|
---|
| 60 |
|
---|
| 61 | // create tesselation
|
---|
| 62 | TesselStruct = new Tesselation;
|
---|
[c15ca2] | 63 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
|
---|
| 64 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
|
---|
| 65 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
|
---|
[e138de] | 66 | TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
|
---|
[d04966] | 67 |
|
---|
[c15ca2] | 68 | CandidateForTesselation *baseline = NULL;
|
---|
| 69 | BoundaryTriangleSet *T = NULL;
|
---|
| 70 | bool OneLoopWithoutSuccessFlag = true;
|
---|
| 71 | bool TesselationFailFlag = false;
|
---|
| 72 | while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
|
---|
| 73 | // 2a. fill all new OpenLines
|
---|
| 74 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
| 75 | baseline = Runner->second;
|
---|
| 76 | if (baseline->pointlist.empty()) {
|
---|
| 77 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
| 78 | TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
|
---|
| 79 | }
|
---|
[d04966] | 80 | }
|
---|
[c15ca2] | 81 |
|
---|
| 82 | // 2b. search for smallest ShortestAngle among all candidates
|
---|
| 83 | double ShortestAngle = 4.*M_PI;
|
---|
| 84 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
| 85 | if (Runner->second->ShortestAngle < ShortestAngle) {
|
---|
| 86 | baseline = Runner->second;
|
---|
| 87 | ShortestAngle = baseline->ShortestAngle;
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
|
---|
| 91 | OneLoopWithoutSuccessFlag = false;
|
---|
| 92 | else {
|
---|
[474961] | 93 | TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
|
---|
[d04966] | 94 | }
|
---|
| 95 | }
|
---|
| 96 | };
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | void TesselationTest::tearDown()
|
---|
| 100 | {
|
---|
| 101 | delete(LinkedList);
|
---|
| 102 | delete(TesselStruct);
|
---|
[734816] | 103 | for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
|
---|
[d04966] | 104 | delete((*Runner)->node);
|
---|
| 105 | delete(*Runner);
|
---|
| 106 | }
|
---|
| 107 | Corners.clear();
|
---|
[c15ca2] | 108 | logger::purgeInstance();
|
---|
| 109 | errorLogger::purgeInstance();
|
---|
[d04966] | 110 | };
|
---|
| 111 |
|
---|
| 112 | /** UnitTest for Contains...()
|
---|
| 113 | *
|
---|
| 114 | */
|
---|
| 115 | void TesselationTest::ContainmentTest()
|
---|
| 116 | {
|
---|
| 117 | class BoundaryPointSet *point = NULL;
|
---|
| 118 | class BoundaryLineSet *line = NULL;
|
---|
| 119 |
|
---|
| 120 | // check ContainsBoundaryPoint
|
---|
| 121 | for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
|
---|
| 122 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 123 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 124 | }
|
---|
| 125 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 126 | for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
|
---|
| 127 | point = PointRunner->second;
|
---|
| 128 | for (int i=0;i<3;i++)
|
---|
| 129 | if (point == (Runner->second)->endpoints[i])
|
---|
| 130 | point = NULL;
|
---|
| 131 | if (point != NULL)
|
---|
| 132 | break;
|
---|
| 133 | }
|
---|
| 134 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 135 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 136 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
|
---|
| 137 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | // check ContainsBoundaryLine
|
---|
| 141 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 142 | for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
|
---|
| 143 | line = LineRunner->second;
|
---|
| 144 | for (int i=0;i<3;i++)
|
---|
| 145 | if (line == (Runner->second)->lines[i])
|
---|
| 146 | line = NULL;
|
---|
| 147 | if (line != NULL)
|
---|
| 148 | break;
|
---|
| 149 | }
|
---|
| 150 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
|
---|
| 151 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
|
---|
| 152 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
|
---|
| 153 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | // check IsPresentTupel
|
---|
| 157 | CPPUNIT_ASSERT_EQUAL( true, true );
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | /** UnitTest for Tesselation::GetAllTriangles()
|
---|
| 161 | *
|
---|
| 162 | */
|
---|
| 163 | void TesselationTest::GetAllTrianglesTest()
|
---|
| 164 | {
|
---|
| 165 | class BoundaryPointSet *Walker = NULL;
|
---|
| 166 |
|
---|
| 167 | // check that there are three adjacent triangles for every boundary point
|
---|
| 168 | for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
|
---|
| 169 | Walker = Runner->second;
|
---|
[e138de] | 170 | set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
|
---|
[d04966] | 171 | CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
|
---|
| 172 | // check that the returned triangle all contain the Walker
|
---|
| 173 | for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
|
---|
| 174 | CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
|
---|
[c26f44] | 175 | delete(triangles);
|
---|
[d04966] | 176 | }
|
---|
| 177 | }
|
---|