void PointKDTree::rangeQuery(AxisAlignedBox3 const & query, std::vector<Point *> & points_in_range) const
{
  points_in_range.clear();

  // Write a helper function rangeQuery(node, query, points_in_range):
  //   - If node->bbox does not intersect query, return
  //   - If node->lo && node->lo->bbox intersects query, rangeQuery(node->lo, query, points_in_range)
  //   - If node->hi && node->hi->bbox intersects query, rangeQuery(node->hi, query, points_in_range)
  if(!(root->bbox).intersects(query))
		return;
	if((root->points).size()!=0)
	{
		for(int i=0;i<(int)(root->points).size();i++)
		{
			Vector3 rootPoint = root->points[i]->getPosition();
			if(query.contains(rootPoint))
				points_in_range.push_back(root->points[i]);
		}
		return;
	}
	if((root->lo->bbox).intersects(query))
		rangeQuery(root->lo, query, points_in_range);
	if((root->hi->bbox).intersects(query))
		rangeQuery(root->hi, query, points_in_range);
  
}
예제 #2
0
bool is_tetra_inside(Tetrahedral tetra, AxisAlignedBox3 bbox){
	assert(bbox.isNull()!=true);

	list<Vector3> points = tetra.get_sample_points();
	bool is_inside=false;

	assert(points.size()==4);

	for(auto it_pt= points.begin();it_pt!=points.end();++it_pt)
		is_inside = is_inside || bbox.contains(*it_pt);

	return is_inside;
}
void PointKDTree::rangeQuery(Node *node, AxisAlignedBox3 const & query, std::vector<Point *> & points_in_range) const
{
	if(!(node->bbox).intersects(query))
		return;
	if(node->lo == NULL && node->hi == NULL && (node->points).size()!=0)
	{
		for(int i=0;i<(int)(node->points).size();i++)
		{
			Vector3 nodePoint = node->points[i]->getPosition();
			if(query.contains(nodePoint))
				points_in_range.push_back(node->points[i]);
		}
		return;
	}
	
	if((node->lo->bbox).intersects(query) && node->lo !=NULL)
		rangeQuery(node->lo, query, points_in_range);
	if((node->hi->bbox).intersects(query) && node->hi !=NULL)
		rangeQuery(node->hi, query, points_in_range);
}