source: src/unittests/Tesselation_InsideOutsideUnitTest.cpp@ 72d108

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 72d108 was ad011c, checked in by Frederik Heber <heber@…>, 14 years ago

CodePatterns places all includes now in subfolder CodePatterns/.

  • change all includes accordingly.
  • this was necessary as Helpers and Patterns are not very distinctive names for include folders. Already now, we had a conflict between Helpers from CodePatterns and Helpers from this project.
  • changed compilation test in ax_codepatterns.m4 when changing CodePatterns includes.
  • Property mode set to 100644
File size: 5.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 * Tesselation_InsideOutsideUnitTest.cpp
10 *
11 * Created on: Dec 28, 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#include <iostream>
28
29#include "Helpers/defs.hpp"
30#include "TesselPoint.hpp"
31#include "BoundaryLineSet.hpp"
32#include "BoundaryTriangleSet.hpp"
33#include "CandidateForTesselation.hpp"
34#include "CodePatterns/Verbose.hpp"
35
36#include "Tesselation_InsideOutsideUnitTest.hpp"
37
38#ifdef HAVE_TESTRUNNER
39#include "UnitTestMain.hpp"
40#endif /*HAVE_TESTRUNNER*/
41
42const double TesselationInOutsideTest::SPHERERADIUS=2.;
43
44/********************************************** Test classes **************************************/
45
46// Registers the fixture into the 'registry'
47CPPUNIT_TEST_SUITE_REGISTRATION( TesselationInOutsideTest );
48
49void TesselationInOutsideTest::setUp()
50{
51 setVerbosity(2);
52
53 // create corners
54 class TesselPoint *Walker;
55 Walker = new TesselPoint;
56 Walker->setPosition(Vector(0., 0., 0.));
57 Walker->setName("1");
58 Walker->nr = 1;
59 Corners.push_back(Walker);
60 Walker = new TesselPoint;
61 Walker->setPosition(Vector(0., 1., 0.));
62 Walker->setName("2");
63 Walker->nr = 2;
64 Corners.push_back(Walker);
65 Walker = new TesselPoint;
66 Walker->setPosition(Vector(1., 0., 0.));
67 Walker->setName("3");
68 Walker->nr = 3;
69 Corners.push_back(Walker);
70 Walker = new TesselPoint;
71 Walker->setPosition(Vector(1., 1., 0.));
72 Walker->setName("4");
73 Walker->nr = 4;
74 Corners.push_back(Walker);
75 Walker = new TesselPoint;
76 Walker->setPosition(Vector(0., 0., 1.));
77 Walker->setName("5");
78 Walker->nr = 5;
79 Corners.push_back(Walker);
80 Walker = new TesselPoint;
81 Walker->setPosition(Vector(0., 1., 1.));
82 Walker->setName("6");
83 Walker->nr = 6;
84 Corners.push_back(Walker);
85 Walker = new TesselPoint;
86 Walker->setPosition(Vector(1., 0., 1.));
87 Walker->setName("7");
88 Walker->nr = 7;
89 Corners.push_back(Walker);
90 Walker = new TesselPoint;
91 Walker->setPosition(Vector(1., 1., 1.));
92 Walker->setName("8");
93 Walker->nr = 8;
94 Corners.push_back(Walker);
95
96 // create linkedcell
97 LinkedList = new LinkedCell(Corners, 2.*SPHERERADIUS);
98
99 // create tesselation
100 TesselStruct = new Tesselation;
101 TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
102
103 CandidateForTesselation *baseline = NULL;
104 BoundaryTriangleSet *T = NULL;
105 bool OneLoopWithoutSuccessFlag = true;
106 bool TesselationFailFlag = false;
107 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
108 // 2a. fill all new OpenLines
109 DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl);
110 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
111 DoLog(2) && (Log() << Verbose(2) << *(Runner->second) << endl);
112
113 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
114 baseline = Runner->second;
115 if (baseline->pointlist.empty()) {
116 T = (((baseline->BaseLine->triangles.begin()))->second);
117 DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
118 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
119 }
120 }
121
122 // 2b. search for smallest ShortestAngle among all candidates
123 double ShortestAngle = 4.*M_PI;
124 DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl);
125 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
126 DoLog(2) && (Log() << Verbose(2) << *(Runner->second) << endl);
127
128 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
129 if (Runner->second->ShortestAngle < ShortestAngle) {
130 baseline = Runner->second;
131 ShortestAngle = baseline->ShortestAngle;
132 //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl;
133 }
134 }
135 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
136 OneLoopWithoutSuccessFlag = false;
137 else {
138 TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
139 }
140 }
141};
142
143
144void TesselationInOutsideTest::tearDown()
145{
146 delete(LinkedList);
147 delete(TesselStruct);
148 for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
149 delete(*Runner);
150 Corners.clear();
151 logger::purgeInstance();
152 errorLogger::purgeInstance();
153};
154
155/** UnitTest for Tesselation::IsInnerPoint()
156 */
157void TesselationInOutsideTest::IsInnerPointTest()
158{
159 double n[3];
160 const double boundary = 2.;
161 const double step = 1.;
162
163 // go through the mesh and check each point
164 for (n[0] = -boundary; n[0] <= boundary; n[0]+=step)
165 for (n[1] = -boundary; n[1] <= boundary; n[1]+=step)
166 for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) {
167 if ( ((n[0] >= 0.) && (n[1] >= 0.) && (n[2] >= 0.)) && ((n[0] <= 1.) && (n[1] <= 1.) && (n[2] <= 1.)))
168 CPPUNIT_ASSERT_EQUAL( true , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
169 else
170 CPPUNIT_ASSERT_EQUAL( false , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
171 }
172};
Note: See TracBrowser for help on using the repository browser.