int main( int argc, char* argv[] )
{
if( argc != 3 )
{
std::cerr << "Usage: "<< std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName> <OutputFileName>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName = argv[1];
const char * outputFileName = argv[2];
typedef double CoordType;
typedef MeshType::Pointer MeshPointer;
typedef MeshType::PointsContainerPointer MeshPointsContainerPointer;
typedef MeshType::PointsContainerIterator MeshPointsContainerIterator;
typedef MeshType::PointIdentifier MeshPointIdentifier;
typedef MeshType::CellIdentifier MeshCellIdentifier;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFileName );
MeshPointer mesh = reader->GetOutput();
MeshPointer output = MeshType::New();
std::map< MeshPointIdentifier, MeshPointIdentifier > verticesMap;
std::set< MeshCellIdentifier > facesSet;
MeshPointsContainerPointer points = mesh->GetPoints();
MeshPointsContainerIterator pIt = points->Begin();
MeshPointsContainerIterator pEnd = points->End();
while( pIt != pEnd )
{
MeshPointType p = pIt->Value();
if( ( p[2] < 0. ) )
{
MeshPointType q;
q.CastFrom( p );
verticesMap[ pIt->Index() ] = output->AddPoint( q );
MeshType::QEType* qe = p.GetEdge();
MeshType::QEType* temp = qe;
do
{
facesSet.insert( temp->GetLeft() );
temp = temp->GetOnext();
} while( qe != temp );
}
++pIt;
}
MeshType::CellsContainerPointer cells = mesh->GetCells();
for( std::set< MeshType::CellIdentifier >::iterator fIt = facesSet.begin();
fIt != facesSet.end();
++fIt )
{
PolygonType* face = dynamic_cast< PolygonType* >( cells->ElementAt( *fIt ) );
MeshType::PointIdentifier id[3];
if( face )
{
MeshType::QEType *temp = qe;
unsigned int k = 0;
do
{
if( verticesMap.find( temp->GetOrigin() ) == verticesMap.end() )
{
verticesMap[ temp->GetOrigin() ] = output->AddPoint( q );
}
id[ k++ ] = verticesMap[ temp->GetOrigin() ];
temp = temp->GetLnext();
} while( qe != temp );
output->AddFaceTriangle( id[0], id[1], id[2] );
}
}
MeshWriterType::Pointer writer = MeshWriterType::New();
writer->SetInput( output );
writer->SetFileName( outputFileName );
try
{
writer->Update();
}
{
std::cerr << "Error: " << e << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}