[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 |
|
---|
| 15 | #include "defs.hpp"
|
---|
| 16 | #include "tesselation.hpp"
|
---|
| 17 | #include "tesselationunittest.hpp"
|
---|
| 18 |
|
---|
| 19 | #define SPHERERADIUS 2.
|
---|
| 20 |
|
---|
| 21 | /********************************************** Test classes **************************************/
|
---|
| 22 |
|
---|
| 23 | // Registers the fixture into the 'registry'
|
---|
| 24 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | void TesselationTest::setUp()
|
---|
| 28 | {
|
---|
| 29 | // create corners
|
---|
| 30 | class TesselPoint *Walker;
|
---|
| 31 | Walker = new TesselPoint;
|
---|
[c15ca2] | 32 | Walker->node = new Vector(1., 0., -1.);
|
---|
| 33 | Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
|
---|
[d04966] | 34 | strcpy(Walker->Name, "1");
|
---|
| 35 | Walker->nr = 1;
|
---|
| 36 | Corners.push_back(Walker);
|
---|
| 37 | Walker = new TesselPoint;
|
---|
[c15ca2] | 38 | Walker->node = new Vector(-1., 1., -1.);
|
---|
| 39 | Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
|
---|
[d04966] | 40 | strcpy(Walker->Name, "2");
|
---|
| 41 | Walker->nr = 2;
|
---|
| 42 | Corners.push_back(Walker);
|
---|
| 43 | Walker = new TesselPoint;
|
---|
[c15ca2] | 44 | Walker->node = new Vector(-1., -1., -1.);
|
---|
| 45 | Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
|
---|
[d04966] | 46 | strcpy(Walker->Name, "3");
|
---|
| 47 | Walker->nr = 3;
|
---|
| 48 | Corners.push_back(Walker);
|
---|
| 49 | Walker = new TesselPoint;
|
---|
| 50 | Walker->node = new Vector(-1., 0., 1.);
|
---|
[c15ca2] | 51 | Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
|
---|
[d04966] | 52 | strcpy(Walker->Name, "4");
|
---|
| 53 | Walker->nr = 4;
|
---|
| 54 | Corners.push_back(Walker);
|
---|
| 55 |
|
---|
| 56 | // create linkedcell
|
---|
| 57 | LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
|
---|
| 58 |
|
---|
| 59 | // create tesselation
|
---|
| 60 | TesselStruct = new Tesselation;
|
---|
[c15ca2] | 61 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
|
---|
| 62 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
|
---|
| 63 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
|
---|
[e138de] | 64 | TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
|
---|
[d04966] | 65 |
|
---|
[c15ca2] | 66 | CandidateForTesselation *baseline = NULL;
|
---|
| 67 | BoundaryTriangleSet *T = NULL;
|
---|
| 68 | bool OneLoopWithoutSuccessFlag = true;
|
---|
| 69 | bool TesselationFailFlag = false;
|
---|
| 70 | while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
|
---|
| 71 | // 2a. fill all new OpenLines
|
---|
| 72 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
| 73 | baseline = Runner->second;
|
---|
| 74 | if (baseline->pointlist.empty()) {
|
---|
| 75 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
| 76 | TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
|
---|
| 77 | }
|
---|
[d04966] | 78 | }
|
---|
[c15ca2] | 79 |
|
---|
| 80 | // 2b. search for smallest ShortestAngle among all candidates
|
---|
| 81 | double ShortestAngle = 4.*M_PI;
|
---|
| 82 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
| 83 | if (Runner->second->ShortestAngle < ShortestAngle) {
|
---|
| 84 | baseline = Runner->second;
|
---|
| 85 | ShortestAngle = baseline->ShortestAngle;
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
| 88 | if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
|
---|
| 89 | OneLoopWithoutSuccessFlag = false;
|
---|
| 90 | else {
|
---|
| 91 | TesselStruct->AddCandidateTriangle(*baseline);
|
---|
[d04966] | 92 | }
|
---|
| 93 | }
|
---|
| 94 | };
|
---|
| 95 |
|
---|
| 96 |
|
---|
| 97 | void TesselationTest::tearDown()
|
---|
| 98 | {
|
---|
| 99 | delete(LinkedList);
|
---|
| 100 | delete(TesselStruct);
|
---|
| 101 | for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
|
---|
| 102 | delete((*Runner)->node);
|
---|
| 103 | delete(*Runner);
|
---|
| 104 | }
|
---|
| 105 | Corners.clear();
|
---|
[c15ca2] | 106 | MemoryUsageObserver::purgeInstance();
|
---|
| 107 | logger::purgeInstance();
|
---|
| 108 | errorLogger::purgeInstance();
|
---|
[d04966] | 109 | };
|
---|
| 110 |
|
---|
| 111 | /** UnitTest for Contains...()
|
---|
| 112 | *
|
---|
| 113 | */
|
---|
| 114 | void TesselationTest::ContainmentTest()
|
---|
| 115 | {
|
---|
| 116 | class BoundaryPointSet *point = NULL;
|
---|
| 117 | class BoundaryLineSet *line = NULL;
|
---|
| 118 |
|
---|
| 119 | // check ContainsBoundaryPoint
|
---|
| 120 | for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
|
---|
| 121 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 122 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 123 | }
|
---|
| 124 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 125 | for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
|
---|
| 126 | point = PointRunner->second;
|
---|
| 127 | for (int i=0;i<3;i++)
|
---|
| 128 | if (point == (Runner->second)->endpoints[i])
|
---|
| 129 | point = NULL;
|
---|
| 130 | if (point != NULL)
|
---|
| 131 | break;
|
---|
| 132 | }
|
---|
| 133 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 134 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 135 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
|
---|
| 136 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | // check ContainsBoundaryLine
|
---|
| 140 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 141 | for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
|
---|
| 142 | line = LineRunner->second;
|
---|
| 143 | for (int i=0;i<3;i++)
|
---|
| 144 | if (line == (Runner->second)->lines[i])
|
---|
| 145 | line = NULL;
|
---|
| 146 | if (line != NULL)
|
---|
| 147 | break;
|
---|
| 148 | }
|
---|
| 149 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
|
---|
| 150 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
|
---|
| 151 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
|
---|
| 152 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | // check IsPresentTupel
|
---|
| 156 | CPPUNIT_ASSERT_EQUAL( true, true );
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /** UnitTest for Tesselation::GetAllTriangles()
|
---|
| 160 | *
|
---|
| 161 | */
|
---|
| 162 | void TesselationTest::GetAllTrianglesTest()
|
---|
| 163 | {
|
---|
| 164 | class BoundaryPointSet *Walker = NULL;
|
---|
| 165 |
|
---|
| 166 | // check that there are three adjacent triangles for every boundary point
|
---|
| 167 | for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
|
---|
| 168 | Walker = Runner->second;
|
---|
[e138de] | 169 | set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
|
---|
[d04966] | 170 | CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
|
---|
| 171 | // check that the returned triangle all contain the Walker
|
---|
| 172 | for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
|
---|
| 173 | CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
|
---|
[c26f44] | 174 | delete(triangles);
|
---|
[d04966] | 175 | }
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | /********************************************** Main routine **************************************/
|
---|
| 179 |
|
---|
| 180 | int main(int argc, char **argv)
|
---|
| 181 | {
|
---|
| 182 | // Get the top level suite from the registry
|
---|
| 183 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
---|
| 184 |
|
---|
| 185 | // Adds the test to the list of test to run
|
---|
| 186 | CppUnit::TextUi::TestRunner runner;
|
---|
| 187 | runner.addTest( suite );
|
---|
| 188 |
|
---|
| 189 | // Change the default outputter to a compiler error format outputter
|
---|
| 190 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
|
---|
| 191 | std::cerr ) );
|
---|
| 192 | // Run the tests.
|
---|
| 193 | bool wasSucessful = runner.run();
|
---|
| 194 |
|
---|
| 195 | // Return error code 1 if the one of test failed.
|
---|
| 196 | return wasSucessful ? 0 : 1;
|
---|
| 197 | };
|
---|