source: src/unittests/tesselationunittest.cpp@ 986ed3

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 986ed3 was 920c70, checked in by Frederik Heber <heber@…>, 15 years ago

Removed all Malloc/Calloc/ReAlloc (&Free) and replaced by new and delete/delete[].

Due to the new MemDebug framework there is no need (or even unnecessary/unwanted competition between it and) for the MemoryAllocator and ..UsageObserver anymore.
They can however still be used with c codes such as pcp and alikes.

In Molecuilder lots of glibc corruptions arose and the C-like syntax make it generally harder to get allocation and deallocation straight.

Signed-off-by: Frederik Heber <heber@…>

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