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