Changeset c6f395 for src/Shapes


Ignore:
Timestamp:
Jul 24, 2010, 11:43:18 AM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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
Message:

Added methods to calculate the intersections of Shapes with arbitrary lines

Location:
src/Shapes
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Shapes/BaseShapes.cpp

    r40196a rc6f395  
    1212#include "vector.hpp"
    1313#include "Helpers/Assert.hpp"
     14
     15#include "Line.hpp"
     16#include "Plane.hpp"
     17#include "LineSegment.hpp"
     18#include "LineSegmentSet.hpp"
    1419
    1520#include <cmath>
     
    2934  }
    3035  return point;
     36}
     37
     38LineSegmentSet 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;
    3145}
    3246
     
    8195}
    8296
     97LineSegmentSet 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
    83127string Cuboid_impl::toString(){
    84128  return "Cuboid()";
  • src/Shapes/BaseShapes_impl.hpp

    r40196a rc6f395  
    1515  virtual bool isOnSurface(const Vector &point);
    1616  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     17  virtual LineSegmentSet getLineIntersections(const Line&);
    1718  virtual std::string toString();
    1819};
     
    2223  virtual bool isOnSurface(const Vector &point);
    2324  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     25  virtual LineSegmentSet getLineIntersections(const Line&);
    2426  virtual std::string toString();
    2527};
  • src/Shapes/Shape.cpp

    r40196a rc6f395  
    3131Vector Shape::getNormal(const Vector &point) const throw (NotOnSurfaceException){
    3232  return impl->getNormal(point);
     33}
     34
     35LineSegmentSet Shape::getLineIntersections(const Line &line){
     36  return impl->getLineIntersections(line);
    3337}
    3438
     
    126130}
    127131
     132LineSegmentSet AndShape_impl::getLineIntersections(const Line &line){
     133  return intersect(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     134}
     135
    128136string AndShape_impl::toString(){
    129137  return string("(") + lhs->toString() + string("&&") + rhs->toString() + string(")");
     
    190198}
    191199
     200LineSegmentSet OrShape_impl::getLineIntersections(const Line &line){
     201  return merge(lhs->getLineIntersections(line),rhs->getLineIntersections(line));
     202}
     203
    192204string OrShape_impl::toString(){
    193205  return string("(") + lhs->toString() + string("||") + rhs->toString() + string(")");
     
    217229Vector NotShape_impl::getNormal(const Vector &point) throw(NotOnSurfaceException){
    218230  return -1*arg->getNormal(point);
     231}
     232
     233LineSegmentSet NotShape_impl::getLineIntersections(const Line &line){
     234  return invert(arg->getLineIntersections(line));
    219235}
    220236
  • src/Shapes/Shape.hpp

    r40196a rc6f395  
    1616class Vector;
    1717class Shape_impl;
     18class LineSegmentSet;
     19class Line;
    1820
    1921class Shape
     
    3032  bool isOnSurface(const Vector &point) const;
    3133  Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
     34
     35  LineSegmentSet getLineIntersections(const Line&);
    3236
    3337  Shape &operator=(const Shape& rhs);
  • src/Shapes/ShapeOps.cpp

    r40196a rc6f395  
    3232  }
    3333  return translateOutNormal(arg->getNormal(helper));
     34}
     35
     36LineSegmentSet 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;
    3453}
    3554
  • src/Shapes/ShapeOps_impl.hpp

    r40196a rc6f395  
    2020  virtual bool isOnSurface(const Vector &point);
    2121  virtual Vector getNormal(const Vector &point) throw (NotOnSurfaceException);
     22  virtual LineSegmentSet getLineIntersections(const Line&);
    2223protected:
    2324  virtual Vector translateIn(const Vector &point)=0;
  • src/Shapes/Shape_impl.hpp

    r40196a rc6f395  
    1111#include "Shapes/Shape.hpp"
    1212#include "vector.hpp"
     13#include "Line.hpp"
     14#include "LineSegment.hpp"
     15#include "LineSegmentSet.hpp"
     16
    1317
    1418class Shape_impl {
     
    1923  virtual bool isOnSurface(const Vector &point)=0;
    2024  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException)=0;
     25  virtual LineSegmentSet getLineIntersections(const Line&)=0;
    2126  virtual std::string toString()=0;
    2227};
     
    3237  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException){
    3338    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;
    3444  }
    3545  virtual std::string toString(){
     
    4858    throw NotOnSurfaceException(__FILE__,__LINE__);
    4959  }
     60  virtual LineSegmentSet getLineIntersections(const Line &line){
     61    return LineSegmentSet(line);
     62  }
    5063  virtual std::string toString(){
    5164    return "Nowhere()";
     
    6073  virtual bool isOnSurface(const Vector &point);
    6174  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     75  virtual LineSegmentSet getLineIntersections(const Line&);
    6276  virtual std::string toString();
    6377private:
     
    7387  virtual bool isOnSurface(const Vector &point);
    7488  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     89  virtual LineSegmentSet getLineIntersections(const Line&);
    7590  virtual std::string toString();
    7691private:
     
    86101  virtual bool isOnSurface(const Vector &point);
    87102  virtual Vector getNormal(const Vector &point) throw(NotOnSurfaceException);
     103  virtual LineSegmentSet getLineIntersections(const Line&);
    88104  virtual std::string toString();
    89105private:
Note: See TracChangeset for help on using the changeset viewer.