[bcf653] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
[0aa122] | 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[bcf653] | 21 | */
|
---|
| 22 |
|
---|
[d04966] | 23 | /*
|
---|
[f844ef] | 24 | * TesselationUnitTest.cpp
|
---|
[d04966] | 25 | *
|
---|
| 26 | * Created on: Aug 26, 2009
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[bf3817] | 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
[d04966] | 34 |
|
---|
| 35 | using namespace std;
|
---|
| 36 |
|
---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 40 |
|
---|
[49e1ae] | 41 | #include <cstring>
|
---|
| 42 |
|
---|
[53c7fc] | 43 | #include "CodePatterns/Log.hpp"
|
---|
| 44 | #include "Helpers/defs.hpp"
|
---|
| 45 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
---|
[cc21cd] | 46 | #include "LinkedCell/linkedcell.hpp"
|
---|
[d127c8] | 47 | #include "Tesselation/BoundaryLineSet.hpp"
|
---|
| 48 | #include "Tesselation/BoundaryTriangleSet.hpp"
|
---|
| 49 | #include "Tesselation/CandidateForTesselation.hpp"
|
---|
[6f0841] | 50 | #include "Atom/TesselPoint.hpp"
|
---|
[f844ef] | 51 |
|
---|
| 52 | #include "TesselationUnitTest.hpp"
|
---|
[d04966] | 53 |
|
---|
[9b6b2f] | 54 | #ifdef HAVE_TESTRUNNER
|
---|
| 55 | #include "UnitTestMain.hpp"
|
---|
| 56 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 57 |
|
---|
[88b400] | 58 | const double TesselationTest::SPHERERADIUS=2.;
|
---|
[d04966] | 59 |
|
---|
| 60 | /********************************************** Test classes **************************************/
|
---|
| 61 |
|
---|
| 62 | // Registers the fixture into the 'registry'
|
---|
| 63 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | void TesselationTest::setUp()
|
---|
| 67 | {
|
---|
| 68 | // create corners
|
---|
| 69 | class TesselPoint *Walker;
|
---|
| 70 | Walker = new TesselPoint;
|
---|
[d74077] | 71 | Walker->setPosition(Vector(1., 0., -1.));
|
---|
[68f03d] | 72 | Walker->setName("1");
|
---|
[a479fa] | 73 | Walker->setNr(1);
|
---|
[d04966] | 74 | Corners.push_back(Walker);
|
---|
| 75 | Walker = new TesselPoint;
|
---|
[d74077] | 76 | Walker->setPosition(Vector(-1., 1., -1.));
|
---|
[68f03d] | 77 | Walker->setName("2");
|
---|
[a479fa] | 78 | Walker->setNr(2);
|
---|
[d04966] | 79 | Corners.push_back(Walker);
|
---|
| 80 | Walker = new TesselPoint;
|
---|
[d74077] | 81 | Walker->setPosition(Vector(-1., -1., -1.));
|
---|
[68f03d] | 82 | Walker->setName("3");
|
---|
[a479fa] | 83 | Walker->setNr(3);
|
---|
[d04966] | 84 | Corners.push_back(Walker);
|
---|
| 85 | Walker = new TesselPoint;
|
---|
[d74077] | 86 | Walker->setPosition(Vector(-1., 0., 1.));
|
---|
[68f03d] | 87 | Walker->setName("4");
|
---|
[a479fa] | 88 | Walker->setNr(4);
|
---|
[d04966] | 89 | Corners.push_back(Walker);
|
---|
| 90 |
|
---|
| 91 | // create tesselation
|
---|
| 92 | TesselStruct = new Tesselation;
|
---|
[c15ca2] | 93 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
|
---|
| 94 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
|
---|
| 95 | CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
|
---|
[cc21cd] | 96 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
|
---|
| 97 | (*TesselStruct)(cloud, SPHERERADIUS);
|
---|
[d04966] | 98 | };
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | void TesselationTest::tearDown()
|
---|
| 102 | {
|
---|
| 103 | delete(TesselStruct);
|
---|
[34c43a] | 104 | for (TesselPointSTLList::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
|
---|
[d04966] | 105 | delete(*Runner);
|
---|
| 106 | Corners.clear();
|
---|
[c15ca2] | 107 | logger::purgeInstance();
|
---|
| 108 | errorLogger::purgeInstance();
|
---|
[d04966] | 109 | };
|
---|
| 110 |
|
---|
| 111 | /** UnitTest for Contains...()
|
---|
| 112 | *
|
---|
| 113 | */
|
---|
| 114 | void TesselationTest::ContainmentTest()
|
---|
| 115 | {
|
---|
| 116 | class BoundaryPointSet *point = NULL;
|
---|
| 117 | class BoundaryLineSet *line = NULL;
|
---|
| 118 |
|
---|
| 119 | // check ContainsBoundaryPoint
|
---|
| 120 | for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
|
---|
| 121 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 122 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 123 | }
|
---|
| 124 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 125 | for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
|
---|
| 126 | point = PointRunner->second;
|
---|
| 127 | for (int i=0;i<3;i++)
|
---|
| 128 | if (point == (Runner->second)->endpoints[i])
|
---|
| 129 | point = NULL;
|
---|
| 130 | if (point != NULL)
|
---|
| 131 | break;
|
---|
| 132 | }
|
---|
| 133 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
|
---|
| 134 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
|
---|
| 135 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
|
---|
| 136 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | // check ContainsBoundaryLine
|
---|
| 140 | for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
|
---|
| 141 | for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
|
---|
| 142 | line = LineRunner->second;
|
---|
| 143 | for (int i=0;i<3;i++)
|
---|
| 144 | if (line == (Runner->second)->lines[i])
|
---|
| 145 | line = NULL;
|
---|
| 146 | if (line != NULL)
|
---|
| 147 | break;
|
---|
| 148 | }
|
---|
| 149 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
|
---|
| 150 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
|
---|
| 151 | CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
|
---|
| 152 | CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
|
---|
| 153 | }
|
---|
| 154 |
|
---|
| 155 | // check IsPresentTupel
|
---|
| 156 | CPPUNIT_ASSERT_EQUAL( true, true );
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /** UnitTest for Tesselation::GetAllTriangles()
|
---|
| 160 | *
|
---|
| 161 | */
|
---|
| 162 | void TesselationTest::GetAllTrianglesTest()
|
---|
| 163 | {
|
---|
| 164 | class BoundaryPointSet *Walker = NULL;
|
---|
| 165 |
|
---|
| 166 | // check that there are three adjacent triangles for every boundary point
|
---|
| 167 | for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
|
---|
| 168 | Walker = Runner->second;
|
---|
[e138de] | 169 | set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
|
---|
[d04966] | 170 | CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
|
---|
| 171 | // check that the returned triangle all contain the Walker
|
---|
| 172 | for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
|
---|
| 173 | CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
|
---|
[c26f44] | 174 | delete(triangles);
|
---|
[d04966] | 175 | }
|
---|
| 176 | }
|
---|