beginner tutorial, example 2: Demonstrates loading a mesh from a file, finding coordinate locations, connectivity information...In this example, we read in the VTK file (mbex1.vtk) generated in example 1, pick one of the hexahedrons, find out the vertexes that define it (connectivity), and find the coordinates of those vertexes. Finally, we will rotate the mesh a little and write it out to a new file.
- Author
- Milad Fatenejad
#include <iostream>
#include <iomanip>
#include <cmath>
{
std::cout << "Loaded a mesh containing: " << hex_range << std::endl;
double coord[3];
std::cout << std::setw( 6 ) << "Handle" << std::setw( 10 ) << "X" << std::setw( 10 ) << "Y" << std::setw( 10 )
<< "Z" << std::endl;
for( iter = connectivity.
begin(); iter != connectivity.
end(); ++iter )
{
std::cout << std::setw( 6 ) << *iter << std::setw( 10 ) << coord[0] << std::setw( 10 ) << coord[1]
<< std::setw( 10 ) << coord[2] << std::endl;
}
"get_entities_by_type(VERTEX) failed" );
std::vector< double > vertex_coords( 3 * vertex_range.
size() );
unsigned count = 0;
const double PI = 3.14159265359;
const double ANGLE =
PI / 4;
for( iter = vertex_range.
begin(); iter != vertex_range.
end(); ++iter )
{
double x = vertex_coords[count + 0];
double y = vertex_coords[count + 1];
vertex_coords[count + 0] = x * std::cos( ANGLE ) - y * std::sin( ANGLE );
vertex_coords[count + 1] = x * std::sin( ANGLE ) + y * std::cos( ANGLE );
count += 3;
}
return 0;
}