ITK/Examples/Meshes/Decimation: Difference between revisions
Daviddoria (talk | contribs) m (moved Mesh Decimation to ITK/Examples/Meshes/Decimation) |
DVigneault (talk | contribs) (Update example.) |
||
Line 1: | Line 1: | ||
This example | This example demonstrates decimation of an itk::QuadEdgeMesh. The input mesh is created by the itk::RegularSphereMeshSource filter and written out by the example. | ||
Usage is as follows: | |||
<source lang="text"> | <source lang="text"> | ||
./MeshDecimation | ./MeshDecimation inputMesh.obj outputMesh.obj [N] | ||
</source> | </source> | ||
where N is the number of target triangles. | where N is the number of target triangles in the output mesh. The default target is 100, if none is provided. | ||
The | |||
<source lang="cpp"> | <source lang="cpp"> | ||
#include <iostream> | #include <iostream> | ||
#include "itkRegularSphereMeshSource.h" | |||
#include " | |||
#include "itkQuadEdgeMesh.h" | #include "itkQuadEdgeMesh.h" | ||
#include "itkQuadEdgeMeshDecimationCriteria.h" | #include "itkQuadEdgeMeshDecimationCriteria.h" | ||
#include " | #include "itkSquaredEdgeLengthDecimationQuadEdgeMeshFilter.h" | ||
#include "itkMeshFileWriter.h" | |||
const unsigned int Dimension = 3; | const unsigned int Dimension = 3; | ||
typedef itk::QuadEdgeMesh< float, Dimension > | |||
typedef itk::QuadEdgeMesh< float, Dimension > MeshType; | |||
typedef itk::RegularSphereMeshSource< MeshType > MeshSourceType; | |||
typedef itk::NumberOfFacesCriterion<MeshType> CriterionType; | |||
typedef itk::SquaredEdgeLengthDecimationQuadEdgeMeshFilter<MeshType, | |||
MeshType, | |||
CriterionType> DecimationType; | |||
typedef itk::MeshFileWriter< MeshType > MeshWriterType; | |||
int main( int argc, char ** argv ) | int main( int argc, char ** argv ) | ||
{ | { | ||
if (argc < 3) | |||
{ | |||
std::cerr << "Usage: " << argv[0] << " <inputMesh> <outputMesh> [<count>]" << std::endl; | |||
return EXIT_FAILURE; | |||
} | |||
const unsigned int TriangleCount = (argc >= 4) ? atoi(argv[3]) : 100; | |||
MeshSourceType::Pointer source = MeshSourceType::New(); | |||
CriterionType::Pointer criterion = CriterionType::New(); | |||
DecimationType::Pointer decimate = DecimationType::New(); | |||
criterion->SetTopologicalChange(false); | |||
criterion->SetNumberOfElements(TriangleCount); | |||
decimate->SetInput(source->GetOutput()); | |||
decimate->SetCriterion(criterion); | |||
decimate->Update(); | |||
std::cout << "Number of cells in source mesh: " | |||
<< source->GetOutput()->GetNumberOfCells() << std::endl; | |||
std::cout << "Number of cells in decimated mesh: " | |||
<< decimate->GetOutput()->GetNumberOfCells() << std::endl; | |||
MeshWriterType::Pointer writer = MeshWriterType::New(); | |||
writer->SetFileName( argv[1] ); | |||
writer->SetInput( source->GetOutput() ); | |||
writer->Update(); | |||
writer->SetFileName( argv[2] ); | |||
writer->SetInput( decimate->GetOutput() ); | |||
writer->Update(); | |||
return EXIT_SUCCESS; | |||
} | } | ||
</source> | </source> |
Revision as of 16:07, 1 February 2016
This example demonstrates decimation of an itk::QuadEdgeMesh. The input mesh is created by the itk::RegularSphereMeshSource filter and written out by the example.
Usage is as follows:
<source lang="text"> ./MeshDecimation inputMesh.obj outputMesh.obj [N] </source> where N is the number of target triangles in the output mesh. The default target is 100, if none is provided.
<source lang="cpp">
- include <iostream>
- include "itkRegularSphereMeshSource.h"
- include "itkQuadEdgeMesh.h"
- include "itkQuadEdgeMeshDecimationCriteria.h"
- include "itkSquaredEdgeLengthDecimationQuadEdgeMeshFilter.h"
- include "itkMeshFileWriter.h"
const unsigned int Dimension = 3;
typedef itk::QuadEdgeMesh< float, Dimension > MeshType; typedef itk::RegularSphereMeshSource< MeshType > MeshSourceType; typedef itk::NumberOfFacesCriterion<MeshType> CriterionType; typedef itk::SquaredEdgeLengthDecimationQuadEdgeMeshFilter<MeshType,
MeshType, CriterionType> DecimationType;
typedef itk::MeshFileWriter< MeshType > MeshWriterType;
int main( int argc, char ** argv ) {
if (argc < 3) { std::cerr << "Usage: " << argv[0] << " <inputMesh> <outputMesh> [<count>]" << std::endl; return EXIT_FAILURE; }
const unsigned int TriangleCount = (argc >= 4) ? atoi(argv[3]) : 100;
MeshSourceType::Pointer source = MeshSourceType::New(); CriterionType::Pointer criterion = CriterionType::New(); DecimationType::Pointer decimate = DecimationType::New();
criterion->SetTopologicalChange(false); criterion->SetNumberOfElements(TriangleCount);
decimate->SetInput(source->GetOutput()); decimate->SetCriterion(criterion); decimate->Update();
std::cout << "Number of cells in source mesh: " << source->GetOutput()->GetNumberOfCells() << std::endl;
std::cout << "Number of cells in decimated mesh: " << decimate->GetOutput()->GetNumberOfCells() << std::endl;
MeshWriterType::Pointer writer = MeshWriterType::New();
writer->SetFileName( argv[1] ); writer->SetInput( source->GetOutput() ); writer->Update();
writer->SetFileName( argv[2] ); writer->SetInput( decimate->GetOutput() ); writer->Update();
return EXIT_SUCCESS;
} </source>