76 const Tag* file_id_tag )
78 int num_material_sets = 0;
79 const int* material_set_list = 0;
95 std::set< int > blocks;
96 for(
const int* mat_set_end = material_set_list + num_material_sets; material_set_list != mat_set_end;
98 blocks.insert( *material_set_list );
101 std::map< long, EntityHandle > node_id_map;
105 FILE* file_ptr = fopen( filename,
"r" );
113 const char*
const start_tokens[] = {
"$NOD",
"$MeshFormat", 0 };
114 int format_version = tokens.
match_token( start_tokens );
118 if( 2 == format_version )
123 if( version != 2.0 && version != 2.1 && version != 2.2 )
134 const char*
const phys_tokens[] = {
"$Nodes",
"$PhysicalNames", 0 };
141 for(
long loop_phys = 0; loop_phys < num_phys; loop_phys++ )
165 std::vector< double* > coord_arrays;
171 double *x = coord_arrays[0], *y = coord_arrays[1], *z = coord_arrays[2];
172 for(
long i = 0; i < num_nodes; ++i, ++handle )
179 if( !node_id_map.insert( std::pair< long, EntityHandle >(
id, handle ) ).second )
186 std::vector< int > ids( num_nodes );
187 std::vector< int >::iterator id_iter = ids.begin();
188 std::vector< EntityHandle > handles( num_nodes );
189 std::vector< EntityHandle >::iterator h_iter = handles.begin();
190 for( std::map< long, EntityHandle >::iterator i = node_id_map.begin(); i != node_id_map.end();
191 ++i, ++id_iter, ++h_iter )
208 if( !tokens.
match_token( format_version == 1 ?
"$ENDNOD" :
"$EndNodes" ) ||
209 !tokens.
match_token( format_version == 1 ?
"$ELM" :
"$Elements" ) )
217 std::vector< EntityHandle > connectivity;
218 std::vector< int > mat_set_list, geom_set_list, part_set_list, id_list;
220 std::vector< int > int_data( 5 ), tag_data( 2 );
221 std::vector< long > tmp_conn;
222 int curr_elem_type = -1;
223 for(
long i = 0; i < num_elem; ++i )
227 if( 1 == format_version )
230 tag_data[0] = int_data[2];
231 tag_data[1] = int_data[3];
236 "Invalid node count for element type at line " << tokens.
line_number() );
243 tag_data.resize( int_data[2] );
251 if( !blocks.empty() && ( tag_data.empty() || blocks.find( tag_data[0] ) != blocks.end() ) )
continue;
257 if( int_data[1] != curr_elem_type )
259 if( !id_list.empty() )
262 part_set_list, connectivity, file_id_tag );
267 mat_set_list.clear();
268 geom_set_list.clear();
269 part_set_list.clear();
270 connectivity.clear();
271 curr_elem_type = int_data[1];
276 "Unsupported element type " << curr_elem_type <<
" at line " << tokens.
line_number() );
282 id_list.push_back( int_data[0] );
283 if( tag_data.size() > 3 )
284 part_set_list.push_back( tag_data[3] );
286 else if( tag_data.size() > 2 )
287 part_set_list.push_back( tag_data[2] );
289 part_set_list.push_back( 0 );
290 geom_set_list.push_back( tag_data.size() > 1 ? tag_data[1] : 0 );
291 mat_set_list.push_back( tag_data.size() > 0 ? tag_data[0] : 0 );
297 for(
unsigned j = 0; j < tmp_conn.size(); ++j )
299 std::map< long, EntityHandle >::iterator k = node_id_map.find( tmp_conn[j] );
300 if( k == node_id_map.end() )
304 connectivity.push_back( k->second );
309 if( !id_list.empty() )
312 part_set_list, connectivity, file_id_tag );
326 const std::vector< int >& elem_ids,
327 const std::vector< int >& matl_ids,
328 const std::vector< int >& geom_ids,
329 const std::vector< int >& prtn_ids,
330 const std::vector< EntityHandle >& connectivity,
331 const Tag* file_id_tag )
336 const unsigned long num_elem = elem_ids.size();
337 const int node_per_elem = type.
num_nodes;
338 if( matl_ids.size() != num_elem || geom_ids.size() != num_elem || prtn_ids.size() != num_elem ||
339 connectivity.size() != num_elem * node_per_elem )
347 elements.
insert< std::vector< EntityHandle > >( connectivity.begin(), connectivity.end() );
362 for(
unsigned long i = 0; i < num_elem; ++i )
363 for(
int j = 0; j < node_per_elem; ++j )
364 conn_array[i * node_per_elem + type.
node_order[j]] = connectivity[i * node_per_elem + j];
368 memcpy( conn_array, &connectivity[0], connectivity.size() *
sizeof(
EntityHandle ) );
376 Range elements( handle, handle + num_elem - 1 );
400 const Range& elements,
401 const std::vector< int >& set_ids,
408 for( std::vector< int >::const_iterator i = set_ids.begin(); i != set_ids.end(); ++i )
412 if( ids.empty() || ( ids.size() == 1 && *ids.begin() == 0 ) )
return MB_SUCCESS;
418 const void* tag_values[2] = { &tag_val, NULL };
436 tag_values[1] = NULL;
444 for( std::set< int >::iterator i = ids.begin(); i != ids.end(); ++i )
447 if( *i == 0 )
continue;
451 std::vector< int >::const_iterator j = set_ids.begin();
453 if( *i == *j )
entities.insert( *k );