21 if( !options->
all_seen() )
return MB_FAILURE;
31 if( !tree_root_set ) tree_root_set = &tmp_root;
39 std::vector< Node > tree_nodes;
41 std::vector< HandleData > handle_data_vec;
46 for( std::vector< HandleData >::const_iterator i = handle_data_vec.begin(); i != handle_data_vec.end(); ++i )
50 std::cerr <<
"BB:" <<
boundBox <<
"EB:" << i->myBox << std::endl;
56 if( !handle_data_vec.empty() )
59 tree_nodes.push_back(
Node() );
62 std::set< EntityHandle > entity_handles;
63 for( std::vector< Node >::iterator n = tree_nodes.begin(); n != tree_nodes.end(); ++n )
65 for( HandleDataVec::const_iterator j = n->entities.begin(); j != n->entities.end(); ++j )
67 entity_handles.insert( j->myHandle );
70 if( entity_handles.size() !=
entities.size() )
72 std::cout <<
"Entity Handle Size Mismatch!" << std::endl;
76 if( entity_handles.find( *i ) == entity_handles.end() )
77 std::cout <<
"Tree is missing an entity! " << std::endl;
102 std::vector< unsigned int > tmp_flags( tree_nodes.size(),
meshsetFlags );
111 std::vector< Node >::iterator it;
112 myTree.reserve( tree_nodes.size() );
113 for( it = tree_nodes.begin(); it != tree_nodes.end(); ++it, set_handle++ )
115 if( it != tree_nodes.begin() && !it->entities.empty() )
118 for( HandleDataVec::iterator hit = it->entities.begin(); hit != it->entities.end(); ++hit )
119 range.
insert( hit->myHandle );
123 myTree.push_back(
TreeNode( it->dim, it->child, it->Lmax, it->Rmin, it->box ) );
151 HandleDataVec::const_iterator end,
153 std::vector< std::vector< Bucket > >& buckets )
const
156 for( HandleDataVec::const_iterator i = begin; i != end; ++i )
159 for(
unsigned int dim = 0;
dim < 3; ++
dim )
162 assert( index < buckets[
dim].
size() );
174 for( HandleDataVec::const_iterator i = begin; i != end; ++i )
178 for(
unsigned int dim = 0;
dim < 3; ++
dim )
187 std::cout <<
"element union: " << std::endl << elt_union;
188 std::cout <<
"intervals: " << std::endl << interval;
189 std::cout <<
"union of elts does not contain original box!" << std::endl;
193 std::cout <<
"original box does not contain union of elts" << std::endl;
194 std::cout << interval << std::endl << elt_union << std::endl;
196 for(
unsigned int d = 0; d < 3; ++d )
198 std::vector< unsigned int > nonempty;
199 const std::vector< Bucket >& buckets_ = buckets[d];
201 for( std::vector< Bucket >::const_iterator i = buckets_.begin(); i != buckets_.end(); ++i, ++j )
205 nonempty.push_back( j );
208 BoundBox test_box = buckets_[nonempty.front()].boundingBox;
209 for(
unsigned int i = 0; i < nonempty.size(); ++i )
210 test_box.
update( buckets_[nonempty[i]].boundingBox );
213 std::cout <<
"union of buckets in dimension: " << d <<
"does not contain original box!" << std::endl;
216 std::cout <<
"original box does "
217 <<
"not contain union of buckets"
218 <<
"in dimension: " << d << std::endl;
219 std::cout << interval << std::endl << test_box << std::endl;
226 const std::vector< std::vector< Bucket > >& buckets,
229 for(
unsigned int d = 0; d < 3; ++d )
231 std::vector< SplitData >::iterator splits_begin = splits[d].begin();
232 std::vector< SplitData >::iterator splits_end = splits[d].end();
233 std::vector< Bucket >::const_iterator left_begin = buckets[d].begin();
234 std::vector< Bucket >::const_iterator _end = buckets[d].end();
235 std::vector< Bucket >::const_iterator left_end = buckets[d].begin() + 1;
236 for( std::vector< SplitData >::iterator s = splits_begin; s != splits_end; ++s, ++left_end )
238 s->nl =
set_interval( s->leftBox, left_begin, left_end );
242 s->leftBox.
bMax[d] = s->leftBox.bMin[d];
248 s->rightBox.
bMin[d] = s->rightBox.bMax[d];
250 s->Lmax = s->leftBox.bMax[d];
251 s->Rmin = s->rightBox.bMin[d];
252 s->split = std::distance( splits_begin, s );
256 for( std::vector< SplitData >::iterator s = splits_begin; s != splits_end; ++s )
259 test_box.
update( s->rightBox );
262 std::cout <<
"nr: " << s->nr << std::endl;
263 std::cout <<
"Test box: " << std::endl << test_box;
264 std::cout <<
"Left box: " << std::endl << s->leftBox;
265 std::cout <<
"Right box: " << std::endl << s->rightBox;
266 std::cout <<
"Interval: " << std::endl << data.
boundingBox;
267 std::cout <<
"Split boxes larger than bb" << std::endl;
271 std::cout <<
"bb larger than union of split boxes" << std::endl;
281 for( HandleDataVec::iterator i = begin; i != end; ++i )
283 i->myDim = 0.5 * ( i->myBox.bMin[
dim], i->myBox.bMax[
dim] );
286 const unsigned int total = std::distance( begin, end );
287 HandleDataVec::iterator middle = begin + ( total / 2 );
288 double middle_center = middle->myDim;
289 middle_center += ( ++middle )->myDim;
290 middle_center *= 0.5;
291 data.
split = middle_center;
292 data.
nl = std::distance( begin, middle ) + 1;
293 data.
nr = total - data.
nl;
297 for( HandleDataVec::iterator i = begin; i != middle; ++i )
302 for( HandleDataVec::iterator i = middle; i != end; ++i )
313 std::cerr <<
"MEDIAN: BB Does not contain splits" << std::endl;
314 std::cerr <<
"test_box: " << test_box << std::endl;
315 std::cerr <<
"data.boundingBox: " << data.
boundingBox << std::endl;
322 std::vector< std::vector< Bucket > > buckets( 3, std::vector< Bucket >(
splitsPerDir + 1 ) );
323 std::vector< std::vector< SplitData > > splits( 3, std::vector< SplitData >(
splitsPerDir, data ) );
329 const bool use_median = ( 0 == data.
nl ) || ( data.
nr == 0 );
336 bool seen_one =
false, issue =
false;
337 bool first_left =
true, first_right =
true;
338 unsigned int count_left = 0, count_right = 0;
340 for( HandleDataVec::iterator i = begin; i != end; ++i )
342 int order = i->myDim;
343 if( order != 0 && order != 1 )
345 std::cerr <<
"Invalid order element !";
346 std::cerr << order << std::endl;
362 if( !
right_box.intersects_box( i->myBox ) )
366 std::cerr <<
"Bounding right box issue!" << std::endl;
387 std::cerr <<
"Bounding left box issue!" << std::endl;
393 std::cerr <<
"Invalid ordering!" << std::endl;
394 std::cout << ( i - 1 )->myDim << order << std::endl;
399 if( !
left_box.intersects_box( data.
leftBox ) ) std::cout <<
"left elts do not contain left box" << std::endl;
401 if( !
right_box.intersects_box( data.
rightBox ) ) std::cout <<
"right elts do not contain right box" << std::endl;
404 if( count_left != data.
nl || count_right != data.
nr )
406 std::cerr <<
"counts are off!" << std::endl;
407 std::cerr <<
"total: " << std::distance( begin, end ) << std::endl;
408 std::cerr <<
"Dim: " << data.
dim << std::endl;
409 std::cerr << data.
Lmax <<
" , " << data.
Rmin << std::endl;
410 std::cerr <<
"Right box: " << std::endl << data.
rightBox <<
"Left box: " << std::endl << data.
leftBox;
411 std::cerr <<
"supposed to be: " << data.
nl <<
" " << data.
nr << std::endl;
412 std::cerr <<
"accountant says: " << count_left <<
" " << count_right << std::endl;
419 HandleDataVec::iterator begin,
420 HandleDataVec::iterator end,
426 for( HandleDataVec::const_iterator i = begin; i != end; ++i )
430 std::cerr <<
"depth: " << depth << std::endl;
431 std::cerr <<
"BB:" << box <<
"EB:" << i->myBox << std::endl;
437 const unsigned int total_num_elements = std::distance( begin, end );
438 tree_nodes[index].box = box;
447 tree_nodes[index].Lmax = data.
Lmax;
448 tree_nodes[index].Rmin = data.
Rmin;
449 tree_nodes[index].dim = data.
dim;
450 tree_nodes[index].child = tree_nodes.size();
452 tree_nodes.push_back(
Node() );
453 tree_nodes.push_back(
Node() );
454 const int left_depth =
456 const int right_depth =
458 return std::max( left_depth, right_depth );
461 tree_nodes[index].dim = 3;
462 std::copy( begin, end, std::back_inserter( tree_nodes[index].
entities ) );
467 const unsigned int& index,
468 const double iter_tol,
469 const double inside_tol,
470 std::pair< EntityHandle, CartVect >& result )
493 result.second = params;
502 std::vector< EntityHandle >
children;
506 if( ( node.
Lmax + iter_tol ) < ( node.
Rmin - iter_tol ) )
508 if( point[node.
dim] <= ( node.
Lmax + iter_tol ) )
510 else if( point[node.
dim] >= ( node.
Rmin - iter_tol ) )
512 result = std::make_pair( 0,
CartVect( &point[0] ) );
520 if( point[node.
dim] < ( node.
Rmin - iter_tol ) )
523 else if( point[node.
dim] > ( node.
Lmax + iter_tol ) )
540 if( result.first == 0 )
551 for(
unsigned int i = 0; i <
myTree.size(); i++ )
553 if(
myTree[i].
dim != 3 || !
myTree[i].box.contains_point( point, iter_tol ) )
continue;
588 const double iter_tol,
589 const double inside_tol,
590 bool* multiple_leaves,
600 else if( this_set ==
myRoot )
603 std::vector< EntityHandle > candidates,
608 while( !candidates.empty() )
614 candidates.pop_back();
632 if( leaf_out ||
MB_SUCCESS != rval )
return rval;
637 result_list.push_back( this_set );
641 if( !result_list.empty() ) leaf_out = result_list[0];
642 if( multiple_leaves && result_list.size() > 1 ) *multiple_leaves =
true;
647 const double distance,
648 std::vector< EntityHandle >& result_list,
649 const double iter_tol,
650 const double inside_tol,
651 std::vector< double >* result_dists,
652 std::vector< CartVect >* result_params,
660 else if( this_set ==
myRoot )
665 const double dist_sqr = distance * distance;
667 std::vector< EntityHandle > candidates;
677 while( !candidates.empty() )
682 candidates.pop_back();
692 if( d_sqr > dist_sqr )
continue;
702 if(
myEval && result_params )
712 result_list.push_back( ent );
713 result_params->push_back( params );
714 if( result_dists ) result_dists->push_back( 0.0 );
720 result_list.push_back( this_set );
721 if( result_dists ) result_dists->push_back( sqrt( d_sqr ) );
731 std::vector< Node >::iterator it;
732 for( it = nodes.begin(), i = 0; it != nodes.end(); ++it, i++ )
734 std::cout <<
"Node " << i <<
": dim = " << it->dim <<
", child = " << it->child <<
", Lmax/Rmin = " << it->Lmax
735 <<
"/" << it->Rmin <<
", box = " << it->box << std::endl;
743 std::vector< TreeNode >::iterator it;
744 for( it =
myTree.begin(), i = 0; it !=
myTree.end(); ++it, i++ )
746 std::cout <<
"Node " << i <<
": dim = " << it->dim <<
", child = " << it->child <<
", Lmax/Rmin = " << it->Lmax
747 <<
"/" << it->Rmin <<
", box = " << it->box << std::endl;