source: src/unittests/tesselation_insideoutsideunittest.cpp@ 13e3c3

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 13e3c3 was bf3817, checked in by Frederik Heber <heber@…>, 14 years ago

Added ifdef HAVE_CONFIG and config.h include to each and every cpp file.

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