Changeset 6c438f for src/Shapes


Ignore:
Timestamp:
Aug 28, 2010, 3:21:11 AM (15 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:
a6e6b5, f8982c
Parents:
2ad482 (diff), fd4905 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Frederik Heber <heber@…> (08/28/10 03:17:48)
git-committer:
Frederik Heber <heber@…> (08/28/10 03:21:11)
Message:

Merge branch 'StructureRefactoring' into Shapes

Conflicts:

src/Box.cpp
src/Box.hpp
src/Descriptors/AtomShapeDescriptor.cpp
src/Descriptors/AtomShapeDescriptor.hpp
src/Descriptors/AtomShapeDescriptor_impl.hpp
src/LinearAlgebra/Line.cpp
src/LinearAlgebra/Line.hpp
src/LinearAlgebra/Matrix.cpp
src/LinearAlgebra/Matrix.hpp
src/Makefile.am
src/Shapes/BaseShapes.cpp
src/Shapes/BaseShapes_impl.hpp
src/Shapes/Shape.cpp
src/Shapes/Shape.hpp
src/Shapes/ShapeOps_impl.hpp
src/Shapes/Shape_impl.hpp
src/unittests/ShapeUnittest.cpp

Location:
src/Shapes
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Shapes/BaseShapes.cpp

    r2ad482 r6c438f  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * BaseShapes_impl.cpp
     
    613 */
    714
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
     20#include "Helpers/MemDebug.hpp"
     21
    822#include "Shapes/BaseShapes.hpp"
    923#include "Shapes/BaseShapes_impl.hpp"
    1024#include "Shapes/ShapeOps.hpp"
    1125
    12 #include "vector.hpp"
     26#include "defs.hpp"
     27
    1328#include "Helpers/Assert.hpp"
    14 
    15 #include "Line.hpp"
    16 #include "Plane.hpp"
    17 #include "LineSegment.hpp"
    18 #include "LineSegmentSet.hpp"
     29#include "LinearAlgebra/Vector.hpp"
     30#include "LinearAlgebra/Line.hpp"
     31#include "LinearAlgebra/Plane.hpp"
     32#include "LinearAlgebra/LineSegment.hpp"
     33#include "LinearAlgebra/LineSegmentSet.hpp"
    1934
    2035#include <cmath>
     
    4964}
    5065
     66/**
     67 * algorithm taken from http://www.cgafaq.info/wiki/Evenly_distributed_points_on_sphere
     68 * \param N number of points on surface
     69 */
     70std::vector<Vector> Sphere_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     71  std::vector<Vector> PointsOnSurface;
     72
     73  const double dlength = M_PI*(3.-sqrt(5.));
     74  double length = 0;
     75  const double dz = 2.0/N;
     76  double z = 1. - dz/2.;
     77  Vector point;
     78  for (size_t ka = 0; ka<N; ka++){
     79    const double r = sqrt(1.-z*z);
     80    point.Zero();
     81    point[0] = cos(length)*r;
     82    point[1] = sin(length)*r;
     83    point[2] = z;
     84    PointsOnSurface.push_back(point);
     85    z = z - dz;
     86    length = length + dlength;
     87  }
     88
     89  ASSERT(PointsOnSurface.size() == N, "Sphere_impl::getHomogeneousPointsOnSurface() did not create enough points.");
     90  return PointsOnSurface;
     91}
     92
     93
    5194Shape Sphere(){
    5295  Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl());
     
    63106
    64107bool Cuboid_impl::isInside(const Vector &point){
    65   return fabs(point[0])<=1 && fabs(point[1])<=1 && fabs(point[2])<=1;
     108  return (point[0]>=0 && point[0]<=1) && (point[1]>=0 && point[1]<=1) && (point[2]>=0 && point[2]<=1);
    66109}
    67110
     
    71114  // double fabs
    72115  retVal = retVal &&
    73            ((fabs(fabs(point[0])-1)  < MYEPSILON) ||
    74             (fabs(fabs(point[1])-1)  < MYEPSILON) ||
    75             (fabs(fabs(point[2])-1)  < MYEPSILON));
     116           (((fabs(point[0]-1.)  < MYEPSILON) || (fabs(point[0])  < MYEPSILON)) ||
     117            ((fabs(point[1]-1.)  < MYEPSILON) || (fabs(point[1])  < MYEPSILON)) ||
     118            ((fabs(point[2]-1.)  < MYEPSILON) || (fabs(point[2])  < MYEPSILON)));
    76119  return retVal;
    77120}
     
    129172}
    130173
     174/**
     175 * \param N number of points on surface
     176 */
     177std::vector<Vector> Cuboid_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     178  std::vector<Vector> PointsOnSurface;
     179  ASSERT(false, "Cuboid_impl::getHomogeneousPointsOnSurface() not implemented yet");
     180  return PointsOnSurface;
     181}
     182
    131183Shape Cuboid(){
    132184  Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl());
  • src/Shapes/BaseShapes_impl.hpp

    r2ad482 r6c438f  
    99#define BASESHAPES_IMPL_HPP_
    1010
     11class Vector;
     12class LineSegmentSet;
     13
    1114#include "Shapes/Shape_impl.hpp"
    1215
     
    1720  virtual LineSegmentSet getLineIntersections(const Line&);
    1821  virtual std::string toString();
     22  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    1923};
    2024
     
    2529  virtual LineSegmentSet getLineIntersections(const Line&);
    2630  virtual std::string toString();
     31  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    2732};
    2833
  • src/Shapes/Shape.cpp

    r2ad482 r6c438f  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * Shape.cpp
     
    613 */
    714
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
     20#include "Helpers/MemDebug.hpp"
     21
     22#include "Helpers/Assert.hpp"
     23#include "LinearAlgebra/Vector.hpp"
     24
    825#include "Shape.hpp"
    926#include "Shape_impl.hpp"
    1027
    11 #include "Helpers/Assert.hpp"
    12 
    1328#include <string>
    1429
    15 using namespace std;
    1630
    1731Shape::Shape(const Shape& src) :
     
    3549LineSegmentSet Shape::getLineIntersections(const Line &line){
    3650  return impl->getLineIntersections(line);
     51}
     52
     53std::vector<Vector> Shape::getHomogeneousPointsOnSurface(const size_t N) const {
     54  return impl->getHomogeneousPointsOnSurface(N);
    3755}
    3856
     
    138156}
    139157
     158std::vector<Vector> AndShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     159  std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
     160  std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
     161  std::vector<Vector> PointsOnSurface;
     162
     163  for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
     164    if (rhs->isInside(*iter))
     165      PointsOnSurface.push_back(*iter);
     166  }
     167  for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
     168    if (lhs->isInside(*iter))
     169      PointsOnSurface.push_back(*iter);
     170  }
     171
     172  return PointsOnSurface;
     173}
     174
     175
    140176Shape operator&&(const Shape &lhs,const Shape &rhs){
    141177  Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    206242}
    207243
     244std::vector<Vector> OrShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     245  std::vector<Vector> PointsOnSurface_lhs = lhs->getHomogeneousPointsOnSurface(N);
     246  std::vector<Vector> PointsOnSurface_rhs = rhs->getHomogeneousPointsOnSurface(N);
     247  std::vector<Vector> PointsOnSurface;
     248
     249  for (std::vector<Vector>::const_iterator iter = PointsOnSurface_lhs.begin(); iter != PointsOnSurface_lhs.end(); ++iter) {
     250    if (!rhs->isInside(*iter))
     251      PointsOnSurface.push_back(*iter);
     252  }
     253  for (std::vector<Vector>::const_iterator iter = PointsOnSurface_rhs.begin(); iter != PointsOnSurface_rhs.end(); ++iter) {
     254    if (!lhs->isInside(*iter))
     255      PointsOnSurface.push_back(*iter);
     256  }
     257
     258  return PointsOnSurface;
     259}
     260
    208261Shape operator||(const Shape &lhs,const Shape &rhs){
    209262  Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs)));
     
    237290string NotShape_impl::toString(){
    238291  return string("!") + arg->toString();
     292}
     293
     294std::vector<Vector> NotShape_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     295  // surfaces are the same, only normal direction is different
     296  return arg->getHomogeneousPointsOnSurface(N);
    239297}
    240298
  • src/Shapes/Shape.hpp

    r2ad482 r6c438f  
    1313
    1414#include "Exceptions/NotOnSurfaceException.hpp"
     15
     16#include <vector>
    1517
    1618class Vector;
     
    3436
    3537  LineSegmentSet getLineIntersections(const Line&);
     38  std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    3639
    3740  Shape &operator=(const Shape& rhs);
  • src/Shapes/ShapeOps.cpp

    r2ad482 r6c438f  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * ShapeOps.cpp
     
    613 */
    714
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
     20#include "Helpers/MemDebug.hpp"
     21
    822#include "Shapes/ShapeOps.hpp"
    923#include "Shapes/ShapeOps_impl.hpp"
    1024
     25#include "LinearAlgebra/Vector.hpp"
    1126#include "Helpers/Assert.hpp"
    1227
     
    5570}
    5671
    57 Shape::impl_ptr ShapeOpsBase_impl::getArg(){
     72std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     73  return getArg()->getHomogeneousPointsOnSurface(N);;
     74}
     75
     76Shape::impl_ptr ShapeOpsBase_impl::getArg() const{
    5877  return arg;
    5978}
     
    6988Resize_impl::~Resize_impl(){}
    7089
     90bool Resize_impl::isInside(const Vector& point){
     91  return getArg()->isInside((1/size) * point);
     92}
     93
    7194Vector Resize_impl::translateIn(const Vector& point){
    7295  return (1/size) * point;
     
    86109  return sstr.str();
    87110}
     111
     112std::vector<Vector> Resize_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     113  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
     114  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
     115    *iter *= size;
     116  }
     117  return PointsOnSurface;
     118}
     119
    88120
    89121Shape resize(const Shape &arg,double size){
     
    100132Translate_impl::~Translate_impl(){}
    101133
     134bool Translate_impl::isInside(const Vector& point){
     135  return getArg()->isInside(point-offset);
     136}
     137
    102138Vector Translate_impl::translateIn(const Vector& point){
    103139  return point-offset;
     
    116152  sstr << "translate(" << getArg()->toString() << "," << offset << ")";
    117153  return sstr.str();
     154}
     155
     156std::vector<Vector> Translate_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     157  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
     158  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
     159    *iter += offset;
     160  }
     161  return PointsOnSurface;
    118162}
    119163
     
    138182Stretch_impl::~Stretch_impl(){}
    139183
     184bool Stretch_impl::isInside(const Vector& point){
     185  Vector helper=point;
     186  helper.ScaleAll(reciFactors);
     187  return getArg()->isInside(helper);
     188}
     189
    140190Vector Stretch_impl::translateIn(const Vector& point){
    141191  Vector helper=point;
     
    168218}
    169219
     220std::vector<Vector> Stretch_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     221  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
     222  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
     223    (*iter).ScaleAll(reciFactors);
     224  }
     225  return PointsOnSurface;
     226}
     227
    170228Shape stretch(const Shape &arg, const Vector &factors){
    171229  Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors));
     
    183241Transform_impl::~Transform_impl(){}
    184242
     243bool Transform_impl::isInside(const Vector& point){
     244  return getArg()->isInside(transformationInv * point);
     245}
     246
    185247Vector Transform_impl::translateIn(const Vector& point){
    186248  return transformationInv * point;
     
    202264}
    203265
     266std::vector<Vector> Transform_impl::getHomogeneousPointsOnSurface(const size_t N) const {
     267  std::vector<Vector> PointsOnSurface = getArg()->getHomogeneousPointsOnSurface(N);
     268  for(std::vector<Vector>::iterator iter = PointsOnSurface.begin(); iter != PointsOnSurface.end(); ++iter) {
     269    *iter = transformation * (*iter);
     270  }
     271  return PointsOnSurface;
     272}
     273
    204274Shape transform(const Shape &arg, const Matrix &transformation){
    205275  Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation));
  • src/Shapes/ShapeOps_impl.hpp

    r2ad482 r6c438f  
    1010
    1111#include "Shapes/Shape_impl.hpp"
    12 #include "vector.hpp"
    13 #include "Matrix.hpp"
     12#include "LinearAlgebra/Vector.hpp"
     13#include "LinearAlgebra/Matrix.hpp"
     14
     15#include <vector>
     16
     17class LineSegment;
    1418
    1519class ShapeOpsBase_impl : public Shape_impl{
     
    2125  virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException);
    2226  virtual LineSegmentSet getLineIntersections(const Line&);
     27  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    2328protected:
    2429  virtual Vector translateIn(const Vector &point)=0;
    2530  virtual Vector translateOutPos(const Vector &point)=0;
    2631  virtual Vector translateOutNormal(const Vector &point)=0;
    27   Shape::impl_ptr getArg();
     32  Shape::impl_ptr getArg() const;
    2833private:
    2934  Shape::impl_ptr arg;
     
    4045  virtual Vector translateOutNormal(const Vector &point);
    4146  virtual std::string toString();
     47  virtual bool isInside(const Vector& point);
     48  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    4249private:
    4350  double size;
     
    5461  virtual Vector translateOutNormal(const Vector &point);
    5562  virtual std::string toString();
     63  virtual bool isInside(const Vector& point);
     64  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    5665private:
    5766  Vector offset;
     
    6877  virtual Vector translateOutNormal(const Vector &point);
    6978  virtual std::string toString();
     79  virtual bool isInside(const Vector& point);
     80  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    7081private:
    7182  Vector factors;
     
    8394  virtual Vector translateOutNormal(const Vector &point);
    8495  virtual std::string toString();
     96  virtual bool isInside(const Vector& point);
     97  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    8598private:
    8699  Matrix transformation;
  • src/Shapes/Shape_impl.hpp

    r2ad482 r6c438f  
    99#define SHAPE_IMPL_HPP_
    1010
     11#include <vector>
     12
    1113#include "Shapes/Shape.hpp"
    12 #include "vector.hpp"
    13 #include "Line.hpp"
    14 #include "LineSegment.hpp"
    15 #include "LineSegmentSet.hpp"
     14#include "LinearAlgebra/Line.hpp"
     15#include "LinearAlgebra/LineSegment.hpp"
     16#include "LinearAlgebra/LineSegmentSet.hpp"
     17#include "LinearAlgebra/Vector.hpp"
    1618
    1719
     
    2527  virtual LineSegmentSet getLineIntersections(const Line&)=0;
    2628  virtual std::string toString()=0;
     29  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
    2730};
    2831
     
    4649    return "Everywhere()";
    4750  }
     51  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
     52    std::vector<Vector> PointsOnSurface;
     53    return PointsOnSurface;
     54  }
    4855};
    4956
     
    6471    return "Nowhere()";
    6572  }
     73  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
     74    std::vector<Vector> PointsOnSurface;
     75    return PointsOnSurface;
     76  }
    6677};
    6778
     
    7586  virtual LineSegmentSet getLineIntersections(const Line&);
    7687  virtual std::string toString();
     88  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    7789private:
    7890  Shape::impl_ptr lhs;
     
    89101  virtual LineSegmentSet getLineIntersections(const Line&);
    90102  virtual std::string toString();
     103  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    91104private:
    92105  Shape::impl_ptr lhs;
     
    103116  virtual LineSegmentSet getLineIntersections(const Line&);
    104117  virtual std::string toString();
     118  virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
    105119private:
    106120  Shape::impl_ptr arg;
Note: See TracChangeset for help on using the changeset viewer.