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