34 if( MB_SUCCESS != result ) return result
35 #define SWAP( a, b ) \
37 EntityHandle tmp_ent = a; \
81 unsigned int dummy = 0;
122 Range regions, faces, edges, vertices;
125 if( NULL ==
entities || 0 == num_entities )
147 std::vector< int > gid_vec( regions.
size() );
153 for( rit = regions.
begin(), i = 0; rit != regions.
end(); ++rit, i++ )
174 if(
debug ) std::cout <<
"Constructed " << dual_verts.
size() <<
" dual vertices." << std::endl;
180 if(
debug ) std::cout <<
"Constructed " << dual_edges.
size() <<
" dual edges." << std::endl;
186 if(
debug ) std::cout <<
"Constructed " << dual_faces.
size() <<
" dual faces." << std::endl;
192 if(
debug ) std::cout <<
"Constructed " << dual_cells.
size() <<
" dual cells." << std::endl;
210 for( rit = all_regions.
begin(); rit != all_regions.
end(); ++rit )
212 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
215 if(
MB_SUCCESS == tmp_result && 0 != dual_ent )
217 dual_ents.
insert( dual_ent );
227 dual_ents.
insert( dual_ent );
236 const bool add_graphics_pt )
239 unsigned int is_dual = 0x1;
262 if( add_graphics_pt )
275 if( NULL == avg_pos )
281 for(
int i = 0; i < 3; i++ )
282 my_pos[i] = avg_pos[i];
299 unsigned int is_dual = 0x1;
303 for( rit = all_faces.
begin(); rit != all_faces.
end(); ++rit )
305 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
308 if(
MB_SUCCESS == tmp_result && 0 != dual_ent )
310 dual_ents.
insert( dual_ent );
315 std::vector< EntityHandle > out_ents;
317 if(
MB_SUCCESS != tmp_result || out_ents.empty() )
continue;
320 std::vector< EntityHandle > dual_verts( out_ents.size() );
323 assert( dual_verts.size() <= 2 );
326 bool bdy_face = ( dual_verts.size() == 1 ? true : false );
333 dual_verts.push_back( dual_ent );
336 assert( dual_verts.size() == 2 );
340 if(
MB_SUCCESS != tmp_result || 0 == dual_ent )
continue;
343 dual_ents.
insert( dual_ent );
383 unsigned int is_dual = 0x1;
388 if( MB_SUCCESS != tmp_result ) \
390 result = tmp_result; \
393 for( rit = all_edges.
begin(); rit != all_edges.
end(); ++rit )
397 if(
MB_SUCCESS == tmp_result && 0 != dual_ent )
399 dual_ents.
insert( dual_ent );
405 std::vector< EntityHandle > rad_dverts;
408 TRC if( rad_dverts.empty() )
continue;
420 dual_ents.
insert( dual_ent );
454 Range dum_edges, dum_poly( dual_ent, dual_ent );
459 equiv_edges.
merge( dum_edges );
475 Range all_dedges( dual_edges );
480 Range connect, dum_range( *rit, *rit );
488 Range save_all_2cells;
491 while( !all_dedges.
empty() )
501 Range dum_edges, verts;
502 verts.
insert( connect[0] );
503 verts.
insert( connect[1] );
510 if( dum_edges.
size() == 1 )
530 Range dum_quad_range( dedge_quad, dedge_quad ), adj_pedges;
538 std::vector< EntityHandle > dcells;
539 dcells.resize( adj_pedges.
size() );
547 std::vector< EntityHandle >::iterator vit;
548 for( vit = dcells.begin(); vit != dcells.end(); ++vit )
550 save_all_2cells.
insert( *vit );
564 if( NULL == adjs || std::find( adjs, adjs + num_adjs, *vit ) == adjs + num_adjs )
565 std::cout <<
"Add_adjacencies failed in construct_dual_faces." << std::endl;
588 Range adj_edges, dum_quad_range;
589 dum_quad_range.
insert( *vit );
613 unsigned int is_dual = 0x1;
616 std::vector< EntityHandle > edges, dfaces;
618 for( rit = all_verts.
begin(); rit != all_verts.
end(); ++rit )
620 if( tmp_result !=
MB_SUCCESS ) result = tmp_result;
623 if(
MB_SUCCESS == tmp_result && 0 != dual_ent )
625 dual_ents.
insert( dual_ent );
636 dfaces.resize( edges.size() );
642 if(
MB_SUCCESS != tmp_result || 0 == dual_ent )
continue;
645 dual_ents.
insert( dual_ent );
664 std::vector< EntityHandle >& rad_dverts,
669 std::vector< EntityHandle > rad_faces, rad_ents;
676 rad_ents.push_back( *rad_faces.rbegin() );
677 rad_ents.push_back( *rad_faces.begin() );
680 rad_dverts.resize( rad_ents.size() );
681 for(
unsigned int i = 0; i < rad_ents.size(); i++ )
685 if( !bdy_edge || i < rad_ents.size() - 2 )
686 rad_dverts[i] = dual_ent;
699 int last_hex = ( i == rad_ents.size() - 1 ? 0 : i - 1 );
700 EntityHandle last_face = ( connect[0] == rad_dverts[last_hex] ? connect[1] : connect[0] );
701 rad_dverts[i] = last_face;
711 std::vector< EntityHandle > evec;
725 std::cerr <<
"Error constructing dual entities for primal entities." << std::endl;
733 std::cerr <<
"Problem traversing 1d hyperplanes." << std::endl;
740 std::cerr <<
"Problem traversing 2d hyperplanes." << std::endl;
747 std::cerr <<
"Problem constructing parent/child relations between hyperplanes." << std::endl;
761 unsigned int dum = 0x1;
762 const void* dum_ptr = &
dum;
769 if( 0 ==
entities || 0 == num_entities )
779 std::vector< EntityHandle > dual_ents_vec( dim_ents.
size() );
782 std::copy( dual_ents_vec.begin(), dual_ents_vec.end(),
range_inserter( dual_ents ) );
791 const int num_entities,
792 std::vector< EntityHandle >& dual_ents )
799 dual_ents.reserve( dual_ents.size() + tmp_range.
size() );
802 dual_ents.push_back( *it );
831 int num_quads, num_hexes;
834 (
dim != 1 &&
dim != 2 ) ||
839 ( num_quads == 0 &&
dim == 1 ) ||
841 ( num_hexes == 0 &&
dim == 2 ) )
848 std::vector< EntityHandle > tot_untreated;
858 while( !tot_untreated.empty() )
861 std::cout <<
"Untreated list size " << tot_untreated.size() <<
"." << std::endl;
863 this_ent = tot_untreated.back();
864 tot_untreated.pop_back();
869 else if( this_hp != 0 )
878 std::cout <<
"Failed to traverse hyperplane ";
882 std::cout <<
"0." << std::endl;
895 Range tmp_star, star, tmp_range, new_hyperplane_ents;
896 std::vector< EntityHandle > hp_untreated;
902 unsigned short mark_val = 0x0;
908 while( 0 != this_ent )
911 if( 0 == this_hp && 0 != tmp_hp ) this_hp = tmp_hp;
913 if( 0 == tmp_hp ) new_hyperplane_ents.
insert( this_ent );
915 if(
debug && hp_untreated.size() % 10 == 0 )
916 std::cout <<
"Dual surface " << this_hp <<
", hp_untreated list size = " << hp_untreated.size() <<
"."
927 tmp_range =
subtract( star, tmp_star );
931 if( new_hyperplane_ents.
find( *rit ) != new_hyperplane_ents.
end() )
continue;
935 unsigned short tmp_mark = 0x0;
937 if(
MB_SUCCESS == result && mark_val == tmp_mark )
continue;
944 hp_untreated.push_back( *rit );
950 if( hp_untreated.empty() )
954 this_ent = hp_untreated.back();
955 hp_untreated.pop_back();
968 std::cout <<
"Constructed new " << hp_name <<
" with ";
973 std::cout <<
"Added to " << hp_name <<
" " << this_id <<
" ";
976 std::cout <<
"edges:" << std::endl;
978 std::cout <<
"quads:" << std::endl;
979 std::vector< EntityHandle > pents( new_hyperplane_ents.
size() );
981 for( std::vector< EntityHandle >::iterator vit = pents.begin(); vit != pents.end(); ++vit )
983 if( vit != pents.begin() ) std::cout <<
", ";
986 std::cout << std::endl;
1000 std::cout <<
" sheet ";
1002 std::cout <<
" chord ";
1003 std::cout << new_id <<
" constructed." << std::endl;
1008 std::vector< EntityHandle > hp_tags( new_hyperplane_ents.
size() );
1009 std::fill( hp_tags.begin(), hp_tags.end(), this_hp );
1026 Range verts, one_cells;
1043 if( 0 == last_vert ) last_vert = *verts.
begin();
1046 std::vector< EntityHandle > ordered_1cells;
1052 while( ordered_1cells.size() != one_cells.
size() )
1056 if( 0 != last_1cell ) dum1.
erase( last_1cell );
1058 if( 0 != last_1cell && 1 != dum1.
size() )
1060 std::cerr <<
"unexpected size traversing chord." << std::endl;
1061 tmp_result = MB_FAILURE;
1064 last_1cell = *dum1.
begin();
1065 ordered_1cells.push_back( last_1cell );
1067 if( last_vert == connect[0] )
1068 last_vert = connect[1];
1070 last_vert = connect[0];
1094 Range all_hyperplanes;
1096 std::vector< int > gids( all_hyperplanes.
size() );
1098 for(
unsigned int i = 0; i < gids.size(); i++ )
1099 if( gids[i] >
id )
id = gids[i];
1109 static const char dual_category_names[2][
CATEGORY_TAG_SIZE] = {
"Chord\0",
"Sheet\0" };
1143 Range dual_surfs, dual_cells, dual_edges;
1146 std::vector< EntityHandle > dual_curve_sets;
1157 dual_curve_sets.resize( dual_edges.
size() );
1163 for(
unsigned int i = 0; i < dual_edges.
size(); i++ )
1164 if( dual_curve_sets[i] != 0 ) dual_cells.
insert( dual_curve_sets[i] );
1178 std::vector< int >& npts,
1179 std::vector< GraphicsPoint >& points )
1195 if(
MB_SUCCESS == result ) points.push_back( gp_array[0] );
1209 points.push_back( gp_array[0] );
1210 points.push_back( gp_array[0] );
1211 points.push_back( gp_array[1] );
1213 if(
MB_SUCCESS == result ) points[1] = gp_array[0];
1216 npts.push_back( 3 );
1229 std::vector< int >& npts,
1230 std::vector< GraphicsPoint >& points )
1238 tc_range.
insert( dual_ent );
1241 int num_edges = one_cells.
size();
1242 std::vector< GraphicsPoint > dum_gps( num_edges + 1 );
1253 for( i = 0, eit = one_cells.
begin(); i < num_edges; i++, ++eit )
1261 npts.push_back( 3 );
1262 points.push_back( dum_gps[num_edges] );
1263 points.push_back( vert_gps[0] );
1264 points.push_back( dum_gps[i] );
1266 npts.push_back( 3 );
1267 points.push_back( dum_gps[num_edges] );
1268 points.push_back( dum_gps[i] );
1269 points.push_back( vert_gps[1] );
1276 std::vector< GraphicsPoint >& points,
1277 const bool assign_ids,
1278 const int start_id )
1287 Range two_cells, all_cells;
1302 two_cells.
insert( *rit );
1312 points.resize( all_cells.
size() );
1320 for( std::vector< GraphicsPoint >::iterator vit = points.begin(); vit != points.end(); ++vit )
1346 Range tcells, tcells2, verts;
1362 other_verts.
swap( tmp_verts );
1363 if( 0 != last_v ) other_verts.
erase( last_v );
1367 tmp_verts = other_verts;
1383 std::vector< EntityHandle > adj_sets;
1388 for( std::vector< EntityHandle >::iterator vit = adj_sets.begin(); vit != adj_sets.end(); ++vit )
1401 const int dual_entity_dimension )
1403 if( 1 == dual_entity_dimension )
1405 else if( 2 == dual_entity_dimension )
1452 std::cout <<
"-AP(";
1454 std::cout <<
")" << std::endl;
1460 assert( 0 != quad1 );
1466 Range star_cells, tmp_cells;
1469 star_cells.
merge( tmp_cells );
1470 star_cells.
insert( odedge );
1476 std::vector< EntityHandle > verts;
1480 double coords[12], avg[3] = { 0.0, 0.0, 0.0 };
1482 for(
int i = 0; i < 4; i++ )
1484 avg[0] += coords[3 * i];
1485 avg[1] += coords[3 * i + 1];
1486 avg[2] += coords[3 * i + 2];
1488 for(
int i = 0; i < 3; i++ )
1492 double new_coords[12];
1493 for(
int i = 0; i < 4; i++ )
1495 new_coords[3 * i] = avg[0] + .5 * ( coords[3 * i] - avg[0] );
1496 new_coords[3 * i + 1] = avg[1] + .5 * ( coords[3 * i + 1] - avg[1] );
1497 new_coords[3 * i + 2] = avg[2] + .5 * ( coords[3 * i + 2] - avg[2] );
1501 for(
int i = 0; i < 4; i++ )
1503 verts.push_back( 0 );
1510 assert( hexes.
size() <= 2 );
1515 if( hexes.
size() == 2 )
1522 std::vector< EntityHandle > tmp_verts;
1523 std::copy( verts.begin(), verts.end(), std::back_inserter( tmp_verts ) );
1529 std::reverse( verts.begin(), verts.begin() + 4 );
1530 std::reverse( verts.begin() + 4, verts.end() );
1555 verts[1] = verts[4];
1557 if(
MB_SUCCESS != result || new_edge.
size() != 1 )
return result;
1570 std::cout <<
"-AP(";
1572 std::cout <<
")" << std::endl;
1577 assert( 2 == dverts.
size() );
1581 assert( hexes[0] != 0 && hexes[1] != 0 );
1583 std::vector< EntityHandle > dcells[4];
1586 std::copy( dverts.
begin(), dverts.
end(), std::back_inserter( dcells[0] ) );
1590 dcells[3 -
dim].resize( pcells[
dim].
size() );
1601 for(
int i = 3; i >= 0; i-- )
1608 Range del_faces, del_edges, del_verts, tmp_faces, tmp_verts;
1612 assert( 5 == del_faces.
size() );
1613 std::copy( pcells[2].begin(), pcells[2].end(),
range_inserter( tmp_faces ) );
1614 tmp_faces =
subtract( tmp_faces, del_faces );
1617 std::copy( pcells[0].begin(), pcells[0].end(),
range_inserter( del_verts ) );
1618 del_verts =
subtract( del_verts, tmp_verts );
1619 assert( 4 == del_verts.
size() );
1621 assert( 8 == del_edges.
size() );
1652 Range ents_to_delete;
1670 ents_to_delete.
insert( this_entity );
1681 else if( extra && extra != this_entity )
1684 ents_to_delete.
insert( extra );
1699 std::vector< int > ids;
1701 assert( num_connect < 20 );
1704 ids.resize( num_connect );
1707 for(
int i = 0; i < num_connect; i++ )
1709 if( !
first ) std::cout <<
"-";
1711 if( this_type ==
MBHEX )
1713 else if( this_type ==
MBQUAD )
1719 std::cout << ids[i];
1737 std::cout <<
")" << std::endl;
1740 EntityHandle split_quads[2] = { 0 }, split_edges[3] = { 0 }, split_nodes[2] = { 0 }, other_edges[6] = { 0 },
1741 other_nodes[6] = { 0 };
1743 ErrorCode result =
foc_get_ents( ocl, ocr, split_quads, split_edges, split_nodes, hexes, other_edges, other_nodes );
RR;
1746 std::vector< EntityHandle > star_dp1[2], star_dp2[2];
1747 result =
foc_get_stars( split_quads, split_edges, star_dp1, star_dp2 );
RR;
1757 other_nodes, new_quads, new_edges, new_nodes );
1762 #define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
1763 #define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
1764 #define KEEP_DELETE( a, b, c, d ) \
1766 ( c ) = MIN( a, b ); \
1767 ( d ) = MAX( a, b ); \
1771 int num_shared_edges = ( split_edges[2] ? 3 : ( split_edges[1] ? 2 : 1 ) );
1774 for(
int i = 0; i < 3 - num_shared_edges; i++ )
1776 KEEP_DELETE( other_nodes[2 + 2 * i], other_nodes[3 + 2 * i], keepit, deleteit );
1781 for(
int i = 0; i < 4 - num_shared_edges; i++ )
1783 KEEP_DELETE( other_edges[2 * i], other_edges[2 * i + 1], keepit, deleteit );
1788 KEEP_DELETE( split_quads[0], split_quads[1], keepit, deleteit );
1838 if( common_edges.
empty() )
return MB_FAILURE;
1839 for(
unsigned int i = 0; i < common_edges.
size(); i++ )
1840 split_edges[i] = common_edges[i];
1844 if( common_edges.
size() == 3 )
1847 for(
int i = 0; i < 2; i++ )
1852 tmp_edges =
subtract( tmp_edges, common_edges );
1853 assert( tmp_edges.
size() == 1 );
1854 other_edges[i] = *tmp_edges.
begin();
1856 assert( other_edges[0] && other_edges[1] && other_edges[0] != other_edges[1] );
1859 result = mtu.
opposite_entity( split_quads[0], other_edges[0], split_edges[1] );
RR;
1860 common_edges.
erase( split_edges[1] );
1861 split_edges[0] = *common_edges.
begin();
1862 split_edges[2] = *common_edges.
rbegin();
1863 common_edges.
insert( split_edges[1] );
1866 split_nodes[0] = mtu.
common_entity( split_edges[0], split_edges[1], 0 );
1867 split_nodes[1] = mtu.
common_entity( split_edges[2], split_edges[1], 0 );
1868 other_nodes[0] = mtu.
common_entity( split_edges[0], other_edges[0], 0 );
1869 other_nodes[1] = mtu.
common_entity( split_edges[2], other_edges[1], 0 );
1871 assert( other_nodes[0] && other_nodes[1] && split_nodes[0] && split_nodes[1] );
1872 assert( split_edges[0] && split_edges[1] && split_edges[2] && split_edges[0] != split_edges[1] &&
1873 split_edges[1] != split_edges[2] && split_edges[0] != split_edges[2] );
1875 else if( common_edges.
size() == 2 )
1878 split_nodes[0] = mtu.
common_entity( split_edges[0], split_edges[1], 0 );
1879 if( 0 == split_nodes[0] )
return MB_FAILURE;
1881 result = mtu.
opposite_entity( split_edges[0], split_nodes[0], other_nodes[0] );
RR;
1882 result = mtu.
opposite_entity( split_edges[1], split_nodes[0], other_nodes[1] );
RR;
1884 for(
int i = 0; i < 2; i++ )
1887 result = mtu.
opposite_entity( split_quads[i], split_edges[1], other_edges[i] );
RR;
1889 result = mtu.
opposite_entity( split_quads[i], split_edges[0], other_edges[2 + i] );
RR;
1891 result = mtu.
opposite_entity( split_quads[i], split_nodes[0], other_nodes[2 + i] );
RR;
1901 other_nodes[0] = connect[0];
1902 other_nodes[1] = connect[1];
1905 for(
int i = 0; i < 2; i++ )
1909 Range tmp_range1, tmp_range2;
1910 tmp_range1.
insert( connect[0] );
1911 tmp_range1.
insert( split_quads[i] );
1914 tmp_range2.
erase( split_edges[0] );
1915 assert( tmp_range2.
size() == 1 );
1916 other_edges[i] = *tmp_range2.
begin();
1919 result = mtu.
opposite_entity( split_quads[i], other_edges[i], other_edges[4 + i] );
RR;
1921 result = mtu.
opposite_entity( split_quads[i], split_edges[0], other_edges[2 + i] );
RR;
1924 other_nodes[2 + i] = mtu.
common_entity( other_edges[i], other_edges[2 + i], 0 );
1925 other_nodes[4 + i] = mtu.
common_entity( other_edges[4 + i], other_edges[2 + i], 0 );
1926 if( 0 == other_nodes[2 + i] || 0 == other_nodes[4 + i] )
return MB_FAILURE;
1933 assert(
"split node not in other_nodes" && other_nodes[0] != split_nodes[0] && other_nodes[0] != split_nodes[1] &&
1934 other_nodes[1] != split_nodes[0] && other_nodes[1] != split_nodes[1] );
1935 assert(
"each split node on an end of a split edge" && mtu.
common_entity( other_nodes[0], split_edges[0], 0 ) &&
1936 ( ( ( split_edges[2] && mtu.
common_entity( other_nodes[1], split_edges[2], 0 ) ) ||
1937 ( split_edges[1] && mtu.
common_entity( other_nodes[1], split_edges[1], 0 ) ) ||
1938 mtu.
common_entity( other_nodes[1], split_edges[0], 0 ) ) ) );
1939 assert(
"opposite other edges meet at an other node" &&
1940 ( mtu.
common_entity( other_edges[0], other_edges[1], 0 ) == other_nodes[0] ||
1941 ( split_edges[2] && mtu.
common_entity( other_edges[0], other_edges[1], 0 ) == other_nodes[1] ) ) &&
1943 ( split_edges[1] && mtu.
common_entity( other_edges[2], other_edges[3], 0 ) == other_nodes[1] ) ||
1944 mtu.
common_entity( other_edges[4], other_edges[5], 0 ) == other_nodes[1] ) );
1952 std::vector< EntityHandle >* star_dp1,
1953 std::vector< EntityHandle >* star_dp2,
1968 if( std::find( star_dp1[0].begin(), star_dp1[0].end(), split_quads[0] ) != star_dp1[0].end() )
1970 else if( std::find( star_dp1[1].begin(), star_dp1[1].end(), split_quads[0] ) != star_dp1[1].end() )
1972 assert( -1 != new_side );
1973 if( -1 == new_side )
return MB_FAILURE;
1977 for(
int i = 0; i < 2; i++ )
1983 for( std::vector< EntityHandle >::iterator vit = star_dp2[new_side].begin(); vit != star_dp2[new_side].end();
1992 assert( 0 != gowith_hex );
2002 Range tmp_addl_faces[2], addl_faces[2];
2003 for(
int i = 0; i < 2; i++ )
2005 std::copy( star_dp1[i].begin(), star_dp1[i].end(),
range_inserter( tmp_addl_faces[i] ) );
2006 tmp_addl_faces[new_side].
insert( new_quads[i] );
2009 bool cond1 = (
"split_quads on 1, new_quads on 0" &&
2010 tmp_addl_faces[0].
find( split_quads[0] ) == tmp_addl_faces[0].
end() &&
2011 tmp_addl_faces[0].
find( split_quads[1] ) == tmp_addl_faces[0].
end() &&
2012 tmp_addl_faces[1].
find( split_quads[0] ) != tmp_addl_faces[1].
end() &&
2013 tmp_addl_faces[1].
find( split_quads[1] ) != tmp_addl_faces[1].
end() &&
2014 tmp_addl_faces[0].
find( new_quads[0] ) != tmp_addl_faces[0].
end() &&
2015 tmp_addl_faces[0].
find( new_quads[1] ) != tmp_addl_faces[0].
end() &&
2016 tmp_addl_faces[1].
find( new_quads[0] ) == tmp_addl_faces[1].
end() &&
2017 tmp_addl_faces[1].
find( new_quads[1] ) == tmp_addl_faces[1].
end() ),
2018 cond2 = (
"split_quads on 0, new_quads on 1" &&
2019 tmp_addl_faces[0].find( split_quads[0] ) != tmp_addl_faces[0].
end() &&
2020 tmp_addl_faces[0].
find( split_quads[1] ) != tmp_addl_faces[0].
end() &&
2021 tmp_addl_faces[1].
find( split_quads[0] ) == tmp_addl_faces[1].
end() &&
2022 tmp_addl_faces[1].
find( split_quads[1] ) == tmp_addl_faces[1].
end() &&
2023 tmp_addl_faces[0].
find( new_quads[0] ) == tmp_addl_faces[0].
end() &&
2024 tmp_addl_faces[0].
find( new_quads[1] ) == tmp_addl_faces[0].
end() &&
2025 tmp_addl_faces[1].
find( new_quads[0] ) != tmp_addl_faces[1].
end() &&
2026 tmp_addl_faces[1].
find( new_quads[1] ) != tmp_addl_faces[1].
end() );
2028 assert( cond1 || cond2 );
2032 for(
int j = 0; j < 3; j++ )
2034 if( !split_edges[j] )
break;
2037 addl_faces[0] = tmp_addl_faces[0];
2038 addl_faces[1] = tmp_addl_faces[1];
2039 for(
int i = 0; i < 2; i++ )
2051 for(
int j = 0; j < 2; j++ )
2053 if( !split_nodes[j] )
break;
2057 Range tmp_addl_edges[2];
2058 result =
foc_get_addl_ents( star_dp1, star_dp2, split_edges, split_nodes[j], tmp_addl_edges );
RR;
2062 for(
int i = 0; i < 3; i++ )
2064 if( !split_edges[i] )
break;
2065 tmp_addl_edges[new_side].
insert( new_edges[i] );
2066 tmp_addl_edges[1 - new_side].
insert( split_edges[i] );
2070 for(
int i = 0; i < 2; i++ )
2072 std::copy( star_dp1[i].begin(), star_dp1[i].end(),
range_inserter( tmp_addl_edges[i] ) );
2073 std::copy( star_dp2[i].begin(), star_dp2[i].end(),
range_inserter( tmp_addl_edges[i] ) );
2077 for(
int i = 0; i < 2; i++ )
2078 tmp_addl_edges[new_side].insert( new_quads[i] );
2081 Range addl_edges[2];
2082 for(
int i = 0; i < 2; i++ )
2099 std::vector< EntityHandle >* ,
2118 for(
int i = 0; i < 2; i++ )
2123 for(
int j = 0; j < 3; j++ )
2124 if( split_edges[j] ) R3.
erase( split_edges[j] );
2125 addl_ents[i].
merge( R3 );
2133 std::vector< EntityHandle >* star_dp1,
2134 std::vector< EntityHandle >* star_dp2 )
2136 bool on_bdy =
false, on_bdy_tmp;
2141 std::vector< EntityHandle > qstar, hstar;
2142 unsigned int qpos = 0;
2144 for(
int i = 0; i < 3; i++ )
2146 if( !split_edges[i] )
break;
2149 unsigned int qpos_tmp = 0;
2150 std::vector< EntityHandle > qstar_tmp, hstar_tmp;
2151 result = mtu.
star_entities( split_edges[i], qstar_tmp, on_bdy_tmp, 0, &hstar_tmp );
RR;
2155 assert( hstar_tmp.size() == qstar_tmp.size() - 1 );
2156 hstar_tmp.push_back( 0 );
2161 while( qpos_tmp < qstar_tmp.size() && qstar_tmp[qpos_tmp] != split_quads[0] )
2163 if( qpos_tmp == qstar_tmp.size() )
return MB_FAILURE;
2167 if( 0 == i ) forward =
true;
2170 else if( hstar[qpos] == hstar_tmp[qpos_tmp] )
2172 else if( hstar[qpos] == hstar_tmp[( qpos_tmp + qstar_tmp.size() - 1 ) % qstar_tmp.size()] &&
2173 hstar_tmp[qpos_tmp] == hstar[( qpos + qstar.size() - 1 ) % qstar.size()] )
2182 star_dp2[0].push_back( hstar_tmp[qpos_tmp] );
2183 qpos_tmp = ( qpos_tmp + 1 ) % qstar_tmp.size();
2184 while( qstar_tmp[qpos_tmp] != split_quads[1] )
2186 star_dp1[0].push_back( qstar_tmp[qpos_tmp] );
2187 star_dp2[0].push_back( hstar_tmp[qpos_tmp] );
2188 qpos_tmp = ( qpos_tmp + 1 ) % qstar_tmp.size();
2192 star_dp2[1].push_back( hstar_tmp[qpos_tmp] );
2193 qpos_tmp = ( qpos_tmp + 1 ) % qstar_tmp.size();
2194 while( qstar_tmp[qpos_tmp] != split_quads[0] )
2196 star_dp1[1].push_back( qstar_tmp[qpos_tmp] );
2197 star_dp2[1].push_back( hstar_tmp[qpos_tmp] );
2198 qpos_tmp = ( qpos_tmp + 1 ) % qstar_tmp.size();
2207 qpos_tmp = ( qpos_tmp + qstar_tmp.size() - 1 ) % qstar_tmp.size();
2208 star_dp2[0].push_back( hstar_tmp[qpos_tmp] );
2209 while( qstar_tmp[qpos_tmp] != split_quads[1] )
2211 star_dp1[0].push_back( qstar_tmp[qpos_tmp] );
2212 qpos_tmp = ( qpos_tmp + qstar_tmp.size() - 1 ) % qstar_tmp.size();
2213 star_dp2[0].push_back( hstar_tmp[qpos_tmp] );
2217 qpos_tmp = ( qpos_tmp + qstar_tmp.size() - 1 ) % qstar_tmp.size();
2218 star_dp2[1].push_back( hstar_tmp[qpos_tmp] );
2219 while( qstar_tmp[qpos_tmp] != split_quads[0] )
2221 star_dp1[1].push_back( qstar_tmp[qpos_tmp] );
2222 qpos_tmp = ( qpos_tmp + qstar_tmp.size() - 1 ) % qstar_tmp.size();
2223 star_dp2[1].push_back( hstar_tmp[qpos_tmp] );
2231 qstar.swap( qstar_tmp );
2232 hstar.swap( hstar_tmp );
2233 on_bdy = on_bdy_tmp;
2241 if( std::find( star_dp2[0].begin(), star_dp2[0].end(), 0 ) != star_dp2[0].end() )
2244 star_dp2[0].erase( std::remove( star_dp2[0].begin(), star_dp2[0].end(), 0 ), star_dp2[0].end() );
2246 star_dp1[0].push_back( split_quads[0] );
2247 star_dp1[0].push_back( split_quads[1] );
2251 star_dp2[1].erase( std::remove( star_dp2[1].begin(), star_dp2[1].end(), 0 ), star_dp2[1].end() );
2253 star_dp1[1].push_back( split_quads[0] );
2254 star_dp1[1].push_back( split_quads[1] );
2259 star_dp1[1].push_back( split_quads[0] );
2260 star_dp1[1].push_back( split_quads[1] );
2264 if( !( ( ( std::find( star_dp1[0].begin(), star_dp1[0].end(), split_quads[0] ) == star_dp1[0].end() &&
2265 std::find( star_dp1[0].begin(), star_dp1[0].end(), split_quads[1] ) == star_dp1[0].end() &&
2266 std::find( star_dp1[1].begin(), star_dp1[1].end(), split_quads[0] ) != star_dp1[1].end() &&
2267 std::find( star_dp1[1].begin(), star_dp1[1].end(), split_quads[1] ) != star_dp1[1].end() ) ||
2269 ( std::find( star_dp1[1].begin(), star_dp1[1].end(), split_quads[0] ) == star_dp1[1].end() &&
2270 std::find( star_dp1[1].begin(), star_dp1[1].end(), split_quads[1] ) == star_dp1[1].end() &&
2271 std::find( star_dp1[0].begin(), star_dp1[0].end(), split_quads[0] ) != star_dp1[0].end() &&
2272 std::find( star_dp1[0].begin(), star_dp1[0].end(), split_quads[1] ) != star_dp1[0].end() ) ) ) )
2274 std::cerr <<
"foc_get_stars: both split quads should be on the same star list half and not "
2275 <<
"on the other, failed" << std::endl;
2279 if( !( std::find( star_dp2[0].begin(), star_dp2[0].end(), 0 ) == star_dp2[0].end() &&
2280 std::find( star_dp2[1].begin(), star_dp2[1].end(), 0 ) == star_dp2[1].end() ) )
2282 std::cerr <<
"foc_get_stars: no NULLs on the hstar lists, failed";
2299 assert( 0 != sheet1 && 0 != chordl && 0 != chordr );
2300 Range parentsl, parentsr;
2305 parentsl.
erase( sheet1 );
2306 parentsr.
erase( sheet1 );
2310 Range adj_ents, dual_ents, cells1or2;
2311 for(
int i = 0; i < 3; i++ )
2324 dual_ents.
insert( this_ent );
2326 if( 1 ==
dim || 2 ==
dim ) cells1or2.
insert( this_ent );
2339 sheet_delete = *parentsl.
begin();
2341 sheet_delete = *parentsr.
begin();
2351 sheet_delete = ( numl > numr ? *parentsr.
begin() : *parentsl.
begin() );
2353 assert( 0 != sheet_delete );
2361 if( tmp_ents.
empty() )
2366 else if( *rit == sheet_delete )
2383 hexes.
merge( tmp_hexes );
2406 if( 0 == dual_ent )
continue;
2419 std::vector< EntityHandle > chord_edges;
2424 std::vector< EntityHandle >::iterator vit = std::find( chord_edges.begin(), chord_edges.end(), middle_edge );
2429 vit == chord_edges.end() ||
2431 chord_edges.size() == 1 ||
2433 ( ( vit == chord_edges.begin() || vit == chord_edges.end() - 1 ) && !
is_blind( chord ) ) )
2436 else if( chord_edges.size() == 2 )
2439 verts[0] = connect[1];
2440 verts[1] = connect[0];
2445 if( vit == chord_edges.begin() )
2446 vit = chord_edges.end() - 1;
2449 Range dum_connect, middle_connect;
2452 dum_connect =
subtract( dum_connect, middle_connect );
2453 if( dum_connect.
size() != 1 )
2455 std::cerr <<
"Trouble traversing chord." << std::endl;
2460 verts[0] = *dum_connect.
begin();
2464 if( vit == chord_edges.end() ) vit = chord_edges.begin();
2466 dum_connect.
clear();
2468 dum_connect =
subtract( dum_connect, middle_connect );
2469 if( dum_connect.
size() != 1 )
2471 std::cerr <<
"Trouble traversing chord." << std::endl;
2476 verts[1] = *dum_connect.
begin();
2483 verts[0] = verts[1];
2489 std::cerr <<
"Trouble traversing chord." << std::endl;
2501 Range* dedges_loop )
2505 if( NULL != dcells )
2511 if( NULL != dedges )
2513 if( NULL != dcells )
2521 if( NULL != dverts )
2523 if( NULL != dcells )
2525 else if( NULL != dedges )
2537 if( NULL != dverts_loop && NULL != dverts )
2539 static std::vector< EntityHandle > dual_ents;
2540 dual_ents.resize( dverts->
size() );
2545 for( rit = dverts->
begin(), i = 0; rit != dverts->
end(); ++rit, i++ )
2549 if( NULL != dedges_loop && NULL != dedges )
2551 static std::vector< EntityHandle > dual_ents;
2552 dual_ents.resize( dedges->
size() );
2557 for( rit = dedges->
begin(), i = 0; rit != dedges->
end(); ++rit, i++ )
2568 if( NULL ==
entities && 0 == num_entities )
2571 else if( NULL ==
entities && 0 < num_entities )
2575 std::cout << std::endl;
2619 if( 0 != chord ) std::cout <<
"(Dual chord " <<
id <<
")" << std::endl;
2620 if( 0 != sheet ) std::cout <<
"(Dual sheet " <<
id <<
")" << std::endl;
2624 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
2639 std::cout <<
")" << std::endl;
2642 std::vector< EntityHandle > connects[4], side_quads[2];
2659 Range adj_verts, adj_edges, dual_ents, cells1or2;
2665 for(
int i = 1; i <= 3; i++ )
2681 dual_ents.
insert( odedge );
2691 if( tmp_ents.
empty() )
2700 for(
int i = 0; i < 4; i++ )
2702 for(
int j = 0; j < 2; j++ )
2710 double q2coords[12], avg[3] = { 0.0, 0.0, 0.0 };
2713 for(
int i = 0; i < 4; i++ )
2715 avg[0] += q2coords[3 * i];
2716 avg[1] += q2coords[3 * i + 1];
2717 avg[2] += q2coords[3 * i + 2];
2723 connects[3].resize( 4 );
2724 for(
int i = 0; i < 4; i++ )
2726 q2coords[3 * i] = avg[0] + .25 * ( q2coords[3 * i] - avg[0] );
2727 q2coords[3 * i + 1] = avg[1] + .25 * ( q2coords[3 * i + 1] - avg[1] );
2728 q2coords[3 * i + 2] = avg[2] + .25 * ( q2coords[3 * i + 2] - avg[2] );
2737 for(
int i = 0; i < 4; i++ )
2739 int i1 = i, i2 = ( i + 1 ) % 4;
2740 hconnect[0] = connects[0][i1];
2741 hconnect[1] = connects[0][i2];
2742 hconnect[2] = connects[3][i2];
2743 hconnect[3] = connects[3][i1];
2745 hconnect[4] = connects[1][i1];
2746 hconnect[5] = connects[1][i2];
2747 hconnect[6] = connects[2][i2];
2748 hconnect[7] = connects[2][i1];
2755 for(
int j = 0; j < 2; j++ )
2782 for(
int i = 0; i < 4; i++ )
2784 hconnect[i] = connects[3][i];
2785 hconnect[4 + i] = connects[2][i];
2790 for(
int i = 0; i < 4; i++ )
2792 hconnect[i] = connects[0][i];
2793 hconnect[4 + i] = connects[3][i];
2822 std::vector< EntityHandle >* connects,
2823 std::vector< EntityHandle >* side_quads )
2825 for(
int i = 0; i < 4; i++ )
2827 for(
int j = 0; j < 2; j++ )
2829 Range adj_ents, dum_quads;
2830 adj_ents.
insert( hexes[j] );
2831 adj_ents.
insert( connects[j][i] );
2832 adj_ents.
insert( connects[j][( i + 1 ) % 4] );
2833 adj_ents.
insert( connects[j + 1][i] );
2834 adj_ents.
insert( connects[j + 1][( i + 1 ) % 4] );
2838 assert( 1 == dum_quads.
size() );
2839 side_quads[j].push_back( *dum_quads.
begin() );
2850 int dum1, dum2, sense = 0;
2853 assert( 0 != sense );
2858 connects[0][0] = connects[0][2];
2859 connects[0][2] =
dum;
2863 int index0 = -1, index2 = -1, sense0 = 0, sense2 = 0;
2865 for(
int i = 0; i < 4; i++ )
2867 if( 0 != mtu.
common_entity( connects[0][0], connects[1][i], 1 ) )
2870 if( 0 != mtu.
common_entity( connects[0][1], connects[1][( i + 1 ) % 4], 1 ) )
2872 else if( 0 != mtu.
common_entity( connects[0][1], connects[1][( i + 4 - 1 ) % 4], 1 ) )
2878 assert( index0 != -1 && sense0 != 0 );
2883 connects[1][0] = connects[1][2];
2884 connects[1][2] = dumh;
2885 if( index0 % 2 == 0 ) index0 = ( index0 + 2 ) % 4;
2890 std::vector< EntityHandle > tmpc;
2891 for(
int i = 0; i < 4; i++ )
2892 tmpc.push_back( connects[1][( index0 + i ) % 4] );
2893 connects[1].swap( tmpc );
2896 for(
int i = 0; i < 4; i++ )
2898 if( 0 != mtu.
common_entity( connects[1][0], connects[2][i], 1 ) )
2901 if( 0 != mtu.
common_entity( connects[1][1], connects[2][( i + 1 ) % 4], 1 ) )
2903 else if( 0 != mtu.
common_entity( connects[1][1], connects[2][( i + 4 - 1 ) % 4], 1 ) )
2909 assert( index2 != -1 && sense2 != 0 );
2914 connects[2][0] = connects[2][2];
2915 connects[2][2] = dumh;
2916 if( index2 % 2 == 0 ) index2 = ( index2 + 2 ) % 4;
2921 std::vector< EntityHandle > tmpc;
2922 for(
int i = 0; i < 4; i++ )
2923 tmpc.push_back( connects[2][( index2 + i ) % 4] );
2924 connects[2].swap( tmpc );
2938 std::cout <<
"-FS(";
2940 std::cout <<
")" << std::endl;
2943 std::vector< EntityHandle > connects[4], side_quads[2];
2958 std::cout <<
"Can't do -FS here, two hexes must be adjacent to ring of 4 hexes." << std::endl;
2962 Range adj_ents, outer_hexes, all_adjs;
2965 for(
int i = 1; i <= 3; i++ )
2973 for(
int i = 0; i < 3; i++ )
2980 Range dual_ents, dual_hps;
2984 dual_ents.
insert( this_ent );
3003 if( tmp_ents.
empty() )
3013 bool need_explicit =
false;
3021 need_explicit =
true;
3031 std::vector< EntityHandle > new_connect;
3032 std::copy( connects[3].begin(), connects[3].end(), std::back_inserter( new_connect ) );
3033 std::copy( connects[2].begin(), connects[2].end(), std::back_inserter( new_connect ) );
3037 new_connect.clear();
3038 std::copy( connects[0].begin(), connects[0].end(), std::back_inserter( new_connect ) );
3039 std::copy( connects[3].begin(), connects[3].end(), std::back_inserter( new_connect ) );
3046 for(
int j = 0; j < 2; j++ )
3048 for(
int i = 0; i < 4; i++ )
3059 adj_ents.
erase( hexes[0] );
3060 adj_ents.
erase( hexes[1] );
3083 std::vector< EntityHandle >* side_quads )
3090 for(
int i = 0; i < 4; i++ )
3092 Range start_verts, tmp_verts, quads;
3093 for(
int j = 0; j < 3; j++ )
3094 start_verts.
insert( connects[j][i] );
3097 assert( quads.
size() == 1 );
3099 tmp_verts =
subtract( tmp_verts, start_verts );
3100 assert( 1 == tmp_verts.
size() );
3101 connects[3].push_back( *tmp_verts.
begin() );
3105 for(
int i = 0; i < 4; i++ )
3107 Range dum_ents, hexes;
3108 dum_ents.
insert( connects[1][i] );
3109 dum_ents.
insert( connects[1][( i + 1 ) % 4] );
3110 dum_ents.
insert( connects[3][i] );
3113 assert( 1 == hexes.
size() );
3115 hexes.
insert( connects[0][i] );
3116 hexes.
insert( connects[0][( i + 1 ) % 4] );
3117 hexes.
insert( connects[3][i] );
3118 hexes.
insert( connects[3][( i + 1 ) % 4] );
3122 assert( dum_ents.
size() == 1 );
3123 side_quads[0].push_back( *dum_ents.
begin() );
3125 hexes.
erase( connects[0][i] );
3126 hexes.
erase( connects[0][( i + 1 ) % 4] );
3127 hexes.
insert( connects[2][i] );
3128 hexes.
insert( connects[2][( i + 1 ) % 4] );
3132 side_quads[1].push_back( *dum_ents.
begin() );
3141 std::vector< EntityHandle >* connects )
3145 if( 0 == chord )
return MB_FAILURE;
3147 std::vector< EntityHandle > edges;
3149 if( MB_FAILURE == result )
return result;
3151 std::vector< EntityHandle >::iterator vit = std::find( edges.begin(), edges.end(), odedge );
3153 if( vit == edges.end() || *edges.begin() == *vit || *edges.rbegin() == *vit )
return MB_FAILURE;
3159 for(
int i = 0; i < 3; i++ )
3168 assert( tmph.
size() == 1 );
3169 hexes[0] = *tmph.
begin();
3174 assert( tmph.
size() == 1 );
3175 hexes[1] = *tmph.
begin();
3183 Range dual_surfs, dual_curves;
3202 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
3243 for(
int i = 2; i >= 0; i-- )
3249 #define PRENT( ent ) CN::EntityTypeName( TYPE_FROM_HANDLE( ent ) ) << " " << ID_FROM_HANDLE( ent )
3251 for(
int pd = 1; pd <= 3; pd++ )
3257 if( 0 == dual_ent ) std::cerr <<
"Problem getting dual entity for " <<
PRENT( *prit ) << std::endl;
3260 for(
int sd = 0; sd < pd; sd++ )
3271 std::cerr <<
PRENT( *prit ) <<
": number of adj ents in "
3272 <<
"primal/dual don't agree for dimension " << sd <<
"." << std::endl;
3273 overall_result = MB_FAILURE;
3280 if( R2.
find( tmp_dual ) == R2.
end() )
3282 std::cerr <<
PRENT( *prit ) <<
": adj entity " <<
PRENT( *r1it ) <<
" isn't adjacent in dual."
3284 overall_result = MB_FAILURE;
3291 if( R1.
find( tmp_prim ) == R1.
end() )
3293 std::cerr <<
PRENT( *prit ) <<
": adj entity " <<
PRENT( *r2it ) <<
" isn't adjacent in primal."
3295 overall_result = MB_FAILURE;
3302 return overall_result;