Changeset 6acc2f3 for src


Ignore:
Timestamp:
Mar 28, 2012, 3:17:38 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Branches:
Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, 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_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
Children:
5a8d61
Parents:
84721b
git-author:
Frederik Heber <heber@…> (01/18/12 20:17:24)
git-committer:
Frederik Heber <heber@…> (03/28/12 15:17:38)
Message:

Added getCenter() and getRadius to all Shapes.

Location:
src/Shapes
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/Shapes/BaseShapes.cpp

    r84721b r6acc2f3  
    5151  return point;
    5252}
     53
     54Vector Sphere_impl::getCenter() const
     55{
     56  return Vector(0.,0.,0.);
     57}
     58
     59double Sphere_impl::getRadius() const
     60{
     61  return 1.;
     62}
     63
    5364
    5465LineSegmentSet Sphere_impl::getLineIntersections(const Line &line) const{
     
    167178}
    168179
     180
     181Vector Cuboid_impl::getCenter() const
     182{
     183  return Vector(0.5,0.5,0.5);
     184}
     185
     186double Cuboid_impl::getRadius() const
     187{
     188  return .5;
     189}
     190
    169191LineSegmentSet Cuboid_impl::getLineIntersections(const Line &line) const{
    170192  LineSegmentSet res(line);
  • src/Shapes/BaseShapes_impl.hpp

    r84721b r6acc2f3  
    2626  virtual bool isOnSurface(const Vector &point) const;
    2727  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     28  virtual Vector getCenter() const;
     29  virtual double getRadius() const;
    2830  virtual LineSegmentSet getLineIntersections(const Line&) const;
    2931  virtual std::string toString() const;
     
    3638  virtual bool isOnSurface(const Vector &point) const;
    3739  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     40  virtual Vector getCenter() const;
     41  virtual double getRadius() const;
    3842  virtual LineSegmentSet getLineIntersections(const Line&) const;
    3943  virtual std::string toString() const;
  • src/Shapes/Shape.cpp

    r84721b r6acc2f3  
    2828#include "Shapes/ShapeType.hpp"
    2929
     30#include <algorithm>
     31#include <limits>
    3032#include <string>
    3133
     
    4749Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){
    4850  return impl->getNormal(point);
     51}
     52
     53Vector Shape::getCenter() const{
     54  return impl->getCenter();
     55}
     56
     57double Shape::getRadius() const{
     58  return impl->getRadius();
    4959}
    5060
     
    158168}
    159169
     170Vector AndShape_impl::getCenter() const
     171{
     172  // calculate closest position on sphere surface to other center ..
     173  const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((lhs->getCenter() - rhs->getCenter()).getNormalized());
     174  const Vector lhsDistance = lhs->getCenter() + lhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
     175  // .. and then it's right in between those two
     176  return 0.5*(rhsDistance + lhsDistance);
     177}
     178
     179double AndShape_impl::getRadius() const
     180{
     181  const double distance = (lhs->getCenter() - rhs->getCenter()).Norm();
     182  const double minradii = std::min(lhs->getRadius(), rhs->getRadius());
     183  // if no intersection
     184  if (distance > (lhs->getRadius() + rhs->getRadius()))
     185    return 0.;
     186  else // if intersection it can only be the smaller one
     187    return minradii;
     188}
     189
    160190LineSegmentSet AndShape_impl::getLineIntersections(const Line &line) const{
    161191  return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     
    248278}
    249279
     280Vector OrShape_impl::getCenter() const
     281{
     282  // calculate furthest position on sphere surface to other center ..
     283  const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
     284  const Vector lhsDistance = lhs->getCenter() + lhs->getRadius()*((lhs->getCenter() - rhs->getCenter()).getNormalized());
     285  // .. and then it's right in between those two
     286  return .5*(rhsDistance + lhsDistance);
     287}
     288
     289double OrShape_impl::getRadius() const
     290{
     291  const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
     292  const Vector lhsDistance = lhs->getCenter() + lhs->getRadius()*((lhs->getCenter() - rhs->getCenter()).getNormalized());
     293  return .5*(rhsDistance - lhsDistance).Norm();
     294}
     295
    250296LineSegmentSet OrShape_impl::getLineIntersections(const Line &line) const{
    251297  return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     
    302348}
    303349
     350Vector NotShape_impl::getCenter() const
     351{
     352  return arg->getCenter();
     353}
     354
     355double NotShape_impl::getRadius() const
     356{
     357  return std::numeric_limits<double>::infinity();
     358}
     359
    304360LineSegmentSet NotShape_impl::getLineIntersections(const Line &line) const{
    305361  return invert(arg->getLineIntersections(line));
  • src/Shapes/Shape.hpp

    r84721b r6acc2f3  
    4343
    4444  Vector getCenter() const;
    45   Vector getRadius() const;
     45  double getRadius() const;
    4646
    4747  LineSegmentSet getLineIntersections(const Line&) const;
  • src/Shapes/ShapeOps.cpp

    r84721b r6acc2f3  
    5151  return res;
    5252}
     53
     54Vector ShapeOpsBase_impl::getCenter() const
     55{
     56  return arg->getCenter();
     57}
     58
     59double ShapeOpsBase_impl::getRadius() const
     60{
     61  return translateOutPos(Vector(arg->getRadius(), 0., 0.)).Norm();
     62}
     63
    5364
    5465LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line) const{
     
    141152}
    142153
     154Vector Translate_impl::getCenter() const
     155{
     156  return getArg()->getCenter()+offset;
     157}
     158
     159double Translate_impl::getRadius() const
     160{
     161  return getArg()->getRadius();
     162}
     163
     164
    143165Vector Translate_impl::translateIn(const Vector& point) const{
    144166  return point-offset;
  • src/Shapes/ShapeOps_impl.hpp

    r84721b r6acc2f3  
    3232  virtual bool isOnSurface(const Vector &point) const;
    3333  virtual Vector getNormal(const Vector &point) const throw (NotOnSurfaceException);
     34  virtual Vector getCenter() const;
     35  virtual double getRadius() const;
    3436  virtual LineSegmentSet getLineIntersections(const Line&) const;
    3537  virtual enum ShapeType getType() const;
     
    6668  virtual ~Translate_impl();
    6769protected:
     70  virtual Vector getCenter() const;
     71  virtual double getRadius() const;
    6872  virtual Vector translateIn(const Vector &point) const;
    6973  virtual Vector translateOutPos(const Vector &point) const;
  • src/Shapes/Shape_impl.hpp

    r84721b r6acc2f3  
    1515
    1616
     17#include <limits>
    1718#include <vector>
    1819
     
    3334  virtual bool isOnSurface(const Vector &point) const=0;
    3435  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException)=0;
     36  virtual Vector getCenter() const=0;
     37  virtual double getRadius() const=0;
    3538  virtual LineSegmentSet getLineIntersections(const Line&) const=0;
    3639  virtual std::string toString() const =0;
     
    4952  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
    5053    throw NotOnSurfaceException() << ShapeVector(&point);
     54  }
     55  virtual Vector getCenter() const {
     56    return Vector(0.,0.,0.);
     57  }
     58  virtual double getRadius() const {
     59    return std::numeric_limits<double>::infinity();
    5160  }
    5261  virtual LineSegmentSet getLineIntersections(const Line &line) const{
     
    7786    throw NotOnSurfaceException() << ShapeVector(&point);
    7887  }
     88  virtual Vector getCenter() const {
     89    return Vector(0.,0.,0.);
     90  }
     91  virtual double getRadius() const {
     92    return 0.;
     93  }
    7994  virtual LineSegmentSet getLineIntersections(const Line &line) const{
    8095    return LineSegmentSet(line);
     
    99114  virtual bool isOnSurface(const Vector &point) const;
    100115  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     116  virtual Vector getCenter() const;
     117  virtual double getRadius() const;
    101118  virtual LineSegmentSet getLineIntersections(const Line&) const;
    102119  virtual std::string toString() const;
     
    115132  virtual bool isOnSurface(const Vector &point) const;
    116133  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     134  virtual Vector getCenter() const;
     135  virtual double getRadius() const;
    117136  virtual LineSegmentSet getLineIntersections(const Line&) const;
    118137  virtual std::string toString() const;
     
    131150  virtual bool isOnSurface(const Vector &point) const;
    132151  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     152  virtual Vector getCenter() const;
     153  virtual double getRadius() const;
    133154  virtual LineSegmentSet getLineIntersections(const Line&) const;
    134155  virtual std::string toString() const;
  • src/Shapes/unittests/BaseShapesUnitTest.cpp

    r84721b r6acc2f3  
    3434#include "Shapes/BaseShapes.hpp"
    3535#include "Shapes/Shape.hpp"
     36#include "Shapes/ShapeOps.hpp"
    3637
    3738#include "BaseShapesUnitTest.hpp"
     
    658659  CPPUNIT_ASSERT_EQUAL((size_t)194, PointsOnSurface.size());
    659660}
    660 
  • src/Shapes/unittests/ShapeOpsUnitTest.cpp

    r84721b r6acc2f3  
    2323
    2424#include <cmath>
     25#include <limits>
    2526
    2627#ifdef HAVE_TESTRUNNER
     
    107108}
    108109
     110void ShapeOpsTest::getCenterTest()
     111{
     112  Shape s = Sphere();
     113  Shape t = Sphere(Vector(2.,0.,0.),1.);
     114  Vector offset(1.,0.,0);
     115  RealSpaceMatrix M;
     116  M.setRotation(45.,0.,0.);
     117
     118  // Sphere
     119  {
     120    // sphere at origin
     121    CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), s.getCenter() );
     122
     123    // translated sphere
     124    CPPUNIT_ASSERT_EQUAL( offset, translate(s, offset).getCenter() );
     125
     126    // resized sphere
     127    CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), resize(s, 2.).getCenter() );
     128
     129    // stretched sphere
     130    CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), stretch(s, Vector(2.,1.,1.)).getCenter() );
     131
     132    // transformed sphere
     133    CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), transform(s, M).getCenter() );
     134
     135    // resized and translated sphere
     136    CPPUNIT_ASSERT_EQUAL( offset, translate(resize(s, 2.), offset).getCenter() );
     137  }
     138
     139  // AND spheres
     140  {
     141    // sphere at origin
     142    CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (s && t).getCenter() );
     143
     144    // translated sphere
     145    CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate((s && t), offset).getCenter() );
     146
     147    // resized sphere
     148    CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), resize((s && t), 2.).getCenter() );
     149
     150    // stretched sphere
     151    CPPUNIT_ASSERT_EQUAL( Vector(1.5,0.,0), (stretch(s, Vector(2.,1.,1.)) && t).getCenter() );
     152
     153    // transformed sphere
     154    CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (transform(s, M) && t).getCenter() );
     155
     156    // resized and translated sphere
     157    CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate(resize((s && t), 2.), offset).getCenter() );
     158  }
     159
     160  // OR spheres
     161  {
     162    // sphere at origin
     163    CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (s || t).getCenter() );
     164
     165    // translated sphere
     166    CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate((s || t), offset).getCenter() );
     167
     168    // resized sphere
     169    CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), resize((s || t), 2.).getCenter() );
     170
     171    // stretched sphere
     172    CPPUNIT_ASSERT_EQUAL( Vector(0.5,0.,0), (stretch(s, Vector(2.,1.,1.)) || t).getCenter() );
     173
     174    // transformed sphere
     175    CPPUNIT_ASSERT_EQUAL( Vector(1.,0.,0), (transform(s, M) || t).getCenter() );
     176
     177    // resized and translated sphere
     178    CPPUNIT_ASSERT_EQUAL( Vector(2.,0.,0), translate(resize((s || t), 2.), offset).getCenter() );
     179  }
     180
     181  // NOT spheres
     182  {
     183    // sphere at origin
     184    CPPUNIT_ASSERT_EQUAL( Vector(0.,0.,0), (!s).getCenter() );
     185  }
     186}
     187
     188void ShapeOpsTest::getRadiusTest()
     189{
     190  Shape s = Sphere();
     191  Shape t = Sphere(Vector(2.,0.,0.),1.);
     192  Vector offset(1.,0.,0);
     193  RealSpaceMatrix M;
     194  M.setRotation(45.,0.,0.);
     195
     196  // Sphere
     197  {
     198    // sphere at origin
     199    CPPUNIT_ASSERT_EQUAL( 1., s.getRadius() );
     200
     201    // translated sphere
     202    CPPUNIT_ASSERT_EQUAL( 1., translate(s, offset).getRadius() );
     203
     204    // resized sphere
     205    CPPUNIT_ASSERT_EQUAL( 2., resize(s, 2.).getRadius() );
     206
     207    // stretched sphere
     208    CPPUNIT_ASSERT_EQUAL( 2., stretch(s, Vector(2.,1.,1.)).getRadius() );
     209
     210    // transformed sphere
     211    CPPUNIT_ASSERT_EQUAL( 1., transform(s, M).getRadius() );
     212
     213    // resized and translated sphere
     214    CPPUNIT_ASSERT_EQUAL( 2., translate(resize(s, 2.), offset).getRadius() );
     215  }
     216
     217  // AND spheres
     218  {
     219    // sphere at origin
     220    CPPUNIT_ASSERT_EQUAL( 1., (s && t).getRadius() );
     221
     222    // translated sphere
     223    CPPUNIT_ASSERT_EQUAL( 1., translate((s && t), offset).getRadius() );
     224
     225    // resized sphere
     226    CPPUNIT_ASSERT_EQUAL( 2., resize((s && t), 2.).getRadius() );
     227
     228    // stretched sphere
     229    CPPUNIT_ASSERT_EQUAL( 1., (stretch(s, Vector(2.,1.,1.)) && t).getRadius() );
     230
     231    // transformed sphere
     232    CPPUNIT_ASSERT_EQUAL( 1., (transform(s, M) && t).getRadius() );
     233
     234    // resized and translated sphere
     235    CPPUNIT_ASSERT_EQUAL( 2., translate(resize((s && t), 2.), offset).getRadius() );
     236  }
     237
     238  // OR spheres
     239  {
     240    // sphere at origin
     241    CPPUNIT_ASSERT_EQUAL( 2., (s || t).getRadius() );
     242
     243    // translated sphere
     244    CPPUNIT_ASSERT_EQUAL( 2., translate((s || t), offset).getRadius() );
     245
     246    // resized sphere
     247    CPPUNIT_ASSERT_EQUAL( 4., resize((s || t), 2.).getRadius() );
     248
     249    // stretched sphere
     250    CPPUNIT_ASSERT_EQUAL( 2.5, (stretch(s, Vector(2.,1.,1.)) || t).getRadius() );
     251
     252    // transformed sphere
     253    CPPUNIT_ASSERT_EQUAL( 2., (transform(s, M) || t).getRadius() );
     254
     255    // resized and translated sphere
     256    CPPUNIT_ASSERT_EQUAL( 4., translate(resize((s || t), 2.), offset).getRadius() );
     257  }
     258
     259  // NOT spheres
     260  {
     261    // sphere at origin
     262    CPPUNIT_ASSERT_EQUAL( std::numeric_limits<double>::infinity(), (!s).getRadius() );
     263  }
     264}
     265
  • src/Shapes/unittests/ShapeOpsUnitTest.hpp

    r84721b r6acc2f3  
    2424  CPPUNIT_TEST ( stretchTest );
    2525  CPPUNIT_TEST ( transformTest );
     26  CPPUNIT_TEST ( getCenterTest );
     27  CPPUNIT_TEST ( getRadiusTest );
    2628  CPPUNIT_TEST_SUITE_END();
    2729
     
    3436  void stretchTest();
    3537  void transformTest();
     38  void getCenterTest();
     39  void getRadiusTest();
    3640};
    3741
Note: See TracChangeset for help on using the changeset viewer.