Changeset f06cbb for src


Ignore:
Timestamp:
Sep 19, 2013, 8:24:28 PM (11 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:
aeb694
Parents:
52bb5a
git-author:
Frederik Heber <heber@…> (08/30/13 22:32:37)
git-committer:
Frederik Heber <heber@…> (09/19/13 20:24:28)
Message:

AndShape and OrShape now use Cacheable to store center and radius once calculated.

  • otherwise we might have to traverse a huge tree all the time when actually the shape cannot change and hence a once determined center is always true.
  • getRadius() and getCenter() functionality moved into private functions calculate...().
Location:
src/Shapes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Shapes/Shape.cpp

    r52bb5a rf06cbb  
    4646#include "Tesselation/ApproximateShapeVolume.hpp"
    4747
     48#include <boost/bind.hpp>
    4849#include <algorithm>
    4950#include <limits>
     
    152153}
    153154
    154 std::string Shape::toString() const{
     155std::string Shape::toString() const {
    155156  return impl->toString();
    156157}
     
    186187
    187188AndShape_impl::AndShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
    188   lhs(_lhs),rhs(_rhs)
     189  lhs(_lhs),
     190  rhs(_rhs),
     191  radius(NULL, boost::bind(&AndShape_impl::calculateRadius, this), "radius"),
     192  center(NULL, boost::bind(&AndShape_impl::calculateCenter, this), "center")
    189193{}
    190194
     
    238242}
    239243
    240 Vector AndShape_impl::getCenter() const
     244Vector AndShape_impl::calculateCenter() const
    241245{
    242246  // calculate closest position on sphere surface to other center ..
     
    247251}
    248252
    249 double AndShape_impl::getRadius() const
     253double AndShape_impl::calculateRadius() const
    250254{
    251255  const double distance = (lhs->getCenter() - rhs->getCenter()).Norm();
     
    314318
    315319OrShape_impl::OrShape_impl(const Shape::impl_ptr &_lhs, const Shape::impl_ptr &_rhs) :
    316   lhs(_lhs),rhs(_rhs)
     320  lhs(_lhs),
     321  rhs(_rhs),
     322  radius(NULL, boost::bind(&OrShape_impl::calculateRadius, this), "radius"),
     323  center(NULL, boost::bind(&OrShape_impl::calculateCenter, this), "center")
    317324{}
    318325
     
    366373}
    367374
    368 Vector OrShape_impl::getCenter() const
     375Vector OrShape_impl::calculateCenter() const
    369376{
    370377  // calculate furthest position on sphere surface to other center ..
     
    375382}
    376383
    377 double OrShape_impl::getRadius() const
     384double OrShape_impl::calculateRadius() const
    378385{
    379386  const Vector rhsDistance = rhs->getCenter() + rhs->getRadius()*((rhs->getCenter() - lhs->getCenter()).getNormalized());
  • src/Shapes/Shape_impl.hpp

    r52bb5a rf06cbb  
    2828#include "LinearAlgebra/LineSegmentSet.hpp"
    2929#include "LinearAlgebra/Vector.hpp"
     30
     31#include "CodePatterns/Cacheable.hpp"
    3032
    3133
     
    146148  virtual bool isOnSurface(const Vector &point) const;
    147149  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
    148   virtual Vector getCenter() const;
    149   virtual double getRadius() const;
     150  virtual Vector getCenter() const
     151  { return *center; }
     152  virtual double getRadius() const
     153  { return *radius; }
    150154  virtual double getVolume() const;
    151155  virtual double getSurfaceArea() const;
     
    156160  virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
    157161private:
     162  double calculateRadius() const;
     163  Vector calculateCenter() const;
     164
    158165  Shape::impl_ptr lhs;
    159166  Shape::impl_ptr rhs;
     167  Cacheable<double> radius;
     168  Cacheable<Vector> center;
    160169};
    161170
     
    167176  virtual bool isOnSurface(const Vector &point) const;
    168177  virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
    169   virtual Vector getCenter() const;
    170   virtual double getRadius() const;
     178  virtual Vector getCenter() const
     179  { return *center; }
     180  virtual double getRadius() const
     181  { return *radius; }
    171182  virtual double getVolume() const;
    172183  virtual double getSurfaceArea() const;
     
    177188  virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
    178189private:
     190  double calculateRadius() const;
     191  Vector calculateCenter() const;
     192
    179193  Shape::impl_ptr lhs;
    180194  Shape::impl_ptr rhs;
     195  Cacheable<double> radius;
     196  Cacheable<Vector> center;
    181197};
    182198
Note: See TracChangeset for help on using the changeset viewer.