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