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