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