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