17 #pragma warning( disable : 4786 )
30 if( MB_SUCCESS != result ) return result; \
55 std::vector< EntityHandle > ent_vec;
56 std::copy(
entities.begin(),
entities.end(), std::back_inserter( ent_vec ) );
62 const int num_entities,
63 double* avg_position )
66 avg_position[0] = avg_position[1] = avg_position[2] = 0.0;
72 if( connect.
empty() )
return MB_FAILURE;
78 avg_position[0] += dum_pos[0];
79 avg_position[1] += dum_pos[1];
80 avg_position[2] += dum_pos[2];
82 avg_position[0] /= (double)connect.
size();
83 avg_position[1] /= (double)connect.
size();
84 avg_position[2] /= (double)connect.
size();
107 std::vector< EntityHandle >& star_ents,
110 std::vector< EntityHandle >* star_entities_dp2,
111 Range* star_candidates_dp2 )
115 EntityHandle last_entity = starting_star_entity, last_dp2 = 0, next_entity, next_dp2;
116 std::vector< EntityHandle > star_dp2;
120 Range tmp_candidates_dp2;
121 if( NULL != star_candidates_dp2 )
122 tmp_candidates_dp2 = *star_candidates_dp2;
132 result =
star_next_entity( star_center, last_entity, last_dp2, &tmp_candidates_dp2, next_entity, next_dp2 );
137 if( star_ents.empty() && next_entity == 0 && next_dp2 == 0 )
139 star_ents.push_back( last_entity );
148 if( 0 == next_dp2 && !bdy_entity )
150 star_ents.push_back( next_entity );
152 std::reverse( star_ents.begin(), star_ents.end() );
153 star_ents.pop_back();
154 last_entity = star_ents.back();
155 if( !star_dp2.empty() )
157 std::reverse( star_dp2.begin(), star_dp2.end() );
158 last_dp2 = star_dp2.back();
164 else if( !bdy_entity && std::find( star_ents.begin(), star_ents.end(), next_entity ) != star_ents.end() &&
165 ( std::find( star_dp2.begin(), star_dp2.end(), next_dp2 ) != star_dp2.end() || !next_dp2 ) )
173 if( std::find( star_ents.begin(), star_ents.end(), next_entity ) == star_ents.end() )
174 star_ents.push_back( next_entity );
177 star_dp2.push_back( next_dp2 );
178 tmp_candidates_dp2.
erase( next_dp2 );
180 last_entity = next_entity;
183 }
while( 0 != last_dp2 );
186 if( NULL != star_entities_dp2 ) ( *star_entities_dp2 ).swap( star_dp2 );
194 Range* star_candidates_dp1,
202 Range from_ents, to_ents;
203 from_ents.
insert( star_center );
204 if( 0 != last_dp1 ) from_ents.
insert( last_dp1 );
212 if( 0 != last_entity ) to_ents.
erase( last_entity );
215 if( 0 != last_entity && 0 == last_dp1 )
222 to_ents = tmp_to_ents;
225 if( 0 == last_dp1 && to_ents.
size() > 1 && NULL != star_candidates_dp1 && !star_candidates_dp1->
empty() )
231 to_ents =
intersect( to_ents, from_ents );
234 if( !to_ents.
empty() )
235 next_entity = *to_ents.
begin();
244 if( 0 != star_candidates_dp1 )
245 to_ents = *star_candidates_dp1;
253 if( 0 != last_dp1 ) to_ents.
erase( last_dp1 );
255 if( !to_ents.
empty() ) next_dp1 = *to_ents.
begin();
265 std::vector< std::vector< EntityHandle > >& stars,
266 std::vector< bool >* bdy_flags,
267 std::vector< std::vector< EntityHandle > >* dp2_stars )
288 if( 3 <= this_dim || 0 > this_dim )
return MB_FAILURE;
306 result =
get_manifold( star_entity, this_dim + 1, dp1_manifold );
310 while( !dp1_manifold.
empty() )
318 std::vector< EntityHandle > this_star_dp1, this_star_dp2;
320 result =
star_entities( star_entity, this_star_dp1, on_bdy, this_ent, &this_star_dp2, &dp2_manifold );
326 if( this_star_dp1.empty() )
331 if( dum_range.
empty() ) this_star_dp1.push_back( this_ent );
338 if( !this_star_dp1.empty() )
340 stars.push_back( this_star_dp1 );
341 if( NULL != bdy_flags ) bdy_flags->push_back( on_bdy );
342 if( NULL != dp2_stars ) dp2_stars->push_back( this_star_dp2 );
346 for( std::vector< EntityHandle >::iterator vit = this_star_dp2.begin(); vit != this_star_dp2.end(); ++vit )
347 dp2_manifold.
erase( *vit );
350 for( std::vector< EntityHandle >::iterator vit = this_star_dp1.begin(); vit != this_star_dp1.end(); ++vit )
351 dp1_manifold.
erase( *vit );
358 if( !dp2_manifold.
empty() )
381 if( target_dim == 3 )
383 manifold.
merge( tmp_range );
395 if( 1 >= dum_range.
size() ) manifold.
insert( *rit );
408 Range bridge_ents, accum_layers, new_toents( from_entities );
410 if( 0 == num_layers || from_entities.
empty() )
return MB_FAILURE;
413 for(
int nl = 0;
nl < num_layers;
nl++ )
426 for(
int d = 2; d >= 1; d-- )
439 accum_layers.
merge( new_layer );
440 if(
nl < num_layers - 1 ) new_toents =
subtract( new_layer, new_toents );
442 to_ents.
merge( accum_layers );
449 const int bridge_dim,
460 connect = &from_entity;
475 if( bridge_dim < from_dim )
480 for(
int i = 0; i < num_connect; i++ )
483 EntityHandle verts_on_edge[2] = { connect[i], connect[( i + 1 ) % num_connect] };
487 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
488 to_adjs.
merge( to_ents );
502 for(
int j = 0; j < num_bridge_verts; ++j )
504 if( bridge_indices[j] >= 0 && bridge_indices[j] < num_connect )
505 bridge_verts[j] = connect[bridge_indices[j]];
516 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
518 to_adjs.
merge( to_ents );
525 Range bridge_ents, tmp_ents;
526 tmp_ents.
insert( from_entity );
528 if(
MB_SUCCESS != tmp_result )
return tmp_result;
531 if(
MB_SUCCESS != tmp_result )
return tmp_result;
535 if( to_dim == from_dim ) to_adjs.
erase( from_entity );
543 Range tmp_range, tmp_range2;
550 return *tmp_range2.
begin();
565 int side_no, offset, sense;
570 int opposite_index, opposite_dim;
572 opposite_index, opposite_dim );
573 if( 0 != status )
return MB_FAILURE;
576 result =
mbImpl->
side_element( parent, opposite_dim, opposite_index, opposite_element );
584 Range tmp_range, *tmp_ptr_fill_entity;
585 if( NULL != fill_entities )
586 tmp_ptr_fill_entity = &tmp_range;
588 tmp_ptr_fill_entity = NULL;
593 if( NULL != tmp_ptr_fill_entity ) tmp_ptr_fill_entity->
clear();
599 new_entities.
insert( new_entity );
600 if( NULL != fill_entities ) fill_entities->
merge( *tmp_ptr_fill_entity );
607 const int num_entities,
609 Range* fill_entities,
616 #define ITERATE_RANGE( range, it ) for( Range::iterator it = ( range ).begin(); ( it ) != ( range ).end(); ++( it ) )
617 #define GET_CONNECT_DECL( ent, connect, num_connect ) \
618 const EntityHandle* connect = NULL; \
619 int num_connect = 0; \
621 ErrorCode connect_result = mbImpl->get_connectivity( ent, connect, num_connect ); \
622 if( MB_SUCCESS != connect_result ) return connect_result; \
624 #define GET_CONNECT( ent, connect, num_connect ) \
626 ErrorCode connect_result = mbImpl->get_connectivity( ent, connect, num_connect ); \
627 if( MB_SUCCESS != connect_result ) return connect_result; \
630 if( MB_SUCCESS != tmp_result ) \
632 result = tmp_result; \
637 for(
int i = 0; i < num_entities; i++ )
645 bool valid_up_adjs =
true;
652 valid_up_adjs =
false;
656 if( !valid_up_adjs )
return MB_FAILURE;
689 if( gowith_ents && up_elem2 && gowith_ents[i] != up_elem1 && gowith_ents[i] == up_elem2 )
701 if( !up_elem2 )
continue;
712 if( NULL != fill_entities )
719 tmp_ents[1] = new_entity;
734 tmp_ents[1] = new_entity;
739 if( 0 == fill_entity )
744 fill_entities->
insert( fill_entity );
747 new_entities[i] = new_entity;
793 else if( split_ent != new_entity )
798 for(
int i = 1; i < 4; i++ )
802 other_adjs =
subtract( other_adjs, old_adjs );
803 other_adjs =
subtract( other_adjs, new_adjs );
818 if( found )
continue;
829 if( !found )
return MB_FAILURE;
833 std::vector< EntityHandle > connect;
838 std::replace( connect.begin(), connect.end(), split_ent, new_entity );
989 if( NULL != equiv_ents )