- Timestamp:
- Mar 28, 2012, 3:17:38 PM (13 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:
- 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)
- Location:
- src/Shapes
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Shapes/BaseShapes.cpp
r84721b r6acc2f3 51 51 return point; 52 52 } 53 54 Vector Sphere_impl::getCenter() const 55 { 56 return Vector(0.,0.,0.); 57 } 58 59 double Sphere_impl::getRadius() const 60 { 61 return 1.; 62 } 63 53 64 54 65 LineSegmentSet Sphere_impl::getLineIntersections(const Line &line) const{ … … 167 178 } 168 179 180 181 Vector Cuboid_impl::getCenter() const 182 { 183 return Vector(0.5,0.5,0.5); 184 } 185 186 double Cuboid_impl::getRadius() const 187 { 188 return .5; 189 } 190 169 191 LineSegmentSet Cuboid_impl::getLineIntersections(const Line &line) const{ 170 192 LineSegmentSet res(line); -
src/Shapes/BaseShapes_impl.hpp
r84721b r6acc2f3 26 26 virtual bool isOnSurface(const Vector &point) const; 27 27 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 28 virtual Vector getCenter() const; 29 virtual double getRadius() const; 28 30 virtual LineSegmentSet getLineIntersections(const Line&) const; 29 31 virtual std::string toString() const; … … 36 38 virtual bool isOnSurface(const Vector &point) const; 37 39 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 40 virtual Vector getCenter() const; 41 virtual double getRadius() const; 38 42 virtual LineSegmentSet getLineIntersections(const Line&) const; 39 43 virtual std::string toString() const; -
src/Shapes/Shape.cpp
r84721b r6acc2f3 28 28 #include "Shapes/ShapeType.hpp" 29 29 30 #include <algorithm> 31 #include <limits> 30 32 #include <string> 31 33 … … 47 49 Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){ 48 50 return impl->getNormal(point); 51 } 52 53 Vector Shape::getCenter() const{ 54 return impl->getCenter(); 55 } 56 57 double Shape::getRadius() const{ 58 return impl->getRadius(); 49 59 } 50 60 … … 158 168 } 159 169 170 Vector 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 179 double 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 160 190 LineSegmentSet AndShape_impl::getLineIntersections(const Line &line) const{ 161 191 return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line)); … … 248 278 } 249 279 280 Vector 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 289 double 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 250 296 LineSegmentSet OrShape_impl::getLineIntersections(const Line &line) const{ 251 297 return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line)); … … 302 348 } 303 349 350 Vector NotShape_impl::getCenter() const 351 { 352 return arg->getCenter(); 353 } 354 355 double NotShape_impl::getRadius() const 356 { 357 return std::numeric_limits<double>::infinity(); 358 } 359 304 360 LineSegmentSet NotShape_impl::getLineIntersections(const Line &line) const{ 305 361 return invert(arg->getLineIntersections(line)); -
src/Shapes/Shape.hpp
r84721b r6acc2f3 43 43 44 44 Vector getCenter() const; 45 VectorgetRadius() const;45 double getRadius() const; 46 46 47 47 LineSegmentSet getLineIntersections(const Line&) const; -
src/Shapes/ShapeOps.cpp
r84721b r6acc2f3 51 51 return res; 52 52 } 53 54 Vector ShapeOpsBase_impl::getCenter() const 55 { 56 return arg->getCenter(); 57 } 58 59 double ShapeOpsBase_impl::getRadius() const 60 { 61 return translateOutPos(Vector(arg->getRadius(), 0., 0.)).Norm(); 62 } 63 53 64 54 65 LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line) const{ … … 141 152 } 142 153 154 Vector Translate_impl::getCenter() const 155 { 156 return getArg()->getCenter()+offset; 157 } 158 159 double Translate_impl::getRadius() const 160 { 161 return getArg()->getRadius(); 162 } 163 164 143 165 Vector Translate_impl::translateIn(const Vector& point) const{ 144 166 return point-offset; -
src/Shapes/ShapeOps_impl.hpp
r84721b r6acc2f3 32 32 virtual bool isOnSurface(const Vector &point) const; 33 33 virtual Vector getNormal(const Vector &point) const throw (NotOnSurfaceException); 34 virtual Vector getCenter() const; 35 virtual double getRadius() const; 34 36 virtual LineSegmentSet getLineIntersections(const Line&) const; 35 37 virtual enum ShapeType getType() const; … … 66 68 virtual ~Translate_impl(); 67 69 protected: 70 virtual Vector getCenter() const; 71 virtual double getRadius() const; 68 72 virtual Vector translateIn(const Vector &point) const; 69 73 virtual Vector translateOutPos(const Vector &point) const; -
src/Shapes/Shape_impl.hpp
r84721b r6acc2f3 15 15 16 16 17 #include <limits> 17 18 #include <vector> 18 19 … … 33 34 virtual bool isOnSurface(const Vector &point) const=0; 34 35 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException)=0; 36 virtual Vector getCenter() const=0; 37 virtual double getRadius() const=0; 35 38 virtual LineSegmentSet getLineIntersections(const Line&) const=0; 36 39 virtual std::string toString() const =0; … … 49 52 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){ 50 53 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(); 51 60 } 52 61 virtual LineSegmentSet getLineIntersections(const Line &line) const{ … … 77 86 throw NotOnSurfaceException() << ShapeVector(&point); 78 87 } 88 virtual Vector getCenter() const { 89 return Vector(0.,0.,0.); 90 } 91 virtual double getRadius() const { 92 return 0.; 93 } 79 94 virtual LineSegmentSet getLineIntersections(const Line &line) const{ 80 95 return LineSegmentSet(line); … … 99 114 virtual bool isOnSurface(const Vector &point) const; 100 115 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 116 virtual Vector getCenter() const; 117 virtual double getRadius() const; 101 118 virtual LineSegmentSet getLineIntersections(const Line&) const; 102 119 virtual std::string toString() const; … … 115 132 virtual bool isOnSurface(const Vector &point) const; 116 133 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 134 virtual Vector getCenter() const; 135 virtual double getRadius() const; 117 136 virtual LineSegmentSet getLineIntersections(const Line&) const; 118 137 virtual std::string toString() const; … … 131 150 virtual bool isOnSurface(const Vector &point) const; 132 151 virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 152 virtual Vector getCenter() const; 153 virtual double getRadius() const; 133 154 virtual LineSegmentSet getLineIntersections(const Line&) const; 134 155 virtual std::string toString() const; -
src/Shapes/unittests/BaseShapesUnitTest.cpp
r84721b r6acc2f3 34 34 #include "Shapes/BaseShapes.hpp" 35 35 #include "Shapes/Shape.hpp" 36 #include "Shapes/ShapeOps.hpp" 36 37 37 38 #include "BaseShapesUnitTest.hpp" … … 658 659 CPPUNIT_ASSERT_EQUAL((size_t)194, PointsOnSurface.size()); 659 660 } 660 -
src/Shapes/unittests/ShapeOpsUnitTest.cpp
r84721b r6acc2f3 23 23 24 24 #include <cmath> 25 #include <limits> 25 26 26 27 #ifdef HAVE_TESTRUNNER … … 107 108 } 108 109 110 void 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 188 void 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 24 24 CPPUNIT_TEST ( stretchTest ); 25 25 CPPUNIT_TEST ( transformTest ); 26 CPPUNIT_TEST ( getCenterTest ); 27 CPPUNIT_TEST ( getRadiusTest ); 26 28 CPPUNIT_TEST_SUITE_END(); 27 29 … … 34 36 void stretchTest(); 35 37 void transformTest(); 38 void getCenterTest(); 39 void getRadiusTest(); 36 40 }; 37 41
Note:
See TracChangeset
for help on using the changeset viewer.