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;
238 Range faces_from_connectivity =
239 subtract( connectivity, nodes_from_connectivity );
241 Range connected_nodes;
243 connected_nodes.
merge( nodes_from_connectivity );
248 unsigned long num_elems, num_uses;
249 num_elems = num_uses = elems.
size();
251 std::map< EntityHandle, int > sizeFieldsPolyhedra;
262 std::vector< EntityHandle > storage;
265 num_uses += conn_len;
270 for(
int j = 0; j < conn_len; j++ )
275 numFields += num_nd + 1;
277 sizeFieldsPolyhedra[elem] = numFields;
278 num_uses += ( numFields - conn_len );
283 stream <<
"CELLS " << num_elems +
freeNodes <<
' ' << num_uses + 2 *
freeNodes << std::endl;
286 std::vector< int > conn_data;
287 std::vector< unsigned > vtk_types( elems.
size() +
freeNodes );
288 std::vector< unsigned >::iterator t = vtk_types.begin();
299 std::vector< EntityHandle > storage;
312 MB_SET_ERR( MB_FAILURE,
"Vtk file format does not support elements of type "
325 assert( conn_len > 0 );
326 conn_data.resize( conn_len );
327 for(
int j = 0; j < conn_len; ++j )
328 conn_data[j] = nodes.
index( connect[j] );
333 for(
int k = 0; k < conn_len; ++k )
334 stream <<
' ' << conn_data[vtk_type->
node_order[k]];
336 for(
int k = 0; k < conn_len; ++k )
337 stream <<
' ' << conn_data[k];
343 stream << sizeFieldsPolyhedra[elem] <<
" " << conn_len;
344 for(
int k = 0; k < conn_len; k++ )
351 conn_data.resize( num_nodes );
352 for(
int j = 0; j < num_nodes; ++j )
353 conn_data[j] = nodes.
index( conn[j] );
355 stream <<
' ' << num_nodes;
357 for(
int j = 0; j < num_nodes; ++j )
358 stream <<
' ' << conn_data[j];
368 stream <<
"1 " << nodes.
index( node ) << std::endl;
373 stream <<
"CELL_TYPES " << vtk_types.size() << std::endl;
374 for( std::vector< unsigned >::const_iterator i = vtk_types.begin(); i != vtk_types.end(); ++i )
375 stream << *i << std::endl;
382 const Range& entities,
395 EntityType low_type, high_type;
408 std::vector< Tag > tags;
409 std::vector< Tag >::iterator i;
414 bool entities_have_tags =
false;
415 for( i = tags.begin(); i != tags.end(); ++i )
430 if( count < 1 || ( count > 4 && count != 9 ) )
continue;
435 for( EntityType type = low_type; type < high_type; ++type )
440 tmp_tagged =
intersect( tmp_tagged, entities );
441 tagged.
merge( tmp_tagged );
445 if( !tagged.
empty() )
450 if( !entities_have_tags )
452 entities_have_tags =
true;
454 stream <<
"POINT_DATA " << entities.
size() << std::endl;
456 stream <<
"CELL_DATA " << entities.
size() +
freeNodes << std::endl;
460 rval =
write_tag( stream, *i, entities, tagged );
468 template <
typename T >
471 typename std::vector< T >::const_iterator d = data.begin();
472 const unsigned long n = data.size() / vals_per_tag;
474 for(
unsigned long i = 0; i < n; ++i )
476 for(
unsigned j = 0; j < vals_per_tag; ++j, ++d )
478 if(
sizeof( T ) == 1 )
479 stream << (
unsigned int)*d <<
' ';
502 template <
typename T >
506 int addFreeNodes = 0;
511 const unsigned long n = entities.
size() + addFreeNodes;
523 std::vector< T > data;
524 data.resize( n * vals_per_tag, 0 );
526 std::vector< T > def_value( vals_per_tag );
531 typename std::vector< T >::iterator d = data.begin();
551 const unsigned long n = entities.
size();
560 if( vals_per_tag > 8 )
562 MB_SET_ERR( MB_FAILURE,
"Invalid tag size for bit tag \"" << name <<
"\"" );
570 std::vector< unsigned short > data;
571 data.resize( n * vals_per_tag, 0 );
573 std::vector< unsigned short >::iterator d = data.begin();
581 for(
int j = 0; j < vals_per_tag; ++j, ++d )
582 *d = (
unsigned short)( value & ( 1 << j ) ? 1 : 0 );
613 for( std::string::iterator i = name.begin(); i != name.end(); ++i )
615 if( isspace( *i ) || iscntrl( *i ) ) *i =
'_';
621 else if( 9 == vals_per_tag )
625 <<
"LOOKUP_TABLE default" << std::endl;
631 return write_tag< unsigned char >( s, tag, entities, tagged, 0 );
633 return write_tag< int >( s, tag, entities, tagged, 0 );
635 return write_tag< double >( s, tag, entities, tagged, 0 );