20 #pragma warning( disable : 4786 )
45 #define INS_ID( stringvar, prefix, id ) sprintf( stringvar, prefix, id )
59 : mbImpl( impl ), writeTool( 0 ), mStrict(
DEFAULT_STRICT ), freeNodes( 0 ), createOneNodeCells( false )
61 assert( impl != NULL );
75 const std::vector< std::string >& ,
97 rval =
gather_mesh( output_list, num_sets, nodes, elems );
108 std::ofstream file( file_name );
113 file.precision( precision );
134 if( !set_list || !num_sets )
144 nodes.
merge( node_i, elem_i );
145 elems.
merge( elem_i, set_i );
154 elems.
erase( eit, ep1it );
159 std::set< EntityHandle > visited;
160 std::vector< EntityHandle > sets;
161 sets.reserve( num_sets );
162 std::copy( set_list, set_list + num_sets, std::back_inserter( sets ) );
163 while( !sets.empty() )
169 if( !visited.insert( set ).second )
continue;
179 nodes.
merge( node_i, elem_i );
180 elems.
merge( elem_i, set_i );
181 std::copy( set_i, a.
end(), std::back_inserter( sets ) );
185 std::copy( a.
begin(), a.
end(), std::back_inserter( sets ) );
190 std::vector< EntityHandle > connect;
194 for(
unsigned int i = 0; i < connect.size(); ++i )
195 nodes.
insert( connect[i] );
209 stream <<
"# vtk DataFile Version 3.0" << std::endl;
211 stream <<
"ASCII" << std::endl;
212 stream <<
"DATASET UNSTRUCTURED_GRID" << std::endl;
220 stream <<
"POINTS " << nodes.
size() <<
" double" << std::endl;
225 coords[1] = coords[2] = 0.0;
228 stream << coords[0] <<
' ' << coords[1] <<
' ' << coords[2] << std::endl;
242 Range faces_from_connectivity =
243 subtract( connectivity, nodes_from_connectivity );
245 Range connected_nodes;
247 connected_nodes.
merge( nodes_from_connectivity );
252 unsigned long num_elems, num_uses;
253 num_elems = num_uses = elems.
size();
255 std::map< EntityHandle, int > sizeFieldsPolyhedra;
266 std::vector< EntityHandle > storage;
269 num_uses += conn_len;
274 for(
int j = 0; j < conn_len; j++ )
279 numFields += num_nd + 1;
281 sizeFieldsPolyhedra[elem] = numFields;
282 num_uses += ( numFields - conn_len );
287 stream <<
"CELLS " << num_elems +
freeNodes <<
' ' << num_uses + 2 *
freeNodes << std::endl;
290 std::vector< int > conn_data;
291 std::vector< unsigned > vtk_types( elems.
size() +
freeNodes );
292 std::vector< unsigned >::iterator
t = vtk_types.begin();
303 std::vector< EntityHandle > storage;
316 MB_SET_ERR( MB_FAILURE,
"Vtk file format does not support elements of type "
329 assert( conn_len > 0 );
330 conn_data.resize( conn_len );
331 for(
int j = 0; j < conn_len; ++j )
332 conn_data[j] = nodes.
index( connect[j] );
337 for(
int k = 0; k < conn_len; ++k )
338 stream <<
' ' << conn_data[vtk_type->
node_order[k]];
340 for(
int k = 0; k < conn_len; ++k )
341 stream <<
' ' << conn_data[k];
347 stream << sizeFieldsPolyhedra[elem] <<
" " << conn_len;
348 for(
int k = 0; k < conn_len; k++ )
355 conn_data.resize( num_nodes );
356 for(
int j = 0; j < num_nodes; ++j )
357 conn_data[j] = nodes.
index( conn[j] );
359 stream <<
' ' << num_nodes;
361 for(
int j = 0; j < num_nodes; ++j )
362 stream <<
' ' << conn_data[j];
372 stream <<
"1 " << nodes.
index( node ) << std::endl;
377 stream <<
"CELL_TYPES " << vtk_types.size() << std::endl;
378 for( std::vector< unsigned >::const_iterator i = vtk_types.begin(); i != vtk_types.end(); ++i )
379 stream << *i << std::endl;
399 EntityType low_type, high_type;
412 std::vector< Tag > tags;
413 std::vector< Tag >::iterator i;
418 bool entities_have_tags =
false;
419 for( i = tags.begin(); i != tags.end(); ++i )
434 if( count < 1 || ( count > 4 && count != 9 ) )
continue;
439 for( EntityType type = low_type; type < high_type; ++type )
445 tagged.
merge( tmp_tagged );
449 if( !tagged.
empty() )
454 if( !entities_have_tags )
456 entities_have_tags =
true;
458 stream <<
"POINT_DATA " <<
entities.size() << std::endl;
472 template <
typename T >
475 typename std::vector< T >::const_iterator d = data.begin();
476 const unsigned long n = data.size() / vals_per_tag;
478 for(
unsigned long i = 0; i < n; ++i )
480 for(
unsigned j = 0; j < vals_per_tag; ++j, ++d )
482 if(
sizeof(
T ) == 1 )
483 stream << (
unsigned int)*d <<
' ';
506 template <
typename T >
510 int addFreeNodes = 0;
515 const unsigned long n =
entities.size() + addFreeNodes;
527 std::vector< T > data;
528 data.resize( n * vals_per_tag, 0 );
530 std::vector< T > def_value( vals_per_tag );
535 typename std::vector< T >::iterator d = data.begin();
555 const unsigned long n =
entities.size();
564 if( vals_per_tag > 8 )
566 MB_SET_ERR( MB_FAILURE,
"Invalid tag size for bit tag \"" << name <<
"\"" );
574 std::vector< unsigned short > data;
575 data.resize( n * vals_per_tag, 0 );
577 std::vector< unsigned short >::iterator d = data.begin();
585 for(
int j = 0; j < vals_per_tag; ++j, ++d )
586 *d = (
unsigned short)( value & ( 1 << j ) ? 1 : 0 );
617 for( std::string::iterator i = name.begin(); i != name.end(); ++i )
619 if( isspace( *i ) || iscntrl( *i ) ) *i =
'_';
625 else if( 9 == vals_per_tag )
629 <<
"LOOKUP_TABLE default" << std::endl;
635 return write_tag< unsigned char >( s, tag,
entities, tagged, 0 );
637 return write_tag< int >( s, tag,
entities, tagged, 0 );
639 return write_tag< double >( s, tag,
entities, tagged, 0 );