| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
#ifndef _TRIANGLE_H_ |
| 35 |
#define _TRIANGLE_H_ |
| 36 |
|
| 37 |
#include <math.h> |
| 38 |
#include <vector> |
| 39 |
#include <iostream> |
| 40 |
#include "boundingBox.h" |
| 41 |
#include "minivector.h" |
| 42 |
|
| 43 |
class TriangleBasic |
| 44 |
{ |
| 45 |
public: |
| 46 |
|
| 47 |
TriangleBasic(const Vec3d & first_g, const Vec3d & second_g, const Vec3d & third_g): |
| 48 |
first_(first_g), second_(second_g), third_(third_g), index_(0) {} |
| 49 |
|
| 50 |
|
| 51 |
inline const Vec3d & first() const {return first_ ;} |
| 52 |
inline const Vec3d & second() const {return second_ ;} |
| 53 |
inline const Vec3d & third() const {return third_ ;} |
| 54 |
inline int index() const { return index_; } |
| 55 |
|
| 56 |
|
| 57 |
inline void setIndex(int index_) { this->index_ = index_; } |
| 58 |
|
| 59 |
|
| 60 |
double distanceToPoint2(const Vec3d & point) const { std::cout << "Unimplemented..." << std::endl; return 1;} |
| 61 |
double distanceToPoint(const Vec3d & point) const { return sqrt(distanceToPoint2(point));} |
| 62 |
|
| 63 |
bool doesIntersectBox(const BoundingBox & bbox) const; |
| 64 |
|
| 65 |
|
| 66 |
int lineSegmentIntersection(const Vec3d & segmentStart, const Vec3d & segmentEnd, Vec3d * intersectionPoint) const; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
void render() const; |
| 75 |
void renderEdges() const; |
| 76 |
|
| 77 |
Vec3d getBarycentricLocation(double alpha, double beta, double gamma) const { return alpha * first_ + beta * second_ + gamma * third_; } |
| 78 |
|
| 79 |
protected: |
| 80 |
|
| 81 |
Vec3d first_, second_, third_; |
| 82 |
int index_; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
template<class TriangleClass> |
| 87 |
void makeUniqueList(const std::vector<TriangleClass*> & triangleList, std::vector<TriangleClass*> & uniqueList); |
| 88 |
|
| 89 |
template<class TriangleClass> |
| 90 |
void makeUniqueList(std::vector<TriangleClass*> & triangleList); |
| 91 |
|
| 92 |
class TriangleWithCollisionInfo : public TriangleBasic |
| 93 |
{ |
| 94 |
public: |
| 95 |
TriangleWithCollisionInfo(const Vec3d & first_g, const Vec3d & second_g, const Vec3d & third_g): |
| 96 |
TriangleBasic(first_g,second_g,third_g) { ComputeCollisionInfo(); } |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
double distanceToPoint2(const Vec3d & point, int * closestFeature) const; |
| 108 |
double distanceToPoint2(const Vec3d & point, int * closestFeature, double * alpha, double * beta, double * gamma) const; |
| 109 |
|
| 110 |
protected: |
| 111 |
|
| 112 |
|
| 113 |
Mat3d Q; |
| 114 |
Vec3d x0; |
| 115 |
|
| 116 |
double sidea,sideb,sidec,area; |
| 117 |
Vec3d S1,S2,N11,N12,N21,N22; |
| 118 |
|
| 119 |
int permutation[6]; |
| 120 |
|
| 121 |
|
| 122 |
void ComputeCollisionInfo(); |
| 123 |
}; |
| 124 |
|
| 125 |
class TriangleWithCollisionInfoAndPseudoNormals : public TriangleWithCollisionInfo |
| 126 |
{ |
| 127 |
public: |
| 128 |
|
| 129 |
TriangleWithCollisionInfoAndPseudoNormals(const Vec3d & first_g, const Vec3d & second_g, const Vec3d & third_g, const Vec3d pseudoNormals[7]); |
| 130 |
|
| 131 |
inline const Vec3d & pseudoNormal(int closestFeature) const { return pseudoNormal_[closestFeature]; } |
| 132 |
inline Vec3d interpolatedVertexPseudoNormal(double alpha, double beta, double gamma) const { return norm(alpha * pseudoNormal_[0] + beta * pseudoNormal_[1] + gamma * pseudoNormal_[2]); } |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
inline const Vec3d & pseudoClosestPosition(int closestFeature) const { return pseudoClosestPosition_[closestFeature]; } |
| 138 |
|
| 139 |
protected: |
| 140 |
Vec3d pseudoNormal_[7]; |
| 141 |
Vec3d pseudoClosestPosition_[7]; |
| 142 |
|
| 143 |
}; |
| 144 |
|
| 145 |
#endif |
| 146 |
|