20 #pragma warning( disable : 4786 )
57 : mbImpl( impl ), writeTool( 0 ), mStrict(
DEFAULT_STRICT ), freeNodes( 0 ), createOneNodeCells( false )
59 assert( impl != NULL );
73 const std::vector< std::string >& ,
95 rval =
gather_mesh( output_list, num_sets, nodes, elems );
106 std::ofstream file( file_name );
111 file.precision( precision );
132 if( !set_list || !num_sets )
142 nodes.
merge( node_i, elem_i );
143 elems.
merge( elem_i, set_i );
152 elems.
erase( eit, ep1it );
157 std::set< EntityHandle > visited;
158 std::vector< EntityHandle > sets;
159 sets.reserve( num_sets );
160 std::copy( set_list, set_list + num_sets, std::back_inserter( sets ) );
161 while( !sets.empty() )
167 if( !visited.insert( set ).second )
continue;
177 nodes.
merge( node_i, elem_i );
178 elems.
merge( elem_i, set_i );
179 std::copy( set_i, a.
end(), std::back_inserter( sets ) );
183 std::copy( a.
begin(), a.
end(), std::back_inserter( sets ) );
188 std::vector< EntityHandle > connect;
192 for(
unsigned int i = 0; i < connect.size(); ++i )
193 nodes.
insert( connect[i] );
207 stream <<
"# vtk DataFile Version 3.0" << std::endl;
209 stream <<
"ASCII" << std::endl;
210 stream <<
"DATASET UNSTRUCTURED_GRID" << std::endl;
218 stream <<
"POINTS " << nodes.
size() <<
" double" << std::endl;
223 coords[1] = coords[2] = 0.0;
226 stream << coords[0] <<
' ' << coords[1] <<
' ' << coords[2] << std::endl;
240 Range faces_from_connectivity =
241 subtract( connectivity, nodes_from_connectivity );
243 Range connected_nodes;
245 connected_nodes.
merge( nodes_from_connectivity );
250 unsigned long num_elems, num_uses;
251 num_elems = num_uses = elems.
size();
253 std::map< EntityHandle, int > sizeFieldsPolyhedra;
264 std::vector< EntityHandle > storage;
267 num_uses += conn_len;
272 for(
int j = 0; j < conn_len; j++ )
277 numFields += num_nd + 1;
279 sizeFieldsPolyhedra[elem] = numFields;
280 num_uses += ( numFields - conn_len );
285 stream <<
"CELLS " << num_elems +
freeNodes <<
' ' << num_uses + 2 *
freeNodes << std::endl;
288 std::vector< int > conn_data;
289 std::vector< unsigned > vtk_types( elems.
size() +
freeNodes );
290 std::vector< unsigned >::iterator t = vtk_types.begin();
301 std::vector< EntityHandle > storage;
314 MB_SET_ERR( MB_FAILURE,
"Vtk file format does not support elements of type "
327 assert( conn_len > 0 );
328 conn_data.resize( conn_len );
329 for(
int j = 0; j < conn_len; ++j )
330 conn_data[j] = nodes.
index( connect[j] );
335 for(
int k = 0; k < conn_len; ++k )
336 stream <<
' ' << conn_data[vtk_type->
node_order[k]];
338 for(
int k = 0; k < conn_len; ++k )
339 stream <<
' ' << conn_data[k];
345 stream << sizeFieldsPolyhedra[elem] <<
" " << conn_len;
346 for(
int k = 0; k < conn_len; k++ )
353 conn_data.resize( num_nodes );
354 for(
int j = 0; j < num_nodes; ++j )
355 conn_data[j] = nodes.
index( conn[j] );
357 stream <<
' ' << num_nodes;
359 for(
int j = 0; j < num_nodes; ++j )
360 stream <<
' ' << conn_data[j];
370 stream <<
"1 " << nodes.
index( node ) << std::endl;
375 stream <<
"CELL_TYPES " << vtk_types.size() << std::endl;
376 for( std::vector< unsigned >::const_iterator i = vtk_types.begin(); i != vtk_types.end(); ++i )
377 stream << *i << std::endl;
397 EntityType low_type, high_type;
410 std::vector< Tag > tags;
411 std::vector< Tag >::iterator i;
416 bool entities_have_tags =
false;
417 for( i = tags.begin(); i != tags.end(); ++i )
432 if( count < 1 || ( count > 4 && count != 9 ) )
continue;
437 for( EntityType type = low_type; type < high_type; ++type )
443 tagged.
merge( tmp_tagged );
447 if( !tagged.
empty() )
452 if( !entities_have_tags )
454 entities_have_tags =
true;
456 stream <<
"POINT_DATA " <<
entities.size() << std::endl;
470 template <
typename T >
473 typename std::vector< T >::const_iterator d = data.begin();
474 const unsigned long n = data.size() / vals_per_tag;
476 for(
unsigned long i = 0; i < n; ++i )
478 for(
unsigned j = 0; j < vals_per_tag; ++j, ++d )
480 if(
sizeof( T ) == 1 )
481 stream << (
unsigned int)*d <<
' ';
504 template <
typename T >
508 int addFreeNodes = 0;
513 const unsigned long n =
entities.size() + addFreeNodes;
525 std::vector< T > data;
526 data.resize( n * vals_per_tag, 0 );
528 std::vector< T > def_value( vals_per_tag );
533 typename std::vector< T >::iterator d = data.begin();
553 const unsigned long n =
entities.size();
562 if( vals_per_tag > 8 )
564 MB_SET_ERR( MB_FAILURE,
"Invalid tag size for bit tag \"" << name <<
"\"" );
572 std::vector< unsigned short > data;
573 data.resize( n * vals_per_tag, 0 );
575 std::vector< unsigned short >::iterator d = data.begin();
583 for(
int j = 0; j < vals_per_tag; ++j, ++d )
584 *d = (
unsigned short)( value & ( 1 << j ) ? 1 : 0 );
615 for( std::string::iterator i = name.begin(); i != name.end(); ++i )
617 if( isspace( *i ) || iscntrl( *i ) ) *i =
'_';
623 else if( 9 == vals_per_tag )
627 <<
"LOOKUP_TABLE default" << std::endl;
633 return write_tag< unsigned char >( s, tag,
entities, tagged, 0 );
635 return write_tag< int >( s, tag,
entities, tagged, 0 );
637 return write_tag< double >( s, tag,
entities, tagged, 0 );