49 bool p_rootSets_vector,
50 bool restore_rootSets )
51 : mdbImpl( impl ), sense2Tag( 0 ), senseNEntsTag( 0 ), senseNSensesTag( 0 ),
geomTag( 0 ), gidTag( 0 ),
52 obbRootTag( 0 ), obbGsetTag( 0 ), modelSet( modelRootSet ), updated( false ), setOffset( 0 ),
53 m_rootSets_vector( p_rootSets_vector ), oneVolRootSet( 0 )
79 if( restore_rootSets )
151 if( 0 > dimension1 || 3 < dimension1 )
156 const void*
const vals[] = { &id, &dimension1 };
165 return results.
front();
186 if( 1 == bdy.
size() && *bdy.
begin() == not_this )
190 else if( 2 == bdy.
size() )
192 if( *bdy.
begin() == not_this ) other = *bdy.
rbegin();
193 if( *bdy.
rbegin() == not_this )
194 other = *bdy.
begin();
247 for(
int i = 0; i < 5; i++ )
261 const void*
const dim_val[] = { &val };
281 Range surfs_and_vols;
282 surfs_and_vols = vols;
283 surfs_and_vols.
merge( surfs );
311 if( model_ents.
find( eh ) == model_ents.
end() )
313 MB_SET_ERR( MB_FAILURE,
"Entity handle not in model set" );
332 rval =
get_root( gset, root );
MB_CHK_SET_ERR( rval,
"Failed to find an obb tree root for the entity set" );
335 Range nodes_to_delete;
336 nodes_to_delete.
insert( root );
340 if(
dim == 3 && vol_only )
343 Range child_tree_nodes;
348 while( child_tree_nodes.
size() != 0 )
358 Range new_child_tree_nodes;
371 Range all_tree_nodes;
439 std::cerr <<
"Surface obb tree already exists" << std::endl;
452 std::cerr <<
"WARNING: Surface id " <<
global_id(eh) <<
" (handle: " << eh <<
")" <<
"has no facets" << std::endl;
469 Range tmp_surfs, surf_trees;
487 surf_trees.
insert( root );
500 MB_SET_ERR( MB_FAILURE,
"Improper dimension or type for constructing obb tree" );
548 unsigned int index = vol_or_surf -
setOffset;
572 Range surfs, vols, vol_trees;
584 one_vol_trees.
insert( root );
619 std::vector< EntityHandle > parents;
634 std::vector< EntityHandle > owners;
640 owners.resize( dp1ents.
size() );
641 std::fill( owners.begin(), owners.end(), *rit );
651 if( dents.
empty() )
continue;
659 parents.resize( dp1ents.
size() );
669 std::copy( parents.begin(), parents.end(),
range_inserter( tmp_parents ) );
676 if(
dim == 0 )
continue;
678 int len3 = 0, len2 = 0, err = 0, num = 0, sense = 0, offset = 0;
679 for(
size_t i = 0; i < parents.size(); ++i )
685 MB_SET_ERR( MB_FAILURE,
"Connectivity of incorrect length" );
688 if( err )
return MB_FAILURE;
690 result =
set_sense( *d_it, parents[i], sense );
694 std::cerr <<
"Warning: Multiple volumes use surface with same sense." << std::endl
695 <<
" Some geometric sense data lost." << std::endl;
719 std::vector< int > tag_vals( geom_sets.
size() );
723 std::vector< int >::iterator iit;
725 for(
int i = 0; i < 5; i++ )
728 for( git = geom_sets.
begin(), iit = tag_vals.begin(); git != geom_sets.
end(); ++git, ++iit )
730 if( 0 <= *iit && 4 >= *iit )
745 for(
int i = 0; i <= 4; i++ )
767 Range *temp_verts, temp_elems;
777 temp_verts =
new( std::nothrow )
Range();
778 if( NULL == temp_verts )
780 MB_SET_ERR( MB_FAILURE,
"Could not construct Range object" );
789 MB_CHK_SET_ERR( result,
"Failed to get the element's adjacent vertices" );
797 MB_CHK_SET_ERR( result,
"Failed to get the adjacent vertex data" );
815 if( -1 == edim || -1 == wrtdim )
MB_SET_ERR( MB_FAILURE,
"Non-geometric entity provided" );
816 if( wrtdim - edim != 1 )
MB_SET_ERR( MB_FAILURE,
"Entity dimension mismatch" );
817 if( sense < -1 || sense > 1 )
MB_SET_ERR( MB_FAILURE,
"Invalid sense data provided" );
826 std::vector< EntityHandle > higher_ents;
827 std::vector< int > senses;
828 rval =
get_senses( entity, higher_ents, senses );
836 if( !higher_ents.empty() )
838 std::vector< EntityHandle >::iterator it = std::find( higher_ents.begin(), higher_ents.end(), wrt_entity );
839 if( it != higher_ents.end() )
843 unsigned int idx = it - higher_ents.begin();
844 int oldSense = senses[idx];
857 higher_ents.push_back( wrt_entity );
858 senses.push_back( sense );
861 int dum_size = higher_ents.size();
862 void* dum_ptr = &higher_ents[0];
865 dum_ptr = &senses[0];
866 dum_size = higher_ents.size();
884 sense_data[0] = sense_data[1] = wrt_entity;
886 else if( -1 == sense )
889 if( sense_data[1] == wrt_entity )
return MB_SUCCESS;
890 sense_data[1] = wrt_entity;
892 else if( 1 == sense )
895 if( sense_data[0] == wrt_entity )
return MB_SUCCESS;
896 sense_data[0] = wrt_entity;
910 if( -1 == edim || -1 == wrtdim )
MB_SET_ERR( MB_FAILURE,
"Non-geometric entity provided" );
911 if( wrtdim - edim != 1 )
MB_SET_ERR( MB_FAILURE,
"Entity dimension mismatch" );
920 std::vector< EntityHandle > faces;
921 std::vector< int > senses;
923 MB_CHK_SET_ERR( rval,
"Failed to get the curve to surface sense data" );
925 std::vector< EntityHandle >::iterator it = std::find( faces.begin(), faces.end(), wrt_entity );
927 unsigned int index = it - faces.begin();
928 sense = senses[index];
937 MB_CHK_SET_ERR( rval,
"Failed to get the surface to volume sense data" );
938 if( ( wrt_entity == sense_data[0] ) && ( wrt_entity == sense_data[1] ) )
940 else if( wrt_entity == sense_data[0] )
942 else if( wrt_entity == sense_data[1] )
961 MB_SET_ERR( MB_FAILURE,
"Entity dimension is incorrect for surface meshset" );
969 forward_vol = parent_vols[0];
970 reverse_vol = parent_vols[1];
986 MB_SET_ERR( MB_FAILURE,
"Entity dimension is incorrect for surface meshset" );
990 EntityHandle parent_vols[2] = { forward_vol, reverse_vol };
1009 for(
int surf_num = 0; surf_num < num_surfaces; surf_num++ )
1011 get_sense( surfaces[surf_num], volume, senses_out[surf_num] );
1018 std::vector< EntityHandle >& wrt_entities,
1019 std::vector< int >& senses )
1025 if( -1 == edim )
MB_SET_ERR( MB_FAILURE,
"Non-geometric entity provided" );
1028 wrt_entities.clear();
1034 const void* dum_ptr;
1039 std::copy( ents_data, ents_data + num_ents, std::back_inserter( wrt_entities ) );
1043 const int* senses_data =
static_cast< const int*
>( dum_ptr );
1044 std::copy( senses_data, senses_data + num_ents, std::back_inserter( senses ) );
1051 if( sense_data[0] != 0 && sense_data[1] == sense_data[0] )
1053 wrt_entities.push_back( sense_data[0] );
1054 senses.push_back( 0 );
1058 if( sense_data[0] != 0 )
1060 wrt_entities.push_back( sense_data[0] );
1061 senses.push_back( 1 );
1063 if( sense_data[1] != 0 )
1065 wrt_entities.push_back( sense_data[1] );
1066 senses.push_back( -1 );
1074 unsigned int currentSize = 0;
1076 for(
unsigned int index = 0; index < wrt_entities.size(); index++ )
1083 wrt_entities[currentSize] = wrt_entities[index];
1084 senses[currentSize] = senses[index];
1089 wrt_entities.resize( currentSize );
1090 senses.resize( currentSize );
1096 std::vector< EntityHandle >& wrt_entities,
1097 std::vector< int >& senses )
1100 for(
unsigned int i = 0; i < wrt_entities.size(); i++ )
1110 std::vector< EntityHandle > parents;
1115 if( parents.size() != 2 )
1117 else if( parents.front() == old_volume )
1118 new_volume = parents.back();
1119 else if( parents.back() == old_volume )
1120 new_volume = parents.front();
1182 if( dim < 0 || dim > 4 )
MB_SET_ERR( MB_FAILURE,
"Invalid geometric dimension provided" );
1235 bool debugFlag =
false;
1237 Range surface_ents, edge_ents, loop_range;
1265 rval = tool.
find_skin( 0, surface_ents, 1, edge_ents );
MB_CHK_SET_ERR( rval,
"Failed to skin the surface entities" );
1268 std::cout <<
"skinning edges: " << edge_ents.
size() <<
"\n";
1278 std::vector< EntityHandle > edges_loop;
1280 Range pool_of_edges = edge_ents;
1284 while( !pool_of_edges.
empty() )
1294 std::vector< EntityHandle > tris;
1296 if( tris.size() != 1 )
MB_SET_ERR( MB_FAILURE,
"Edge not on boundary" );
1298 int side_n, sense, offset;
1305 if( nnodes2 != 2 )
MB_SET_ERR( MB_FAILURE,
"Incorrect number of nodes found." );
1316 start_node = nn2[0];
1319 if( debugFlag ) std::cout <<
" current edge needs reversed\n";
1323 edges_loop.push_back( current_edge );
1324 used_edges.
insert( current_edge );
1325 pool_of_edges.
erase( current_edge );
1329 std::cout <<
" start node: " << start_node <<
"\n";
1331 std::cout <<
" next node: " << next_node <<
"\n";
1334 while( next_node != start_node )
1337 std::vector< EntityHandle > candidate_edges;
1340 std::vector< EntityHandle > good_edges;
1341 for(
int k = 0; k < (int)candidate_edges.size(); k++ )
1344 if( used_edges.
find( edg ) != used_edges.
end() )
continue;
1345 if( pool_of_edges.
find( edg ) != pool_of_edges.
end() ) good_edges.push_back( edg );
1347 if( good_edges.size() != 1 )
1349 std::cout <<
" good_edges.size()=" << good_edges.size() <<
" STOP\n";
1350 MB_SET_ERR( MB_FAILURE,
"Number of good edges is not one. Could not complete the loop" );
1354 current_edge = good_edges[0];
1356 if( nnodes2 != 2 )
MB_SET_ERR( MB_FAILURE,
"Incorrect number of nodes found" );
1358 if( conn2[0] != next_node )
1360 if( conn2[1] != next_node )
1365 << next_node <<
"\n";
1366 MB_SET_ERR( MB_FAILURE,
"Current edge is not connected to node" );
1381 std::cout <<
" conn2: " << conn2[0] <<
" " << conn2[1] <<
"\n";
1390 next_node = conn2[1];
1396 std::cout <<
"next node: " << next_node <<
"\n ";
1399 edges_loop.push_back( current_edge );
1400 used_edges.
insert( current_edge );
1401 pool_of_edges.
erase( current_edge );
1413 MB_CHK_SET_ERR( rval,
"Failed to add entities to the edge meshset" );
1421 MB_CHK_SET_ERR( rval,
"Failed to add entities to the vertex meshset" );
1437 std::cout <<
"add edge with start node " << start_node <<
" with " << edges_loop.size() <<
" edges\n";
1478 if( pvGEnts != NULL )
1480 unsigned int numGents = pvGEnts->
size();
1481 for(
unsigned int k = 0; k < numGents; k++ )
1487 MB_CHK_SET_ERR( rval,
"Failed to get the geometry set's child meshsets" );
1489 depSets.
insert( geomSet );
1495 std::map< EntityHandle, EntityHandle > relate;
1500 unsigned int set_options = ( ( 1 !=
dim ) ?
MESHSET_SET : MESHSET_ORDERED );
1504 if( pvGEnts != NULL && depSets.
find( set ) == depSets.
end() )
1509 relate[set] = newSet;
1521 std::vector< EntityHandle > mesh_edges;
1539 MB_CHK_SET_ERR( rval,
"Failed to get the child meshsets of the existing set" );
1561 for(
int dd = 1; dd <= 2; dd++ )
1566 if( pvGEnts != NULL && depSets.
find( surf ) == depSets.
end() )
1571 std::vector< EntityHandle > solids;
1572 std::vector< int > senses;
1573 rval = this->
get_senses( surf, solids, senses );
MB_CHK_SET_ERR( rval,
"Failed to get the sense data for the surface with respect to its volumes" );
1575 std::vector< EntityHandle > newSolids;
1576 std::vector< int > newSenses;
1577 for(
unsigned int i = 0; i < solids.size(); i++ )
1579 if( pvGEnts != NULL && depSets.
find( solids[i] ) == depSets.
end() )
1583 newSolids.push_back( newSolid );
1584 newSenses.push_back( senses[i] );
1586 rval = duplicate->
set_senses( newSurf, newSolids, newSenses );
MB_CHK_SET_ERR( rval,
"Failed to set the sense data for the surface with respect to the new volumes" );
1626 std::cout <<
"IPC already exists!" << std::endl;
1635 MB_CHK_SET_ERR( rval,
"Unable to query for implicit complement" );
1690 std::vector< EntityHandle > parent_vols;
1694 parent_vols.clear();
1699 if( parent_vols.size() == 1 )
1710 if( 0 == sense_data[0] && 0 == sense_data[1] )
1711 MB_SET_ERR( MB_FAILURE,
"No sense data for current surface" );
1712 if( 0 == sense_data[0] )
1713 sense_data[0] = implicit_complement_set;
1714 else if( 0 == sense_data[1] )
1715 sense_data[1] = implicit_complement_set;
1717 MB_SET_ERR( MB_FAILURE,
"Could not insert implicit complement into surface sense data" );
1727 #define RETFALSE( a, b ) \
1729 std::cout << ( a ) << "\n"; \
1730 mdbImpl->list_entity( b ); \
1744 if( nodes.
size() != 1 )
RETFALSE(
" number of nodes is different from 1 ", vSet )
1746 if( type !=
MBVERTEX )
RETFALSE(
" entity in vertex set is not a node ", nodes[0] )
1752 if( !notEdges.
empty() )
RETFALSE(
" some parents of a node set are not geo edges ", notEdges[0] )
1759 std::vector< EntityHandle > mesh_edges;
1762 int num_edges = (int)mesh_edges.size();
1763 if( num_edges == 0 )
RETFALSE(
" no mesh edges in edge set ",
edge )
1769 for(
int i = 0; i < num_edges; i++ )
1772 if(
MB_SUCCESS != rval || nnodes2 != 2 )
RETFALSE(
" mesh edge connectivity is wrong ", mesh_edges[i] )
1775 firstNode = conn2[0];
1776 currentNode = conn2[1];
1782 if( conn2[0] != currentNode )
1784 std::cout <<
"i=" << i <<
" conn2:" << conn2[0] <<
" " << conn2[1] <<
" currentNode:" << currentNode
1787 RETFALSE(
" edges are not contiguous in edge set ",
edge )
1789 currentNode = conn2[1];
1797 if( !notVertices.
empty() )
RETFALSE(
" children sets that are not vertices ", notVertices[0] )
1802 RETFALSE(
" a vertex set is not containing the first and last nodes ", *it )
1809 if( !notFaces.
empty() )
RETFALSE(
" parent sets that are not faces ", notFaces[0] )
1818 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get adjacent elements to the edge ", firstMeshEdge )
1829 gFace = possibleFace;
1834 RETFALSE(
" can't find adjacent surface that contains the adjacent element to the edge ",
1839 int side_n, sense, offset;
1841 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get sense and side number of an element ", elem )
1844 rval = this->
get_sense( edge, gFace, topoSense );
1845 if( topoSense != sense )
RETFALSE(
" geometric topo sense and element sense do not agree ",
edge )
1861 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get children edges for a face set ", faceSet )
1863 if( !notEdges.
empty() )
RETFALSE(
" some children of a face set are not geo edges ", notEdges[0] )
1865 Range boundary_mesh_edges;
1869 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get edge elements from the edge set ", *it )
1873 Range surface_ents, edge_ents;
1875 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get surface elements from the face set ", faceSet )
1877 rval = tool.
find_skin( 0, surface_ents, 1, edge_ents );
1881 if( boundary_mesh_edges != edge_ents )
RETFALSE(
"boundary ranges are different", boundary_mesh_edges[0] )
1900 double center[3], axis1[3], axis2[3], axis3[3];
1906 for(
int i = 0; i < 3; i++ )
1908 double sum = fabs( axis1[i] ) + fabs( axis2[i] ) + fabs( axis3[i] );
1931 Range all_children, desired_children;
1933 int actual_dimension;
1935 desired_children.
clear();
1936 all_children.
clear();
1939 for( it = all_children.
begin(); it != all_children.
end(); ++it )
1942 if( actual_dimension == desired_dimension ) desired_children.
insert( *it );
1945 return desired_children;
1954 Range child_surfaces, triangles, vertices;
1972 return ( result != 0 );
1979 bool inserted =
false;
1983 Range child_volumes;
1990 if( tree_volume == ct_root || ( tree_volume != ct_root &&
A_is_in_B( current_volume, tree_volume, GQT ) ) )
1993 parent = tree_volume;
1998 if( child_volumes.
size() > 0 ) tree_volume = child_volumes.
pop_front();
2011 if(
A_is_in_B( tree_volume, current_volume, GQT ) )
2018 if( child_volumes.
size() == 0 )
2024 tree_volume = child_volumes.
pop_front();
2036 std::map< EntityHandle, EntityHandle > volume_surface;
2041 std::string meshset_name =
"build_hierarchy_root";
2051 volume_surface[*vol] = *child_surfaces.
begin();
2061 if( volume_children.
size() != 0 )