1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 19 #include "itkQuadEdgeMesh.h" 20 #include "itkVTKPolyDataReader.h" 21 22 #include <iostream> 23 itkVTKPolyDataReaderQuadEdgeMeshTest(int argc,char * argv[])24int itkVTKPolyDataReaderQuadEdgeMeshTest(int argc, char* argv[] ) 25 { 26 if( argc != 2 ) 27 { 28 std::cerr << "Usage: itkVTKPolyDataReaderTest inputFilename" 29 << std::endl; 30 return EXIT_FAILURE; 31 } 32 33 using MeshType = itk::QuadEdgeMesh<float, 3>; 34 using ReaderType = itk::VTKPolyDataReader< MeshType >; 35 36 ReaderType::Pointer polyDataReader = ReaderType::New(); 37 38 using PointType = ReaderType::PointType; 39 40 polyDataReader->SetFileName(argv[1]); 41 42 try 43 { 44 polyDataReader->Update(); 45 } 46 catch( itk::ExceptionObject & excp ) 47 { 48 std::cerr << "Error during Update() " << std::endl; 49 std::cerr << excp << std::endl; 50 } 51 52 std::cout << "polyDataReader:" << std::endl; 53 std::cout << polyDataReader << std::endl; 54 55 MeshType::Pointer mesh = polyDataReader->GetOutput(); 56 57 std::cout << "Using following MeshType :"; 58 std::cout << mesh->GetNameOfClass( ) << std::endl; 59 60 PointType point; 61 62 std::cout << "Testing itk::VTKPolyDataReader" << std::endl; 63 64 unsigned int numberOfPoints = mesh->GetNumberOfPoints(); 65 unsigned int numberOfCells = mesh->GetNumberOfCells(); 66 67 std::cout << "numberOfPoints= " << numberOfPoints << std::endl; 68 std::cout << "numberOfCells= " << numberOfCells << std::endl; 69 70 if( !numberOfPoints ) 71 { 72 std::cerr << "ERROR: numberOfPoints= " << numberOfPoints << std::endl; 73 return EXIT_FAILURE; 74 } 75 76 if( !numberOfCells ) 77 { 78 std::cerr << "ERROR: numberOfCells= " << numberOfCells << std::endl; 79 return EXIT_FAILURE; 80 } 81 82 for(unsigned int i=0; i<numberOfPoints; i++) 83 { 84 // mesh->GetPoint(i, &point); 85 //std::cout << "Point[" << i << "]: " << point << std::endl; 86 } 87 88 std::cout << "Test passed"<< std::endl; 89 return EXIT_SUCCESS; 90 } 91