ESyS-Particle  4.0.1
Triangle.h
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 #ifndef __TRIANGLE_H
00014 #define __TRIANGLE_H
00015 
00016 
00017 //-- Project includes --
00018 #include "Foundation/vec3.h"
00019 #include "Foundation/Matrix3.h"
00020 
00021 //-- STL includes --
00022 #include <utility>
00023 using std::pair;
00024 using std::make_pair;
00025 
00026 //-- IO includes --
00027 #include <iostream>
00028 using std::ostream;
00029 
00031 class TriangleError
00032 {
00033 public:
00034   TriangleError(){};
00035 };
00036 
00037 
00047 class Triangle
00048 {
00049  public: // types
00050   typedef Vec3 (Triangle::* VectorFieldFunction)() const;
00051   typedef double (Triangle::* ScalarFieldFunction)() const;
00052 
00053  private:
00054   Matrix3 m_invtrans;
00055   Matrix3 m_trans;
00056   Vec3 m_p0,m_p1,m_p2;
00057   Vec3 m_normal;
00058   Vec3 m_force;
00059   int m_id0,m_id1,m_id2;
00060   int m_tri_id,m_tag;
00061 
00062   double EdgeSep(const Vec3&, const Vec3& ,const Vec3& ) const;
00063   
00064  public:
00065   Triangle(int,int,int,const Vec3&,const Vec3&,const Vec3&,int,int);
00066 
00067   double sep(const Vec3&) const;
00068   pair<bool,double> dist(const Vec3&) const ; // signed separation according to direction of the normal
00069   Vec3 getBoundingBoxMin() const; 
00070   Vec3 getBoundingBoxMax() const; 
00071   Vec3 getNormal() const {return m_normal;};
00072   Vec3 toGlobal(const Vec3&);
00073   Vec3 toLocal(const Vec3&);
00074   bool containsEdge(const Vec3&,const Vec3&) const;
00075   void moveNode(int,const Vec3&);
00076   void move(const Vec3&);
00077   inline int getID(){return m_tri_id;};
00078   inline void applyForce(const Vec3& f){m_force+=f;};
00079   inline void zeroForce(){m_force=Vec3(0.0,0.0,0.0);};
00080 
00081   // get id/pos pairs for each node -> mainly for checkpointing
00082   pair<int,Vec3> getP0()const{return make_pair(m_id0,m_p0);};
00083   pair<int,Vec3> getP1()const{return make_pair(m_id1,m_p0+m_p1);};
00084   pair<int,Vec3> getP2()const{return make_pair(m_id2,m_p0+m_p2);};
00085 
00086   // access functions
00087   static VectorFieldFunction getVectorFieldFunction(const string&);
00088   static ScalarFieldFunction getScalarFieldFunction(const string&);
00089 
00090   Vec3 getForce()const {return m_force;};
00091   double getPressure() const;
00092 
00094   friend ostream& operator<<(ostream&,const Triangle&); 
00095 };
00096 
00097 #endif //__TRIANGLE_H