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