Removed child ordered traversal.

This commit is contained in:
Marco Di Benedetto 2005-10-26 11:41:07 +00:00
parent 8f621b53ef
commit 2579c02256
1 changed files with 31 additions and 60 deletions

View File

@ -25,6 +25,9 @@
History History
$Log: not supported by cvs2svn $ $Log: not supported by cvs2svn $
Revision 1.3 2005/10/05 01:40:56 m_di_benedetto
Node children are now tested in ascending ray-T order.
Revision 1.2 2005/09/28 19:48:31 m_di_benedetto Revision 1.2 2005/09/28 19:48:31 m_di_benedetto
Removed hit point parameter, #included aabbtree base. Removed hit point parameter, #included aabbtree base.
@ -37,9 +40,6 @@ First Commit.
#ifndef __VCGLIB_AABBBINARYTREE_RAY_H #ifndef __VCGLIB_AABBBINARYTREE_RAY_H
#define __VCGLIB_AABBBINARYTREE_RAY_H #define __VCGLIB_AABBBINARYTREE_RAY_H
// stl headers
#include <limits>
// vcg headers // vcg headers
#include <vcg/space/ray3.h> #include <vcg/space/ray3.h>
#include <vcg/space/index/aabb_binary_tree/base.h> #include <vcg/space/index/aabb_binary_tree/base.h>
@ -71,7 +71,7 @@ public:
const CoordType & rayDirection = ray.Direction(); const CoordType & rayDirection = ray.Direction();
ScalarType rayT = maxDist / rayDirection.Norm(); t = maxDist / rayDirection.Norm();
Ray3Ex rayex; Ray3Ex rayex;
rayex.r = ray; rayex.r = ray;
@ -83,23 +83,7 @@ public:
rayex.sign[2] = (rayex.invDirection[2] < ((ScalarType)0)) ? (1) : (0); rayex.sign[2] = (rayex.invDirection[2] < ((ScalarType)0)) ? (1) : (0);
ObjPtr closestObj = 0; ObjPtr closestObj = 0;
ClassType::DepthFirstRayIsect(pRoot, rayIntersection, rayex, t, closestObj);
ScalarType rt;
if (!ClassType::IntersectionBoxRay(pRoot->boxCenter, pRoot->boxHalfDims, rayex, rt)) {
return (0);
}
if (rt >= rayT) {
return (0);
}
ClassType::DepthFirstRayIsect(pRoot, rayIntersection, rayex, rayT, closestObj);
if (closestObj == 0) {
return (0);
}
t = rayT;
return (closestObj); return (closestObj);
} }
@ -123,69 +107,56 @@ protected:
tmin = (bounds[ray.sign[0]][0] - origin[0]) * ray.invDirection[0]; tmin = (bounds[ray.sign[0]][0] - origin[0]) * ray.invDirection[0];
tmax = (bounds[1 - ray.sign[0]][0] - origin[0]) * ray.invDirection[0]; tmax = (bounds[1 - ray.sign[0]][0] - origin[0]) * ray.invDirection[0];
tcmin = (bounds[ray.sign[1]][1] - origin[1]) * ray.invDirection[1]; tcmin = (bounds[ray.sign[1]][1] - origin[1]) * ray.invDirection[1];
tcmax = (bounds[1 - ray.sign[1]][1] - origin[1]) * ray.invDirection[1]; tcmax = (bounds[1 - ray.sign[1]][1] - origin[1]) * ray.invDirection[1];
if ((tmin > tcmax) || (tcmin > tmax)) { return (false); } if ((tmin > tcmax) || (tcmin > tmax)) { return (false); }
if (tcmin > tmin) { tmin = tcmin; } if (tcmin > tmin) { tmin = tcmin; }
if (tcmax < tmax) { tmax = tcmax; } if (tcmax < tmax) { tmax = tcmax; }
tcmin = (bounds[ray.sign[2]][2] - origin[2]) * ray.invDirection[2]; tcmin = (bounds[ray.sign[2]][2] - origin[2]) * ray.invDirection[2];
tcmax = (bounds[1-ray.sign[2]][2] - origin[2]) * ray.invDirection[2]; tcmax = (bounds[1-ray.sign[2]][2] - origin[2]) * ray.invDirection[2];
if ((tmin > tcmax) || (tcmin > tmax)) { return (false); } if ((tmin > tcmax) || (tcmin > tmax)) { return (false); }
if (tcmin > tmin) { tmin = tcmin; } if (tcmin > tmin) { tmin = tcmin; }
//if (tcmax < tmax) { tmax = tcmax; } //if (tcmax < tmax) { tmax = tcmax; }
t0 = (tmin >= ((ScalarType)0)) ? (tmin) :((ScalarType)0); t0 = (tmin >= ((ScalarType)0)) ? (tmin) :((ScalarType)0);
return (true); return (true);
} }
template <class OBJRAYISECTFUNCT> template <class OBJRAYISECTFUNCT>
static inline void DepthFirstRayIsect(const NodeType * node, OBJRAYISECTFUNCT & rayIntersection, const Ray3Ex & ray, ScalarType & rayT, ObjPtr & closestObj) { static inline void DepthFirstRayIsect(const NodeType * node, OBJRAYISECTFUNCT & rayIntersection, const Ray3Ex & ray, ScalarType & rayT, ObjPtr & closestObj) {
if (node->IsLeaf()) { if (node == 0) {
ObjPtr cObj = 0; return;
ScalarType ar; }
CoordType ap;
ScalarType rt = rayT; ScalarType rt;
for (typename TreeType::ObjPtrVectorConstIterator si=node->oBegin; si!=node->oEnd; ++si) { if (!ClassType::IntersectionBoxRay(node->boxCenter, node->boxHalfDims, ray, rt)) {
if (rayIntersection(*(*si), ray.r, ar)) { return;
if (ar < rt) { }
rt = ar;
cObj = (*si); if (rt >= rayT) {
} return;
} }
}
if (rt < rayT) { if (node->IsLeaf()) {
rayT = rt; for (typename TreeType::ObjPtrVectorConstIterator si=node->oBegin; si!=node->oEnd; ++si) {
closestObj = cObj; if (rayIntersection(*(*si), ray.r, rt)) {
} if (rt < rayT) {
} rayT = rt;
else { closestObj = (*si);
ScalarType rt0, rt1; }
bool b0 = false; }
bool b1 = false; }
if (node->children[0] != 0) { return;
b0 = ClassType::IntersectionBoxRay(node->children[0]->boxCenter, node->children[0]->boxHalfDims, ray, rt0);
}
if (node->children[1] != 0) {
b1 = ClassType::IntersectionBoxRay(node->children[1]->boxCenter, node->children[1]->boxHalfDims, ray, rt1);
} }
if (b0 && b1) {
if (rt0 <= rt1) {
ClassType::DepthFirstRayIsect(node->children[0], rayIntersection, ray, rayT, closestObj); ClassType::DepthFirstRayIsect(node->children[0], rayIntersection, ray, rayT, closestObj);
ClassType::DepthFirstRayIsect(node->children[1], rayIntersection, ray, rayT, closestObj); ClassType::DepthFirstRayIsect(node->children[1], rayIntersection, ray, rayT, closestObj);
} }
else {
ClassType::DepthFirstRayIsect(node->children[1], rayIntersection, ray, rayT, closestObj);
ClassType::DepthFirstRayIsect(node->children[0], rayIntersection, ray, rayT, closestObj);
}
}
else if (b0) {
ClassType::DepthFirstRayIsect(node->children[0], rayIntersection, ray, rayT, closestObj);
}
else if (b1) {
ClassType::DepthFirstRayIsect(node->children[1], rayIntersection, ray, rayT, closestObj);
}
}
}
}; };