source: src/unittests/Tesselation_InsideOutsideUnitTest.cpp@ 5702cdb

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 5702cdb was caa06ef, checked in by Frederik Heber <heber@…>, 14 years ago

Added name to PointCloudAdaptor, set by constructor.

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