Changeset 6393ff


Ignore:
Timestamp:
Sep 12, 2016, 11:48:37 PM (8 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_StructOpt_integration_tests, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, GeometryObjects, Gui_displays_atomic_force_velocity, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, Ubuntu_1604_changes, stable
Children:
2d8c4e
Parents:
3678eb
git-author:
Frederik Heber <heber@…> (07/12/14 11:57:54)
git-committer:
Frederik Heber <heber@…> (09/12/16 23:48:37)
Message:

Added getConnections() to SphericalPointDistribution.

  • we use tesselation in order to extract the connection information between nearest neighboring points from the BoundaryLines of the tesselation. The triangles are ideal as they assure that no point lies within a triangle, hence all these points may be safely combined.
  • functions reside in extra module as with get().
  • added extensive unit tests.
Location:
src/Fragmentation
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/SphericalPointDistribution.hpp

    r3678eb r6393ff  
    1919#include <cmath>
    2020#include <list>
     21#include <map>
     22#include <set>
     23#include <vector>
    2124
    2225#include "LinearAlgebra/Vector.hpp"
     
    4851  //!> typedef for the list of points with integral weights
    4952  typedef std::list<std::pair<Vector, int> > WeightedPolygon_t;
     53  //!> typedef for a sorted list of indices
     54  typedef std::set<unsigned int> IndexSet_t;
     55  //!> typedef for the adjacency list of a polygon
     56  typedef std::map<unsigned int, IndexSet_t > adjacency_t;
    5057
    5158  /** General getter function for the distribution of points on the surface.
     
    5865  {
    5966    ASSERT(0, "SphericalPointDistribution::get() - not specialized for "+toString(N)+".");
     67    return Polygon_t();
     68  }
     69
     70  template <int N> adjacency_t getConnections()
     71  {
     72    ASSERT(0, "SphericalPointDistribution::getConnections() - not specialized for "+toString(N)+".");
    6073    return Polygon_t();
    6174  }
     
    185198template <> SphericalPointDistribution::Polygon_t SphericalPointDistribution::get<14>() const;
    186199
     200template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<0>();
     201template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<1>();
     202template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<2>();
     203template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<3>();
     204template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<4>();
     205template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<5>();
     206template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<6>();
     207template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<7>();
     208template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<8>();
     209template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<9>();
     210template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<10>();
     211template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<11>();
     212template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<12>();
     213template <> SphericalPointDistribution::adjacency_t SphericalPointDistribution::getConnections<14>();
     214
    187215#endif /* SPHERICALPOINTDISTRIBUTION_HPP_ */
  • src/Fragmentation/Exporters/unittests/Makefile.am

    r3678eb r6393ff  
    1212        ../Fragmentation/Exporters/unittests/SaturatedFragmentUnitTest.hpp \
    1313        ../Fragmentation/Exporters/unittests/SaturationDistanceMaximizerUnitTest.hpp \
    14         ../Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.hpp
     14        ../Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.hpp \
     15        ../Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest_assistant.hpp
    1516
    1617FRAGMENTATIONEXPORTERSTESTS = \
  • src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.cpp

    r3678eb r6393ff  
    4545#include "SphericalPointDistributionUnitTest.hpp"
    4646
     47#include <algorithm>
    4748#include <boost/assign.hpp>
    4849#include <boost/math/quaternion.hpp>
     
    5354#include "LinearAlgebra/Line.hpp"
    5455
     56#include "Atom/TesselPoint.hpp"
    5557#include "Fragmentation/Exporters/SphericalPointDistribution.hpp"
    56 
    57 #include "LinearAlgebra/Line.hpp"
     58#include "LinkedCell/linkedcell.hpp"
     59#include "LinkedCell/PointCloudAdaptor.hpp"
     60#include "Tesselation/BoundaryLineSet.hpp"
     61#include "Tesselation/tesselation.hpp"
    5862
    5963#ifdef HAVE_TESTRUNNER
     
    7882  ASSERT_DO(Assert::Throw);
    7983
    80   setVerbosity(6);
     84  setVerbosity(2);
    8185}
    8286
     
    270274}
    271275
    272 /** UnitTest for matchSphericalPointDistributions() with two points
    273  */
    274 void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_2()
    275 {
     276/** UnitTest for getConnections()
     277 */
     278template <>
     279void SphericalPointDistributionTest_assistant::getConnectionTest<0>()
     280{
     281  const int N=0;
    276282  SphericalPointDistribution SPD(1.);
    277   // test with one point, matching trivially
    278   {
    279     SphericalPointDistribution::WeightedPolygon_t polygon;
    280     polygon += std::make_pair(Vector(1.,0.,0.), 1);
    281     SphericalPointDistribution::Polygon_t newpolygon =
    282         SPD.get<2>();
    283     SphericalPointDistribution::Polygon_t expected;
    284     expected += Vector(-1.,0.,0.);
    285     SphericalPointDistribution::Polygon_t remaining =
    286         SphericalPointDistribution::matchSphericalPointDistributions(
    287             polygon,
    288             newpolygon);
    289 //    CPPUNIT_ASSERT_EQUAL( expected, remaining );
    290     CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
    291   }
    292 
    293   // test with one point, just a flip of axis
    294   {
    295     SphericalPointDistribution::WeightedPolygon_t polygon;
    296     polygon += std::make_pair( Vector(0.,1.,0.), 1);
    297     SphericalPointDistribution::Polygon_t newpolygon =
    298         SPD.get<2>();
    299     SphericalPointDistribution::Polygon_t expected;
    300     expected += Vector(0.,-1.,0.);
    301     SphericalPointDistribution::Polygon_t remaining =
    302         SphericalPointDistribution::matchSphericalPointDistributions(
    303             polygon,
    304             newpolygon);
    305 //    CPPUNIT_ASSERT_EQUAL( expected, remaining );
    306     CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
    307   }
    308 
    309   // test with one point, just a flip to another axis
    310   {
    311     SphericalPointDistribution::WeightedPolygon_t polygon;
    312     polygon += std::make_pair( Vector(0.,0.,-1.), 1);
    313     SphericalPointDistribution::Polygon_t newpolygon =
    314         SPD.get<2>();
    315     SphericalPointDistribution::Polygon_t expected;
    316     expected += Vector(0.,0.,1.);
    317     SphericalPointDistribution::Polygon_t remaining =
    318         SphericalPointDistribution::matchSphericalPointDistributions(
    319             polygon,
    320             newpolygon);
    321 //    CPPUNIT_ASSERT_EQUAL( expected, remaining );
    322     CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
    323   }
    324 
    325   // test with one point, full rotation
    326   {
    327     Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
    328     SphericalPointDistribution::WeightedPolygon_t polygon;
    329     polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
    330     SphericalPointDistribution::Polygon_t newpolygon =
    331         SPD.get<2>();
    332     SphericalPointDistribution::Polygon_t expected;
    333     expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
    334     SphericalPointDistribution::Polygon_t remaining =
    335         SphericalPointDistribution::matchSphericalPointDistributions(
    336             polygon,
    337             newpolygon);
    338 //    CPPUNIT_ASSERT_EQUAL( expected, remaining );
    339     CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
    340   }
     283
     284  // create empty adjacency
     285  SphericalPointDistribution::adjacency_t adjacency;
     286
     287  // get the implemented connections
     288  SphericalPointDistribution::adjacency_t expected =
     289      SPD.getConnections<N>();
     290
     291  // and compare the two
     292  CPPUNIT_ASSERT_EQUAL( expected, adjacency );
     293}
     294
     295/** UnitTest for getConnections()
     296 */
     297template <>
     298void SphericalPointDistributionTest_assistant::getConnectionTest<1>()
     299{
     300  const int N=1;
     301  SphericalPointDistribution SPD(1.);
     302
     303  // create empty adjacency
     304  SphericalPointDistribution::adjacency_t adjacency;
     305
     306  // get the implemented connections
     307  SphericalPointDistribution::adjacency_t expected =
     308      SPD.getConnections<N>();
     309
     310  // and compare the two
     311  CPPUNIT_ASSERT_EQUAL( expected, adjacency );
     312}
     313
     314/** UnitTest for getConnections()
     315 */
     316template <>
     317void SphericalPointDistributionTest_assistant::getConnectionTest<2>()
     318{
     319  const int N=2;
     320  SphericalPointDistribution SPD(1.);
     321
     322  // create empty adjacency
     323  SphericalPointDistribution::adjacency_t adjacency;
     324  adjacency +=
     325      make_pair<
     326      unsigned int,
     327      SphericalPointDistribution::IndexSet_t >
     328        (0, list_of<unsigned int>(1));
     329  adjacency +=
     330      make_pair<
     331      unsigned int,
     332      SphericalPointDistribution::IndexSet_t >
     333        (1, list_of<unsigned int>(0));
     334
     335  // get the implemented connections
     336  SphericalPointDistribution::adjacency_t expected =
     337      SPD.getConnections<N>();
     338
     339  // and compare the two
     340  CPPUNIT_ASSERT_EQUAL( expected, adjacency );
    341341}
    342342
     
    460460}
    461461
     462/** UnitTest for matchSphericalPointDistributions() with two points
     463 */
     464void SphericalPointDistributionTest::matchSphericalPointDistributionsTest_2()
     465{
     466  SphericalPointDistribution SPD(1.);
     467  // test with one point, matching trivially
     468  {
     469    SphericalPointDistribution::WeightedPolygon_t polygon;
     470    polygon += std::make_pair(Vector(1.,0.,0.), 1);
     471    SphericalPointDistribution::Polygon_t newpolygon =
     472        SPD.get<2>();
     473    SphericalPointDistribution::Polygon_t expected;
     474    expected += Vector(-1.,0.,0.);
     475    SphericalPointDistribution::Polygon_t remaining =
     476        SphericalPointDistribution::matchSphericalPointDistributions(
     477            polygon,
     478            newpolygon);
     479//    CPPUNIT_ASSERT_EQUAL( expected, remaining );
     480    CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
     481  }
     482
     483  // test with one point, just a flip of axis
     484  {
     485    SphericalPointDistribution::WeightedPolygon_t polygon;
     486    polygon += std::make_pair( Vector(0.,1.,0.), 1);
     487    SphericalPointDistribution::Polygon_t newpolygon =
     488        SPD.get<2>();
     489    SphericalPointDistribution::Polygon_t expected;
     490    expected += Vector(0.,-1.,0.);
     491    SphericalPointDistribution::Polygon_t remaining =
     492        SphericalPointDistribution::matchSphericalPointDistributions(
     493            polygon,
     494            newpolygon);
     495//    CPPUNIT_ASSERT_EQUAL( expected, remaining );
     496    CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
     497  }
     498
     499  // test with one point, just a flip to another axis
     500  {
     501    SphericalPointDistribution::WeightedPolygon_t polygon;
     502    polygon += std::make_pair( Vector(0.,0.,-1.), 1);
     503    SphericalPointDistribution::Polygon_t newpolygon =
     504        SPD.get<2>();
     505    SphericalPointDistribution::Polygon_t expected;
     506    expected += Vector(0.,0.,1.);
     507    SphericalPointDistribution::Polygon_t remaining =
     508        SphericalPointDistribution::matchSphericalPointDistributions(
     509            polygon,
     510            newpolygon);
     511//    CPPUNIT_ASSERT_EQUAL( expected, remaining );
     512    CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
     513  }
     514
     515  // test with one point, full rotation
     516  {
     517    Line RotationAxis(zeroVec, Vector(0.2, 0.43, 0.6893248));
     518    SphericalPointDistribution::WeightedPolygon_t polygon;
     519    polygon += std::make_pair(RotationAxis.rotateVector(Vector(1.,0.,0.), 47.6/180*M_PI), 1);
     520    SphericalPointDistribution::Polygon_t newpolygon =
     521        SPD.get<2>();
     522    SphericalPointDistribution::Polygon_t expected;
     523    expected += RotationAxis.rotateVector(Vector(-1.,0.,0.), 47.6/180*M_PI);
     524    SphericalPointDistribution::Polygon_t remaining =
     525        SphericalPointDistribution::matchSphericalPointDistributions(
     526            polygon,
     527            newpolygon);
     528//    CPPUNIT_ASSERT_EQUAL( expected, remaining );
     529    CPPUNIT_ASSERT( areEqualToWithinBounds(expected, remaining, CenterAccuracy) );
     530  }
     531}
     532
    462533/** UnitTest for matchSphericalPointDistributions() with three points
    463534 */
  • src/Fragmentation/Exporters/unittests/SphericalPointDistributionUnitTest.hpp

    r3678eb r6393ff  
    1919/********************************************** Test classes **************************************/
    2020
    21 class SphericalPointDistributionTest : public CppUnit::TestFixture
     21/** Template specialization needs to be in front of adding the test via CPPUNIT_TEST
     22 * Hence,we put it in an extra class and inherit the functions.
     23 */
     24struct SphericalPointDistributionTest_assistant
    2225{
     26public:
     27  template <int N>
     28  void getConnectionTest();
     29};
     30
     31template <> void SphericalPointDistributionTest_assistant::getConnectionTest<0>();
     32template <> void SphericalPointDistributionTest_assistant::getConnectionTest<1>();
     33template <> void SphericalPointDistributionTest_assistant::getConnectionTest<2>();
     34
     35#include "SphericalPointDistributionUnitTest_assistant.hpp"
     36
     37class SphericalPointDistributionTest :
     38  public CppUnit::TestFixture,
     39  public SphericalPointDistributionTest_assistant
     40{
     41
     42private:
    2343    CPPUNIT_TEST_SUITE( SphericalPointDistributionTest) ;
    2444    CPPUNIT_TEST( calculateCenterOfMinimumDistanceTest );
    2545    CPPUNIT_TEST ( areEqualToWithinBoundsTest );
    2646    CPPUNIT_TEST ( joinPointsTest );
     47    CPPUNIT_TEST ( getConnectionTest<0> );
     48    CPPUNIT_TEST ( getConnectionTest<1> );
     49    CPPUNIT_TEST ( getConnectionTest<2> );
     50    CPPUNIT_TEST ( getConnectionTest<3> );
     51    CPPUNIT_TEST ( getConnectionTest<4> );
     52    CPPUNIT_TEST ( getConnectionTest<5> );
     53    CPPUNIT_TEST ( getConnectionTest<6> );
     54    CPPUNIT_TEST ( getConnectionTest<7> );
     55    CPPUNIT_TEST ( getConnectionTest<8> );
     56    CPPUNIT_TEST ( getConnectionTest<9> );
     57    CPPUNIT_TEST ( getConnectionTest<10> );
     58    CPPUNIT_TEST ( getConnectionTest<11> );
     59    CPPUNIT_TEST ( getConnectionTest<12> );
     60    CPPUNIT_TEST ( getConnectionTest<14> );
    2761    CPPUNIT_TEST ( matchSphericalPointDistributionsTest_2 );
    2862    CPPUNIT_TEST ( matchSphericalPointDistributionsTest_3 );
     
    3266    CPPUNIT_TEST ( matchSphericalPointDistributionsTest_7 );
    3367    CPPUNIT_TEST ( matchSphericalPointDistributionsTest_8 );
    34     CPPUNIT_TEST ( matchSphericalPointDistributionsTest_multiple );
     68//    CPPUNIT_TEST ( matchSphericalPointDistributionsTest_multiple );
    3569    CPPUNIT_TEST_SUITE_END();
    3670
  • src/Fragmentation/Makefile.am

    r3678eb r6393ff  
    1212        Fragmentation/Exporters/SaturationDistanceMaximizer.cpp \
    1313        Fragmentation/Exporters/SphericalPointDistribution.cpp \
     14        Fragmentation/Exporters/SphericalPointDistribution_getConnections.cpp \
    1415        Fragmentation/Exporters/SphericalPointDistribution_getPoints.cpp \
    1516        Fragmentation/Homology/AtomFragmentsMap.cpp \
Note: See TracChangeset for help on using the changeset viewer.