KrisLibrary  1.0.0
TriMesh.h
1 #ifndef MESHING_TRIMESH_H
2 #define MESHING_TRIMESH_H
3 
5 #include <KrisLibrary/math3d/Triangle3D.h>
6 #include <KrisLibrary/math3d/Ray3D.h>
7 #include <KrisLibrary/utils/IntTriple.h>
8 #include <vector>
9 #include <iosfwd>
10 
18 namespace Meshing {
19 
20 using namespace Math3D;
21 using namespace std;
22 
41 struct TriMesh
42 {
43  typedef IntTriple Tri;
44 
46 
47  Vector3& TriangleVertex(int tri,int v);
49  const Vector3& TriangleVertex(int tri,int v) const;
51  Vector3 TriangleNormal(int tri) const;
53  void GetTriangle(int tri,Triangle3D& t) const;
55  void GetIncidentTris(int v,vector<int>& tris) const;
57  void AppendIncidentTris(int v,vector<int>& t) const;
59  void GetEdge(int tri,int e,int& v1,int& v2) const;
62  int GetAdjacentTri(int tri,int e) const;
64 
66 
67  bool IsValid() const;
68  void GetAABB(Vector3& bmin, Vector3& bmax) const;
69  //returns the closest/collided triangle
70  int ClosestPoint(const Vector3& pt,Vector3& cp) const;
71  int RayCast(const Ray3D& r,Vector3& pt) const;
72  bool Intersects(const Plane3D&) const;
73  bool PlaneSplits(const Plane3D&,Real& dmin,Real& dmax) const;
75 
77 
78  void Transform(const Matrix4& mat);
79  void FlipFaces();
80  void Merge(const vector<TriMesh>& meshes);
81  void MergeWith(const TriMesh& mesh);
82  void RemoveUnusedVerts();
84 
85  bool Load(const char* fn);
86  bool Save(const char* fn) const;
87 
88  vector<Vector3> verts;
89  vector<Tri> tris;
90 };
91 
92 istream& operator >> (istream& in,TriMesh& tri);
93 ostream& operator << (ostream& out,const TriMesh& tri);
94 bool LoadMultipleTriMeshes(const char* fn,TriMesh& tri);
95 
96 } //namespace Meshing
97 
98 #endif
A lightweight integer 3-tuple class.
Definition: IntTriple.h:9
The namespace for all classes/functions in the Meshing package.
Definition: AnyGeometry.h:10
A 3D plane classRepresents plane with a normal and offset such that x on the plane satisfy dot(normal...
Definition: Plane3D.h:19
A 3D vector class.
Definition: math3d/primitives.h:136
Definition: rayprimitives.h:132
Class declarations for useful 3D math types.
A 4x4 matrix class.
Definition: math3d/primitives.h:626
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:12
A 3D triangle class.
Definition: Triangle3D.h:26
A basic triangle mesh.
Definition: TriMesh.h:41
Definition: Ray3D.h:8