| [c15ca2] | 1 | /* | 
|---|
|  | 2 | * tesselation_insideoutsideunittest.cpp | 
|---|
|  | 3 | * | 
|---|
|  | 4 | *  Created on: Dec 28, 2009 | 
|---|
|  | 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 |  | 
|---|
| [49e1ae] | 14 | #include <cstring> | 
|---|
|  | 15 |  | 
|---|
| [c15ca2] | 16 | #include "defs.hpp" | 
|---|
|  | 17 | #include "tesselation.hpp" | 
|---|
|  | 18 | #include "tesselation_insideoutsideunittest.hpp" | 
|---|
|  | 19 |  | 
|---|
| [9b6b2f] | 20 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 21 | #include "UnitTestMain.hpp" | 
|---|
|  | 22 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 23 |  | 
|---|
| [c15ca2] | 24 | #define SPHERERADIUS 2. | 
|---|
|  | 25 |  | 
|---|
|  | 26 | /********************************************** Test classes **************************************/ | 
|---|
|  | 27 |  | 
|---|
|  | 28 | // Registers the fixture into the 'registry' | 
|---|
|  | 29 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationInOutsideTest ); | 
|---|
|  | 30 |  | 
|---|
|  | 31 |  | 
|---|
|  | 32 | void TesselationInOutsideTest::setUp() | 
|---|
|  | 33 | { | 
|---|
| [68a53b] | 34 | setVerbosity(2); | 
|---|
| [c15ca2] | 35 |  | 
|---|
|  | 36 | // create corners | 
|---|
|  | 37 | class TesselPoint *Walker; | 
|---|
|  | 38 | Walker = new TesselPoint; | 
|---|
|  | 39 | Walker->node = new Vector(0., 0., 0.); | 
|---|
| [68f03d] | 40 | Walker->setName("1"); | 
|---|
| [c15ca2] | 41 | Walker->nr = 1; | 
|---|
|  | 42 | Corners.push_back(Walker); | 
|---|
|  | 43 | Walker = new TesselPoint; | 
|---|
|  | 44 | Walker->node = new Vector(0., 1., 0.); | 
|---|
| [68f03d] | 45 | Walker->setName("2"); | 
|---|
| [c15ca2] | 46 | Walker->nr = 2; | 
|---|
|  | 47 | Corners.push_back(Walker); | 
|---|
|  | 48 | Walker = new TesselPoint; | 
|---|
|  | 49 | Walker->node = new Vector(1., 0., 0.); | 
|---|
| [68f03d] | 50 | Walker->setName("3"); | 
|---|
| [c15ca2] | 51 | Walker->nr = 3; | 
|---|
|  | 52 | Corners.push_back(Walker); | 
|---|
|  | 53 | Walker = new TesselPoint; | 
|---|
|  | 54 | Walker->node = new Vector(1., 1., 0.); | 
|---|
| [68f03d] | 55 | Walker->setName("4"); | 
|---|
| [c15ca2] | 56 | Walker->nr = 4; | 
|---|
|  | 57 | Corners.push_back(Walker); | 
|---|
|  | 58 | Walker = new TesselPoint; | 
|---|
|  | 59 | Walker->node = new Vector(0., 0., 1.); | 
|---|
| [68f03d] | 60 | Walker->setName("5"); | 
|---|
| [c15ca2] | 61 | Walker->nr = 5; | 
|---|
|  | 62 | Corners.push_back(Walker); | 
|---|
|  | 63 | Walker = new TesselPoint; | 
|---|
|  | 64 | Walker->node = new Vector(0., 1., 1.); | 
|---|
| [68f03d] | 65 | Walker->setName("6"); | 
|---|
| [c15ca2] | 66 | Walker->nr = 6; | 
|---|
|  | 67 | Corners.push_back(Walker); | 
|---|
|  | 68 | Walker = new TesselPoint; | 
|---|
|  | 69 | Walker->node = new Vector(1., 0., 1.); | 
|---|
| [68f03d] | 70 | Walker->setName("7"); | 
|---|
| [c15ca2] | 71 | Walker->nr = 7; | 
|---|
|  | 72 | Corners.push_back(Walker); | 
|---|
|  | 73 | Walker = new TesselPoint; | 
|---|
|  | 74 | Walker->node = new Vector(1., 1., 1.); | 
|---|
| [68f03d] | 75 | Walker->setName("8"); | 
|---|
| [c15ca2] | 76 | Walker->nr = 8; | 
|---|
|  | 77 | Corners.push_back(Walker); | 
|---|
|  | 78 |  | 
|---|
|  | 79 | // create linkedcell | 
|---|
|  | 80 | LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS); | 
|---|
|  | 81 |  | 
|---|
|  | 82 | // create tesselation | 
|---|
|  | 83 | TesselStruct = new Tesselation; | 
|---|
|  | 84 | TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList); | 
|---|
|  | 85 |  | 
|---|
|  | 86 | CandidateForTesselation *baseline = NULL; | 
|---|
|  | 87 | BoundaryTriangleSet *T = NULL; | 
|---|
|  | 88 | bool OneLoopWithoutSuccessFlag = true; | 
|---|
|  | 89 | bool TesselationFailFlag = false; | 
|---|
|  | 90 | while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) { | 
|---|
|  | 91 | // 2a. fill all new OpenLines | 
|---|
| [a67d19] | 92 | DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl); | 
|---|
| [c15ca2] | 93 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) | 
|---|
| [a67d19] | 94 | DoLog(2) && (Log() << Verbose(2) << *(Runner->second) << endl); | 
|---|
| [c15ca2] | 95 |  | 
|---|
|  | 96 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) { | 
|---|
|  | 97 | baseline = Runner->second; | 
|---|
|  | 98 | if (baseline->pointlist.empty()) { | 
|---|
|  | 99 | T = (((baseline->BaseLine->triangles.begin()))->second); | 
|---|
| [a67d19] | 100 | DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl); | 
|---|
| [c15ca2] | 101 | TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one. | 
|---|
|  | 102 | } | 
|---|
|  | 103 | } | 
|---|
|  | 104 |  | 
|---|
|  | 105 | // 2b. search for smallest ShortestAngle among all candidates | 
|---|
|  | 106 | double ShortestAngle = 4.*M_PI; | 
|---|
| [a67d19] | 107 | DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl); | 
|---|
| [c15ca2] | 108 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) | 
|---|
| [a67d19] | 109 | DoLog(2) && (Log() << Verbose(2) << *(Runner->second) << endl); | 
|---|
| [c15ca2] | 110 |  | 
|---|
|  | 111 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) { | 
|---|
|  | 112 | if (Runner->second->ShortestAngle < ShortestAngle) { | 
|---|
|  | 113 | baseline = Runner->second; | 
|---|
|  | 114 | ShortestAngle = baseline->ShortestAngle; | 
|---|
|  | 115 | //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl; | 
|---|
|  | 116 | } | 
|---|
|  | 117 | } | 
|---|
|  | 118 | if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty())) | 
|---|
|  | 119 | OneLoopWithoutSuccessFlag = false; | 
|---|
|  | 120 | else { | 
|---|
| [474961] | 121 | TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList); | 
|---|
| [c15ca2] | 122 | } | 
|---|
|  | 123 | } | 
|---|
|  | 124 | }; | 
|---|
|  | 125 |  | 
|---|
|  | 126 |  | 
|---|
|  | 127 | void TesselationInOutsideTest::tearDown() | 
|---|
|  | 128 | { | 
|---|
|  | 129 | delete(LinkedList); | 
|---|
|  | 130 | delete(TesselStruct); | 
|---|
| [734816] | 131 | for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) { | 
|---|
| [c15ca2] | 132 | delete((*Runner)->node); | 
|---|
|  | 133 | delete(*Runner); | 
|---|
|  | 134 | } | 
|---|
|  | 135 | Corners.clear(); | 
|---|
|  | 136 | logger::purgeInstance(); | 
|---|
|  | 137 | errorLogger::purgeInstance(); | 
|---|
|  | 138 | }; | 
|---|
|  | 139 |  | 
|---|
|  | 140 | /** UnitTest for Tesselation::IsInnerPoint() | 
|---|
|  | 141 | */ | 
|---|
|  | 142 | void TesselationInOutsideTest::IsInnerPointTest() | 
|---|
|  | 143 | { | 
|---|
|  | 144 | double n[3]; | 
|---|
| [97498a] | 145 | const double boundary = 2.; | 
|---|
| [c15ca2] | 146 | const double step = 1.; | 
|---|
|  | 147 |  | 
|---|
|  | 148 | // go through the mesh and check each point | 
|---|
|  | 149 | for (n[0] = -boundary; n[0] <= boundary; n[0]+=step) | 
|---|
|  | 150 | for (n[1] = -boundary; n[1] <= boundary; n[1]+=step) | 
|---|
|  | 151 | for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) { | 
|---|
| [68a53b] | 152 | if ( ((n[0] >= 0.) && (n[1] >= 0.) && (n[2] >= 0.)) && ((n[0] <= 1.) && (n[1] <= 1.) && (n[2] <= 1.))) | 
|---|
| [c15ca2] | 153 | CPPUNIT_ASSERT_EQUAL( true , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) ); | 
|---|
|  | 154 | else | 
|---|
|  | 155 | CPPUNIT_ASSERT_EQUAL( false , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) ); | 
|---|
|  | 156 | } | 
|---|
|  | 157 | }; | 
|---|