Description: read boundary points and loops that form islands and continents and create an edge mesh file
BoundaryContinents <boundary_points.dat> SaveLoopCounts (default values can run if users don't specify input files)
#include <iostream>
#include <fstream>
using namespace std;
string bd_name = string(
MESH_DIR ) + string(
"/../examples/earth/boundary_points.dat" );
string loops = string(
MESH_DIR ) + string(
"/../examples/earth/SaveLoopCounts" );
{
p.normalize();
return asin( p[2] );
}
{
p.normalize();
double lon;
lon = atan2( p[1], p[0] );
if( lon < -2.95 )
{
return 2.0 * M_PI + lon;
}
else
{
return lon;
}
}
int main(
int argc,
char** argv )
{
Interface*
mb =
new( std::nothrow ) Core;
if( NULL ==
mb )
return 1;
if( argc > 1 )
{
}
if( argc > 2 )
{
}
std::vector< double > coords;
ifstream bdFile(
bd_name.c_str() );
if( !bdFile )
{
cout << endl <<
"Failed to open file " <<
bd_name << endl;
;
return 1;
}
coords.resize( 0 );
while( !bdFile.eof() )
{
double co;
bdFile >> co;
coords.push_back( co );
}
cout << " number of boundary points:" << coords.size() / 3 << "\n";
vector< int > loopsindx;
ifstream loopFile(
loops.c_str() );
while( !loopFile.eof() )
{
int indx;
loopFile >> indx;
loopsindx.push_back( indx );
}
cout << "number of loops: " << loopsindx.size() / 2 << "\n";
ReadUtilIface* readMeshIface;
mb->query_interface( readMeshIface );
Range verts;
MB_CHK_SET_ERR(
mb->create_vertices( &coords[0], coords.size() / 3, verts ),
"do not create boundary vertices" );
Tag gid =
mb->globalId_tag();
int num_edges = 0;
for( size_t i = 0; i < loopsindx.size() / 2; i++ )
{
num_edges += ( loopsindx[2 * i + 1] - loopsindx[2 * i] + 1 );
}
MB_CHK_SET_ERR( readMeshIface->get_element_connect( num_edges, 2,
MBEDGE, 1, handle, conn_array ),
"do not elems" );
int i1 = 0;
for( size_t i = 0; i < loopsindx.size() / 2; i++ )
{
for( int j = loopsindx[2 * i]; j <= loopsindx[2 * i + 1]; j++ )
{
int j2;
j2 = j;
if( j == loopsindx[2 * i + 1] ) j2 = loopsindx[2 * i] - 1;
conn_array[2 * i1] = verts[j - 1];
conn_array[2 * i1 + 1] = verts[j2];
i1++;
}
}
Range bedges( handle, handle + num_edges - 1 );
MB_CHK_SET_ERR(
mb->add_entities( bound_set, bedges ),
"Can't add edges to boundary set" );
vector< int > gids;
gids.resize( verts.size() );
for( int j = 0; j < (int)verts.size(); j++ )
{
gids[j] = j + 1;
}
MB_CHK_SET_ERR(
mb->tag_set_data( gid, verts, &gids[0] ),
"Can't set global ids on verts" );
MB_CHK_SET_ERR(
mb->tag_set_data( gid, bedges, &gids[0] ),
"Can't set global ids on edges" );
mb->write_file(
"bound.vtk", 0, 0, &bound_set, 1 );
std::vector< CartVect > co3;
co3.resize( verts.size() );
MB_CHK_SET_ERR(
mb->get_coords( verts, &( co3[0][0] ) ),
"Can't get vertex coords" );
for( size_t i = 0; i < verts.size(); i++ )
{
CartVect p = co3[i];
co3[i] = CartVect( lon1, lat1, 0. );
}
MB_CHK_SET_ERR(
mb->set_coords( verts, &( co3[0][0] ) ),
"Can't set new vertex coords" );
Range longEdges;
{
int nconn;
CartVect c2[2];
if( dist > 36. )
longEdges.insert( eh );
}
mb->write_file(
"bound2d.vtk" );
return 0;
}