cleanup some unneeded class

This commit is contained in:
ZappoMan 2017-05-12 18:33:28 -07:00
parent 89b6a79f68
commit f1bd06cfa0
2 changed files with 24 additions and 58 deletions

View file

@ -42,7 +42,7 @@ bool TriangleSet::findRayIntersection(const glm::vec3& origin, const glm::vec3&
int trianglesTouched = 0; int trianglesTouched = 0;
auto result = _triangleOctree.findRayIntersection(origin, direction, distance, face, surfaceNormal, precision, trianglesTouched); auto result = _triangleOctree.findRayIntersection(origin, direction, distance, face, surfaceNormal, precision, trianglesTouched);
//qDebug() << "trianglesTouched :" << trianglesTouched << "out of:" << _triangleOctree._population; qDebug() << "trianglesTouched :" << trianglesTouched << "out of:" << _triangleOctree._population;
return result; return result;
} }
@ -82,29 +82,13 @@ void TriangleSet::balanceOctree() {
_isBalanced = true; _isBalanced = true;
//debugDump(); debugDump();
} }
void InternalTriangleSet::insert(int triangleIndex) {
auto& triangle = _allTriangles[triangleIndex];
_triangleIndices.push_back(triangleIndex);
_bounds += triangle.v0;
_bounds += triangle.v1;
_bounds += triangle.v2;
}
void InternalTriangleSet::clear() {
_triangleIndices.clear();
_bounds.clear();
}
// Determine of the given ray (origin/direction) in model space intersects with any triangles // Determine of the given ray (origin/direction) in model space intersects with any triangles
// in the set. If an intersection occurs, the distance and surface normal will be provided. // in the set. If an intersection occurs, the distance and surface normal will be provided.
bool InternalTriangleSet::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool TriangleOctreeCell::findRayIntersectionInternal(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precision, int& trianglesTouched) { float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precision, int& trianglesTouched) {
bool intersectedSomething = false; bool intersectedSomething = false;
@ -146,20 +130,20 @@ static const int MAX_DEPTH = 3; // for now
static const int MAX_CHILDREN = 8; static const int MAX_CHILDREN = 8;
TriangleOctreeCell::TriangleOctreeCell(std::vector<Triangle>& allTriangles, const AABox& bounds, int depth) : TriangleOctreeCell::TriangleOctreeCell(std::vector<Triangle>& allTriangles, const AABox& bounds, int depth) :
_allTriangles(allTriangles), _allTriangles(allTriangles)
_triangleSet(allTriangles)
{ {
reset(bounds, depth); reset(bounds, depth);
} }
void TriangleOctreeCell::clear() { void TriangleOctreeCell::clear() {
_triangleSet.clear();
_population = 0; _population = 0;
_triangleIndices.clear();
_bounds.clear();
} }
void TriangleOctreeCell::reset(const AABox& bounds, int depth) { void TriangleOctreeCell::reset(const AABox& bounds, int depth) {
clear(); clear();
_triangleSet._bounds = bounds; _bounds = bounds;
_depth = depth; _depth = depth;
if (depth <= MAX_DEPTH) { if (depth <= MAX_DEPTH) {
int childDepth = depth + 1; int childDepth = depth + 1;
@ -172,7 +156,7 @@ void TriangleOctreeCell::debugDump() {
qDebug() << "bounds:" << getBounds(); qDebug() << "bounds:" << getBounds();
qDebug() << "depth:" << _depth; qDebug() << "depth:" << _depth;
qDebug() << "population:" << _population << "this level or below"; qDebug() << "population:" << _population << "this level or below";
qDebug() << "triangleSet:" << _triangleSet.size() << "in this cell"; qDebug() << "triangleIndices:" << _triangleIndices.size() << "in this cell";
qDebug() << "child cells:" << _children.size(); qDebug() << "child cells:" << _children.size();
if (_depth < MAX_DEPTH) { if (_depth < MAX_DEPTH) {
int childNum = 0; int childNum = 0;
@ -216,7 +200,13 @@ void TriangleOctreeCell::insert(int triangleIndex) {
} }
// either we're at max depth, or the triangle doesn't fit in one of our // either we're at max depth, or the triangle doesn't fit in one of our
// children and so we want to just record it here // children and so we want to just record it here
_triangleSet.insert(triangleIndex); _triangleIndices.push_back(triangleIndex);
/*
_bounds += triangle.v0;
_bounds += triangle.v1;
_bounds += triangle.v2;
*/
} }
bool TriangleOctreeCell::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool TriangleOctreeCell::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
@ -263,7 +253,7 @@ bool TriangleOctreeCell::findRayIntersection(const glm::vec3& origin, const glm:
} }
} }
// also check our local triangle set // also check our local triangle set
if (_triangleSet.findRayIntersection(origin, direction, childDistance, childFace, childNormal, precision, trianglesTouched)) { if (findRayIntersectionInternal(origin, direction, childDistance, childFace, childNormal, precision, trianglesTouched)) {
if (childDistance < bestLocalDistance) { if (childDistance < bestLocalDistance) {
bestLocalDistance = childDistance; bestLocalDistance = childDistance;
bestLocalFace = childFace; bestLocalFace = childFace;

View file

@ -16,38 +16,10 @@
class InternalTriangleSet {
public:
InternalTriangleSet(std::vector<Triangle>& allTriangles) :
_allTriangles(allTriangles)
{ }
virtual void insert(int triangleIndex);
void clear();
// Determine if the given ray (origin/direction) in model space intersects with any triangles in the set. If an
// intersection occurs, the distance and surface normal will be provided.
// note: this might side-effect internal structures
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precision, int& trianglesTouched);
const AABox& getBounds() const { return _bounds; }
size_t size() const { return _triangleIndices.size(); }
protected:
std::vector<Triangle>& _allTriangles;
std::vector<int> _triangleIndices;
AABox _bounds;
friend class TriangleOctreeCell;
};
class TriangleOctreeCell { class TriangleOctreeCell {
public: public:
TriangleOctreeCell(std::vector<Triangle>& allTriangles) : TriangleOctreeCell(std::vector<Triangle>& allTriangles) :
_allTriangles(allTriangles), _allTriangles(allTriangles)
_triangleSet(allTriangles)
{ } { }
@ -60,24 +32,28 @@ public:
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precision, int& trianglesTouched); float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precision, int& trianglesTouched);
const AABox& getBounds() const { return _triangleSet.getBounds(); } const AABox& getBounds() const { return _bounds; }
void debugDump(); void debugDump();
protected: protected:
TriangleOctreeCell(std::vector<Triangle>& allTriangles, const AABox& bounds, int depth); TriangleOctreeCell(std::vector<Triangle>& allTriangles, const AABox& bounds, int depth);
// checks our internal list of triangles
bool findRayIntersectionInternal(const glm::vec3& origin, const glm::vec3& direction,
float& distance, BoxFace& face, glm::vec3& surfaceNormal, bool precision, int& trianglesTouched);
std::vector<Triangle>& _allTriangles; std::vector<Triangle>& _allTriangles;
InternalTriangleSet _triangleSet;
std::vector<TriangleOctreeCell> _children; std::vector<TriangleOctreeCell> _children;
int _depth { 0 }; int _depth { 0 };
int _population { 0 }; int _population { 0 };
AABox _bounds;
std::vector<int> _triangleIndices;
friend class TriangleSet; friend class TriangleSet;
}; };
class TriangleSet { class TriangleSet {
// pass through public implementation all the features of InternalTriangleSet
public: public:
TriangleSet() : TriangleSet() :
_triangleOctree(_triangles) _triangleOctree(_triangles)