[6393ff] | 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 |
|
---|
[2ccdf4] | 45 | // is declared in cpp module
|
---|
| 46 | void freeTesselPointSTLList(TesselPointSTLList &_Corners);
|
---|
| 47 |
|
---|
[6393ff] | 48 | /** UnitTest for getConnections()
|
---|
| 49 | */
|
---|
| 50 | template <int N>
|
---|
| 51 | void SphericalPointDistributionTest_assistant::getConnectionTest()
|
---|
| 52 | {
|
---|
| 53 | SphericalPointDistribution SPD(1.);
|
---|
| 54 | // get the points and convert into TesselPoint list
|
---|
| 55 | SphericalPointDistribution::Polygon_t newpolygon = SPD.get<N>();
|
---|
| 56 | TesselPointSTLList Corners;
|
---|
| 57 | SphericalPointDistribution::IndexList_t indices(N);
|
---|
| 58 | std::generate(indices.begin(), indices.end(), UniqueNumber);
|
---|
| 59 | std::transform(
|
---|
| 60 | newpolygon.begin(), newpolygon.end(),
|
---|
| 61 | indices.begin(),
|
---|
| 62 | std::back_inserter(Corners),
|
---|
| 63 | VectorToTesselPoint());
|
---|
| 64 |
|
---|
| 65 | // create the tesselation
|
---|
| 66 | const double SPHERERADIUS = 1.5;
|
---|
| 67 | Tesselation TesselStruct;
|
---|
| 68 | PointCloudAdaptor<TesselPointSTLList> cloud(&Corners, "TesselPointSTLList");
|
---|
| 69 | TesselStruct(cloud, SPHERERADIUS);
|
---|
| 70 |
|
---|
| 71 | // create a adjacency list from a tesselation of the (convex set of) points
|
---|
| 72 | SphericalPointDistribution::adjacency_t adjacency;
|
---|
| 73 | for (LineMap::const_iterator iter = TesselStruct.LinesOnBoundary.begin();
|
---|
| 74 | iter != TesselStruct.LinesOnBoundary.end(); ++iter) {
|
---|
| 75 | const BoundaryLineSet * const line = iter->second;
|
---|
| 76 | {
|
---|
| 77 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
---|
| 78 | adjacency.insert(
|
---|
| 79 | std::make_pair(
|
---|
| 80 | line->endpoints[0]->Nr,
|
---|
| 81 | SphericalPointDistribution::IndexSet_t() ));
|
---|
| 82 | inserter.first->second.insert(line->endpoints[1]->Nr);
|
---|
| 83 | LOG(6, "DEBUG: Inserting " << line->endpoints[0]->Nr << "," << line->endpoints[1]->Nr);
|
---|
| 84 | }
|
---|
| 85 | {
|
---|
| 86 | std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter =
|
---|
| 87 | adjacency.insert(
|
---|
| 88 | std::make_pair(
|
---|
| 89 | line->endpoints[1]->Nr,
|
---|
| 90 | SphericalPointDistribution::IndexSet_t() ));
|
---|
| 91 | inserter.first->second.insert(line->endpoints[0]->Nr);
|
---|
| 92 | LOG(6, "DEBUG: Inserting " << line->endpoints[1]->Nr << "," << line->endpoints[0]->Nr);
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
[2ccdf4] | 96 | // free allocated TesselPoints
|
---|
| 97 | freeTesselPointSTLList(Corners);
|
---|
| 98 |
|
---|
[6393ff] | 99 | // get the implemented connections
|
---|
| 100 | SphericalPointDistribution::adjacency_t expected =
|
---|
| 101 | SPD.getConnections<N>();
|
---|
| 102 |
|
---|
| 103 | // // print the map: for debugging and extracting the edges for getConnections()
|
---|
| 104 | // std::cout << "\tadjacency_t adjacency;" << std::endl;
|
---|
| 105 | // for (SphericalPointDistribution::adjacency_t::const_iterator iter = adjacency.begin();
|
---|
| 106 | // iter != adjacency.end(); ++iter) {
|
---|
| 107 | // std::cout << "\tadjacency += make_pair<unsigned int, IndexSet_t >( "
|
---|
| 108 | // << iter->first << ", list_of<unsigned int>";
|
---|
| 109 | // for (SphericalPointDistribution::IndexSet_t::const_iterator indexiter = iter->second.begin();
|
---|
| 110 | // indexiter != iter->second.end(); ++indexiter)
|
---|
| 111 | // std::cout << "(" << *indexiter << ")";
|
---|
| 112 | // std::cout << " );" << std::endl;
|
---|
| 113 | // }
|
---|
| 114 |
|
---|
| 115 | // and compare the two
|
---|
| 116 | CPPUNIT_ASSERT_EQUAL( expected, adjacency );
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | #endif /* SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_ */
|
---|