Atoms Crowd  4.1.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 }
AtomsUtils::Triangle2
Triangle 2D class.
Definition: Triangle.h:87
AtomsUtils::Triangle2::id
unsigned int id
Triangle id.
Definition: Triangle.h:142
AtomsUtils::Triangle::boundingbox
AtomsMath::Box3f boundingbox
Triangle bounding box.
Definition: Triangle.h:69
AtomsUtils::Triangle::~Triangle
~Triangle()
Destructor.
AtomsUtils
AtomsCore namespace.
Definition: Base64.h:13
AtomsUtils::Triangle2::Triangle2
Triangle2(const AtomsMath::Vector2f &v0, const AtomsMath::Vector2f &v1, const AtomsMath::Vector2f &v2, unsigned int id=0)
Constructor.
AtomsUtils::Triangle::intersect
bool intersect(const AtomsMath::Box3f &bbox)
Triange/BBox intersector.
AtomsUtils::Triangle2::p1
AtomsMath::Vector2f p1
Vertex 1.
Definition: Triangle.h:127
AtomsUtils::Triangle::bbox
AtomsMath::Box3f bbox()
Get triangle bounding box.
AtomsUtils::Triangle::midPoint
AtomsMath::Vector3f midPoint()
Get triangle mid point.
AtomsUtils::Triangle2::Triangle2
Triangle2()
Constructor.
AtomsUtils::Triangle::p0
AtomsMath::Vector3f p0
Vertex 0.
Definition: Triangle.h:72
AtomsUtils::Triangle::closestPoint
AtomsMath::Vector3f closestPoint(const AtomsMath::Vector3f &inP, float &outU, float &outV, float &sqrDistance)
! Closest point
AtomsUtils::Triangle::p1
AtomsMath::Vector3f p1
Vertex 1.
Definition: Triangle.h:75
AtomsUtils::Triangle::barycentric
AtomsMath::Vector3f barycentric(const AtomsMath::Vector3f &point)
Get the barycentric coordinates of the given point.
AtomsUtils::Triangle
Triangle class.
Definition: Triangle.h:18
AtomsUtils::Triangle2::p2
AtomsMath::Vector2f p2
Vertex 2.
Definition: Triangle.h:130
AtomsUtils::Triangle::p2
AtomsMath::Vector3f p2
Vertex 2.
Definition: Triangle.h:78
AtomsUtils::Triangle::id
unsigned int id
Triangle id.
Definition: Triangle.h:81
AtomsUtils::Triangle2::p0Id
unsigned int p0Id
Vertex 0 id.
Definition: Triangle.h:133
AtomsUtils::Triangle2::p0
AtomsMath::Vector2f p0
Vertex 0.
Definition: Triangle.h:124
AtomsUtils::Triangle::Triangle
Triangle(const AtomsMath::Vector3f &v0, const AtomsMath::Vector3f &v1, const AtomsMath::Vector3f &v2, unsigned int id=0)
Constructor.
AtomsUtils::Triangle::intersect
bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &t, float &u, float &v)
Ray/triangle intersector.
AtomsUtils::Triangle::Triangle
Triangle()
Constructor.
AtomsUtils::Triangle2::p1Id
unsigned int p1Id
Vertex 1 id.
Definition: Triangle.h:136
AtomsUtils::Triangle2::~Triangle2
~Triangle2()
Destructor.
AtomsUtils::Triangle2::p2Id
unsigned int p2Id
Vertex 2 id.
Definition: Triangle.h:139