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