Changeset 6c438f for src/Shapes
- Timestamp:
- Aug 28, 2010, 3:21:11 AM (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:
- 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)
- 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 1 8 /* 2 9 * BaseShapes_impl.cpp … … 6 13 */ 7 14 15 // include config.h 16 #ifdef HAVE_CONFIG_H 17 #include <config.h> 18 #endif 19 20 #include "Helpers/MemDebug.hpp" 21 8 22 #include "Shapes/BaseShapes.hpp" 9 23 #include "Shapes/BaseShapes_impl.hpp" 10 24 #include "Shapes/ShapeOps.hpp" 11 25 12 #include "vector.hpp" 26 #include "defs.hpp" 27 13 28 #include "Helpers/Assert.hpp" 14 15 #include "Line .hpp"16 #include " Plane.hpp"17 #include "Line Segment.hpp"18 #include "Line SegmentSet.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" 19 34 20 35 #include <cmath> … … 49 64 } 50 65 66 /** 67 * algorithm taken from http://www.cgafaq.info/wiki/Evenly_distributed_points_on_sphere 68 * \param N number of points on surface 69 */ 70 std::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 51 94 Shape Sphere(){ 52 95 Shape::impl_ptr impl = Shape::impl_ptr(new Sphere_impl()); … … 63 106 64 107 bool 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); 66 109 } 67 110 … … 71 114 // double fabs 72 115 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))); 76 119 return retVal; 77 120 } … … 129 172 } 130 173 174 /** 175 * \param N number of points on surface 176 */ 177 std::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 131 183 Shape Cuboid(){ 132 184 Shape::impl_ptr impl = Shape::impl_ptr(new Cuboid_impl()); -
src/Shapes/BaseShapes_impl.hpp
r2ad482 r6c438f 9 9 #define BASESHAPES_IMPL_HPP_ 10 10 11 class Vector; 12 class LineSegmentSet; 13 11 14 #include "Shapes/Shape_impl.hpp" 12 15 … … 17 20 virtual LineSegmentSet getLineIntersections(const Line&); 18 21 virtual std::string toString(); 22 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 19 23 }; 20 24 … … 25 29 virtual LineSegmentSet getLineIntersections(const Line&); 26 30 virtual std::string toString(); 31 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 27 32 }; 28 33 -
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 1 8 /* 2 9 * Shape.cpp … … 6 13 */ 7 14 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 8 25 #include "Shape.hpp" 9 26 #include "Shape_impl.hpp" 10 27 11 #include "Helpers/Assert.hpp"12 13 28 #include <string> 14 29 15 using namespace std;16 30 17 31 Shape::Shape(const Shape& src) : … … 35 49 LineSegmentSet Shape::getLineIntersections(const Line &line){ 36 50 return impl->getLineIntersections(line); 51 } 52 53 std::vector<Vector> Shape::getHomogeneousPointsOnSurface(const size_t N) const { 54 return impl->getHomogeneousPointsOnSurface(N); 37 55 } 38 56 … … 138 156 } 139 157 158 std::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 140 176 Shape operator&&(const Shape &lhs,const Shape &rhs){ 141 177 Shape::impl_ptr newImpl = Shape::impl_ptr(new AndShape_impl(getShapeImpl(lhs),getShapeImpl(rhs))); … … 206 242 } 207 243 244 std::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 208 261 Shape operator||(const Shape &lhs,const Shape &rhs){ 209 262 Shape::impl_ptr newImpl = Shape::impl_ptr(new OrShape_impl(getShapeImpl(lhs),getShapeImpl(rhs))); … … 237 290 string NotShape_impl::toString(){ 238 291 return string("!") + arg->toString(); 292 } 293 294 std::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); 239 297 } 240 298 -
src/Shapes/Shape.hpp
r2ad482 r6c438f 13 13 14 14 #include "Exceptions/NotOnSurfaceException.hpp" 15 16 #include <vector> 15 17 16 18 class Vector; … … 34 36 35 37 LineSegmentSet getLineIntersections(const Line&); 38 std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 36 39 37 40 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 1 8 /* 2 9 * ShapeOps.cpp … … 6 13 */ 7 14 15 // include config.h 16 #ifdef HAVE_CONFIG_H 17 #include <config.h> 18 #endif 19 20 #include "Helpers/MemDebug.hpp" 21 8 22 #include "Shapes/ShapeOps.hpp" 9 23 #include "Shapes/ShapeOps_impl.hpp" 10 24 25 #include "LinearAlgebra/Vector.hpp" 11 26 #include "Helpers/Assert.hpp" 12 27 … … 55 70 } 56 71 57 Shape::impl_ptr ShapeOpsBase_impl::getArg(){ 72 std::vector<Vector> ShapeOpsBase_impl::getHomogeneousPointsOnSurface(const size_t N) const { 73 return getArg()->getHomogeneousPointsOnSurface(N);; 74 } 75 76 Shape::impl_ptr ShapeOpsBase_impl::getArg() const{ 58 77 return arg; 59 78 } … … 69 88 Resize_impl::~Resize_impl(){} 70 89 90 bool Resize_impl::isInside(const Vector& point){ 91 return getArg()->isInside((1/size) * point); 92 } 93 71 94 Vector Resize_impl::translateIn(const Vector& point){ 72 95 return (1/size) * point; … … 86 109 return sstr.str(); 87 110 } 111 112 std::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 88 120 89 121 Shape resize(const Shape &arg,double size){ … … 100 132 Translate_impl::~Translate_impl(){} 101 133 134 bool Translate_impl::isInside(const Vector& point){ 135 return getArg()->isInside(point-offset); 136 } 137 102 138 Vector Translate_impl::translateIn(const Vector& point){ 103 139 return point-offset; … … 116 152 sstr << "translate(" << getArg()->toString() << "," << offset << ")"; 117 153 return sstr.str(); 154 } 155 156 std::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; 118 162 } 119 163 … … 138 182 Stretch_impl::~Stretch_impl(){} 139 183 184 bool Stretch_impl::isInside(const Vector& point){ 185 Vector helper=point; 186 helper.ScaleAll(reciFactors); 187 return getArg()->isInside(helper); 188 } 189 140 190 Vector Stretch_impl::translateIn(const Vector& point){ 141 191 Vector helper=point; … … 168 218 } 169 219 220 std::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 170 228 Shape stretch(const Shape &arg, const Vector &factors){ 171 229 Shape::impl_ptr impl = Shape::impl_ptr(new Stretch_impl(getShapeImpl(arg),factors)); … … 183 241 Transform_impl::~Transform_impl(){} 184 242 243 bool Transform_impl::isInside(const Vector& point){ 244 return getArg()->isInside(transformationInv * point); 245 } 246 185 247 Vector Transform_impl::translateIn(const Vector& point){ 186 248 return transformationInv * point; … … 202 264 } 203 265 266 std::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 204 274 Shape transform(const Shape &arg, const Matrix &transformation){ 205 275 Shape::impl_ptr impl = Shape::impl_ptr(new Transform_impl(getShapeImpl(arg),transformation)); -
src/Shapes/ShapeOps_impl.hpp
r2ad482 r6c438f 10 10 11 11 #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 17 class LineSegment; 14 18 15 19 class ShapeOpsBase_impl : public Shape_impl{ … … 21 25 virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException); 22 26 virtual LineSegmentSet getLineIntersections(const Line&); 27 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 23 28 protected: 24 29 virtual Vector translateIn(const Vector &point)=0; 25 30 virtual Vector translateOutPos(const Vector &point)=0; 26 31 virtual Vector translateOutNormal(const Vector &point)=0; 27 Shape::impl_ptr getArg() ;32 Shape::impl_ptr getArg() const; 28 33 private: 29 34 Shape::impl_ptr arg; … … 40 45 virtual Vector translateOutNormal(const Vector &point); 41 46 virtual std::string toString(); 47 virtual bool isInside(const Vector& point); 48 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 42 49 private: 43 50 double size; … … 54 61 virtual Vector translateOutNormal(const Vector &point); 55 62 virtual std::string toString(); 63 virtual bool isInside(const Vector& point); 64 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 56 65 private: 57 66 Vector offset; … … 68 77 virtual Vector translateOutNormal(const Vector &point); 69 78 virtual std::string toString(); 79 virtual bool isInside(const Vector& point); 80 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 70 81 private: 71 82 Vector factors; … … 83 94 virtual Vector translateOutNormal(const Vector &point); 84 95 virtual std::string toString(); 96 virtual bool isInside(const Vector& point); 97 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 85 98 private: 86 99 Matrix transformation; -
src/Shapes/Shape_impl.hpp
r2ad482 r6c438f 9 9 #define SHAPE_IMPL_HPP_ 10 10 11 #include <vector> 12 11 13 #include "Shapes/Shape.hpp" 12 #include " vector.hpp"13 #include "Line .hpp"14 #include "Line Segment.hpp"15 #include "Line SegmentSet.hpp"14 #include "LinearAlgebra/Line.hpp" 15 #include "LinearAlgebra/LineSegment.hpp" 16 #include "LinearAlgebra/LineSegmentSet.hpp" 17 #include "LinearAlgebra/Vector.hpp" 16 18 17 19 … … 25 27 virtual LineSegmentSet getLineIntersections(const Line&)=0; 26 28 virtual std::string toString()=0; 29 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0; 27 30 }; 28 31 … … 46 49 return "Everywhere()"; 47 50 } 51 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const { 52 std::vector<Vector> PointsOnSurface; 53 return PointsOnSurface; 54 } 48 55 }; 49 56 … … 64 71 return "Nowhere()"; 65 72 } 73 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const { 74 std::vector<Vector> PointsOnSurface; 75 return PointsOnSurface; 76 } 66 77 }; 67 78 … … 75 86 virtual LineSegmentSet getLineIntersections(const Line&); 76 87 virtual std::string toString(); 88 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 77 89 private: 78 90 Shape::impl_ptr lhs; … … 89 101 virtual LineSegmentSet getLineIntersections(const Line&); 90 102 virtual std::string toString(); 103 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 91 104 private: 92 105 Shape::impl_ptr lhs; … … 103 116 virtual LineSegmentSet getLineIntersections(const Line&); 104 117 virtual std::string toString(); 118 virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const; 105 119 private: 106 120 Shape::impl_ptr arg;
Note:
See TracChangeset
for help on using the changeset viewer.