1 | /*
|
---|
2 | * tesselation_insideoutsideunittest.cpp
|
---|
3 | *
|
---|
4 | * Created on: Dec 28, 2009
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 | #include <cppunit/CompilerOutputter.h>
|
---|
11 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
12 | #include <cppunit/ui/text/TestRunner.h>
|
---|
13 |
|
---|
14 | #include "defs.hpp"
|
---|
15 | #include "tesselation.hpp"
|
---|
16 | #include "tesselation_insideoutsideunittest.hpp"
|
---|
17 |
|
---|
18 | #define SPHERERADIUS 2.
|
---|
19 |
|
---|
20 | /********************************************** Test classes **************************************/
|
---|
21 |
|
---|
22 | // Registers the fixture into the 'registry'
|
---|
23 | CPPUNIT_TEST_SUITE_REGISTRATION( TesselationInOutsideTest );
|
---|
24 |
|
---|
25 |
|
---|
26 | void TesselationInOutsideTest::setUp()
|
---|
27 | {
|
---|
28 | setVerbosity(5);
|
---|
29 |
|
---|
30 | // create corners
|
---|
31 | class TesselPoint *Walker;
|
---|
32 | Walker = new TesselPoint;
|
---|
33 | Walker->node = new Vector(0., 0., 0.);
|
---|
34 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
35 | strcpy(Walker->Name, "1");
|
---|
36 | Walker->nr = 1;
|
---|
37 | Corners.push_back(Walker);
|
---|
38 | Walker = new TesselPoint;
|
---|
39 | Walker->node = new Vector(0., 1., 0.);
|
---|
40 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
41 | strcpy(Walker->Name, "2");
|
---|
42 | Walker->nr = 2;
|
---|
43 | Corners.push_back(Walker);
|
---|
44 | Walker = new TesselPoint;
|
---|
45 | Walker->node = new Vector(1., 0., 0.);
|
---|
46 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
47 | strcpy(Walker->Name, "3");
|
---|
48 | Walker->nr = 3;
|
---|
49 | Corners.push_back(Walker);
|
---|
50 | Walker = new TesselPoint;
|
---|
51 | Walker->node = new Vector(1., 1., 0.);
|
---|
52 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
53 | strcpy(Walker->Name, "4");
|
---|
54 | Walker->nr = 4;
|
---|
55 | Corners.push_back(Walker);
|
---|
56 | Walker = new TesselPoint;
|
---|
57 | Walker->node = new Vector(0., 0., 1.);
|
---|
58 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
59 | strcpy(Walker->Name, "5");
|
---|
60 | Walker->nr = 5;
|
---|
61 | Corners.push_back(Walker);
|
---|
62 | Walker = new TesselPoint;
|
---|
63 | Walker->node = new Vector(0., 1., 1.);
|
---|
64 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
65 | strcpy(Walker->Name, "6");
|
---|
66 | Walker->nr = 6;
|
---|
67 | Corners.push_back(Walker);
|
---|
68 | Walker = new TesselPoint;
|
---|
69 | Walker->node = new Vector(1., 0., 1.);
|
---|
70 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
71 | strcpy(Walker->Name, "7");
|
---|
72 | Walker->nr = 7;
|
---|
73 | Corners.push_back(Walker);
|
---|
74 | Walker = new TesselPoint;
|
---|
75 | Walker->node = new Vector(1., 1., 1.);
|
---|
76 | Walker->Name = Malloc<char>(3, "TesselationInOutsideTest::setUp - *Name");
|
---|
77 | strcpy(Walker->Name, "8");
|
---|
78 | Walker->nr = 8;
|
---|
79 | Corners.push_back(Walker);
|
---|
80 |
|
---|
81 | // create linkedcell
|
---|
82 | LinkedList = new LinkedCell(&Corners, 2.*SPHERERADIUS);
|
---|
83 |
|
---|
84 | // create tesselation
|
---|
85 | TesselStruct = new Tesselation;
|
---|
86 | TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
|
---|
87 |
|
---|
88 | CandidateForTesselation *baseline = NULL;
|
---|
89 | BoundaryTriangleSet *T = NULL;
|
---|
90 | bool OneLoopWithoutSuccessFlag = true;
|
---|
91 | bool TesselationFailFlag = false;
|
---|
92 | while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
|
---|
93 | // 2a. fill all new OpenLines
|
---|
94 | Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl;
|
---|
95 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
|
---|
96 | Log() << Verbose(2) << *(Runner->second) << endl;
|
---|
97 |
|
---|
98 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
99 | baseline = Runner->second;
|
---|
100 | if (baseline->pointlist.empty()) {
|
---|
101 | T = (((baseline->BaseLine->triangles.begin()))->second);
|
---|
102 | Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl;
|
---|
103 | TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | // 2b. search for smallest ShortestAngle among all candidates
|
---|
108 | double ShortestAngle = 4.*M_PI;
|
---|
109 | Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl;
|
---|
110 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
|
---|
111 | Log() << Verbose(2) << *(Runner->second) << endl;
|
---|
112 |
|
---|
113 | for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
|
---|
114 | if (Runner->second->ShortestAngle < ShortestAngle) {
|
---|
115 | baseline = Runner->second;
|
---|
116 | ShortestAngle = baseline->ShortestAngle;
|
---|
117 | //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl;
|
---|
118 | }
|
---|
119 | }
|
---|
120 | if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
|
---|
121 | OneLoopWithoutSuccessFlag = false;
|
---|
122 | else {
|
---|
123 | TesselStruct->AddCandidateTriangle(*baseline);
|
---|
124 | }
|
---|
125 | }
|
---|
126 | };
|
---|
127 |
|
---|
128 |
|
---|
129 | void TesselationInOutsideTest::tearDown()
|
---|
130 | {
|
---|
131 | delete(LinkedList);
|
---|
132 | delete(TesselStruct);
|
---|
133 | for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
|
---|
134 | delete((*Runner)->node);
|
---|
135 | delete(*Runner);
|
---|
136 | }
|
---|
137 | Corners.clear();
|
---|
138 | MemoryUsageObserver::purgeInstance();
|
---|
139 | logger::purgeInstance();
|
---|
140 | errorLogger::purgeInstance();
|
---|
141 | };
|
---|
142 |
|
---|
143 | /** UnitTest for Tesselation::IsInnerPoint()
|
---|
144 | */
|
---|
145 | void TesselationInOutsideTest::IsInnerPointTest()
|
---|
146 | {
|
---|
147 | double n[3];
|
---|
148 | const double boundary = 2.;
|
---|
149 | const double step = 1.;
|
---|
150 |
|
---|
151 | // go through the mesh and check each point
|
---|
152 | for (n[0] = -boundary; n[0] <= boundary; n[0]+=step)
|
---|
153 | for (n[1] = -boundary; n[1] <= boundary; n[1]+=step)
|
---|
154 | for (n[2] = -boundary; n[2] <= boundary; n[2]+=step) {
|
---|
155 | if ( ((n[0] >= 0.) && (n[1] >= 0.) && (n[2] >= 0.)) && (fabs(n[0])+fabs(n[1])+fabs(n[2]) <= 1.))
|
---|
156 | CPPUNIT_ASSERT_EQUAL( true , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
|
---|
157 | else
|
---|
158 | CPPUNIT_ASSERT_EQUAL( false , TesselStruct->IsInnerPoint(Vector(n[0], n[1], n[2]), LinkedList) );
|
---|
159 | }
|
---|
160 | };
|
---|
161 |
|
---|
162 | /********************************************** Main routine **************************************/
|
---|
163 |
|
---|
164 | int main(int argc, char **argv)
|
---|
165 | {
|
---|
166 | // Get the top level suite from the registry
|
---|
167 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest();
|
---|
168 |
|
---|
169 | // Adds the test to the list of test to run
|
---|
170 | CppUnit::TextUi::TestRunner runner;
|
---|
171 | runner.addTest( suite );
|
---|
172 |
|
---|
173 | // Change the default outputter to a compiler error format outputter
|
---|
174 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(),
|
---|
175 | std::cerr ) );
|
---|
176 | // Run the tests.
|
---|
177 | bool wasSucessful = runner.run();
|
---|
178 |
|
---|
179 | // Return error code 1 if the one of test failed.
|
---|
180 | return wasSucessful ? 0 : 1;
|
---|
181 | };
|
---|