1 | /*
|
---|
2 | * SphericalPointDistribution_assistant.hpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 12, 2014
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_
|
---|
9 | #define SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include "SphericalPointDistributionUnitTest.hpp"
|
---|
17 |
|
---|
18 | #include "CodePatterns/Log.hpp"
|
---|
19 |
|
---|
20 | #include "Atom/TesselPoint.hpp"
|
---|
21 | #include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
|
---|
22 | #include "LinkedCell/linkedcell.hpp"
|
---|
23 | #include "LinkedCell/PointCloudAdaptor.hpp"
|
---|
24 | #include "Tesselation/BoundaryLineSet.hpp"
|
---|
25 | #include "Tesselation/tesselation.hpp"
|
---|
26 |
|
---|
27 |
|
---|
28 | // class generator: taken from www.cplusplus.com example std::generate
|
---|
29 | struct c_unique {
|
---|
30 | unsigned int current;
|
---|
31 | c_unique() {current=0;}
|
---|
32 | unsigned int operator()() {return current++;}
|
---|
33 | } UniqueNumber;
|
---|
34 |
|
---|
35 | struct VectorToTesselPoint
|
---|
36 | {
|
---|
37 | TesselPoint * operator()(const Vector &_v, const unsigned int _index) {
|
---|
38 | TesselPoint *t = new TesselPoint();
|
---|
39 | t->setPosition(_v);
|
---|
40 | t->setNr(_index);
|
---|
41 | return t;
|
---|
42 | }
|
---|
43 | };
|
---|
44 |
|
---|
45 | /** UnitTest for getConnections()
|
---|
46 | */
|
---|
47 | template <int N>
|
---|
48 | void SphericalPointDistributionTest_assistant::getConnectionTest()
|
---|
49 | {
|
---|
50 | SphericalPointDistribution SPD(1.);
|
---|
51 | // get the points and convert into TesselPoint list
|
---|
52 | SphericalPointDistribution::Polygon_t newpolygon = SPD.get<N>();
|
---|
53 | TesselPointSTLList Corners;
|
---|
54 | SphericalPointDistribution::IndexList_t indices(N);
|
---|
55 | std::generate(indices.begin(), indices.end(), UniqueNumber);
|
---|
56 | std::transform(
|
---|
57 | newpolygon.begin(), newpolygon.end(),
|
---|
58 | indices.begin(),
|
---|
59 | std::back_inserter(Corners),
|
---|
60 | VectorToTesselPoint());
|
---|
61 |
|
---|
62 | // create the tesselation
|
---|
63 | const double SPHERERADIUS = 1.5;
|
---|
64 | Tesselation TesselStruct;
|
---|
65 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
|
---|
66 | TesselStruct(cloud, SPHERERADIUS);
|
---|
67 |
|
---|
68 | // create a adjacency list from a tesselation of the (convex set of) points
|
---|
69 | SphericalPointDistribution::adjacency_t adjacency;
|
---|
70 | for (LineMap::const_iterator iter = TesselStruct.LinesOnBoundary.begin();
|
---|
71 | iter != TesselStruct.LinesOnBoundary.end(); ++iter) {
|
---|
72 | const BoundaryLineSet * const line = iter->second;
|
---|
73 | {
|
---|
74 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
---|
75 | adjacency.insert(
|
---|
76 | std::make_pair(
|
---|
77 | line->endpoints[0]->Nr,
|
---|
78 | SphericalPointDistribution::IndexSet_t() ));
|
---|
79 | inserter.first->second.insert(line->endpoints[1]->Nr);
|
---|
80 | LOG(6, "DEBUG: Inserting " << line->endpoints[0]->Nr << "," << line->endpoints[1]->Nr);
|
---|
81 | }
|
---|
82 | {
|
---|
83 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
---|
84 | adjacency.insert(
|
---|
85 | std::make_pair(
|
---|
86 | line->endpoints[1]->Nr,
|
---|
87 | SphericalPointDistribution::IndexSet_t() ));
|
---|
88 | inserter.first->second.insert(line->endpoints[0]->Nr);
|
---|
89 | LOG(6, "DEBUG: Inserting " << line->endpoints[1]->Nr << "," << line->endpoints[0]->Nr);
|
---|
90 | }
|
---|
91 | }
|
---|
92 |
|
---|
93 | // get the implemented connections
|
---|
94 | SphericalPointDistribution::adjacency_t expected =
|
---|
95 | SPD.getConnections<N>();
|
---|
96 |
|
---|
97 | // // print the map: for debugging and extracting the edges for getConnections()
|
---|
98 | // std::cout << "\tadjacency_t adjacency;" << std::endl;
|
---|
99 | // for (SphericalPointDistribution::adjacency_t::const_iterator iter = adjacency.begin();
|
---|
100 | // iter != adjacency.end(); ++iter) {
|
---|
101 | // std::cout << "\tadjacency += make_pair<unsigned int, IndexSet_t >( "
|
---|
102 | // << iter->first << ", list_of<unsigned int>";
|
---|
103 | // for (SphericalPointDistribution::IndexSet_t::const_iterator indexiter = iter->second.begin();
|
---|
104 | // indexiter != iter->second.end(); ++indexiter)
|
---|
105 | // std::cout << "(" << *indexiter << ")";
|
---|
106 | // std::cout << " );" << std::endl;
|
---|
107 | // }
|
---|
108 |
|
---|
109 | // and compare the two
|
---|
110 | CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
---|
111 | }
|
---|
112 |
|
---|
113 |
|
---|
114 | #endif /* SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_ */
|
---|