|
|
Line 1: |
Line 1: |
| This example reads a mesh from a vtk file. It then compute normals for the mesh.
| | {{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. |
| | }} |
|
| |
|
| The sample sphere file is [http://www.itk.org/Wiki/images/8/89/Sphere.vtk.zip here].
| | [https://itk.org/ITKExamples[ITK Sphinx Examples]] |
| | |
| '''Please Note:''' In ITKv4, itkQuadEdgeMeshNormalFilter was renamed to itkNormalQuadEdgeMeshFilter.
| |
| | |
| ==QuadEdgeMeshNormalFilter.cxx==
| |
| <source lang="cpp">
| |
| #include "itkVector.h"
| |
| #include "itkQuadEdgeMesh.h"
| |
| #include "itkVTKPolyDataReader.h"
| |
| | |
| #include "itkQuadEdgeMeshExtendedTraits.h"
| |
| #if ITK_VERSION_MAJOR >= 4
| |
| #include "itkNormalQuadEdgeMeshFilter.h"
| |
| #else
| |
| #include "itkQuadEdgeMeshNormalFilter.h"
| |
| #endif
| |
| #include <stdlib.h>
| |
| | |
| int main( int argc, char* argv[] )
| |
| {
| |
| if( argc < 2 )
| |
| {
| |
| std::cout <<"This program requires at least 1 argument" <<std::endl;
| |
| std::cout <<"1- Input filename" <<std::endl;
| |
| std::cout <<"2- Weight type" <<std::endl;
| |
| std::cout <<" * 0: GOURAUD" <<std::endl;
| |
| std::cout <<" * 1: THURMER" <<std::endl;
| |
| std::cout <<" * 2: AREA" <<std::endl;
| |
| return EXIT_FAILURE;
| |
| }
| |
| | |
| const unsigned int Dimension = 3;
| |
| typedef double CoordType;
| |
| | |
| typedef itk::QuadEdgeMesh< CoordType, Dimension > InputMeshType;
| |
| | |
| typedef itk::Vector< CoordType, Dimension > VectorType;
| |
| | |
| typedef itk::QuadEdgeMeshExtendedTraits <
| |
| VectorType,
| |
| Dimension,
| |
| 2,
| |
| CoordType,
| |
| CoordType,
| |
| VectorType,
| |
| bool,
| |
| bool > Traits;
| |
| | |
| typedef itk::QuadEdgeMesh < VectorType, Dimension, Traits > OutputMeshType;
| |
| | |
| typedef itk::VTKPolyDataReader< InputMeshType > ReaderType;
| |
| #if ITK_VERSION_MAJOR >= 4
| |
| typedef itk::NormalQuadEdgeMeshFilter< InputMeshType, OutputMeshType > NormalFilterType;
| |
| #else
| |
| typedef itk::QuadEdgeMeshNormalFilter< InputMeshType, OutputMeshType > NormalFilterType;
| |
| #endif
| |
| NormalFilterType::WeightType weight_type;
| |
| | |
| int param = atoi( argv[2] );
| |
| | |
| if( ( param < 0 ) || ( param > 2 ) )
| |
| {
| |
| std::cout <<"Weight type must be either: " <<std::endl;
| |
| std::cout <<" * 0: GOURAUD" <<std::endl;
| |
| std::cout <<" * 1: THURMER" <<std::endl;
| |
| std::cout <<" * 2: AREA" <<std::endl;
| |
| return EXIT_FAILURE;
| |
| }
| |
| else
| |
| {
| |
| switch( param )
| |
| {
| |
| default:
| |
| case 0:
| |
| weight_type = NormalFilterType::GOURAUD;
| |
| break;
| |
| case 1:
| |
| weight_type = NormalFilterType::THURMER;
| |
| break;
| |
| case 2:
| |
| weight_type = NormalFilterType::AREA;
| |
| break;
| |
| }
| |
| }
| |
| | |
| ReaderType::Pointer reader = ReaderType::New( );
| |
| reader->SetFileName( argv[1] );
| |
| | |
| try
| |
| {
| |
| reader->Update( );
| |
| }
| |
| catch( itk::ExceptionObject & excp )
| |
| {
| |
| std::cerr << "Exception thrown while reading the input file " << std::endl;
| |
| std::cerr << excp << std::endl;
| |
| return EXIT_FAILURE;
| |
| }
| |
| | |
| InputMeshType::Pointer mesh = reader->GetOutput( );
| |
| | |
| NormalFilterType::Pointer normals = NormalFilterType::New( );
| |
| normals->SetInput( mesh );
| |
| normals->SetWeight( weight_type );
| |
| | |
| try
| |
| {
| |
| normals->Update( );
| |
| }
| |
| catch( itk::ExceptionObject & excp )
| |
| {
| |
| std::cerr << excp << std::endl;
| |
| return EXIT_FAILURE;
| |
| }
| |
| | |
| OutputMeshType::Pointer output = normals->GetOutput( );
| |
| | |
| std::cout << normals << std::endl;
| |
| | |
| return EXIT_SUCCESS;
| |
| }
| |
| </source>
| |
| | |
| {{ITKCMakeLists|{{SUBPAGENAME}}}}
| |