ESyS-Particle  4.0.1
Triangle.h
1 
2 // //
3 // Copyright (c) 2003-2011 by The University of Queensland //
4 // Earth Systems Science Computational Centre (ESSCC) //
5 // http://www.uq.edu.au/esscc //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.opensource.org/licenses/osl-3.0.php //
10 // //
12 
13 #ifndef __TRIANGLE_H
14 #define __TRIANGLE_H
15 
16 
17 //-- Project includes --
18 #include "Foundation/vec3.h"
19 #include "Foundation/Matrix3.h"
20 
21 //-- STL includes --
22 #include <utility>
23 using std::pair;
24 using std::make_pair;
25 
26 //-- IO includes --
27 #include <iostream>
28 using std::ostream;
29 
32 {
33 public:
34  TriangleError(){};
35 };
36 
37 
47 class Triangle
48 {
49  public: // types
50  typedef Vec3 (Triangle::* VectorFieldFunction)() const;
51  typedef double (Triangle::* ScalarFieldFunction)() const;
52 
53  private:
54  Matrix3 m_invtrans;
55  Matrix3 m_trans;
56  Vec3 m_p0,m_p1,m_p2;
57  Vec3 m_normal;
58  Vec3 m_force;
59  int m_id0,m_id1,m_id2;
60  int m_tri_id,m_tag;
61 
62  double EdgeSep(const Vec3&, const Vec3& ,const Vec3& ) const;
63 
64  public:
65  Triangle(int,int,int,const Vec3&,const Vec3&,const Vec3&,int,int);
66 
67  double sep(const Vec3&) const;
68  pair<bool,double> dist(const Vec3&) const ; // signed separation according to direction of the normal
69  Vec3 getBoundingBoxMin() const;
70  Vec3 getBoundingBoxMax() const;
71  Vec3 getNormal() const {return m_normal;};
72  Vec3 toGlobal(const Vec3&);
73  Vec3 toLocal(const Vec3&);
74  bool containsEdge(const Vec3&,const Vec3&) const;
75  void moveNode(int,const Vec3&);
76  void move(const Vec3&);
77  inline int getID(){return m_tri_id;};
78  inline void applyForce(const Vec3& f){m_force+=f;};
79  inline void zeroForce(){m_force=Vec3(0.0,0.0,0.0);};
80 
81  // get id/pos pairs for each node -> mainly for checkpointing
82  pair<int,Vec3> getP0()const{return make_pair(m_id0,m_p0);};
83  pair<int,Vec3> getP1()const{return make_pair(m_id1,m_p0+m_p1);};
84  pair<int,Vec3> getP2()const{return make_pair(m_id2,m_p0+m_p2);};
85 
86  // access functions
87  static VectorFieldFunction getVectorFieldFunction(const string&);
88  static ScalarFieldFunction getScalarFieldFunction(const string&);
89 
90  Vec3 getForce()const {return m_force;};
91  double getPressure() const;
92 
94  friend ostream& operator<<(ostream&,const Triangle&);
95 };
96 
97 #endif //__TRIANGLE_H