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];
using CoordType = double;
using MeshPointsContainerPointer = MeshType::PointsContainerPointer;
using MeshPointsContainerIterator = MeshType::PointsContainerIterator;
using MeshPointIdentifier = MeshType::PointIdentifier;
using MeshCellIdentifier = MeshType::CellIdentifier;
reader->SetFileName(inputFileName);
MeshPointer mesh = reader->GetOutput();
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 (auto fIt : facesSet)
{
auto * 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]);
}
}
writer->SetInput(output);
writer->SetFileName(outputFileName);
try
{
writer->Update();
}
catch (
const itk::ExceptionObject &
e)
{
std::cerr <<
"Error: " <<
e << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}