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 )
102 MB_CHK_SET_ERR( result,
"Failed to get the geometry dimension tag" );
152 if( 0 > dimension1 || 3 < dimension1 )
157 const void*
const vals[] = { &id, &dimension1 };
166 return results.
front();
187 if( 1 == bdy.
size() && *bdy.
begin() == not_this )
191 else if( 2 == bdy.
size() )
193 if( *bdy.
begin() == not_this ) other = *bdy.
rbegin();
194 if( *bdy.
rbegin() == not_this )
195 other = *bdy.
begin();
214 for(
int dim = 2; dim <= 3; dim++ )
238 "Failed to get geom dimension tag handle" );
242 "Failed to get the geometry entities" );
248 for(
int i = 0; i < 5; i++ )
260 const void*
const dim_val[] = { &val };
262 "Failed to get entity set by type and tag" );
278 Range surfs_and_vols;
279 surfs_and_vols = vols;
280 surfs_and_vols.
merge( surfs );
308 if( model_ents.
find( eh ) == model_ents.
end() )
310 MB_SET_ERR( MB_FAILURE,
"Entity handle not in model set" );
329 Range nodes_to_delete;
330 nodes_to_delete.
insert( root );
334 if( dim == 3 && vol_only )
337 Range child_tree_nodes;
342 while( child_tree_nodes.
size() != 0 )
352 Range new_child_tree_nodes;
354 "Problem getting child nodes" );
356 nodes_to_delete.
insert( child );
359 child_tree_nodes.
erase( child );
366 Range all_tree_nodes;
427 std::cerr <<
"Surface obb tree already exists" << std::endl;
440 std::cerr <<
"WARNING: Surface id " <<
global_id( eh ) <<
" (handle: " << eh <<
")" <<
"has no facets"
458 Range tmp_surfs, surf_trees;
476 surf_trees.
insert( root );
489 MB_SET_ERR( MB_FAILURE,
"Improper dimension or type for constructing obb tree" );
557 Range surfs, vols, vol_trees;
569 one_vol_trees.
insert( root );
604 std::vector< EntityHandle > parents;
609 for(
int dim = 2; dim >= 0; dim-- )
619 std::vector< EntityHandle > owners;
625 owners.resize( dp1ents.
size() );
626 std::fill( owners.begin(), owners.end(), *rit );
636 if( dents.
empty() )
continue;
644 parents.resize( dp1ents.
size() );
654 std::copy( parents.begin(), parents.end(),
range_inserter( tmp_parents ) );
658 MB_CHK_SET_ERR( result,
"Failed to create parent child relationship" );
662 if( dim == 0 )
continue;
664 int len3 = 0, len2 = 0, err = 0, num = 0, sense = 0, offset = 0;
665 for(
size_t i = 0; i < parents.size(); ++i )
668 MB_CHK_SET_ERR( result,
"Failed to get the connectivity of the element" );
670 MB_CHK_SET_ERR( result,
"Failed to get the connectivity of the first element" );
673 MB_SET_ERR( MB_FAILURE,
"Connectivity of incorrect length" );
676 if( err )
return MB_FAILURE;
678 result =
set_sense( *d_it, parents[i], sense );
682 std::cerr <<
"Warning: Multiple volumes use surface with same sense." << std::endl
683 <<
" Some geometric sense data lost." << std::endl;
706 MB_CHK_SET_ERR( result,
"Could not verify geometry dimension tag" );
709 std::vector< int > tag_vals( geom_sets.
size() );
711 MB_CHK_SET_ERR( result,
"Failed to get the geometry dimension tag" );
714 std::vector< int >::iterator iit;
716 for(
int i = 0; i < 5; i++ )
719 for( git = geom_sets.
begin(), iit = tag_vals.begin(); git != geom_sets.
end(); ++git, ++iit )
721 if( 0 <= *iit && 4 >= *iit )
736 for(
int i = 0; i <= 4; i++ )
758 Range *temp_verts, temp_elems;
766 MB_CHK_SET_ERR( result,
"Failed to get the geometry set entities" );
769 temp_verts =
new( std::nothrow )
Range();
770 if( NULL == temp_verts )
772 MB_SET_ERR( MB_FAILURE,
"Could not construct Range object" );
781 MB_CHK_SET_ERR( result,
"Failed to get the element's adjacent vertices" );
789 MB_CHK_SET_ERR( result,
"Failed to get the adjacent vertex data" );
807 if( -1 == edim || -1 == wrtdim )
MB_SET_ERR( MB_FAILURE,
"Non-geometric entity provided" );
808 if( wrtdim - edim != 1 )
MB_SET_ERR( MB_FAILURE,
"Entity dimension mismatch" );
809 if( sense < -1 || sense > 1 )
MB_SET_ERR( MB_FAILURE,
"Invalid sense data provided" );
818 std::vector< EntityHandle > higher_ents;
819 std::vector< int > senses;
820 rval =
get_senses( entity, higher_ents, senses );
828 if( !higher_ents.empty() )
830 std::vector< EntityHandle >::iterator it = std::find( higher_ents.begin(), higher_ents.end(), wrt_entity );
831 if( it != higher_ents.end() )
835 unsigned int idx = it - higher_ents.begin();
836 int oldSense = senses[idx];
849 higher_ents.push_back( wrt_entity );
850 senses.push_back( sense );
853 int dum_size = higher_ents.size();
854 void* dum_ptr = &higher_ents[0];
856 "Failed to set the sense data" );
858 dum_ptr = &senses[0];
859 dum_size = higher_ents.size();
861 "Failed to set the sense data by pointer" );
878 sense_data[0] = sense_data[1] = wrt_entity;
880 else if( -1 == sense )
883 if( sense_data[1] == wrt_entity )
return MB_SUCCESS;
884 sense_data[1] = wrt_entity;
886 else if( 1 == sense )
889 if( sense_data[0] == wrt_entity )
return MB_SUCCESS;
890 sense_data[0] = wrt_entity;
904 if( -1 == edim || -1 == wrtdim )
MB_SET_ERR( MB_FAILURE,
"Non-geometric entity provided" );
905 if( wrtdim - edim != 1 )
MB_SET_ERR( MB_FAILURE,
"Entity dimension mismatch" );
914 std::vector< EntityHandle > faces;
915 std::vector< int > senses;
917 MB_CHK_SET_ERR( rval,
"Failed to get the curve to surface sense data" );
919 std::vector< EntityHandle >::iterator it = std::find( faces.begin(), faces.end(), wrt_entity );
921 unsigned int index = it - faces.begin();
922 sense = senses[
index];
931 MB_CHK_SET_ERR( rval,
"Failed to get the surface to volume sense data" );
932 if( ( wrt_entity == sense_data[0] ) && ( wrt_entity == sense_data[1] ) )
934 else if( wrt_entity == sense_data[0] )
936 else if( wrt_entity == sense_data[1] )
954 MB_SET_ERR( MB_FAILURE,
"Entity dimension is incorrect for surface meshset" );
960 "Failed to get surface sense data" );
963 forward_vol = parent_vols[0];
964 reverse_vol = parent_vols[1];
979 MB_SET_ERR( MB_FAILURE,
"Entity dimension is incorrect for surface meshset" );
983 EntityHandle parent_vols[2] = { forward_vol, reverse_vol };
985 "Failed to set surface sense data" );
1003 for(
int surf_num = 0; surf_num < num_surfaces; surf_num++ )
1005 get_sense( surfaces[surf_num], volume, senses_out[surf_num] );
1012 std::vector< EntityHandle >& wrt_entities,
1013 std::vector< int >& senses )
1019 if( -1 == edim )
MB_SET_ERR( MB_FAILURE,
"Non-geometric entity provided" );
1021 wrt_entities.clear();
1027 const void* dum_ptr;
1032 std::copy( ents_data, ents_data + num_ents, std::back_inserter( wrt_entities ) );
1036 const int* senses_data =
static_cast< const int*
>( dum_ptr );
1037 std::copy( senses_data, senses_data + num_ents, std::back_inserter( senses ) );
1044 "Failed to get the surface to volume sense data" );
1045 if( sense_data[0] != 0 && sense_data[1] == sense_data[0] )
1047 wrt_entities.push_back( sense_data[0] );
1048 senses.push_back( 0 );
1052 if( sense_data[0] != 0 )
1054 wrt_entities.push_back( sense_data[0] );
1055 senses.push_back( 1 );
1057 if( sense_data[1] != 0 )
1059 wrt_entities.push_back( sense_data[1] );
1060 senses.push_back( -1 );
1068 unsigned int currentSize = 0;
1077 wrt_entities[currentSize] = wrt_entities[
index];
1078 senses[currentSize] = senses[
index];
1083 wrt_entities.resize( currentSize );
1084 senses.resize( currentSize );
1090 std::vector< EntityHandle >& wrt_entities,
1091 std::vector< int >& senses )
1094 for(
unsigned int i = 0; i < wrt_entities.size(); i++ )
1104 std::vector< EntityHandle > parents;
1109 if( parents.size() != 2 )
1111 else if( parents.front() == old_volume )
1112 new_volume = parents.back();
1113 else if( parents.back() == old_volume )
1114 new_volume = parents.front();
1129 "Could not get/create the geometry dimension tag" );
1141 "Could not get/create the global id tag" );
1155 "Could not get/create the sense2Tag" );
1168 "Failed to get the curve to surface entity tag handle" );
1171 "Failed to get the curve to surface sense tag handle" );
1178 if( dim < 0 || dim > 4 )
MB_SET_ERR( MB_FAILURE,
"Invalid geometric dimension provided" );
1191 MB_CHK_SET_ERR( result,
"Failed to get the geometry dimension tag handle" );
1201 MB_CHK_SET_ERR( result,
"Failed set the geometry dimension tag value" );
1208 MB_CHK_SET_ERR( result,
"Failed to add new geometry set to the tool's modelSet" );
1219 MB_CHK_SET_ERR( result,
"Failed to get the global id tag value for the geom entity" );
1235 bool debugFlag =
false;
1237 Range surface_ents, edge_ents, loop_range;
1241 "Failed to get the surface entities" );
1263 "Failed to add surface entities to the surface meshset" );
1270 std::cout <<
"skinning edges: " << edge_ents.
size() <<
"\n";
1280 std::vector< EntityHandle > edges_loop;
1282 Range pool_of_edges = edge_ents;
1286 while( !pool_of_edges.
empty() )
1296 std::vector< EntityHandle > tris;
1298 "Failed to get the adjacent triangles to the current edge" );
1299 if( tris.size() != 1 )
MB_SET_ERR( MB_FAILURE,
"Edge not on boundary" );
1301 int side_n, sense, offset;
1303 "Failed to get the current edge's side number" );
1308 "Failed to get the current edge's connectivity" );
1310 if( nnodes2 != 2 )
MB_SET_ERR( MB_FAILURE,
"Incorrect number of nodes found." );
1320 "Failed to set the connectivity of the current edge" );
1322 start_node = nn2[0];
1325 if( debugFlag ) std::cout <<
" current edge needs reversed\n";
1329 edges_loop.push_back( current_edge );
1330 used_edges.
insert( current_edge );
1331 pool_of_edges.
erase( current_edge );
1335 std::cout <<
" start node: " << start_node <<
"\n";
1337 std::cout <<
" next node: " << next_node <<
"\n";
1340 while( next_node != start_node )
1343 std::vector< EntityHandle > candidate_edges;
1345 "Failed to get the adjacent edges to the next node" );
1347 std::vector< EntityHandle > good_edges;
1348 for(
int k = 0; k < (int)candidate_edges.size(); k++ )
1351 if( used_edges.
find( edg ) != used_edges.
end() )
continue;
1352 if( pool_of_edges.
find( edg ) != pool_of_edges.
end() ) good_edges.push_back( edg );
1354 if( good_edges.size() != 1 )
1356 std::cout <<
" good_edges.size()=" << good_edges.size() <<
" STOP\n";
1357 MB_SET_ERR( MB_FAILURE,
"Number of good edges is not one. Could not complete the loop" );
1361 current_edge = good_edges[0];
1363 "Failed to get the connectivity of the current edge" );
1364 if( nnodes2 != 2 )
MB_SET_ERR( MB_FAILURE,
"Incorrect number of nodes found" );
1366 if( conn2[0] != next_node )
1368 if( conn2[1] != next_node )
1373 << next_node <<
"\n";
1374 MB_SET_ERR( MB_FAILURE,
"Current edge is not connected to node" );
1385 "Failed to set the connectivity of the current edge" );
1390 std::cout <<
" conn2: " << conn2[0] <<
" " << conn2[1] <<
"\n";
1399 next_node = conn2[1];
1405 std::cout <<
"next node: " << next_node <<
"\n ";
1408 edges_loop.push_back( current_edge );
1409 used_edges.
insert( current_edge );
1410 pool_of_edges.
erase( current_edge );
1422 "Failed to add entities to the edge meshset" );
1430 "Failed to add entities to the vertex meshset" );
1433 "Failed to create the edge to face parent child relationship" );
1436 "Failed to create the vertex to edge parent child relationship" );
1444 "Failed to add the vertex meshset to the output set" );
1448 std::cout <<
"add edge with start node " << start_node <<
" with " << edges_loop.size() <<
" edges\n";
1480 "Failed to get the geometry dimension tag handle" );
1490 if( pvGEnts != NULL )
1492 unsigned int numGents = pvGEnts->
size();
1493 for(
unsigned int k = 0; k < numGents; k++ )
1500 "Failed to get the geometry set's child meshsets" );
1502 depSets.
insert( geomSet );
1508 std::map< EntityHandle, EntityHandle > relate;
1510 for(
int dim = 0; dim < 5; dim++ )
1513 unsigned int set_options = ( ( 1 != dim ) ?
MESHSET_SET : MESHSET_ORDERED );
1517 if( pvGEnts != NULL && depSets.
find( set ) == depSets.
end() )
1522 relate[set] = newSet;
1524 "Failed to add the new meshset to the tool's modelSet" );
1528 "Failed to set the new meshset's geometry dimension data" );
1532 "Failed to get the new meshset's global id data" );
1537 std::vector< EntityHandle > mesh_edges;
1539 "Failed to get the meshset entities by handle" );
1542 "Failed to add the new entities to the new meshset" );
1548 "Failed to add the entities to the existing meshset" );
1551 "Failed to add the entities to the new meshset" );
1560 "Failed to get the child meshsets of the existing set" );
1566 "Failed to create parent child relationship to the new meshset" );
1583 for(
int dd = 1; dd <= 2; dd++ )
1588 if( pvGEnts != NULL && depSets.
find( surf ) == depSets.
end() )
1593 std::vector< EntityHandle > solids;
1594 std::vector< int > senses;
1596 "Failed to get the sense data for the surface with respect to its volumes" );
1598 std::vector< EntityHandle > newSolids;
1599 std::vector< int > newSenses;
1600 for(
unsigned int i = 0; i < solids.size(); i++ )
1602 if( pvGEnts != NULL && depSets.
find( solids[i] ) == depSets.
end() )
1606 newSolids.push_back( newSolid );
1607 newSenses.push_back( senses[i] );
1610 "Failed to set the sense data for the surface with respect to the new volumes" );
1622 for(
int dim = 0; dim < 5; dim++ )
1625 "Failed to add the geometric meshsets to the tool's modelSet" );
1651 std::cout <<
"IPC already exists!" << std::endl;
1660 MB_CHK_SET_ERR( rval,
"Unable to query for implicit complement" );
1663 if( entities.
size() == 1 )
1673 if( entities.
empty() )
1679 "Could not set the name tag for the implicit complement" );
1689 "Could not get the category tag" );
1693 "Could not set the category tag for the implicit complement" );
1704 "Failed to create mesh set for implicit complement" );
1717 std::vector< EntityHandle > parent_vols;
1721 parent_vols.clear();
1726 if( parent_vols.size() == 1 )
1731 "Could not add surface to implicit complement set" );
1736 "Could not get surface sense data" );
1739 if( 0 == sense_data[0] && 0 == sense_data[1] )
1740 MB_SET_ERR( MB_FAILURE,
"No sense data for current surface" );
1741 if( 0 == sense_data[0] )
1742 sense_data[0] = implicit_complement_set;
1743 else if( 0 == sense_data[1] )
1744 sense_data[1] = implicit_complement_set;
1746 MB_SET_ERR( MB_FAILURE,
"Could not insert implicit complement into surface sense data" );
1750 "Failed to set sense tag data" );
1757 #define RETFALSE( a, b ) \
1759 std::cout << ( a ) << "\n"; \
1760 mdbImpl->list_entity( b ); \
1774 if( nodes.
size() != 1 )
RETFALSE(
" number of nodes is different from 1 ", vSet )
1776 if( type !=
MBVERTEX )
RETFALSE(
" entity in vertex set is not a node ", nodes[0] )
1782 if( !notEdges.
empty() )
RETFALSE(
" some parents of a node set are not geo edges ", notEdges[0] )
1789 std::vector< EntityHandle > mesh_edges;
1792 int num_edges = (int)mesh_edges.size();
1793 if( num_edges == 0 )
RETFALSE(
" no mesh edges in edge set ",
edge )
1799 for(
int i = 0; i < num_edges; i++ )
1802 if(
MB_SUCCESS != rval || nnodes2 != 2 )
RETFALSE(
" mesh edge connectivity is wrong ", mesh_edges[i] )
1805 firstNode = conn2[0];
1806 currentNode = conn2[1];
1812 if( conn2[0] != currentNode )
1814 std::cout <<
"i=" << i <<
" conn2:" << conn2[0] <<
" " << conn2[1] <<
" currentNode:" << currentNode
1817 RETFALSE(
" edges are not contiguous in edge set ",
edge )
1819 currentNode = conn2[1];
1827 if( !notVertices.
empty() )
RETFALSE(
" children sets that are not vertices ", notVertices[0] )
1832 RETFALSE(
" a vertex set is not containing the first and last nodes ", *it )
1839 if( !notFaces.
empty() )
RETFALSE(
" parent sets that are not faces ", notFaces[0] )
1848 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get adjacent elements to the edge ", firstMeshEdge )
1859 gFace = possibleFace;
1864 RETFALSE(
" can't find adjacent surface that contains the adjacent element to the edge ",
1869 int side_n, sense, offset;
1871 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get sense and side number of an element ", elem )
1874 rval = this->
get_sense( edge, gFace, topoSense );
1875 if( topoSense != sense )
RETFALSE(
" geometric topo sense and element sense do not agree ",
edge )
1891 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get children edges for a face set ", faceSet )
1893 if( !notEdges.
empty() )
RETFALSE(
" some children of a face set are not geo edges ", notEdges[0] )
1895 Range boundary_mesh_edges;
1899 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get edge elements from the edge set ", *it )
1903 Range surface_ents, edge_ents;
1905 if(
MB_SUCCESS != rval )
RETFALSE(
" can't get surface elements from the face set ", faceSet )
1907 rval = tool.
find_skin( 0, surface_ents, 1, edge_ents );
1911 if( boundary_mesh_edges != edge_ents )
RETFALSE(
"boundary ranges are different", boundary_mesh_edges[0] )
1930 double center[3], axis1[3], axis2[3], axis3[3];
1934 "Failed to get the oriented bounding box of the volume" );
1937 for(
int i = 0; i < 3; i++ )
1939 double sum = fabs( axis1[i] ) + fabs( axis2[i] ) + fabs( axis3[i] );
1962 Range all_children, desired_children;
1964 int actual_dimension;
1966 desired_children.
clear();
1967 all_children.
clear();
1970 for( it = all_children.
begin(); it != all_children.
end(); ++it )
1973 if( actual_dimension == desired_dimension ) desired_children.
insert( *it );
1976 return desired_children;
1983 Range child_surfaces, triangles, vertices;
2001 return ( result != 0 );
2006 bool inserted =
false;
2010 Range child_volumes;
2017 if( tree_volume == ct_root || ( tree_volume != ct_root &&
A_is_in_B( current_volume, tree_volume, GQT ) ) )
2020 parent = tree_volume;
2025 if( child_volumes.
size() > 0 ) tree_volume = child_volumes.
pop_front();
2030 "Failed to add parent-child relationship." );
2039 if(
A_is_in_B( tree_volume, current_volume, GQT ) )
2043 "Failed to remove parent-child relationship." );
2045 "Failed to add parent-child relationship." );
2048 if( child_volumes.
size() == 0 )
2051 "Failed to add parent-child relationship." );
2055 tree_volume = child_volumes.
pop_front();
2065 std::map< EntityHandle, EntityHandle > volume_surface;
2070 std::string meshset_name =
"build_hierarchy_root";
2080 volume_surface[*vol] = *child_surfaces.
begin();
2090 if( volume_children.
size() != 0 )
2098 "Failed to set sense." );
2103 "Failed to add parent-child relationship." );
2105 "Failed to remove parent-child relationship." );