Changeset 5de9da
- Timestamp:
- Jul 14, 2010, 2:52:07 PM (15 years ago)
- 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:
- ef84ca
- Parents:
- 06300d
- Location:
- src/Shapes
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Shapes/BaseShapes.cpp
r06300d r5de9da 10 10 11 11 #include "vector.hpp" 12 #include "Helpers/Assert.hpp" 13 14 #include <cmath> 12 15 13 16 bool Sphere_impl::isInside(const Vector &point){ 14 17 return point.NormSquared()<=1; 18 } 19 20 bool Sphere_impl::isOnSurface(const Vector &point){ 21 return fabs(point.NormSquared()-1)<MYEPSILON; 22 } 23 24 Vector Sphere_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){ 25 if(!isOnSurface(point)){ 26 throw NotOnSurfaceException(__FILE__,__LINE__); 27 } 28 return point; 15 29 } 16 30 … … 21 35 22 36 bool Cuboid_impl::isInside(const Vector &point){ 23 return point[0]<=1 && point[1]<=1 && point[2]<=1; 37 return fabs(point[0])<=1 && fabs(point[1])<=1 && fabs(point[2])<=1; 38 } 39 40 bool Cuboid_impl::isOnSurface(const Vector &point){ 41 bool retVal = isInside(point); 42 // test all borders of the cuboid 43 // double fabs 44 retVal = retVal && 45 ((fabs(fabs(point[0])-1) < MYEPSILON) || 46 (fabs(fabs(point[1])-1) < MYEPSILON) || 47 (fabs(fabs(point[2])-1) < MYEPSILON)); 48 return retVal; 49 } 50 51 Vector Cuboid_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){ 52 if(!isOnSurface(point)){ 53 throw NotOnSurfaceException(__FILE__,__LINE__); 54 } 55 Vector res; 56 // figure out on which sides the Vector lies (maximum 3, when it is in a corner) 57 for(int i=NDIM;i--;){ 58 if(fabs(fabs(point[i])-1)<MYEPSILON){ 59 // add the scaled (-1/+1) Vector to the set of surface vectors 60 res[i] = point[i]; 61 } 62 } 63 ASSERT(res.NormSquared()>=1 && res.NormSquared()<=3,"To many or to few sides found for this Vector"); 64 65 res.Normalize(); 66 return res; 24 67 } 25 68 26 69 Shape Cuboid(){ 27 Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl());70 Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl()); 28 71 return Shape(impl); 29 72 } -
src/Shapes/BaseShapes_impl.hpp
r06300d r5de9da 13 13 class Sphere_impl : public Shape_impl { 14 14 virtual bool isInside(const Vector &point); 15 virtual bool isOnSurface(const Vector &point); 16 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 15 17 }; 16 18 17 19 class Cuboid_impl : public Shape_impl { 18 20 virtual bool isInside(const Vector &point); 21 virtual bool isOnSurface(const Vector &point); 22 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 19 23 }; 20 24 -
src/Shapes/Shape.cpp
r06300d r5de9da 9 9 #include "Shape_impl.hpp" 10 10 11 #include "Helpers/Assert.hpp" 12 11 13 Shape::Shape(const Shape& src) : 12 14 impl(src.getImpl()) … … 17 19 bool Shape::isInside(const Vector &point) const{ 18 20 return impl->isInside(point); 21 } 22 23 bool Shape::isOnSurface(const Vector &point) const{ 24 return impl->isOnSurface(point); 25 } 26 27 Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){ 28 return impl->getNormal(point); 19 29 } 20 30 … … 65 75 } 66 76 77 bool AndShape_impl::isOnSurface(const Vector &point){ 78 // check the number of surfaces that this point is on 79 int surfaces =0; 80 surfaces += lhs->isOnSurface(point); 81 surfaces += rhs->isOnSurface(point); 82 83 switch(surfaces){ 84 case 0: 85 return false; 86 // no break necessary 87 case 1: 88 // if it is inside for the object where it does not lie on 89 // the surface the whole point lies inside 90 return (lhs->isOnSurface(point) && !rhs->isInside(point)) || 91 (rhs->isOnSurface(point) && !lhs->isInside(point)); 92 // no break necessary 93 case 2: 94 { 95 // it lies on both Shapes... could be an edge or an inner point 96 // test the direction of the normals 97 Vector direction=lhs->getNormal(point)+rhs->getNormal(point); 98 // if the directions are opposite we lie on the inside 99 return !direction.IsZero(); 100 } 101 // no break necessary 102 default: 103 // if this happens there is something wrong 104 ASSERT(0,"Default case should have never been used"); 105 } 106 return false; // never reached 107 } 108 109 Vector AndShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){ 110 Vector res; 111 if(!isOnSurface(point)){ 112 throw NotOnSurfaceException(__FILE__,__LINE__); 113 } 114 res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec; 115 res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec; 116 res.Normalize(); 117 return res; 118 } 119 67 120 Shape operator&&(const Shape &lhs,const Shape &rhs){ 68 121 Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs))); … … 82 135 } 83 136 137 bool OrShape_impl::isOnSurface(const Vector &point){ 138 // check the number of surfaces that this point is on 139 int surfaces =0; 140 surfaces += lhs->isOnSurface(point); 141 surfaces += rhs->isOnSurface(point); 142 143 switch(surfaces){ 144 case 0: 145 return false; 146 // no break necessary 147 case 1: 148 // if it is inside for the object where it does not lie on 149 // the surface the whole point lies inside 150 return (lhs->isOnSurface(point) && rhs->isInside(point)) || 151 (rhs->isOnSurface(point) && lhs->isInside(point)); 152 // no break necessary 153 case 2: 154 { 155 // it lies on both Shapes... could be an edge or an inner point 156 // test the direction of the normals 157 Vector direction=lhs->getNormal(point)+rhs->getNormal(point); 158 // if the directions are opposite we lie on the inside 159 return !direction.IsZero(); 160 } 161 // no break necessary 162 default: 163 // if this happens there is something wrong 164 ASSERT(0,"Default case should have never been used"); 165 } 166 return false; // never reached 167 } 168 169 Vector OrShape_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){ 170 Vector res; 171 if(!isOnSurface(point)){ 172 throw NotOnSurfaceException(__FILE__,__LINE__); 173 } 174 res += lhs->isOnSurface(point)?lhs->getNormal(point):zeroVec; 175 res += rhs->isOnSurface(point)?rhs->getNormal(point):zeroVec; 176 res.Normalize(); 177 return res; 178 } 179 84 180 Shape operator||(const Shape &lhs,const Shape &rhs){ 85 181 Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs))); … … 99 195 } 100 196 197 bool NotShape_impl::isOnSurface(const Vector &point){ 198 return arg->isOnSurface(point); 199 } 200 201 Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){ 202 return -1*arg->getNormal(point); 203 } 204 101 205 Shape operator!(const Shape &arg){ 102 206 Shape::impl_ptr newImpl = Shape::impl_ptr(new NotShape_impl(getShapeImpl(arg))); -
src/Shapes/Shape.hpp
r06300d r5de9da 10 10 11 11 #include <boost/shared_ptr.hpp> 12 13 #include "Exceptions/NotOnSurfaceException.hpp" 12 14 13 15 class Vector; … … 25 27 26 28 bool isInside(const Vector &point) const; 29 bool isOnSurface(const Vector &point) const; 30 Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 27 31 28 32 Shape &operator=(const Shape& rhs); -
src/Shapes/ShapeOps.cpp
r06300d r5de9da 11 11 #include "Helpers/Assert.hpp" 12 12 13 /*************** Base case ***********************/ 14 15 ShapeOpsBase_impl::ShapeOpsBase_impl(const Shape::impl_ptr &_arg) : 16 arg(_arg){} 17 18 ShapeOpsBase_impl::~ShapeOpsBase_impl(){} 19 20 bool ShapeOpsBase_impl::isInside(const Vector &point){ 21 return arg->isInside(translateIn(point)); 22 } 23 24 bool ShapeOpsBase_impl::isOnSurface(const Vector &point){ 25 return arg->isOnSurface(translateIn(point)); 26 } 27 28 Vector ShapeOpsBase_impl::getNormal(const Vector &point) throw (NotOnSurfaceException){ 29 Vector helper = translateIn(point); 30 if(!arg->isOnSurface(helper)){ 31 throw NotOnSurfaceException(__FILE__,__LINE__); 32 } 33 return translateOutNormal(arg->getNormal(helper)); 34 } 35 13 36 /********************* Resize ********************/ 14 37 15 38 Resize_impl::Resize_impl(const Shape::impl_ptr &_arg,double _size) : 16 arg(_arg), size(_size)39 ShapeOpsBase_impl(_arg), size(_size) 17 40 { 18 41 ASSERT(size>0,"Cannot resize a Shape to size zero or below"); … … 21 44 Resize_impl::~Resize_impl(){} 22 45 23 bool Resize_impl::isInside(const Vector& point){ 24 return arg->isInside((1/size) * point); 46 Vector Resize_impl::translateIn(const Vector& point){ 47 return (1/size) * point; 48 } 49 50 Vector Resize_impl::translateOutPos(const Vector& point){ 51 return size * point; 52 } 53 54 Vector Resize_impl::translateOutNormal(const Vector& point){ 55 return point; 25 56 } 26 57 … … 33 64 34 65 Translate_impl::Translate_impl(const Shape::impl_ptr &_arg, const Vector &_offset) : 35 arg(_arg),offset(_offset)66 ShapeOpsBase_impl(_arg),offset(_offset) 36 67 {} 37 68 38 69 Translate_impl::~Translate_impl(){} 39 70 40 bool Translate_impl::isInside(const Vector& point){ 41 return arg->isInside(point-offset); 71 Vector Translate_impl::translateIn(const Vector& point){ 72 return point-offset; 73 } 74 75 Vector Translate_impl::translateOutPos(const Vector& point){ 76 return point+offset; 77 } 78 79 Vector Translate_impl::translateOutNormal(const Vector& point){ 80 return point; 42 81 } 43 82 … … 50 89 51 90 Stretch_impl::Stretch_impl(const Shape::impl_ptr &_arg, const Vector &_factors) : 52 arg(_arg),factors(_factors)91 ShapeOpsBase_impl(_arg),factors(_factors) 53 92 { 54 93 ASSERT(factors[0]>0,"cannot stretch a shape by a negative amount"); … … 62 101 Stretch_impl::~Stretch_impl(){} 63 102 64 bool Stretch_impl::isInside(const Vector& point){103 Vector Stretch_impl::translateIn(const Vector& point){ 65 104 Vector helper=point; 66 105 helper.ScaleAll(reciFactors); 67 return arg->isInside(helper); 106 return helper; 107 } 108 109 Vector Stretch_impl::translateOutPos(const Vector& point){ 110 Vector helper=point; 111 helper.ScaleAll(factors); 112 return helper; 113 } 114 115 Vector Stretch_impl::translateOutNormal(const Vector& point){ 116 Vector helper=point; 117 // the normalFactors are derived from appearances of the factors 118 // with in the vectorproduct 119 Vector normalFactors; 120 normalFactors[0]=factors[1]*factors[2]; 121 normalFactors[1]=factors[0]*factors[2]; 122 normalFactors[2]=factors[0]*factors[1]; 123 helper.ScaleAll(normalFactors); 124 return helper; 68 125 } 69 126 … … 76 133 77 134 Transform_impl::Transform_impl(const Shape::impl_ptr &_arg, const Matrix &_transformation) : 78 arg(_arg),transformation(_transformation)135 ShapeOpsBase_impl(_arg),transformation(_transformation) 79 136 { 80 137 transformationInv = transformation.invert(); … … 83 140 Transform_impl::~Transform_impl(){} 84 141 85 bool Transform_impl::isInside(const Vector& point){ 86 return arg->isInside(transformationInv * point); 142 Vector Transform_impl::translateIn(const Vector& point){ 143 return transformationInv * point; 144 } 145 146 Vector Transform_impl::translateOutPos(const Vector& point){ 147 return transformation * point; 148 } 149 150 Vector Transform_impl::translateOutNormal(const Vector& point){ 151 Matrix mat = transformation.determinant() * transformation.invert().transpose(); 152 return mat * point; 87 153 } 88 154 -
src/Shapes/ShapeOps_impl.hpp
r06300d r5de9da 13 13 #include "Matrix.hpp" 14 14 15 class Resize_impl : public Shape_impl 15 class ShapeOpsBase_impl : public Shape_impl{ 16 public: 17 ShapeOpsBase_impl(const Shape::impl_ptr&); 18 virtual ~ShapeOpsBase_impl(); 19 virtual bool isInside(const Vector &point); 20 virtual bool isOnSurface(const Vector &point); 21 virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException); 22 protected: 23 virtual Vector translateIn(const Vector &point)=0; 24 virtual Vector translateOutPos(const Vector &point)=0; 25 virtual Vector translateOutNormal(const Vector &point)=0; 26 private: 27 Shape::impl_ptr arg; 28 }; 29 30 class Resize_impl : public ShapeOpsBase_impl 16 31 { 17 32 public: 18 33 Resize_impl(const Shape::impl_ptr&,double); 19 34 virtual ~Resize_impl(); 20 virtual bool isInside(const Vector& point); 35 protected: 36 virtual Vector translateIn(const Vector &point); 37 virtual Vector translateOutPos(const Vector &point); 38 virtual Vector translateOutNormal(const Vector &point); 21 39 private: 22 Shape::impl_ptr arg;23 40 double size; 24 41 }; 25 42 26 class Translate_impl : public Shape _impl43 class Translate_impl : public ShapeOpsBase_impl 27 44 { 28 45 public: 29 46 Translate_impl(const Shape::impl_ptr&, const Vector&); 30 47 virtual ~Translate_impl(); 31 virtual bool isInside(const Vector& point); 48 protected: 49 virtual Vector translateIn(const Vector &point); 50 virtual Vector translateOutPos(const Vector &point); 51 virtual Vector translateOutNormal(const Vector &point); 32 52 private: 33 Shape::impl_ptr arg;34 53 Vector offset; 35 54 }; 36 55 37 class Stretch_impl : public Shape _impl56 class Stretch_impl : public ShapeOpsBase_impl 38 57 { 39 58 public: 40 59 Stretch_impl(const Shape::impl_ptr&, const Vector&); 41 60 virtual ~Stretch_impl(); 42 virtual bool isInside(const Vector& point); 61 protected: 62 virtual Vector translateIn(const Vector &point); 63 virtual Vector translateOutPos(const Vector &point); 64 virtual Vector translateOutNormal(const Vector &point); 43 65 private: 44 Shape::impl_ptr arg;45 66 Vector factors; 46 67 Vector reciFactors; 47 68 }; 48 69 49 class Transform_impl : public Shape _impl70 class Transform_impl : public ShapeOpsBase_impl 50 71 { 51 72 public: 52 73 Transform_impl(const Shape::impl_ptr&, const Matrix&); 53 74 virtual ~Transform_impl(); 54 virtual bool isInside(const Vector& point); 75 protected: 76 virtual Vector translateIn(const Vector &point); 77 virtual Vector translateOutPos(const Vector &point); 78 virtual Vector translateOutNormal(const Vector &point); 55 79 private: 56 Shape::impl_ptr arg;57 80 Matrix transformation; 58 81 Matrix transformationInv; -
src/Shapes/Shape_impl.hpp
r06300d r5de9da 10 10 11 11 #include "Shapes/Shape.hpp" 12 #include "vector.hpp" 12 13 13 14 class Shape_impl { … … 16 17 virtual ~Shape_impl(){}; 17 18 virtual bool isInside(const Vector &point)=0; 19 virtual bool isOnSurface(const Vector &point)=0; 20 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0; 18 21 }; 19 22 … … 23 26 return true; 24 27 } 28 virtual bool isOnSurface(const Vector &point){ 29 return false; 30 } 31 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){ 32 throw NotOnSurfaceException(__FILE__,__LINE__); 33 } 25 34 }; 26 35 … … 28 37 virtual bool isInside(const Vector &point){ 29 38 return false; 39 } 40 virtual bool isOnSurface(const Vector &point){ 41 return false; 42 } 43 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){ 44 throw NotOnSurfaceException(__FILE__,__LINE__); 30 45 } 31 46 }; … … 36 51 virtual ~AndShape_impl(); 37 52 virtual bool isInside(const Vector &point); 53 virtual bool isOnSurface(const Vector &point); 54 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 38 55 private: 39 56 Shape::impl_ptr lhs; … … 46 63 virtual ~OrShape_impl(); 47 64 virtual bool isInside(const Vector &point); 65 virtual bool isOnSurface(const Vector &point); 66 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 48 67 private: 49 68 Shape::impl_ptr lhs; … … 56 75 virtual ~NotShape_impl(); 57 76 virtual bool isInside(const Vector &point); 77 virtual bool isOnSurface(const Vector &point); 78 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 58 79 private: 59 80 Shape::impl_ptr arg;
Note:
See TracChangeset
for help on using the changeset viewer.