source: src/Tesselation/unittests/Tesselation_BoundaryTriangleUnitTest.cpp@ 2a0271

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 2a0271 was 0aa122, checked in by Frederik Heber <heber@…>, 13 years ago

Updated all source files's copyright note to current year 2012.

  • Property mode set to 100644
File size: 7.4 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 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
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>
27#include <iostream>
28
29#include "CodePatterns/Log.hpp"
30#include "Helpers/defs.hpp"
31#include "Atom/TesselPoint.hpp"
32#include "Tesselation/BoundaryPointSet.hpp"
33#include "Tesselation/BoundaryLineSet.hpp"
34#include "Tesselation/BoundaryTriangleSet.hpp"
35#include "Tesselation/CandidateForTesselation.hpp"
36
37#include "Tesselation_BoundaryTriangleUnitTest.hpp"
38
39#ifdef HAVE_TESTRUNNER
40#include "UnitTestMain.hpp"
41#endif /*HAVE_TESTRUNNER*/
42
43const double TesselationBoundaryTriangleTest::SPHERERADIUS=2.;
44
45/********************************************** Test classes **************************************/
46
47// Registers the fixture into the 'registry'
48CPPUNIT_TEST_SUITE_REGISTRATION( TesselationBoundaryTriangleTest );
49
50
51void TesselationBoundaryTriangleTest::setUp()
52{
53 setVerbosity(5);
54
55 // create nodes
56 tesselpoints[0] = new TesselPoint;
57 tesselpoints[0]->setPosition(Vector(0., 0., 0.));
58 tesselpoints[0]->setName("1");
59 tesselpoints[0]->setNr(1);
60 points[0] = new BoundaryPointSet(tesselpoints[0]);
61 tesselpoints[1] = new TesselPoint;
62 tesselpoints[1]->setPosition(Vector(0., 1., 0.));
63 tesselpoints[1]->setName("2");
64 tesselpoints[1]->setNr(2);
65 points[1] = new BoundaryPointSet(tesselpoints[1]);
66 tesselpoints[2] = new TesselPoint;
67 tesselpoints[2]->setPosition(Vector(1., 0., 0.));
68 tesselpoints[2]->setName("3");
69 tesselpoints[2]->setNr(3);
70 points[2] = new BoundaryPointSet(tesselpoints[2] );
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
83void TesselationBoundaryTriangleTest::tearDown()
84{
85 delete(triangle);
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 }
90 logger::purgeInstance();
91 errorLogger::purgeInstance();
92};
93
94/** UnitTest for Tesselation::IsInnerPoint()
95 */
96void TesselationBoundaryTriangleTest::GetClosestPointOnPlaneTest()
97{
98 Vector TestIntersection;
99 Vector Point;
100
101 // simple test on y line
102 Point = Vector(-1.,0.5,0.);
103 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
104 Point = Vector(0.,0.5,0.);
105 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
106 Point = Vector(-4.,0.5,0.);
107 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
108 Point = Vector(0.,0.5,0.);
109 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
110
111 // simple test on x line
112 Point = Vector(0.5,-1.,0.);
113 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
114 Point = Vector(0.5,0.,0.);
115 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
116 Point = Vector(0.5,-6.,0.);
117 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
118 Point = Vector(0.5,0.,0.);
119 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
120
121 // simple test on slanted line
122 Point = Vector(1.,1.,0.);
123 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
124 Point = Vector(0.5,0.5,0.);
125 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
126 Point = Vector(5.,5.,0.);
127 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
128 Point = Vector(0.5,0.5,0.);
129 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
130
131 // simple test on first node
132 Point = Vector(-1.,-1.,0.);
133 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
134 Point = Vector(0.,0.,0.);
135 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
136
137 // simple test on second node
138 Point = Vector(0.,2.,0.);
139 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
140 Point = Vector(0.,1.,0.);
141 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
142
143 // simple test on third node
144 Point = Vector(2.,0.,0.);
145 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
146 Point = Vector(1.,0.,0.);
147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
148};
149
150/** UnitTest for Tesselation::IsInnerPoint()
151 */
152void TesselationBoundaryTriangleTest::GetClosestPointOffPlaneTest()
153{
154 Vector TestIntersection;
155 Vector Point;
156
157 // straight down/up
158 Point = Vector(1./3.,1./3.,+5.);
159 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
160 Point = Vector(1./3.,1./3.,0.);
161 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
162 Point = Vector(1./3.,1./3.,-5.);
163 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
164 Point = Vector(1./3.,1./3.,0.);
165 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
166
167 // simple test on y line
168 Point = Vector(-1.,0.5,+2.);
169 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
170 Point = Vector(0.,0.5,0.);
171 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
172 Point = Vector(-1.,0.5,-3.);
173 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
174 Point = Vector(0.,0.5,0.);
175 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
176
177 // simple test on x line
178 Point = Vector(0.5,-1.,+1.);
179 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
180 Point = Vector(0.5,0.,0.);
181 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
182 Point = Vector(0.5,-1.,-2.);
183 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
184 Point = Vector(0.5,0.,0.);
185 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
186
187 // simple test on slanted line
188 Point = Vector(1.,1.,+3.);
189 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
190 Point = Vector(0.5,0.5,0.);
191 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
192 Point = Vector(1.,1.,-4.);
193 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
194 Point = Vector(0.5,0.5,0.);
195 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
196
197 // simple test on first node
198 Point = Vector(-1.,-1.,5.);
199 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
200 Point = Vector(0.,0.,0.);
201 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
202
203 // simple test on second node
204 Point = Vector(0.,2.,5.);
205 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
206 Point = Vector(0.,1.,0.);
207 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
208
209 // simple test on third node
210 Point = Vector(2.,0.,5.);
211 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(Point, TestIntersection) );
212 Point = Vector(1.,0.,0.);
213 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection );
214};
Note: See TracBrowser for help on using the repository browser.