source: src/unittests/tesselation_insideoutsideunittest.cpp@ 5ec8e3

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 5ec8e3 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: 5.4 KB
Line 
1/*
2 * tesselation_insideoutsideunittest.cpp
3 *
4 * Created on: Dec 28, 2009
5 * Author: heber
6 */
7
8using namespace std;
9
10#include <cppunit/CompilerOutputter.h>
11#include <cppunit/extensions/TestFactoryRegistry.h>
12#include <cppunit/ui/text/TestRunner.h>
13
14#include <cstring>
15
16#include "defs.hpp"
17#include "tesselation.hpp"
18#include "tesselation_insideoutsideunittest.hpp"
19
20#ifdef HAVE_TESTRUNNER
21#include "UnitTestMain.hpp"
22#endif /*HAVE_TESTRUNNER*/
23
24#define SPHERERADIUS 2.
25
26/********************************************** Test classes **************************************/
27
28// Registers the fixture into the 'registry'
29CPPUNIT_TEST_SUITE_REGISTRATION( TesselationInOutsideTest );
30
31
32void TesselationInOutsideTest::setUp()
33{
34 setVerbosity(2);
35
36 // create corners
37 class TesselPoint *Walker;
38 Walker = new TesselPoint;
39 Walker->node = new Vector(0., 0., 0.);
40 Walker->setName("1");
41 Walker->nr = 1;
42 Corners.push_back(Walker);
43 Walker = new TesselPoint;
44 Walker->node = new Vector(0., 1., 0.);
45 Walker->setName("2");
46 Walker->nr = 2;
47 Corners.push_back(Walker);
48 Walker = new TesselPoint;
49 Walker->node = new Vector(1., 0., 0.);
50 Walker->setName("3");
51 Walker->nr = 3;
52 Corners.push_back(Walker);
53 Walker = new TesselPoint;
54 Walker->node = new Vector(1., 1., 0.);
55 Walker->setName("4");
56 Walker->nr = 4;
57 Corners.push_back(Walker);
58 Walker = new TesselPoint;
59 Walker->node = new Vector(0., 0., 1.);
60 Walker->setName("5");
61 Walker->nr = 5;
62 Corners.push_back(Walker);
63 Walker = new TesselPoint;
64 Walker->node = new Vector(0., 1., 1.);
65 Walker->setName("6");
66 Walker->nr = 6;
67 Corners.push_back(Walker);
68 Walker = new TesselPoint;
69 Walker->node = new Vector(1., 0., 1.);
70 Walker->setName("7");
71 Walker->nr = 7;
72 Corners.push_back(Walker);
73 Walker = new TesselPoint;
74 Walker->node = new Vector(1., 1., 1.);
75 Walker->setName("8");
76 Walker->nr = 8;
77 Corners.push_back(Walker);
78
79 // create linkedcell
80 LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
81
82 // create tesselation
83 TesselStruct = new Tesselation;
84 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
85
86 CandidateForTesselation *baseline = NULL;
87 BoundaryTriangleSet *T = NULL;
88 bool OneLoopWithoutSuccessFlag = true;
89 bool TesselationFailFlag = false;
90 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
91 // 2a. fill all new OpenLines
92 DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl);
93 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
94 DoLog(2) && (Log() << Verbose(2) << *(Runner->second) << endl);
95
96 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
97 baseline = Runner->second;
98 if (baseline->pointlist.empty()) {
99 T = (((baseline->BaseLine->triangles.begin()))->second);
100 DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
101 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
102 }
103 }
104
105 // 2b. search for smallest ShortestAngle among all candidates
106 double ShortestAngle = 4.*M_PI;
107 DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl);
108 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
109 DoLog(2) && (Log() << Verbose(2) << *(Runner->second) << endl);
110
111 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
112 if (Runner->second->ShortestAngle < ShortestAngle) {
113 baseline = Runner->second;
114 ShortestAngle = baseline->ShortestAngle;
115 //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl;
116 }
117 }
118 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
119 OneLoopWithoutSuccessFlag = false;
120 else {
121 TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
122 }
123 }
124};
125
126
127void TesselationInOutsideTest::tearDown()
128{
129 delete(LinkedList);
130 delete(TesselStruct);
131 for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
132 delete((*Runner)->node);
133 delete(*Runner);
134 }
135 Corners.clear();
136 logger::purgeInstance();
137 errorLogger::purgeInstance();
138};
139
140/** UnitTest for Tesselation::IsInnerPoint()
141 */
142void TesselationInOutsideTest::IsInnerPointTest()
143{
144 double n[3];
145 const double boundary = 2.;
146 const double step = 1.;
147
148 // go through the mesh and check each point
149 for (n[0] = -boundary; n[0] <= boundary; n[0]+=step)
150 for (n[1] = -boundary; n[1] <= boundary; n[1]+=step)
151 for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) {
152 if ( ((n[0] >= 0.) && (n[1] >= 0.) && (n[2] >= 0.)) && ((n[0] <= 1.) && (n[1] <= 1.) && (n[2] <= 1.)))
153 CPPUNIT_ASSERT_EQUAL( true , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
154 else
155 CPPUNIT_ASSERT_EQUAL( false , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
156 }
157};
Note: See TracBrowser for help on using the repository browser.