64 #include "BSPImplT.hh"
73 template <
class BSPCore>
80 data.dist = infinity_;
82 throw std::runtime_error(
"It seems like the BSP hasn't been built, yet. Did you call build(...)?");
83 _nearest(this->root_, data);
91 template <
class BSPCore>
94 _nearest(Node* _node, NearestNeighborData& _data)
const
97 if (!_node->left_child_)
100 for (HandleIter it=_node->begin(); it!=_node->end(); ++it)
102 dist = this->traits_.sqrdist(*it, _data.ref);
103 if (dist < _data.dist)
114 Scalar dist = _node->plane_.distance(_data.ref);
117 _nearest(_node->left_child_, _data);
118 if (dist*dist < _data.dist)
119 _nearest(_node->right_child_, _data);
123 _nearest(_node->right_child_, _data);
124 if (dist*dist < _data.dist)
125 _nearest(_node->left_child_, _data);
132 template <
class BSPCore>
141 data.hit_handles.clear();
143 _raycollision_non_directional(this->root_, data);
149 template <
class BSPCore>
158 data.hit_handles.clear();
160 _raycollision_directional(this->root_, data);
167 template <
class BSPCore>
176 data.hit_handles.clear();
178 _raycollision_nearest_directional(this->root_, data);
186 template <
class BSPCore>
192 if (!_node->left_child_)
198 for (HandleIter it=_node->begin(); it!=_node->end(); ++it)
200 this->traits_.points(*it, v0, v1, v2);
203 _data.hit_handles.push_back(std::pair<Handle,Scalar>(*it,dist));
213 _raycollision_non_directional(_node->left_child_, _data);
216 _raycollision_non_directional(_node->right_child_, _data);
224 template <
class BSPCore>
230 if (!_node->left_child_)
236 for (HandleIter it=_node->begin(); it!=_node->end(); ++it)
238 this->traits_.points(*it, v0, v1, v2);
241 _data.hit_handles.push_back(std::pair<Handle,Scalar>(*it,dist));
252 _raycollision_directional(_node->left_child_, _data);
255 _raycollision_directional(_node->right_child_, _data);
263 template <
class BSPCore>
269 if (!_node->left_child_)
275 for (HandleIter it=_node->begin(); it!=_node->end(); ++it)
277 this->traits_.points(*it, v0, v1, v2);
280 _data.hit_handles.push_back(std::pair<Handle,Scalar>(*it, dist));
285 if(!_data.hit_handles.empty()) {
286 std::partial_sort(_data.hit_handles.begin(), _data.hit_handles.begin() + 1, _data.hit_handles.end(), less_pair_second<Handle, Scalar>());
287 _data.hit_handles.resize(1);
295 Node* first_node = _node->left_child_, *second_node = _node->right_child_;
296 if (!_node->plane_(_data.ref)) {
297 std::swap(first_node, second_node);
302 _raycollision_nearest_directional(first_node, _data);
306 if(!_data.hit_handles.empty()) {
307 dist = _data.hit_handles.front().second;
310 _raycollision_nearest_directional(second_node, _data);
std::vector< std::pair< Handle, Scalar > > RayCollision
Store nearest neighbor information.
bool triangleIntersection(const Vec &_o, const Vec &_dir, const Vec &_v0, const Vec &_v1, const Vec &_v2, typename Vec::value_type &_t, typename Vec::value_type &_u, typename Vec::value_type &_v)
Intersect a ray and a triangle.
RayCollision raycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
void _raycollision_directional(Node *_node, RayCollisionData &_data) const
recursive part of directionalRaycollision()
void _raycollision_non_directional(Node *_node, RayCollisionData &_data) const
recursive part of raycollision()
static Scalar max()
Return the maximum absolte value a scalar type can store.
RayCollision directionalRaycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
RayCollision nearestRaycollision(const Point &_p, const Point &_r) const
intersect mesh with ray
Store ray collide information.
NearestNeighbor nearest(const Point &_p) const
Return handle of the nearest neighbor face.
Store nearest neighbor information.
bool axisAlignedBBIntersection(const Vec &_o, const Vec &_dir, const Vec &_bbmin, const Vec &_bbmax, typename Vec::value_type &tmin, typename Vec::value_type &tmax)
Intersect a ray and an axis aligned bounding box.
Store nearest neighbor information.