17 #pragma warning( disable : 4786 )
31 #include <sys/types.h>
54 if( 0 == stat( file_name, &s ) )
58 else if( errno == ENOENT )
74 if( !ent_sets || num_sets == 0 )
80 for(
int i = 0; i < num_sets; i++ )
94 const int start_node_id,
95 std::vector< double* >& arrays )
99 if( num_arrays < 1 || num_arrays > 3 )
return MB_FAILURE;
110 arrays.resize( num_arrays, NULL );
115 int tmp_num_arrays = 0;
116 for(
unsigned int i = 0; i < 3; i++ )
117 if( i + 1 <= arrays.size() && NULL != arrays[i] ) tmp_num_arrays++;
118 if( 0 == tmp_num_arrays )
return MB_FAILURE;
122 num_arrays < 2 || arrays.size() < 2 ? NULL : arrays[1],
123 num_arrays < 3 || arrays.size() < 3 ? NULL : arrays[2] );
125 if( 0 == node_id_tag ||
MB_SUCCESS != result )
return result;
128 std::vector< int > ids( num_nodes );
129 int node_id = start_node_id;
130 for(
int i = 0; i < num_nodes; i++ )
140 const size_t output_array_len,
141 double*
const output_array )
145 if( which_array < -1 || which_array > 2 )
return MB_FAILURE;
148 if( iter == end )
return MB_FAILURE;
151 if( NULL == output_array || 0 == output_array_len )
return MB_FAILURE;
159 double* output_iter = output_array;
160 double*
const output_end = output_array + output_array_len;
164 while( seq_iter != seq_end && ( *seq_iter )->end_handle() < *iter )
166 if( seq_iter == seq_end || *iter < ( *seq_iter )->start_handle() )
return MB_FAILURE;
173 EntityHandle sequence_end = ( *seq_iter )->end_handle();
174 EntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
175 if( end_handle > *prev ) end_handle = *prev;
179 assert( *iter >= ( *seq_iter )->start_handle() );
180 EntityHandle offset = *iter - ( *seq_iter )->start_handle();
183 double* coord_array[3];
188 if( -1 != which_array )
190 if( output_iter + count > output_end )
return MB_FAILURE;
191 memcpy( output_iter, coord_array[which_array] + offset, count *
sizeof(
double ) );
192 output_iter += count;
196 if( output_iter + 3 * count > output_end )
return MB_FAILURE;
197 for(
unsigned int i = 0; i < count; i++ )
199 *output_iter = coord_array[0][i + offset];
201 *output_iter = coord_array[1][i + offset];
203 *output_iter = coord_array[2][i + offset];
216 const int verts_per_element,
218 const Range& elements,
220 int start_element_id,
225 if( num_elements < 1 )
return MB_FAILURE;
226 if( verts_per_element < 1 )
return MB_FAILURE;
227 if( elements.
empty() )
return MB_FAILURE;
228 if( !element_array )
return MB_FAILURE;
241 ++seq_iter_lookahead;
242 for( ; seq_iter_lookahead != seq_iter_end && ( *seq_iter_lookahead )->start_handle() < *range_iter; )
245 ++seq_iter_lookahead;
252 for( ; range_iter != range_iter_end && seq_iter != seq_iter_end; )
255 for( ; range_iter_lookahead != range_iter_end && *range_iter_lookahead <= ( *seq_iter )->end_handle();
256 ++range_iter_lookahead )
268 ++seq_iter_lookahead2;
269 for( ; seq_iter_lookahead2 != seq_iter_end && ( *seq_iter_lookahead2 )->start_handle() < *range_iter; )
272 ++seq_iter_lookahead2;
281 EntityHandle start_handle = ( *seq_iter )->start_handle();
289 if( add_sizes ) *element_array++ = i;
292 for(
int j = 0; j < i; j++ )
294 EntityHandle node = *( conn_array + j + i * ( *tmp_iter - start_handle ) );
303 range_iter = range_iter_lookahead;
311 const int vertices_per_elem,
313 const size_t elem_array_size,
314 int*
const element_array,
318 if( iter == end )
return MB_FAILURE;
319 if( vertices_per_elem < 1 )
return MB_FAILURE;
320 if( !element_array || elem_array_size < (
unsigned)vertices_per_elem )
return MB_FAILURE;
327 int* output_iter = element_array;
328 int*
const output_end = element_array + elem_array_size;
334 if( type != current_type )
343 while( seq_iter != seq_end && ( *seq_iter )->end_handle() < *iter )
345 if( seq_iter == seq_end || *iter < ( *seq_iter )->start_handle() )
return MB_FAILURE;
357 EntityHandle sequence_end = ( *seq_iter )->end_handle();
358 EntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
359 if( end_handle > *prev ) end_handle = *prev;
363 assert( *iter >= ( *seq_iter )->start_handle() );
364 EntityHandle offset = *iter - ( *seq_iter )->start_handle();
367 if( ( !add_sizes && output_iter + ( count * conn_size ) > output_end ) ||
368 ( add_sizes && output_iter + ( count * ( conn_size + 1 ) ) > output_end ) )
372 conn_array += ( conn_size * offset );
373 if( vertices_per_elem == conn_size && !add_sizes )
378 output_iter += count * conn_size;
383 int min = vertices_per_elem > conn_size ? conn_size : vertices_per_elem;
386 *output_iter++ = min;
391 conn_array += conn_size;
393 if( vertices_per_elem > conn_size )
395 memset( output_iter, 0,
sizeof(
int ) * ( vertices_per_elem - conn_size ) );
396 output_iter += ( vertices_per_elem - conn_size );
409 const int vertices_per_elem,
410 const size_t elem_array_size,
414 if( iter == end )
return MB_FAILURE;
415 if( vertices_per_elem < 1 )
return MB_FAILURE;
416 if( !element_array || elem_array_size < (
unsigned)vertices_per_elem )
return MB_FAILURE;
424 EntityHandle*
const output_end = element_array + elem_array_size;
430 if( type != current_type )
439 while( seq_iter != seq_end && ( *seq_iter )->end_handle() < *iter )
441 if( seq_iter == seq_end || *iter < ( *seq_iter )->start_handle() )
return MB_FAILURE;
446 if( conn_size != vertices_per_elem )
return MB_FAILURE;
454 EntityHandle sequence_end = ( *seq_iter )->end_handle();
455 EntityHandle end_handle = range_end > sequence_end ? sequence_end : range_end;
456 if( end_handle > *prev ) end_handle = *prev;
460 assert( *iter >= ( *seq_iter )->start_handle() );
461 EntityHandle offset = *iter - ( *seq_iter )->start_handle();
464 if( output_iter + ( count * conn_size ) > output_end )
return MB_FAILURE;
466 if( conn_array == NULL )
469 int temp_buff_size = conn_size *
sizeof(
EntityHandle );
470 for(
unsigned i = 0; i < count; i++ )
472 std::vector< EntityHandle > connect;
478 memcpy( output_iter, &connect[0], temp_buff_size );
479 output_iter += conn_size;
486 conn_array += ( conn_size * offset );
487 memcpy( output_iter, conn_array, count * conn_size *
sizeof(
EntityHandle ) );
488 output_iter += count * conn_size;
517 bool printed_warning =
false;
525 Tag exporting_nodes_tag = 0;
526 if( node_bit_mark_tag )
527 exporting_nodes_tag = node_bit_mark_tag;
536 std::vector< EntityHandle > tmp_conn;
543 if( !printed_warning )
545 std::cerr <<
"Warning: ignoring invalid element handle(s) in gather_nodes_from_elements" << std::endl;
546 printed_warning =
true;
571 if( node < lower_bound ) lower_bound = node;
572 if( node > upper_bound ) upper_bound = node;
573 unsigned char bit = 0x1;
591 for(
int j = 0; j < num_face; j++ )
594 int face_num_conn = 0;
597 for(
int k = 0; k < face_num_conn; k++ )
600 if( node < lower_bound ) lower_bound = node;
601 if( node > upper_bound ) upper_bound = node;
602 unsigned char bit = 0x1;
619 if( node_bit_mark_tag == 0 )
mMB->
tag_delete( exporting_nodes_tag );
624 for(
size_t j = 0; j < tmp_conn.size(); j++ )
627 if( node < lower_bound ) lower_bound = node;
628 if( node > upper_bound ) upper_bound = node;
629 unsigned char bit = 0x1;
637 assert( lower_bound != 0 );
639 for( ; upper_bound >= lower_bound; --upper_bound )
641 unsigned char node_marked = 0;
642 mMB->
tag_get_data( exporting_nodes_tag, &upper_bound, 1, &node_marked );
643 if( node_marked == 0x1 ) nodes.
insert( upper_bound );
647 if( node_bit_mark_tag == 0 )
mMB->
tag_delete( exporting_nodes_tag );
668 for( i = start_id, rit = elements.
begin(); rit != elements.
end(); ++rit, i++ )
671 if(
MB_SUCCESS != tmp_result ) result = tmp_result;
692 adj.resize( num_adj );
696 for(
const EntityHandle* iter = adj_array; iter != end; ++iter )
715 const Tag* user_tag_list,
716 int user_tag_list_length,
717 bool include_variable_length_tags )
724 result_list.reserve( user_tag_list_length );
725 for(
int i = 0; i < user_tag_list_length; ++i )
728 rval =
mMB->
tag_get_name( user_tag_list[i], name );
MB_CHK_SET_ERR( rval,
"Error " << (
int)rval <<
" getting name for tag (Invalid input tag handle?)" );
736 if( !include_variable_length_tags &&
742 result_list.push_back( user_tag_list[i] );
747 std::vector< Tag > temp_list;
751 result_list.reserve( temp_list.size() );
753 std::vector< Tag >::iterator i;
754 for( i = temp_list.begin(); i != temp_list.end(); ++i )
760 if( name.empty() )
continue;
763 if( name.size() >= 2 && name[0] ==
'_' && name[1] ==
'_' )
continue;
769 result_list.push_back( *i );
781 unsigned char* flags )
818 *flags = (
unsigned char)set->
flags();
827 const bool topological = ( relation ==
TOPOLOGICAL );
854 if( MB_FAILURE == rval )
865 unsigned char* flags )
870 for(
int i = 0; i < num_entities; i++ )
904 *flags = (
unsigned char)set->
flags();
911 const bool topological = ( relation ==
TOPOLOGICAL );