|
|
Line 1: |
Line 1: |
| This example demonstrates decimation of an itk::QuadEdgeMesh. The input mesh is created by the itk::RegularSphereMeshSource filter and written out by the example.
| | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}} |
| | |
| 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>
| |