38 std::vector< EntityHandle >& storage )
45 vect_out = &storage[0];
46 count_out = storage.size();
57 assert( NULL != mdb );
72 for( i = seqman.
begin(); i != seqman.
end(); ++i )
74 std::vector< EntityHandle >** adj_list = ( *i )->data()->get_adjacency_data();
75 if( !adj_list )
continue;
76 adj_list += ( *i )->start_handle() - ( *i )->data()->start_handle();
78 for(
EntityID j = 0; j < ( *i )->size(); ++j )
93 const unsigned int target_dimension,
94 std::vector< EntityHandle >& target_entities,
95 const bool create_if_missing,
96 const int create_adjacency_option )
100 const unsigned source_dimension =
CN::Dimension( source_type );
102 if( source_type >=
MBENTITYSET || target_dimension < 1 || target_dimension > 3 )
106 else if( source_dimension == target_dimension )
108 target_entities.push_back( source_entity );
119 if( source_dimension == 0 )
122 create_adjacency_option );
124 else if( source_dimension > target_dimension )
127 create_adjacency_option );
132 create_adjacency_option );
139 std::vector< EntityHandle >& target_entities )
153 std::vector< EntityHandle >& target_entities )
161 if( result !=
MB_SUCCESS || adj_vec == NULL )
return result;
172 target_entities.insert( target_entities.end(), start_ent, end_ent );
184 const int vertex_list_size,
185 const EntityType target_type,
187 const bool create_if_missing,
204 if( result !=
MB_SUCCESS || adj_vec == NULL )
return result;
211 int temp_vec_size = 0;
215 for( ; i_adj != end_adj; ++i_adj )
221 temp_vec[temp_vec_size++] = *i_adj;
225 if( temp_vec_size == 0 && !create_if_missing )
return result;
228 assert( temp_vec_size <= 15 );
231 if( temp_vec_size == 0 &&
true == create_if_missing )
240 else if( temp_vec_size == 1 )
241 target_entity = temp_vec[0];
247 if( 0 != source_entity )
251 for(
dum = 0;
dum < temp_vec_size;
dum++ )
254 if( std::find( adj_vec, ( adj_vec + num_adjs ), source_entity ) != ( adj_vec + num_adjs ) )
257 target_entity = temp_vec[
dum];
262 if( 0 == target_entity &&
270 for(
dum = 0;
dum < temp_vec_size;
dum++ )
274 target_entity = temp_vec[
dum];
281 if( target_entity == 0 )
285 target_entity = temp_vec[0];
295 const int vertex_list_size,
296 const EntityType target_type )
302 if( this_type != target_type )
305 else if( this_type ==
MBVERTEX && ( vertex_list_size > 1 || vertex_list[0] != this_entity ) )
310 int num_this_vertices = 0;
311 std::vector< EntityHandle > storage;
315 assert( vertex_list_size > 0 );
316 int num_corner_verts =
319 const EntityHandle* iter = std::find( this_vertices, ( this_vertices + num_corner_verts ), vertex_list[0] );
320 if( iter == ( this_vertices + num_corner_verts ) )
return false;
323 bool they_match =
true;
327 int offset = iter - this_vertices;
330 for( i = 1; i < num_corner_verts; ++i )
332 if( i >= vertex_list_size )
338 if( vertex_list[i] != this_vertices[( offset + i ) % num_corner_verts] )
345 if( they_match ==
true )
return true;
352 offset += num_corner_verts;
353 for( i = 1; i < num_corner_verts; i++ )
355 if( vertex_list[i] != this_vertices[( offset - i ) % num_corner_verts] )
379 AdjacencyVector::iterator adj_iter;
380 if( !adj_list_ptr->empty() )
382 adj_iter = std::lower_bound( adj_list_ptr->begin(), adj_list_ptr->end(), to_ent );
384 if( adj_iter == adj_list_ptr->end() || to_ent != *adj_iter )
386 adj_list_ptr->insert( adj_iter, to_ent );
390 adj_list_ptr->push_back( to_ent );
409 if( adj_list == NULL ||
MB_SUCCESS != result )
return result;
413 adj_list->erase( std::remove( adj_list->begin(), adj_list->end(), adj_to_remove ), adj_list->end() );
434 int numconn = 0, numadj = 0;
435 std::vector< EntityHandle > connstorage;
436 result =
get_vertices( base_entity, connvect, numconn, connstorage );
439 for(
int i = 0; i < numconn; ++i )
444 bool remove_this =
false;
445 for(
int j = 0; j < numadj; ++j )
447 if( adjvect[j] == base_entity ) remove_this =
true;
461 if(
MB_SUCCESS != result || !adj_list )
return result;
464 for( AdjacencyVector::reverse_iterator it = adj_list->rbegin(); it != adj_list->rend(); ++it )
467 if( delete_adj_list )
483 std::vector< EntityHandle > aux_connect;
491 handle_range.
clear();
497 for( i_range = handle_range.
begin(); i_range != handle_range.
end(); ++i_range )
499 result =
get_vertices( *i_range, connectivity, number_nodes, aux_connect );
503 for(
int k = 0; k < number_nodes; k++ )
513 int& num_entities )
const
519 adjacent_entities = 0;
524 num_entities = vec_ptr->size();
525 adjacent_entities = ( vec_ptr->empty() ) ? NULL : &( ( *vec_ptr )[0] );
535 adjacent_entities.clear();
539 adjacent_entities = *vec_ptr;
547 if(
MB_SUCCESS == result && !adj_vec && create )
561 const unsigned int target_dimension,
562 bool create_if_missing,
563 std::vector< EntityHandle >& target_entities )
566 const unsigned source_dimension =
CN::Dimension( source_type );
569 if( target_dimension == 4 )
573 else if( target_dimension == ( source_type !=
MBPOLYHEDRON ? 0 : 2 ) )
575 std::vector< EntityHandle > tmp_storage;
579 target_entities.insert( target_entities.end(), conn, conn + len );
581 else if( target_dimension == 0 && source_type ==
MBPOLYHEDRON )
585 else if( source_dimension == target_dimension )
587 target_entities.push_back( source_entity );
598 if( source_dimension == 0 )
602 else if( source_dimension > target_dimension )
617 const int number_nodes )
626 std::vector< EntityHandle > verts;
628 if(
MB_SUCCESS != tmp_result )
return tmp_result;
629 for( std::vector< EntityHandle >::iterator vit = verts.begin(); vit != verts.end(); ++vit )
632 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
637 for(
unsigned int i = number_nodes; i--; )
640 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
649 const unsigned int target_dimension,
650 std::vector< EntityHandle >& target_entities,
651 const bool create_if_missing,
654 AdjacencyVector::iterator start_ent, end_ent;
659 if( result !=
MB_SUCCESS || adj_vec == NULL )
return result;
661 if( target_dimension < 3 && create_if_missing )
663 std::vector< EntityHandle > tmp_ents;
665 start_ent = std::lower_bound( adj_vec->begin(), adj_vec->end(),
670 std::vector< EntityHandle > elems( start_ent, end_ent );
673 for( start_ent = elems.begin(); start_ent != elems.end(); ++start_ent )
681 start_ent = std::lower_bound( adj_vec->begin(), adj_vec->end(),
FIRST_HANDLE( dim_pair.first ) );
682 end_ent = std::lower_bound( start_ent, adj_vec->end(),
LAST_HANDLE( dim_pair.second ) );
683 target_entities.insert( target_entities.end(), start_ent, end_ent );
688 const unsigned int target_dimension,
689 std::vector< EntityHandle >& target_entities,
690 const bool create_if_missing,
691 const int create_adjacency_option )
698 create_adjacency_option );
709 std::vector< EntityHandle > storage;
713 int has_mid_nodes[4];
716 std::vector< int > index_list;
719 for(
int j = 0; j < num_sub_ents; j++ )
726 for(
int i = 0; i < verts_per_sub; i++ )
727 vertex_array[i] = vertices[cmap.
conn[j][i]];
730 if( has_mid_nodes[1] && target_dimension > 1 )
736 if( 0 != int_result )
return MB_FAILURE;
737 for(
unsigned int k = 0; k < index_list.size(); k++ )
739 int tmp_index =
CN::HONodeIndex( source_type, num_verts, 1, index_list[k] );
743 vertex_array[verts_per_sub++] = vertices[tmp_index];
747 if( has_mid_nodes[target_dimension] )
750 int tmp_index =
CN::HONodeIndex( source_type, num_verts, target_dimension, j );
752 vertex_array[verts_per_sub++] = vertices[tmp_index];
756 temp_result =
get_element( vertex_array, verts_per_sub, cmap.
target_type[j], tmp_target, create_if_missing,
757 source_entity, create_adjacency_option );
760 result = temp_result;
761 else if( 0 != tmp_target )
762 target_entities.push_back( tmp_target );
772 const unsigned int target_dimension,
773 std::vector< EntityHandle >& target_entities,
774 const bool create_if_missing,
780 if( !( source_type ==
MBPOLYHEDRON && target_dimension > 0 && target_dimension < 3 ) &&
781 !( source_type ==
MBPOLYGON && target_dimension == 1 ) )
785 std::vector< EntityHandle > vertex_array;
797 vertex_array.push_back( *vertex_array.begin() );
798 for(
unsigned int i = 0; i < vertex_array.size() - 1; i++ )
800 Range vrange, adj_edges;
801 vrange.
insert( vertex_array[i] );
802 vrange.
insert( vertex_array[i + 1] );
804 if( vrange.
size() == 1 )
continue;
806 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
807 if( adj_edges.
size() == 1 )
810 target_entities.push_back( *adj_edges.
begin() );
812 else if( adj_edges.
size() != 0 )
815 unsigned int start_sz = target_entities.size();
822 if( NULL != explicit_adjs &&
823 std::find( explicit_adjs, explicit_adjs + num_exp, source_entity ) != explicit_adjs + num_exp )
824 target_entities.push_back( *rit );
826 if( target_entities.size() == start_sz )
829 target_entities.push_back( *adj_edges.
begin() );
836 if( create_if_missing )
839 EntityHandle v[2] = { vertex_array[i], vertex_array[i + 1] };
851 target_entities.push_back( newEdge );
861 if( target_dimension == 2 )
867 std::vector< EntityHandle > dum_vec;
870 result =
thisMB->
get_adjacencies( &dum_vec[0], dum_vec.size(), 1, create_if_missing, target_entities,
885 template <
typename T1,
typename T2>
886 static inline T1
intersect( T1 set1_begin, T1 set1_end,
887 T2 set2_begin, T2 set2_end )
889 T1 set1_write = set1_begin;
890 while (set1_begin != set1_end) {
891 if (set2_begin == set2_end)
893 while (*set2_begin < *set1_begin)
894 if (++set2_begin == set2_end)
896 if (!(*set1_begin < *set2_begin)) {
897 *set1_write = *set1_begin;
909 const unsigned int target_dimension,
910 std::vector<EntityHandle>& target_entities,
911 const bool create_if_missing,
915 const std::vector<EntityHandle> *vtx_adj, *vtx2_adj;
916 std::vector<EntityHandle> duplicates;
919 const size_t in_size = target_entities.size();
929 std::vector<EntityHandle> conn_storage;
937 assert(conn_len > 1);
941 if (create_if_missing && target_dimension < 3 &&
CN::Dimension(src_type) < 2) {
942 for (
size_t i = 0; i < conn_len; ++i) {
946 assert(vtx_adj != NULL);
948 std::vector<EntityHandle> tmp2, tmp(*vtx_adj);
949 for (
size_t j = 0; j < tmp.size(); ++j) {
967 assert(vtx_adj != NULL);
972 assert(vtx2_adj != NULL);
976 std::vector<EntityHandle>::const_iterator it1, it2, end1, end2;
977 it1 = std::lower_bound( vtx_adj->begin(), vtx_adj->end(), src_beg_handle );
978 it2 = std::lower_bound( vtx2_adj->begin(), vtx2_adj->end(), src_beg_handle );
979 end1 = std::lower_bound( it1, vtx_adj->end(), src_end_handle );
980 end2 = std::lower_bound( it2, vtx2_adj->end(), src_end_handle );
982 duplicates.resize( end1 - it1 - 1 );
983 std::vector<EntityHandle>::iterator ins = duplicates.begin();
984 for (; it1 != end1; ++it1) {
985 if (*it1 != source_entity) {
990 duplicates.erase(
intersect( duplicates.begin(), duplicates.end(), it2, end2 ), duplicates.end() );
993 it1 = std::lower_bound( end1, vtx_adj->end(), tgt_beg_handle );
994 it2 = std::lower_bound( end2, vtx2_adj->end(), tgt_beg_handle );
995 end1 = std::lower_bound( it1, vtx_adj->end(), tgt_end_handle );
996 end2 = std::lower_bound( it2, vtx2_adj->end(), tgt_end_handle );
997 std::set_intersection( it1, end1, it2, end2, std::back_inserter( target_entities ) );
1000 for (
int i = 2; i < conn_len; ++i) {
1004 assert(vtx_adj != NULL);
1006 it1 = std::lower_bound( vtx_adj->begin(), vtx_adj->end(), src_beg_handle );
1007 end1 = std::lower_bound( it1, vtx_adj->end(), src_end_handle );
1008 duplicates.erase(
intersect( duplicates.begin(), duplicates.end(), it1, end1 ), duplicates.end() );
1010 it1 = std::lower_bound( end1, vtx_adj->end(), tgt_beg_handle );
1011 end1 = std::lower_bound( it1, vtx_adj->end(), tgt_end_handle );
1012 target_entities.erase(
intersect( target_entities.begin()+in_size, target_entities.end(),
1013 it1, end1 ), target_entities.end() );
1017 if (duplicates.empty())
1024 const std::vector<EntityHandle>* adj_ptr;
1026 for (
size_t i = 0; i < duplicates.size(); ++i) {
1033 for (
size_t j = 0; j < adj_ptr->size(); ++j) {
1034 std::vector<EntityHandle>::iterator k =
1035 std::find( target_entities.begin()+in_size, target_entities.end(), (*adj_ptr)[j] );
1036 if (k != target_entities.end())
1037 target_entities.erase(k);
1048 for (
size_t i = 0; i < duplicates.size(); ++i) {
1056 for (j = 0; j < adj_ptr->size(); ++j) {
1057 const std::vector<EntityHandle>* adj_ptr2;
1064 for (
size_t k = 0; k < adj_ptr2->size(); ++k) {
1065 std::vector<EntityHandle>::iterator it;
1066 it = std::find( target_entities.begin()+in_size, target_entities.end(), (*adj_ptr2)[k] );
1067 if (it != target_entities.end()) {
1068 target_entities.erase(it);
1069 j = adj_ptr->size();
1080 const unsigned int target_dimension,
1081 std::vector< EntityHandle >& target_entities,
1082 const bool create_if_missing,
1089 int num_source_vertices = 0;
1090 std::vector< EntityHandle > conn_storage;
1102 result =
get_element( source_vertices, num_source_vertices, source_type, temp_entity,
false, 0 );
1106 std::vector< EntityHandle > tmp_vec;
1107 if( !equiv_entities )
1110 std::vector< std::vector< EntityHandle > > elems( num_source_vertices );
1112 for( i = 0; i < num_source_vertices; i++ )
1118 std::sort( elems[i].begin(), elems[i].end() );
1123 for( i = 1; i < num_source_vertices; i++ )
1128 std::set_intersection( elems[0].begin(), elems[0].end(), elems[i].begin(), elems[i].end(),
1129 std::back_insert_iterator< std::vector< EntityHandle > >( tmp_vec ) );
1132 elems[0].swap( tmp_vec );
1136 target_entities.insert( target_entities.end(), elems[0].begin(), elems[0].end() );
1147 int num_connect = 0;
1148 std::vector< EntityHandle > storage;
1149 for(
unsigned int i = 0; i < tmp_vec.size(); i++ )
1153 if( std::find( connect, connect + num_connect, source_entity ) != connect + num_connect )
1154 target_entities.push_back( tmp_vec[i] );
1168 else if( adj_vec == NULL )
1175 Range tmp_ents, target_ents;
1179 AdjacencyVector::iterator start_ent_dp1 =
1180 std::lower_bound( adj_vec->begin(), adj_vec->end(),
1184 std::lower_bound( adj_vec->begin(), adj_vec->end(),
1187 end_ent_td = std::lower_bound( adj_vec->begin(), adj_vec->end(),
1192 std::copy( start_ent_dp1, start_ent_td,
range_inserter( tmp_ents ) );
1197 std::copy( start_ent_td, end_ent_td,
range_inserter( target_ents ) );
1200 #ifdef MOAB_NO_VECTOR_TEMPLATE_INSERT
1201 std::copy( target_ents.
begin(), target_ents.
end(), std::back_inserter( target_entities ) );
1203 target_entities.insert( target_entities.end(), target_ents.
begin(), target_ents.
end() );
1220 std::vector< EntityHandle > old_verts, new_verts;
1222 for( i = 0; i < number_verts; i++ )
1224 if( old_array[i] != new_array[i] )
1226 old_verts.push_back( old_array[i] );
1227 new_verts.push_back( new_array[i] );
1236 std::vector< EntityHandle >::iterator adj_iter;
1237 for( adj_iter = old_verts.begin(); adj_iter != old_verts.end(); ++adj_iter )
1239 if( std::find( new_verts.begin(), new_verts.end(), *adj_iter ) == new_verts.end() )
1245 for( adj_iter = new_verts.begin(); adj_iter != new_verts.end(); ++adj_iter )
1247 if( std::find( old_verts.begin(), old_verts.end(), *adj_iter ) == old_verts.end() )
1264 if( std::find( explicit_adjs, explicit_adjs + num_exp, ent2 ) != explicit_adjs + num_exp )
1285 for(
int dim = 1;
dim < ent_dim;
dim++ )
1302 std::vector< EntityHandle > conn, adjs;
1306 for(
unsigned int i = 0; i < adjs.size(); i++ )
1317 else if( ent_dim == 0 )
1324 std::replace( conn.begin(), conn.end(), entity_to_remove, entity_to_keep );
1348 Range adjs_keep, adjs_remove;
1365 two_ents[0] = *rit_rm;
1373 two_ents[1] = *rit_kp;
1378 assert( all_verts.
find( entity_to_keep ) != all_verts.
end() &&
1379 all_verts.
find( entity_to_remove ) != all_verts.
end() );
1458 entity_total = memory_total = 0;
1466 for( i = seqman.
begin(); i != seqman.
end(); ++i )
1468 if( !( *i )->data()->get_adjacency_data() )
continue;
1470 if( prev_data != ( *i )->data() )
1472 prev_data = ( *i )->data();
1477 for(
EntityHandle h = ( *i )->start_handle(); h <= ( *i )->end_handle(); ++h )
1485 memory_total +=
sizeof( *this ) + entity_total;
1489 unsigned long long& min_per_ent,
1490 unsigned long long& amortized )
1492 min_per_ent = amortized = 0;
1501 if( !array )
continue;
1515 for(
EntityID i = 0; i < count; ++i )
1521 amortized += min_per_ent;
1522 return ( rval == MB_FAILURE ) ?
MB_SUCCESS : rval;
1533 std::vector< EntityHandle > adj_entities;
1538 if( !adj_entities.empty() )
return MB_FAILURE;