ESyS-Particle  4.0.1
SimpleParticle.hpp
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 
00014 SimpleParticle::SimpleParticle(const Vec3& pos,double rad,int id, int tag)
00015   : SimpleParticleData(pos, rad, id, tag)
00016 {
00017 }
00018 
00019 SimpleParticle::SimpleParticle(const SimpleParticle& p)
00020   : SimpleParticleData(p)
00021 {
00022 }
00023 
00024 SimpleParticle &SimpleParticle::operator=(const SimpleParticle& p)
00025 {
00026   SimpleParticleData::operator=(p);
00027   return *this;
00028 }
00029 
00030 const Vec3 &SimpleParticle::getPos() const
00031 {
00032   return getPosition();
00033 }
00034 
00035 void SimpleParticle::setPos(const Vec3 &pos)
00036 {
00037   setPosition(pos);
00038 }
00039 
00040 void SimpleParticle::moveTo(const Vec3 &v)
00041 {
00042   setPosition(v);
00043 }
00044 
00045 void SimpleParticle::translateBy(const Vec3 &v)
00046 {
00047   setPosition(getPosition()+v);
00048 }
00049 
00050 void SimpleParticle::moveBy(const Vec3 &v)
00051 {
00052   translateBy(v);
00053 }
00054 
00055 void SimpleParticle::rotate(const Vec3 &rotation, const Vec3 &posn)
00056 {
00057   // From http://mathworld.wolfram.com/RotationFormula.html
00058   const double phi = rotation.norm();
00059   if (phi > 0.0)
00060   {
00061     const Vec3 r = getPosition() - posn;
00062     const Vec3 n = rotation/phi;
00063     const double cosPhi = cos(phi);
00064     const Vec3 rotatedR =
00065       r*cosPhi + n*((dot(n, r))*(1-cosPhi)) + cross(r, n)*sin(phi);
00066     setPosition(rotatedR + posn);
00067   }
00068 }
00069 
00070 double SimpleParticle::getRad() const
00071 {
00072   return getRadius();
00073 }
00074 
00075 void SimpleParticle::setRad(double r)
00076 {
00077   setRadius(r);
00078 }
00079 
00080 bool SimpleParticle::isValid() const
00081 {
00082   return (getID() >= 0);
00083 }
00084 
00085 template <typename TmplVisitor>
00086 void SimpleParticle::visit(const TmplVisitor &visitor) const
00087 {
00088   visitor.visitSimpleParticle(*this);
00089 }
00090 
00091 template <typename TmplVisitor>
00092 void SimpleParticle::visit(TmplVisitor &visitor)
00093 {
00094   visitor.visitSimpleParticle(*this);
00095 }
00096 
00097 ostream& operator<<(ostream& ost,const SimpleParticle& p)
00098 {
00099   ost
00100     << "Particle- id " << p.getId()
00101     << " pos: " << p.getPosition()
00102     << " rad: " << p.getRadius()
00103     << " tag : " << p.getTag() << std::endl;
00104   return ost;
00105 }
00106 
00107 ParticleComparer::ParticleComparer(const SimpleParticle &particle) : m_pParticle(&particle)
00108 {
00109 }
00110 
00115 bool ParticleComparer::operator()(const SimpleParticle &p1, const SimpleParticle &p2) const
00116 {
00117   return (((p1.getPos() - m_pParticle->getPos()).norm() - p1.getRad())<
00118             ((p2.getPos() - m_pParticle->getPos()).norm() - p2.getRad()));
00119 }
00120 
00125 bool ParticleComparer::operator()(const SimpleParticle *p1, const SimpleParticle *p2) const
00126 {
00127   return (*this)(*p1, *p2);
00128 }