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