Changeset c6f395 for src/Shapes
- Timestamp:
- Jul 24, 2010, 11:43:18 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:
- 400170
- Parents:
- 40196a
- Location:
- src/Shapes
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Shapes/BaseShapes.cpp
r40196a rc6f395 12 12 #include "vector.hpp" 13 13 #include "Helpers/Assert.hpp" 14 15 #include "Line.hpp" 16 #include "Plane.hpp" 17 #include "LineSegment.hpp" 18 #include "LineSegmentSet.hpp" 14 19 15 20 #include <cmath> … … 29 34 } 30 35 return point; 36 } 37 38 LineSegmentSet Sphere_impl::getLineIntersections(const Line &line){ 39 LineSegmentSet res(line); 40 std::vector<Vector> intersections = line.getSphereIntersections(); 41 if(intersections.size()==2){ 42 res.insert(LineSegment(intersections[0],intersections[1])); 43 } 44 return res; 31 45 } 32 46 … … 81 95 } 82 96 97 LineSegmentSet Cuboid_impl::getLineIntersections(const Line &line){ 98 LineSegmentSet res(line); 99 // get the intersection on each of the six faces 100 vector<Vector> intersections; 101 intersections.resize(2); 102 int c=0; 103 int x[2]={-1,+1}; 104 for(int i=NDIM;i--;){ 105 for(int p=0;p<2;++p){ 106 if(c==2) goto end; // I know this sucks, but breaking two loops is stupid 107 Vector base; 108 base[i]=x[p]; 109 // base now points to the surface and is normal to it at the same time 110 Plane p(base,base); 111 Vector intersection = p.GetIntersection(line); 112 if(isInside(intersection)){ 113 // if we have a point on the edge it might already be contained 114 if(c==1 && intersections[0]==intersection) 115 continue; 116 intersections[c++]=intersection; 117 } 118 } 119 } 120 end: 121 if(c==2){ 122 res.insert(LineSegment(intersections[0],intersections[1])); 123 } 124 return res; 125 } 126 83 127 string Cuboid_impl::toString(){ 84 128 return "Cuboid()"; -
src/Shapes/BaseShapes_impl.hpp
r40196a rc6f395 15 15 virtual bool isOnSurface(const Vector &point); 16 16 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 17 virtual LineSegmentSet getLineIntersections(const Line&); 17 18 virtual std::string toString(); 18 19 }; … … 22 23 virtual bool isOnSurface(const Vector &point); 23 24 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 25 virtual LineSegmentSet getLineIntersections(const Line&); 24 26 virtual std::string toString(); 25 27 }; -
src/Shapes/Shape.cpp
r40196a rc6f395 31 31 Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){ 32 32 return impl->getNormal(point); 33 } 34 35 LineSegmentSet Shape::getLineIntersections(const Line &line){ 36 return impl->getLineIntersections(line); 33 37 } 34 38 … … 126 130 } 127 131 132 LineSegmentSet AndShape_impl::getLineIntersections(const Line &line){ 133 return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line)); 134 } 135 128 136 string AndShape_impl::toString(){ 129 137 return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")"); … … 190 198 } 191 199 200 LineSegmentSet OrShape_impl::getLineIntersections(const Line &line){ 201 return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line)); 202 } 203 192 204 string OrShape_impl::toString(){ 193 205 return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")"); … … 217 229 Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){ 218 230 return -1*arg->getNormal(point); 231 } 232 233 LineSegmentSet NotShape_impl::getLineIntersections(const Line &line){ 234 return invert(arg->getLineIntersections(line)); 219 235 } 220 236 -
src/Shapes/Shape.hpp
r40196a rc6f395 16 16 class Vector; 17 17 class Shape_impl; 18 class LineSegmentSet; 19 class Line; 18 20 19 21 class Shape … … 30 32 bool isOnSurface(const Vector &point) const; 31 33 Vector getNormal(const Vector &point) const throw(NotOnSurfaceException); 34 35 LineSegmentSet getLineIntersections(const Line&); 32 36 33 37 Shape &operator=(const Shape& rhs); -
src/Shapes/ShapeOps.cpp
r40196a rc6f395 32 32 } 33 33 return translateOutNormal(arg->getNormal(helper)); 34 } 35 36 LineSegmentSet ShapeOpsBase_impl::getLineIntersections(const Line &line){ 37 Line newLine(translateIn(line.getOrigin()),translateIn(line.getDirection())); 38 LineSegmentSet res(line); 39 LineSegmentSet helper = getArg()->getLineIntersections(newLine); 40 for(LineSegmentSet::iterator iter = helper.begin();iter!=helper.end();++iter){ 41 LinePoint lpBegin = iter->getBegin(); 42 LinePoint lpEnd = iter->getBegin(); 43 // translate both linepoints 44 lpBegin = lpBegin.isNegInfinity()? 45 line.negEndpoint(): 46 line.getLinePoint(translateOutPos(lpBegin.getPoint())); 47 lpEnd = lpEnd.isPosInfinity()? 48 line.posEndpoint(): 49 line.getLinePoint(translateOutPos(lpEnd.getPoint())); 50 res.insert(LineSegment(lpBegin,lpEnd)); 51 } 52 return res; 34 53 } 35 54 -
src/Shapes/ShapeOps_impl.hpp
r40196a rc6f395 20 20 virtual bool isOnSurface(const Vector &point); 21 21 virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException); 22 virtual LineSegmentSet getLineIntersections(const Line&); 22 23 protected: 23 24 virtual Vector translateIn(const Vector &point)=0; -
src/Shapes/Shape_impl.hpp
r40196a rc6f395 11 11 #include "Shapes/Shape.hpp" 12 12 #include "vector.hpp" 13 #include "Line.hpp" 14 #include "LineSegment.hpp" 15 #include "LineSegmentSet.hpp" 16 13 17 14 18 class Shape_impl { … … 19 23 virtual bool isOnSurface(const Vector &point)=0; 20 24 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0; 25 virtual LineSegmentSet getLineIntersections(const Line&)=0; 21 26 virtual std::string toString()=0; 22 27 }; … … 32 37 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){ 33 38 throw NotOnSurfaceException(__FILE__,__LINE__); 39 } 40 virtual LineSegmentSet getLineIntersections(const Line &line){ 41 LineSegmentSet res(line); 42 res.insert(LineSegment(line.negEndpoint(),line.posEndpoint())); 43 return res; 34 44 } 35 45 virtual std::string toString(){ … … 48 58 throw NotOnSurfaceException(__FILE__,__LINE__); 49 59 } 60 virtual LineSegmentSet getLineIntersections(const Line &line){ 61 return LineSegmentSet(line); 62 } 50 63 virtual std::string toString(){ 51 64 return "Nowhere()"; … … 60 73 virtual bool isOnSurface(const Vector &point); 61 74 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 75 virtual LineSegmentSet getLineIntersections(const Line&); 62 76 virtual std::string toString(); 63 77 private: … … 73 87 virtual bool isOnSurface(const Vector &point); 74 88 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 89 virtual LineSegmentSet getLineIntersections(const Line&); 75 90 virtual std::string toString(); 76 91 private: … … 86 101 virtual bool isOnSurface(const Vector &point); 87 102 virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException); 103 virtual LineSegmentSet getLineIntersections(const Line&); 88 104 virtual std::string toString(); 89 105 private:
Note:
See TracChangeset
for help on using the changeset viewer.