source: src/Tesselation/unittests/Tesselation_BoundaryTriangleUnitTest.cpp@ 70a0ba

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 70a0ba was 03a713, checked in by Frederik Heber <heber@…>, 14 years ago

BUG: Added failing test case to Tesselation_BoundaryTriangleUnitTest.

  • test case is from larger filling example.
  • Property mode set to 100644
File size: 11.9 KB
RevLine 
[bcf653]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
[0aa122]4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
[bcf653]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]20using 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"
[6f0841]31#include "Atom/TesselPoint.hpp"
[471dec]32#include "LinearAlgebra/Plane.hpp"
33#include "LinearAlgebra/VectorSet.hpp"
[d127c8]34#include "Tesselation/BoundaryPointSet.hpp"
35#include "Tesselation/BoundaryLineSet.hpp"
36#include "Tesselation/BoundaryTriangleSet.hpp"
37#include "Tesselation/CandidateForTesselation.hpp"
[f844ef]38
39#include "Tesselation_BoundaryTriangleUnitTest.hpp"
[e9c677]40
[9b6b2f]41#ifdef HAVE_TESTRUNNER
42#include "UnitTestMain.hpp"
43#endif /*HAVE_TESTRUNNER*/
44
[88b400]45const double TesselationBoundaryTriangleTest::SPHERERADIUS=2.;
[e9c677]46
47/********************************************** Test classes **************************************/
48
49// Registers the fixture into the 'registry'
50CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
51
52
[471dec]53void TesselationBoundaryTriangleTest::createTriangle(const std::vector<Vector> &Vectors)
[e9c677]54{
[471dec]55 CPPUNIT_ASSERT_EQUAL( (size_t)3, Vectors.size() );
[e9c677]56
57 // create nodes
[471dec]58 for (size_t count = 0; count < NDIM; ++count) {
59 tesselpoints[count] = new TesselPoint;
60 tesselpoints[count]->setPosition( Vectors[count] );
61 tesselpoints[count]->setName(toString(count));
62 tesselpoints[count]->setNr(count);
63 points[count] = new BoundaryPointSet(tesselpoints[count]);
64 }
[e9c677]65
66 // create line
67 lines[0] = new BoundaryLineSet(points[0], points[1], 0);
68 lines[1] = new BoundaryLineSet(points[1], points[2], 1);
69 lines[2] = new BoundaryLineSet(points[0], points[2], 2);
70
71 // create triangle
72 triangle = new BoundaryTriangleSet(lines, 0);
[471dec]73 Plane p(Vectors[0], Vectors[1], Vectors[2]);
74 triangle->GetNormalVector(p.getNormal());
75}
[e9c677]76
[471dec]77void TesselationBoundaryTriangleTest::setUp()
78{
79 setVerbosity(5);
80
81 // create nodes
82 std::vector<Vector> Vectors;
83 Vectors.push_back( Vector(0., 0., 0.) );
84 Vectors.push_back( Vector(0., 1., 0.) );
85 Vectors.push_back( Vector(1., 0., 0.) );
86
87 // create triangle
88 createTriangle(Vectors);
89}
[e9c677]90
91void TesselationBoundaryTriangleTest::tearDown()
92{
93 delete(triangle);
[5c8592]94 for (int i=0;i<3;++i) {
95 // TesselPoint does not delete its vector as it only got a reference
96 delete tesselpoints[i];
97 }
[e9c677]98 logger::purgeInstance();
99 errorLogger::purgeInstance();
100};
101
[471dec]102/** UnitTest for Tesselation::IsInsideTriangle()
103 */
104void TesselationBoundaryTriangleTest::IsInsideTriangleTest()
105{
106 // inside points
107 {
108 // check each endnode
109 for (size_t i=0; i< NDIM; ++i) {
110 const Vector testPoint(triangle->endpoints[i]->node->getPosition());
111 LOG(1, "INFO: Testing whether " << testPoint << " is an inner point.");
112 CPPUNIT_ASSERT( triangle->IsInsideTriangle( testPoint ) );
113 }
114 }
115
116 {
117 // check points along each BoundaryLine
118 for (size_t i=0; i< NDIM; ++i) {
119 Vector offset = triangle->endpoints[i%3]->node->getPosition();
120 Vector direction = triangle->endpoints[(i+1)%3]->node->getPosition() - offset;
121 for (double s = 0.1; s < 1.; s+= 0.1) {
122 Vector testPoint = offset + s*direction;
123 LOG(1, "INFO: Testing whether " << testPoint << " is an inner point.");
124 CPPUNIT_ASSERT( triangle->IsInsideTriangle( testPoint ) );
125 }
126 }
127 }
128
129 {
130 // check central point
131 Vector center;
132 triangle->GetCenter(center);
133 LOG(1, "INFO: Testing whether " << center << " is an inner point.");
134 CPPUNIT_ASSERT( triangle->IsInsideTriangle( center ) );
135 }
136
137 // outside points
138 {
139 // check points outside (i.e. those not in xy-plane through origin)
140 double n[3];
141 const double boundary = 4.;
142 const double step = 1.;
143 // go through the cube and check each point
144 for (n[0] = -boundary; n[0] <= boundary; n[0]+=step)
145 for (n[1] = -boundary; n[1] <= boundary; n[1]+=step)
146 for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) {
147 const Vector testPoint(n[0], n[1], n[2]);
148 if (n[2] != 0) {
149 LOG(1, "INFO: Testing whether " << testPoint << " is not an inner point.");
150 CPPUNIT_ASSERT( !triangle->IsInsideTriangle( testPoint ) );
151 }
152 }
153 }
154
155 {
156 // check points within the plane but outside of triangle
157 double n[3];
158 const double boundary = 4.;
159 const double step = 1.;
160 n[2] = 0;
161 for (n[0] = -boundary; n[0] <= boundary; n[0]+=step)
162 for (n[1] = -boundary; n[1] <= boundary; n[1]+=step) {
163 const Vector testPoint(n[0], n[1], n[2]);
164 if ((n[0] >=0) && (n[1] >=0) && (n[0]<=1) && (n[1]<=1)) {
165 if (n[0]+n[1] <= 1) {
166 LOG(1, "INFO: Testing whether " << testPoint << " is an inner point.");
167 CPPUNIT_ASSERT( triangle->IsInsideTriangle( testPoint) );
168 } else {
169 LOG(1, "INFO: Testing whether " << testPoint << " is not an inner point.");
170 CPPUNIT_ASSERT( !triangle->IsInsideTriangle( testPoint) );
171 }
172 } else {
173 LOG(1, "INFO: Testing whether " << testPoint << " is not an inner point.");
174 CPPUNIT_ASSERT( !triangle->IsInsideTriangle( testPoint) );
175 }
176 }
177 }
178}
179
180/** UnitTest for Tesselation::IsInsideTriangle()
181 *
182 * We test for some specific points that occured in larger examples of the code.
183 *
184 */
185void TesselationBoundaryTriangleTest::IsInsideTriangle_specificTest()
186{
187 {
[03a713]188 delete triangle;
[471dec]189 // test is from --create-micelle 200 --radius 30. --position "0,0,0" of sles.data
190 // failure is: Intersection (23.1644,24.1867,65.1272) is not inside triangle [659|Na2451,O3652,Na3762].
191 const Vector testPoint(1.57318,1.57612,10.9874);
192 const Vector testIntersection(23.1644,24.1867,65.1272);
193 std::vector<Vector> vectors;
194 vectors.push_back( Vector(23.0563,30.4673,73.7555) );
195 vectors.push_back( Vector(25.473,25.1512,68.5467) );
196 vectors.push_back( Vector(23.1644,24.1867,65.1272) );
197 createTriangle(vectors);
198 CPPUNIT_ASSERT( triangle->IsInsideTriangle( testIntersection ) );
[03a713]199 }
200 {
201 delete triangle;
202 // test is from --create-micelle 200 --radius 30. --position "0,0,0" of sles.data
203 // failure is: Intersection (20.6787,70.655,71.5657) is not inside triangle [622|Na1197,Na2166,O3366].
204 // fix is lower LINALG_MYEPSILON (not std::numeric_limits<doubble>*100 but *1e-4)
205 const Vector testPoint(1.57318,14.185,61.2155);
206 const Vector testIntersection(20.67867516517798,70.65496977054023,71.56572984946152);
207 std::vector<Vector> vectors;
208 vectors.push_back( Vector(22.9592,68.7791,77.5907) );
209 vectors.push_back( Vector(18.4729,72.0386,68.08839999999999) );
210 vectors.push_back( Vector(20.3834,71.0154,70.1443) );
211 createTriangle(vectors);
212 CPPUNIT_ASSERT( triangle->IsInsideTriangle( testIntersection ) );
[471dec]213 }
214}
215
[e9c677]216/** UnitTest for Tesselation::IsInnerPoint()
217 */
218void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
219{
220 Vector TestIntersection;
221 Vector Point;
222
223 // simple test on y line
[1bd79e]224 Point = Vector(-1.,0.5,0.);
[d74077]225 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]226 Point = Vector(0.,0.5,0.);
[e9c677]227 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]228 Point = Vector(-4.,0.5,0.);
[d74077]229 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]230 Point = Vector(0.,0.5,0.);
[e9c677]231 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
232
233 // simple test on x line
[1bd79e]234 Point = Vector(0.5,-1.,0.);
[d74077]235 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]236 Point = Vector(0.5,0.,0.);
[e9c677]237 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]238 Point = Vector(0.5,-6.,0.);
[d74077]239 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]240 Point = Vector(0.5,0.,0.);
[e9c677]241 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
242
243 // simple test on slanted line
[1bd79e]244 Point = Vector(1.,1.,0.);
[d74077]245 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]246 Point = Vector(0.5,0.5,0.);
[e9c677]247 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]248 Point = Vector(5.,5.,0.);
[d74077]249 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]250 Point = Vector(0.5,0.5,0.);
[e9c677]251 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
252
253 // simple test on first node
[1bd79e]254 Point = Vector(-1.,-1.,0.);
[d74077]255 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]256 Point = Vector(0.,0.,0.);
[e9c677]257 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
258
259 // simple test on second node
[1bd79e]260 Point = Vector(0.,2.,0.);
[d74077]261 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]262 Point = Vector(0.,1.,0.);
[e9c677]263 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
264
265 // simple test on third node
[1bd79e]266 Point = Vector(2.,0.,0.);
[d74077]267 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]268 Point = Vector(1.,0.,0.);
[e9c677]269 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
270};
271
272/** UnitTest for Tesselation::IsInnerPoint()
273 */
274void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
275{
276 Vector TestIntersection;
277 Vector Point;
278
279 // straight down/up
[1bd79e]280 Point = Vector(1./3.,1./3.,+5.);
[d74077]281 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]282 Point = Vector(1./3.,1./3.,0.);
[e9c677]283 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]284 Point = Vector(1./3.,1./3.,-5.);
[d74077]285 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]286 Point = Vector(1./3.,1./3.,0.);
[e9c677]287 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
288
289 // simple test on y line
[1bd79e]290 Point = Vector(-1.,0.5,+2.);
[d74077]291 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]292 Point = Vector(0.,0.5,0.);
[e9c677]293 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]294 Point = Vector(-1.,0.5,-3.);
[d74077]295 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]296 Point = Vector(0.,0.5,0.);
[e9c677]297 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
298
299 // simple test on x line
[1bd79e]300 Point = Vector(0.5,-1.,+1.);
[d74077]301 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]302 Point = Vector(0.5,0.,0.);
[e9c677]303 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]304 Point = Vector(0.5,-1.,-2.);
[d74077]305 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]306 Point = Vector(0.5,0.,0.);
[e9c677]307 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
308
309 // simple test on slanted line
[1bd79e]310 Point = Vector(1.,1.,+3.);
[d74077]311 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]312 Point = Vector(0.5,0.5,0.);
[e9c677]313 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
[1bd79e]314 Point = Vector(1.,1.,-4.);
[d74077]315 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]316 Point = Vector(0.5,0.5,0.);
[e9c677]317 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
318
319 // simple test on first node
[1bd79e]320 Point = Vector(-1.,-1.,5.);
[d74077]321 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]322 Point = Vector(0.,0.,0.);
[e9c677]323 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
324
325 // simple test on second node
[1bd79e]326 Point = Vector(0.,2.,5.);
[d74077]327 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]328 Point = Vector(0.,1.,0.);
[e9c677]329 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
330
331 // simple test on third node
[1bd79e]332 Point = Vector(2.,0.,5.);
[d74077]333 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
[1bd79e]334 Point = Vector(1.,0.,0.);
[e9c677]335 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
336};
Note: See TracBrowser for help on using the repository browser.