Atoms Crowd  7.0.0
Triangle.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsUtils/Globals.h>
11 #include <AtomsUtils/AtomsMath.h>
12 #include <vector>
13 
14 namespace AtomsUtils
15 {
17  class ATOMSUTILS_EXPORT Triangle
18  {
19  public:
20 
23 
25 
31  Triangle(const AtomsMath::Vector3f& v0, const AtomsMath::Vector3f& v1, const AtomsMath::Vector3f& v2, unsigned int id = 0);
32 
35 
37  AtomsMath::Vector3f midPoint();
38 
40  AtomsMath::Box3f bbox();
41 
43  AtomsMath::Vector3f barycentric(const AtomsMath::Vector3f &point);
44 
46 
54  bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &t, float &u, float &v);
55 
57 
61  bool intersect(const AtomsMath::Box3f& bbox);
62 
64  AtomsMath::Vector3f closestPoint(const AtomsMath::Vector3f& inP, float& outU, float& outV, float& sqrDistance);
65 
66  public:
67 
69  AtomsMath::Box3f boundingbox;
70 
72  AtomsMath::Vector3f p0;
73 
75  AtomsMath::Vector3f p1;
76 
78  AtomsMath::Vector3f p2;
79 
81  unsigned int id;
82  };
83 
84 
86  class ATOMSUTILS_EXPORT Triangle2
87  {
88  public:
89 
90 
93 
95 
101  Triangle2(const AtomsMath::Vector2f& v0, const AtomsMath::Vector2f& v1, const AtomsMath::Vector2f& v2, unsigned int id = 0);
102 
103  Triangle2(const AtomsMath::Vector2f& v0, const AtomsMath::Vector2f& v1, const AtomsMath::Vector2f& v2, const unsigned int p0Id, const unsigned int p1Id, const unsigned int p2Id);
104 
107 
108  bool contains(const unsigned int index) const;
109 
110  bool isEqual(const Triangle2 &other) const;
111 
112  void makeCounterClockWise();
113 
114  double distanceToCenter(const AtomsMath::Vector2f &point) const;
115 
116  double distanceTo(const AtomsMath::Vector2f& point) const;
117 
118  AtomsMath::Vector2f closestPoint(const AtomsMath::Vector2f& point, float& outU, float& outV, float& sqrDistance) const;
119 
120 
121  public:
122 
124  AtomsMath::Vector2f p0;
125 
127  AtomsMath::Vector2f p1;
128 
130  AtomsMath::Vector2f p2;
131 
133  unsigned int p0Id;
134 
136  unsigned int p1Id;
137 
139  unsigned int p2Id;
140 
142  unsigned int id;
143  };
144 }
Triangle 2D class.
Definition: Triangle.h:87
AtomsMath::Vector2f p2
Vertex 2.
Definition: Triangle.h:130
~Triangle2()
Destructor.
Triangle2()
Constructor.
unsigned int id
Triangle id.
Definition: Triangle.h:142
AtomsMath::Vector2f p1
Vertex 1.
Definition: Triangle.h:127
unsigned int p2Id
Vertex 2 id.
Definition: Triangle.h:139
Triangle2(const AtomsMath::Vector2f &v0, const AtomsMath::Vector2f &v1, const AtomsMath::Vector2f &v2, unsigned int id=0)
Constructor.
unsigned int p1Id
Vertex 1 id.
Definition: Triangle.h:136
unsigned int p0Id
Vertex 0 id.
Definition: Triangle.h:133
AtomsMath::Vector2f p0
Vertex 0.
Definition: Triangle.h:124
Triangle class.
Definition: Triangle.h:18
AtomsMath::Box3f bbox()
Get triangle bounding box.
AtomsMath::Vector3f midPoint()
Get triangle mid point.
AtomsMath::Box3f boundingbox
Triangle bounding box.
Definition: Triangle.h:69
AtomsMath::Vector3f closestPoint(const AtomsMath::Vector3f &inP, float &outU, float &outV, float &sqrDistance)
! Closest point
AtomsMath::Vector3f p0
Vertex 0.
Definition: Triangle.h:72
Triangle()
Constructor.
AtomsMath::Vector3f barycentric(const AtomsMath::Vector3f &point)
Get the barycentric coordinates of the given point.
AtomsMath::Vector3f p1
Vertex 1.
Definition: Triangle.h:75
~Triangle()
Destructor.
bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &t, float &u, float &v)
Ray/triangle intersector.
unsigned int id
Triangle id.
Definition: Triangle.h:81
Triangle(const AtomsMath::Vector3f &v0, const AtomsMath::Vector3f &v1, const AtomsMath::Vector3f &v2, unsigned int id=0)
Constructor.
bool intersect(const AtomsMath::Box3f &bbox)
Triange/BBox intersector.
AtomsMath::Vector3f p2
Vertex 2.
Definition: Triangle.h:78
AtomsCore namespace.
Definition: Base64.h:13