source: src/unittests/tesselationunittest.cpp@ 4c1230

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 4c1230 was e4fe8d, checked in by Frederik Heber <heber@…>, 14 years ago

Moved defs.?pp to subdir (and library) Helpers.

  • hence, include had to be changed to Helpers/defs.hpp
  • and Makefile.am and Helpers/Makefile.am adapted
  • also in LinearAlgebra where MYEPSILON appears we have added the above include
  • Property mode set to 100644
File size: 6.8 KB
Line 
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 * tesselationunittest.cpp
10 *
11 * Created on: Aug 26, 2009
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
28#include "Helpers/defs.hpp"
29#include "TesselPoint.hpp"
30#include "BoundaryLineSet.hpp"
31#include "BoundaryTriangleSet.hpp"
32#include "CandidateForTesselation.hpp"
33#include "tesselationunittest.hpp"
34
35#ifdef HAVE_TESTRUNNER
36#include "UnitTestMain.hpp"
37#endif /*HAVE_TESTRUNNER*/
38
39const double TesselationTest::SPHERERADIUS=2.;
40
41/********************************************** Test classes **************************************/
42
43// Registers the fixture into the 'registry'
44CPPUNIT_TEST_SUITE_REGISTRATION( TesselationTest );
45
46
47void TesselationTest::setUp()
48{
49 // create corners
50 class TesselPoint *Walker;
51 Walker = new TesselPoint;
52 Walker->setPosition(Vector(1., 0., -1.));
53 Walker->setName("1");
54 Walker->nr = 1;
55 Corners.push_back(Walker);
56 Walker = new TesselPoint;
57 Walker->setPosition(Vector(-1., 1., -1.));
58 Walker->setName("2");
59 Walker->nr = 2;
60 Corners.push_back(Walker);
61 Walker = new TesselPoint;
62 Walker->setPosition(Vector(-1., -1., -1.));
63 Walker->setName("3");
64 Walker->nr = 3;
65 Corners.push_back(Walker);
66 Walker = new TesselPoint;
67 Walker->setPosition(Vector(-1., 0., 1.));
68 Walker->setName("4");
69 Walker->nr = 4;
70 Corners.push_back(Walker);
71
72 // create linkedcell
73 LinkedList = new LinkedCell(Corners, 2.*SPHERERADIUS);
74
75 // create tesselation
76 TesselStruct = new Tesselation;
77 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
78 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
79 CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
80 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
81
82 CandidateForTesselation *baseline = NULL;
83 BoundaryTriangleSet *T = NULL;
84 bool OneLoopWithoutSuccessFlag = true;
85 bool TesselationFailFlag = false;
86 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
87 // 2a. fill all new OpenLines
88 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
89 baseline = Runner->second;
90 if (baseline->pointlist.empty()) {
91 T = (((baseline->BaseLine->triangles.begin()))->second);
92 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
93 }
94 }
95
96 // 2b. search for smallest ShortestAngle among all candidates
97 double ShortestAngle = 4.*M_PI;
98 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
99 if (Runner->second->ShortestAngle < ShortestAngle) {
100 baseline = Runner->second;
101 ShortestAngle = baseline->ShortestAngle;
102 }
103 }
104 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
105 OneLoopWithoutSuccessFlag = false;
106 else {
107 TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
108 }
109 }
110};
111
112
113void TesselationTest::tearDown()
114{
115 delete(LinkedList);
116 delete(TesselStruct);
117 for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
118 delete(*Runner);
119 Corners.clear();
120 logger::purgeInstance();
121 errorLogger::purgeInstance();
122};
123
124/** UnitTest for Contains...()
125 *
126 */
127void TesselationTest::ContainmentTest()
128{
129 class BoundaryPointSet *point = NULL;
130 class BoundaryLineSet *line = NULL;
131
132 // check ContainsBoundaryPoint
133 for(LineMap::iterator Runner = TesselStruct->LinesOnBoundary.begin(); Runner != TesselStruct->LinesOnBoundary.end(); Runner++) {
134 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
135 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
136 }
137 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
138 for(PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
139 point = PointRunner->second;
140 for (int i=0;i<3;i++)
141 if (point == (Runner->second)->endpoints[i])
142 point = NULL;
143 if (point != NULL)
144 break;
145 }
146 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[0]));
147 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[1]));
148 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryPoint((Runner->second)->endpoints[2]));
149 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryPoint(point));
150 }
151
152 // check ContainsBoundaryLine
153 for(TriangleMap::iterator Runner = TesselStruct->TrianglesOnBoundary.begin(); Runner != TesselStruct->TrianglesOnBoundary.end(); Runner++) {
154 for(LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
155 line = LineRunner->second;
156 for (int i=0;i<3;i++)
157 if (line == (Runner->second)->lines[i])
158 line = NULL;
159 if (line != NULL)
160 break;
161 }
162 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[0]));
163 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[1]));
164 CPPUNIT_ASSERT_EQUAL( true, (Runner->second)->ContainsBoundaryLine((Runner->second)->lines[2]));
165 CPPUNIT_ASSERT_EQUAL( false, (Runner->second)->ContainsBoundaryLine(line));
166 }
167
168 // check IsPresentTupel
169 CPPUNIT_ASSERT_EQUAL( true, true );
170}
171
172/** UnitTest for Tesselation::GetAllTriangles()
173 *
174 */
175void TesselationTest::GetAllTrianglesTest()
176{
177 class BoundaryPointSet *Walker = NULL;
178
179 // check that there are three adjacent triangles for every boundary point
180 for (PointMap::iterator Runner = TesselStruct->PointsOnBoundary.begin(); Runner != TesselStruct->PointsOnBoundary.end(); Runner++) {
181 Walker = Runner->second;
182 set<BoundaryTriangleSet*> *triangles = TesselStruct->GetAllTriangles(Walker);
183 CPPUNIT_ASSERT_EQUAL( (size_t)3, triangles->size() );
184 // check that the returned triangle all contain the Walker
185 for (set<BoundaryTriangleSet*>::iterator TriangleRunner = triangles->begin(); TriangleRunner != triangles->end(); TriangleRunner++)
186 CPPUNIT_ASSERT_EQUAL( true, (*TriangleRunner)->ContainsBoundaryPoint(Walker) );
187 delete(triangles);
188 }
189}
Note: See TracBrowser for help on using the repository browser.