| [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 | 
 | 
|---|
| [e9c677] | 8 | /*
 | 
|---|
| [f844ef] | 9 |  * Tesselation_BoundaryTriangleUnitTest.cpp
 | 
|---|
| [e9c677] | 10 |  *
 | 
|---|
 | 11 |  *  Created on: Jan 13, 2010
 | 
|---|
 | 12 |  *      Author: heber
 | 
|---|
 | 13 |  */
 | 
|---|
 | 14 | 
 | 
|---|
| [bf3817] | 15 | // include config.h
 | 
|---|
 | 16 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 17 | #include <config.h>
 | 
|---|
 | 18 | #endif
 | 
|---|
 | 19 | 
 | 
|---|
| [e9c677] | 20 | using namespace std;
 | 
|---|
 | 21 | 
 | 
|---|
 | 22 | #include <cppunit/CompilerOutputter.h>
 | 
|---|
 | 23 | #include <cppunit/extensions/TestFactoryRegistry.h>
 | 
|---|
 | 24 | #include <cppunit/ui/text/TestRunner.h>
 | 
|---|
 | 25 | 
 | 
|---|
 | 26 | #include <cstring>
 | 
|---|
| [d74077] | 27 | #include <iostream>
 | 
|---|
| [e9c677] | 28 | 
 | 
|---|
| [255829] | 29 | #include "CodePatterns/Log.hpp"
 | 
|---|
| [e4fe8d] | 30 | #include "Helpers/defs.hpp"
 | 
|---|
| [d74077] | 31 | #include "TesselPoint.hpp"
 | 
|---|
 | 32 | #include "BoundaryPointSet.hpp"
 | 
|---|
 | 33 | #include "BoundaryLineSet.hpp"
 | 
|---|
 | 34 | #include "BoundaryTriangleSet.hpp"
 | 
|---|
 | 35 | #include "CandidateForTesselation.hpp"
 | 
|---|
| [f844ef] | 36 | 
 | 
|---|
 | 37 | #include "Tesselation_BoundaryTriangleUnitTest.hpp"
 | 
|---|
| [e9c677] | 38 | 
 | 
|---|
| [9b6b2f] | 39 | #ifdef HAVE_TESTRUNNER
 | 
|---|
 | 40 | #include "UnitTestMain.hpp"
 | 
|---|
 | 41 | #endif /*HAVE_TESTRUNNER*/
 | 
|---|
 | 42 | 
 | 
|---|
| [88b400] | 43 | const double TesselationBoundaryTriangleTest::SPHERERADIUS=2.;
 | 
|---|
| [e9c677] | 44 | 
 | 
|---|
 | 45 | /********************************************** Test classes **************************************/
 | 
|---|
 | 46 | 
 | 
|---|
 | 47 | // Registers the fixture into the 'registry'
 | 
|---|
 | 48 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
 | 
|---|
 | 49 | 
 | 
|---|
 | 50 | 
 | 
|---|
 | 51 | void TesselationBoundaryTriangleTest::setUp()
 | 
|---|
 | 52 | {
 | 
|---|
 | 53 |   setVerbosity(5);
 | 
|---|
 | 54 | 
 | 
|---|
 | 55 |   // create nodes
 | 
|---|
| [5c8592] | 56 |   tesselpoints[0] = new TesselPoint;
 | 
|---|
| [d74077] | 57 |   tesselpoints[0]->setPosition(Vector(0., 0., 0.));
 | 
|---|
| [68f03d] | 58 |   tesselpoints[0]->setName("1");
 | 
|---|
| [a479fa] | 59 |   tesselpoints[0]->setNr(1);
 | 
|---|
| [5c8592] | 60 |   points[0] = new BoundaryPointSet(tesselpoints[0]);
 | 
|---|
 | 61 |   tesselpoints[1] = new TesselPoint;
 | 
|---|
| [d74077] | 62 |   tesselpoints[1]->setPosition(Vector(0., 1., 0.));
 | 
|---|
| [68f03d] | 63 |   tesselpoints[1]->setName("2");
 | 
|---|
| [a479fa] | 64 |   tesselpoints[1]->setNr(2);
 | 
|---|
| [5c8592] | 65 |   points[1] = new BoundaryPointSet(tesselpoints[1]);
 | 
|---|
 | 66 |   tesselpoints[2] = new TesselPoint;
 | 
|---|
| [d74077] | 67 |   tesselpoints[2]->setPosition(Vector(1., 0., 0.));
 | 
|---|
| [68f03d] | 68 |   tesselpoints[2]->setName("3");
 | 
|---|
| [a479fa] | 69 |   tesselpoints[2]->setNr(3);
 | 
|---|
| [5c8592] | 70 |   points[2] = new BoundaryPointSet(tesselpoints[2] );
 | 
|---|
| [e9c677] | 71 | 
 | 
|---|
 | 72 |   // create line
 | 
|---|
 | 73 |   lines[0] = new BoundaryLineSet(points[0], points[1], 0);
 | 
|---|
 | 74 |   lines[1] = new BoundaryLineSet(points[1], points[2], 1);
 | 
|---|
 | 75 |   lines[2] = new BoundaryLineSet(points[0], points[2], 2);
 | 
|---|
 | 76 | 
 | 
|---|
 | 77 |   // create triangle
 | 
|---|
 | 78 |   triangle = new BoundaryTriangleSet(lines, 0);
 | 
|---|
 | 79 |   triangle->GetNormalVector(Vector(0.,0.,1.));
 | 
|---|
 | 80 | };
 | 
|---|
 | 81 | 
 | 
|---|
 | 82 | 
 | 
|---|
 | 83 | void TesselationBoundaryTriangleTest::tearDown()
 | 
|---|
 | 84 | {
 | 
|---|
 | 85 |   delete(triangle);
 | 
|---|
| [5c8592] | 86 |   for (int i=0;i<3;++i) {
 | 
|---|
 | 87 |     // TesselPoint does not delete its vector as it only got a reference
 | 
|---|
 | 88 |     delete tesselpoints[i];
 | 
|---|
 | 89 |   }
 | 
|---|
| [e9c677] | 90 |   logger::purgeInstance();
 | 
|---|
 | 91 |   errorLogger::purgeInstance();
 | 
|---|
 | 92 | };
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 | /** UnitTest for Tesselation::IsInnerPoint()
 | 
|---|
 | 95 |  */
 | 
|---|
 | 96 | void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
 | 
|---|
 | 97 | {
 | 
|---|
 | 98 |   Vector TestIntersection;
 | 
|---|
 | 99 |   Vector Point;
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 |   // simple test on y line
 | 
|---|
| [1bd79e] | 102 |   Point = Vector(-1.,0.5,0.);
 | 
|---|
| [d74077] | 103 |   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 104 |   Point = Vector(0.,0.5,0.);
 | 
|---|
| [e9c677] | 105 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 106 |   Point = Vector(-4.,0.5,0.);
 | 
|---|
| [d74077] | 107 |   CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 108 |   Point = Vector(0.,0.5,0.);
 | 
|---|
| [e9c677] | 109 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 110 | 
 | 
|---|
 | 111 |   // simple test on x line
 | 
|---|
| [1bd79e] | 112 |   Point = Vector(0.5,-1.,0.);
 | 
|---|
| [d74077] | 113 |   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 114 |   Point = Vector(0.5,0.,0.);
 | 
|---|
| [e9c677] | 115 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 116 |   Point = Vector(0.5,-6.,0.);
 | 
|---|
| [d74077] | 117 |   CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 118 |   Point = Vector(0.5,0.,0.);
 | 
|---|
| [e9c677] | 119 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 120 | 
 | 
|---|
 | 121 |   // simple test on slanted line
 | 
|---|
| [1bd79e] | 122 |   Point = Vector(1.,1.,0.);
 | 
|---|
| [d74077] | 123 |   CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 124 |   Point = Vector(0.5,0.5,0.);
 | 
|---|
| [e9c677] | 125 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 126 |   Point = Vector(5.,5.,0.);
 | 
|---|
| [d74077] | 127 |   CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 128 |   Point = Vector(0.5,0.5,0.);
 | 
|---|
| [e9c677] | 129 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 130 | 
 | 
|---|
 | 131 |   // simple test on first node
 | 
|---|
| [1bd79e] | 132 |   Point = Vector(-1.,-1.,0.);
 | 
|---|
| [d74077] | 133 |   CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 134 |   Point = Vector(0.,0.,0.);
 | 
|---|
| [e9c677] | 135 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 136 | 
 | 
|---|
 | 137 |   // simple test on second node
 | 
|---|
| [1bd79e] | 138 |   Point = Vector(0.,2.,0.);
 | 
|---|
| [d74077] | 139 |   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 140 |   Point = Vector(0.,1.,0.);
 | 
|---|
| [e9c677] | 141 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 |   // simple test on third node
 | 
|---|
| [1bd79e] | 144 |   Point = Vector(2.,0.,0.);
 | 
|---|
| [d74077] | 145 |   CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 146 |   Point = Vector(1.,0.,0.);
 | 
|---|
| [e9c677] | 147 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 148 | };
 | 
|---|
 | 149 | 
 | 
|---|
 | 150 | /** UnitTest for Tesselation::IsInnerPoint()
 | 
|---|
 | 151 |  */
 | 
|---|
 | 152 | void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
 | 
|---|
 | 153 | {
 | 
|---|
 | 154 |   Vector TestIntersection;
 | 
|---|
 | 155 |   Vector Point;
 | 
|---|
 | 156 | 
 | 
|---|
 | 157 |   // straight down/up
 | 
|---|
| [1bd79e] | 158 |   Point = Vector(1./3.,1./3.,+5.);
 | 
|---|
| [d74077] | 159 |   CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 160 |   Point = Vector(1./3.,1./3.,0.);
 | 
|---|
| [e9c677] | 161 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 162 |   Point = Vector(1./3.,1./3.,-5.);
 | 
|---|
| [d74077] | 163 |   CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 164 |   Point = Vector(1./3.,1./3.,0.);
 | 
|---|
| [e9c677] | 165 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 166 | 
 | 
|---|
 | 167 |   // simple test on y line
 | 
|---|
| [1bd79e] | 168 |   Point = Vector(-1.,0.5,+2.);
 | 
|---|
| [d74077] | 169 |   CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 170 |   Point = Vector(0.,0.5,0.);
 | 
|---|
| [e9c677] | 171 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 172 |   Point = Vector(-1.,0.5,-3.);
 | 
|---|
| [d74077] | 173 |   CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 174 |   Point = Vector(0.,0.5,0.);
 | 
|---|
| [e9c677] | 175 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 176 | 
 | 
|---|
 | 177 |   // simple test on x line
 | 
|---|
| [1bd79e] | 178 |   Point = Vector(0.5,-1.,+1.);
 | 
|---|
| [d74077] | 179 |   CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 180 |   Point = Vector(0.5,0.,0.);
 | 
|---|
| [e9c677] | 181 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 182 |   Point = Vector(0.5,-1.,-2.);
 | 
|---|
| [d74077] | 183 |   CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 184 |   Point = Vector(0.5,0.,0.);
 | 
|---|
| [e9c677] | 185 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 186 | 
 | 
|---|
 | 187 |   // simple test on slanted line
 | 
|---|
| [1bd79e] | 188 |   Point = Vector(1.,1.,+3.);
 | 
|---|
| [d74077] | 189 |   CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 190 |   Point = Vector(0.5,0.5,0.);
 | 
|---|
| [e9c677] | 191 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
| [1bd79e] | 192 |   Point = Vector(1.,1.,-4.);
 | 
|---|
| [d74077] | 193 |   CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 194 |   Point = Vector(0.5,0.5,0.);
 | 
|---|
| [e9c677] | 195 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 196 | 
 | 
|---|
 | 197 |   // simple test on first node
 | 
|---|
| [1bd79e] | 198 |   Point = Vector(-1.,-1.,5.);
 | 
|---|
| [d74077] | 199 |   CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 200 |   Point = Vector(0.,0.,0.);
 | 
|---|
| [e9c677] | 201 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 202 | 
 | 
|---|
 | 203 |   // simple test on second node
 | 
|---|
| [1bd79e] | 204 |   Point = Vector(0.,2.,5.);
 | 
|---|
| [d74077] | 205 |   CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 206 |   Point = Vector(0.,1.,0.);
 | 
|---|
| [e9c677] | 207 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 208 | 
 | 
|---|
 | 209 |   // simple test on third node
 | 
|---|
| [1bd79e] | 210 |   Point = Vector(2.,0.,5.);
 | 
|---|
| [d74077] | 211 |   CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
 | 
|---|
| [1bd79e] | 212 |   Point = Vector(1.,0.,0.);
 | 
|---|
| [e9c677] | 213 |   CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
 | 
|---|
 | 214 | };
 | 
|---|