/* * SphericalPointDistribution_assistant.hpp * * Created on: Jul 12, 2014 * Author: heber */ #ifndef SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_ #define SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "SphericalPointDistributionUnitTest.hpp" #include "CodePatterns/Log.hpp" #include "Atom/TesselPoint.hpp" #include "Fragmentation/Exporters/SphericalPointDistribution.hpp" #include "LinkedCell/linkedcell.hpp" #include "LinkedCell/PointCloudAdaptor.hpp" #include "Tesselation/BoundaryLineSet.hpp" #include "Tesselation/tesselation.hpp" // class generator: taken from www.cplusplus.com example std::generate struct c_unique { unsigned int current; c_unique() {current=0;} unsigned int operator()() {return current++;} } UniqueNumber; struct VectorToTesselPoint { TesselPoint * operator()(const Vector &_v, const unsigned int _index) { TesselPoint *t = new TesselPoint(); t->setPosition(_v); t->setNr(_index); return t; } }; // is declared in cpp module void freeTesselPointSTLList(TesselPointSTLList &_Corners); /** UnitTest for getConnections() */ template void SphericalPointDistributionTest_assistant::getConnectionTest() { SphericalPointDistribution SPD(1.); // get the points and convert into TesselPoint list SphericalPointDistribution::Polygon_t newpolygon = SPD.get(); TesselPointSTLList Corners; SphericalPointDistribution::IndexList_t indices(N); std::generate(indices.begin(), indices.end(), UniqueNumber); std::transform( newpolygon.begin(), newpolygon.end(), indices.begin(), std::back_inserter(Corners), VectorToTesselPoint()); // create the tesselation const double SPHERERADIUS = 1.5; Tesselation TesselStruct; PointCloudAdaptor cloud(&Corners, "TesselPointSTLList"); TesselStruct(cloud, SPHERERADIUS); // create a adjacency list from a tesselation of the (convex set of) points SphericalPointDistribution::adjacency_t adjacency; for (LineMap::const_iterator iter = TesselStruct.LinesOnBoundary.begin(); iter != TesselStruct.LinesOnBoundary.end(); ++iter) { const BoundaryLineSet * const line = iter->second; { std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter = adjacency.insert( std::make_pair( line->endpoints[0]->Nr, SphericalPointDistribution::IndexSet_t() )); inserter.first->second.insert(line->endpoints[1]->Nr); LOG(6, "DEBUG: Inserting " << line->endpoints[0]->Nr << "," << line->endpoints[1]->Nr); } { std::pair< SphericalPointDistribution::adjacency_t::iterator, bool > inserter = adjacency.insert( std::make_pair( line->endpoints[1]->Nr, SphericalPointDistribution::IndexSet_t() )); inserter.first->second.insert(line->endpoints[0]->Nr); LOG(6, "DEBUG: Inserting " << line->endpoints[1]->Nr << "," << line->endpoints[0]->Nr); } } // free allocated TesselPoints freeTesselPointSTLList(Corners); // get the implemented connections SphericalPointDistribution::adjacency_t expected = SPD.getConnections(); // // print the map: for debugging and extracting the edges for getConnections() // std::cout << "\tadjacency_t adjacency;" << std::endl; // for (SphericalPointDistribution::adjacency_t::const_iterator iter = adjacency.begin(); // iter != adjacency.end(); ++iter) { // std::cout << "\tadjacency += make_pair( " // << iter->first << ", list_of"; // for (SphericalPointDistribution::IndexSet_t::const_iterator indexiter = iter->second.begin(); // indexiter != iter->second.end(); ++indexiter) // std::cout << "(" << *indexiter << ")"; // std::cout << " );" << std::endl; // } // and compare the two CPPUNIT_ASSERT_EQUAL( expected, adjacency ); } #endif /* SPHERICALPOINTDISTRIBUTION_ASSISTANT_HPP_ */