[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 |
|
---|
[d04966] | 8 | /*
|
---|
| 9 | * tesselationunittest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Aug 26, 2009
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
[bf3817] | 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
[d04966] | 19 |
|
---|
| 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>
|
---|
| 27 |
|
---|
[d04966] | 28 | #include "defs.hpp"
|
---|
[d74077] | 29 | #include "TesselPoint.hpp"
|
---|
| 30 | #include "BoundaryLineSet.hpp"
|
---|
| 31 | #include "BoundaryTriangleSet.hpp"
|
---|
| 32 | #include "CandidateForTesselation.hpp"
|
---|
[d04966] | 33 | #include "tesselationunittest.hpp"
|
---|
| 34 |
|
---|
[9b6b2f] | 35 | #ifdef HAVE_TESTRUNNER
|
---|
| 36 | #include "UnitTestMain.hpp"
|
---|
| 37 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 38 |
|
---|
[88b400] | 39 | const double TesselationTest::SPHERERADIUS=2.;
|
---|
[d04966] | 40 |
|
---|
| 41 | /********************************************** Test classes **************************************/
|
---|
| 42 |
|
---|
| 43 | // Registers the fixture into the 'registry'
|
---|
| 44 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | void TesselationTest::setUp()
|
---|
| 48 | {
|
---|
| 49 | // create corners
|
---|
| 50 | class TesselPoint *Walker;
|
---|
| 51 | Walker = new TesselPoint;
|
---|
[d74077] | 52 | Walker->setPosition(Vector(1., 0., -1.));
|
---|
[68f03d] | 53 | Walker->setName("1");
|
---|
[d04966] | 54 | Walker->nr = 1;
|
---|
| 55 | Corners.push_back(Walker);
|
---|
| 56 | Walker = new TesselPoint;
|
---|
[d74077] | 57 | Walker->setPosition(Vector(-1., 1., -1.));
|
---|
[68f03d] | 58 | Walker->setName("2");
|
---|
[d04966] | 59 | Walker->nr = 2;
|
---|
| 60 | Corners.push_back(Walker);
|
---|
| 61 | Walker = new TesselPoint;
|
---|
[d74077] | 62 | Walker->setPosition(Vector(-1., -1., -1.));
|
---|
[68f03d] | 63 | Walker->setName("3");
|
---|
[d04966] | 64 | Walker->nr = 3;
|
---|
| 65 | Corners.push_back(Walker);
|
---|
| 66 | Walker = new TesselPoint;
|
---|
[d74077] | 67 | Walker->setPosition(Vector(-1., 0., 1.));
|
---|
[68f03d] | 68 | Walker->setName("4");
|
---|
[d04966] | 69 | Walker->nr = 4;
|
---|
| 70 | Corners.push_back(Walker);
|
---|
| 71 |
|
---|
| 72 | // create linkedcell
|
---|
[af2c424] | 73 | LinkedList = new LinkedCell(Corners, 2.*SPHERERADIUS);
|
---|
[d04966] | 74 |
|
---|
| 75 | // create tesselation
|
---|
| 76 | TesselStruct = new Tesselation;
|
---|
[c15ca2] | 77 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
|
---|
| 78 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
|
---|
| 79 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
|
---|
[e138de] | 80 | TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
|
---|
[d04966] | 81 |
|
---|
[c15ca2] | 82 | CandidateForTesselation *baseline = NULL;
|
---|
| 83 | BoundaryTriangleSet *T = NULL;
|
---|
| 84 | bool OneLoopWithoutSuccessFlag = true;
|
---|
| 85 | bool TesselationFailFlag = false;
|
---|
| 86 | while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
|
---|
| 87 | // 2a. fill all new OpenLines
|
---|
| 88 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
| 89 | baseline = Runner->second;
|
---|
| 90 | if (baseline->pointlist.empty()) {
|
---|
| 91 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
| 92 | TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
|
---|
| 93 | }
|
---|
[d04966] | 94 | }
|
---|
[c15ca2] | 95 |
|
---|
| 96 | // 2b. search for smallest ShortestAngle among all candidates
|
---|
| 97 | double ShortestAngle = 4.*M_PI;
|
---|
| 98 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
| 99 | if (Runner->second->ShortestAngle < ShortestAngle) {
|
---|
| 100 | baseline = Runner->second;
|
---|
| 101 | ShortestAngle = baseline->ShortestAngle;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 | if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
|
---|
| 105 | OneLoopWithoutSuccessFlag = false;
|
---|
| 106 | else {
|
---|
[474961] | 107 | TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
|
---|
[d04966] | 108 | }
|
---|
| 109 | }
|
---|
| 110 | };
|
---|
| 111 |
|
---|
| 112 |
|
---|
| 113 | void TesselationTest::tearDown()
|
---|
| 114 | {
|
---|
| 115 | delete(LinkedList);
|
---|
| 116 | delete(TesselStruct);
|
---|
[d74077] | 117 | for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
|
---|
[d04966] | 118 | delete(*Runner);
|
---|
| 119 | Corners.clear();
|
---|
[c15ca2] | 120 | logger::purgeInstance();
|
---|
| 121 | errorLogger::purgeInstance();
|
---|
[d04966] | 122 | };
|
---|
| 123 |
|
---|
| 124 | /** UnitTest for Contains...()
|
---|
| 125 | *
|
---|
| 126 | */
|
---|
| 127 | void TesselationTest::ContainmentTest()
|
---|
| 128 | {
|
---|
| 129 | class BoundaryPointSet *point = NULL;
|
---|
| 130 | class BoundaryLineSet *line = NULL;
|
---|
| 131 |
|
---|
| 132 | // check ContainsBoundaryPoint
|
---|
| 133 | for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
|
---|
| 134 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 135 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 136 | }
|
---|
| 137 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 138 | for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
|
---|
| 139 | point = PointRunner->second;
|
---|
| 140 | for (int i=0;i<3;i++)
|
---|
| 141 | if (point == (Runner->second)->endpoints[i])
|
---|
| 142 | point = NULL;
|
---|
| 143 | if (point != NULL)
|
---|
| 144 | break;
|
---|
| 145 | }
|
---|
| 146 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 147 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 148 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
|
---|
| 149 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
|
---|
| 150 | }
|
---|
| 151 |
|
---|
| 152 | // check ContainsBoundaryLine
|
---|
| 153 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 154 | for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
|
---|
| 155 | line = LineRunner->second;
|
---|
| 156 | for (int i=0;i<3;i++)
|
---|
| 157 | if (line == (Runner->second)->lines[i])
|
---|
| 158 | line = NULL;
|
---|
| 159 | if (line != NULL)
|
---|
| 160 | break;
|
---|
| 161 | }
|
---|
| 162 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
|
---|
| 163 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
|
---|
| 164 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
|
---|
| 165 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | // check IsPresentTupel
|
---|
| 169 | CPPUNIT_ASSERT_EQUAL( true, true );
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | /** UnitTest for Tesselation::GetAllTriangles()
|
---|
| 173 | *
|
---|
| 174 | */
|
---|
| 175 | void TesselationTest::GetAllTrianglesTest()
|
---|
| 176 | {
|
---|
| 177 | class BoundaryPointSet *Walker = NULL;
|
---|
| 178 |
|
---|
| 179 | // check that there are three adjacent triangles for every boundary point
|
---|
| 180 | for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
|
---|
| 181 | Walker = Runner->second;
|
---|
[e138de] | 182 | set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
|
---|
[d04966] | 183 | CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
|
---|
| 184 | // check that the returned triangle all contain the Walker
|
---|
| 185 | for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
|
---|
| 186 | CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
|
---|
[c26f44] | 187 | delete(triangles);
|
---|
[d04966] | 188 | }
|
---|
| 189 | }
|
---|